| 1 |
|
| 2 |
using System; |
| 3 |
using Novell.Directory.Ldap; |
| 4 |
using Novell.Directory.Ldap.Extensions; |
| 5 |
using Novell.Directory.Ldap.Rfc2251; |
| 6 |
|
| 7 |
|
| 8 |
namespace Novell.Directory.Ldap.Utilclass |
| 9 |
{ |
| 10 |
|
| 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 |
| 23 |
{ |
| 24 |
|
| 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> |
| 36 |
|
| 37 |
static public LdapExtendedResponse convertToExtendedResponse(RfcLdapMessage inResponse) |
| 38 |
{ |
| 39 |
|
| 40 |
LdapExtendedResponse tempResponse = new LdapExtendedResponse(inResponse); |
| 41 |
// Get the oid stored in the Extended response |
| 42 |
System.String inOID = tempResponse.ID; |
| 43 |
|
| 44 |
RespExtensionSet regExtResponses = LdapExtendedResponse.RegisteredResponses; |
| 45 |
try |
| 46 |
{ |
| 47 |
System.Type extRespClass = regExtResponses.findResponseExtension(inOID); |
| 48 |
if (extRespClass == null) |
| 49 |
{ |
| 50 |
return tempResponse; |
| 51 |
} |
| 52 |
System.Type[] argsClass = new System.Type[]{typeof(RfcLdapMessage)}; |
| 53 |
System.Object[] args = new System.Object[]{inResponse}; |
| 54 |
System.Exception ex; |
| 55 |
try |
| 56 |
{ |
| 57 |
System.Reflection.ConstructorInfo extConstructor = extRespClass.GetConstructor(argsClass); |
| 58 |
try |
| 59 |
{ |
| 60 |
System.Object resp = null; |
| 61 |
resp = extConstructor.Invoke(args); |
| 62 |
return (LdapExtendedResponse) resp; |
| 63 |
} |
| 64 |
catch (System.UnauthorizedAccessException e) |
| 65 |
{ |
| 66 |
ex = e; |
| 67 |
} |
| 68 |
catch (System.Reflection.TargetInvocationException e) |
| 69 |
{ |
| 70 |
ex = e; |
| 71 |
} |
| 72 |
catch (System.Exception e) |
| 73 |
{ |
| 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; |
| 78 |
} |
| 79 |
} |
| 80 |
catch (System.MethodAccessException e) |
| 81 |
{ |
| 82 |
// bad class was specified, fall through and return a |
| 83 |
// default LdapExtendedResponse object |
| 84 |
ex = e; |
| 85 |
} |
| 86 |
} |
| 87 |
catch (System.FieldAccessException e) |
| 88 |
{ |
| 89 |
} |
| 90 |
// If we get here we did not have a registered extendedresponse |
| 91 |
// for this oid. Return a default LdapExtendedResponse object. |
| 92 |
return tempResponse; |
| 93 |
} |
| 94 |
} |
| 95 |
} |