**** Merged from MCS ****
[mono-project.git] / mcs / class / Novell.Directory.Ldap / Novell.Directory.Ldap.Utilclass / ExtResponseFactory.cs
blob52f4a567e950d82a77a1f79767552f136a0b5636
2 using System;
3 using Novell.Directory.Ldap;
4 using Novell.Directory.Ldap.Extensions;
5 using Novell.Directory.Ldap.Rfc2251;
8 namespace Novell.Directory.Ldap.Utilclass
11 /// <summary>
12 /// Takes an LdapExtendedResponse and returns an object
13 /// (that implements the base class ParsedExtendedResponse)
14 /// based on the OID.
15 ///
16 /// <p>You can then call methods defined in the child
17 /// class to parse the contents of the response. The methods available
18 /// depend on the child class. All child classes inherit from the
19 /// ParsedExtendedResponse.</p>
20 ///
21 /// </summary>
22 public class ExtResponseFactory
25 /// <summary> Used to Convert an RfcLdapMessage object to the appropriate
26 /// LdapExtendedResponse object depending on the operation being performed.
27 ///
28 /// </summary>
29 /// <param name="inResponse"> The LdapExtendedReponse object as returned by the
30 /// extendedOperation method in the LdapConnection object.
31 /// </param>
32 /// <returns> An object of base class LdapExtendedResponse. The actual child
33 /// class of this returned object depends on the operation being
34 /// performed.
35 /// </returns>
37 static public LdapExtendedResponse convertToExtendedResponse(RfcLdapMessage inResponse)
40 LdapExtendedResponse tempResponse = new LdapExtendedResponse(inResponse);
41 // Get the oid stored in the Extended response
42 System.String inOID = tempResponse.ID;
44 RespExtensionSet regExtResponses = LdapExtendedResponse.RegisteredResponses;
45 try
47 System.Type extRespClass = regExtResponses.findResponseExtension(inOID);
48 if (extRespClass == null)
50 return tempResponse;
52 System.Type[] argsClass = new System.Type[]{typeof(RfcLdapMessage)};
53 System.Object[] args = new System.Object[]{inResponse};
54 System.Exception ex;
55 try
57 System.Reflection.ConstructorInfo extConstructor = extRespClass.GetConstructor(argsClass);
58 try
60 System.Object resp = null;
61 resp = extConstructor.Invoke(args);
62 return (LdapExtendedResponse) resp;
64 catch (System.UnauthorizedAccessException e)
66 ex = e;
68 catch (System.Reflection.TargetInvocationException e)
70 ex = e;
72 catch (System.Exception e)
74 // Could not create the ResponseControl object
75 // All possible exceptions are ignored. We fall through
76 // and create a default LdapControl object
77 ex = e;
80 catch (System.MethodAccessException e)
82 // bad class was specified, fall through and return a
83 // default LdapExtendedResponse object
84 ex = e;
87 catch (System.FieldAccessException e)
90 // If we get here we did not have a registered extendedresponse
91 // for this oid. Return a default LdapExtendedResponse object.
92 return tempResponse;