Debian Codegraph @

mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap.Utilclass/IntermediateResponseFactory.cs

raw
1 /******************************************************************************
2 * The MIT License
3 * Copyright (c) 2003 Novell Inc. www.novell.com
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the Software), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *******************************************************************************/
23 //
24 // Novell.Directory.Ldap.Utilclass.IntermediateResponseFactory.cs
25 //
26 // Author:
27 // Anil Bhatia ([email protected])
28 //
29 // (C) 2003 Novell, Inc (http://www.novell.com)
30 //
31
32 using System;
33 using System.Reflection;
34
35 using Novell.Directory.Ldap;
36 using Novell.Directory.Ldap.Rfc2251;
37
38 namespace Novell.Directory.Ldap.Utilclass
39 {
40 /// <summary>
41 ///
42 /// Takes an LDAPIntermediateResponse and returns an object
43 /// (that implements the base class LDAPIntermediateResponse)
44 /// based on the OID.
45 ///
46 /// You can then call methods defined in the child
47 /// class to parse the contents of the response. The methods available
48 /// depend on the child class. All child classes inherit from the
49 /// LdapIntermediateResponse.
50 ///
51 /// </summary>
52 public class IntermediateResponseFactory
53 {
54
55 /**
56 * Used to Convert an RfcLDAPMessage object to the appropriate
57 * LDAPIntermediateResponse object depending on the operation being performed.
58 *
59 * @param inResponse The LDAPIntermediateResponse object as returned by the
60 * extendedOperation method in the LDAPConnection object.
61 * <br><br>
62 * @return An object of base class LDAPIntermediateResponse. The actual child
63 * class of this returned object depends on the operation being
64 * performed.
65 *
66 * @exception LDAPException A general exception which includes an error message
67 * and an LDAP error code.
68 */
69
70 static public LdapIntermediateResponse convertToIntermediateResponse(RfcLdapMessage inResponse)
71 // throws LDAPException
72 {
73
74 LdapIntermediateResponse tempResponse = new LdapIntermediateResponse(inResponse);
75 // Get the oid stored in the Extended response
76 String inOID = tempResponse.getID();
77
78 RespExtensionSet regExtResponses =
79 LdapIntermediateResponse.getRegisteredResponses();
80 try{
81 Type extRespClass = regExtResponses.findResponseExtension(inOID);
82 if ( extRespClass == null ){
83 return tempResponse;
84 }
85
86 Type[] argsClass = new Type[]{typeof(RfcLdapMessage)};
87 Object[] args = { inResponse };
88 Exception ex;
89 try{
90 ConstructorInfo extConstructor = extRespClass.GetConstructor(argsClass);
91
92 try{
93 Object resp = null;
94 resp = extConstructor.Invoke(args);
95 return (LdapIntermediateResponse) resp;
96 } catch (UnauthorizedAccessException e) {
97 ex = e;
98 } catch (TargetInvocationException e) {
99 ex = e;
100 }
101 } catch (MissingMethodException e) {
102 // bad class was specified, fall through and return a
103 // default LDAPIntermediateResponse object
104 ex = e;
105 }
106 } catch (MissingFieldException e) {
107 // No match with the OID
108 // Do nothing. Fall through and construct a default LDAPControl object.
109
110 }
111 // If we get here we did not have a registered extendedresponse
112 // for this oid. Return a default LDAPIntermediateResponse object.
113 return tempResponse;
114 }
115
116 }
117
118 }
119