Modified extensions to use register functionality provided in ExtResponseFactory
authorSunil Kumar <sunilk@mono-cvs.ximian.com>
Wed, 3 Mar 2004 07:58:54 +0000 (07:58 -0000)
committerSunil Kumar <sunilk@mono-cvs.ximian.com>
Wed, 3 Mar 2004 07:58:54 +0000 (07:58 -0000)
svn path=/trunk/mcs/; revision=23642

mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap.Extensions/GetBindDNRequest.cs
mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap.Extensions/GetEffectivePrivilegesRequest.cs
mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap.Extensions/GetReplicaInfoRequest.cs
mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap.Extensions/GetReplicationFilterRequest.cs
mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap.Extensions/ListReplicasRequest.cs
mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap.Extensions/PartitionEntryCountRequest.cs
mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap.Utilclass/ExtResponseFactory.cs
mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap.dll.sources
mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapExtendedResponse.cs

index 195f7524978228b8b7a3dd4d289ae31e534806a7..68bd376e7bbcb74348e2885d42de6090bdfc7306 100755 (executable)
@@ -56,6 +56,22 @@ namespace Novell.Directory.Ldap.Extensions
        /// </summary>
        public class GetBindDNRequest:LdapExtendedOperation
        {
+
+               static GetBindDNRequest() 
+               {
+                       /*
+                               * Register the extendedresponse class which is returned by the
+                               * server in response to a ListReplicasRequest
+                               */
+                       try
+                       {
+                               LdapExtendedResponse.register(ReplicationConstants.GET_IDENTITY_NAME_RES, System.Type.GetType("Novell.Directory.Ldap.Extensions.GetBindDNResponse"));
+                       }
+                       catch (System.Exception e)
+                       {
+                               System.Console.Error.WriteLine("Could not register Extended Response -" + " Class not found");
+                       }
+               }
                
                /// <summary>   Constructs an extended operation object for retrieving the bind dn.
                /// 
index 1fbd6456e626b0e75b037626f2f56bd80c777335..85d193e1da8fff493bb1a4dd65d310f5c17114da 100755 (executable)
@@ -61,6 +61,21 @@ namespace Novell.Directory.Ldap.Extensions
        /// </summary>
        public class GetEffectivePrivilegesRequest:LdapExtendedOperation
        {
+               static GetEffectivePrivilegesRequest() 
+               {
+                       /*
+                               * Register the extendedresponse class which is returned by the
+                               * server in response to a ListReplicasRequest
+                               */
+                       try
+                       {
+                               LdapExtendedResponse.register(ReplicationConstants.GET_EFFECTIVE_PRIVILEGES_RES, System.Type.GetType("Novell.Directory.Ldap.Extensions.GetEffectivePrivilegesResponse"));
+                       }
+                       catch (System.Exception e)
+                       {
+                               System.Console.Error.WriteLine("Could not register Extended Response -" + " Class not found");
+                       }
+               }
                
                /// <summary> Constructs an extended operation object for checking effective rights.
                /// 
index 23c356199029abf1019fa3d48be65df53b781c25..3abda121d475683b26f1abac1f83a0844077cbde 100755 (executable)
@@ -60,6 +60,22 @@ namespace Novell.Directory.Ldap.Extensions
        public class GetReplicaInfoRequest:LdapExtendedOperation
        {
                
+               static GetReplicaInfoRequest() 
+               {
+                       /*
+                               * Register the extendedresponse class which is returned by the
+                               * server in response to a ListReplicasRequest
+                               */
+                       try
+                       {
+                               LdapExtendedResponse.register(ReplicationConstants.GET_REPLICA_INFO_RES, System.Type.GetType("Novell.Directory.Ldap.Extensions.GetReplicaInfoResponse"));
+                       }
+                       catch (System.Exception e)
+                       {
+                               System.Console.Error.WriteLine("Could not register Extended Response -" + " Class not found");
+                       }
+               }
+
                /// <summary> 
                /// Constructs an extended operations object for reading replica information.
                /// 
index 487f52ac714c936834dc3f278cc9350f14767e8d..4a34342ebec8b603c980b63c752e933bcc8ba946 100755 (executable)
@@ -58,6 +58,22 @@ namespace Novell.Directory.Ldap.Extensions
        public class GetReplicationFilterRequest:LdapExtendedOperation
        {
                
+               static GetReplicationFilterRequest() 
+               {
+                       /*
+                               * Register the extendedresponse class which is returned by the
+                               * server in response to a ListReplicasRequest
+                               */
+                       try
+                       {
+                               LdapExtendedResponse.register(ReplicationConstants.GET_REPLICATION_FILTER_RES, System.Type.GetType("Novell.Directory.Ldap.Extensions.GetReplicationFilterResponse"));
+                       }
+                       catch (System.Exception e)
+                       {
+                               System.Console.Error.WriteLine("Could not register Extended Response -" + " Class not found");
+                       }
+               }
+
                /// <summary> 
                /// Constructs an extended operations object which contains the ber encoded
                /// replication filter.
index 1ec70df9ab25a9d73e84aaa50aa1049923c57293..fd6b005bfa81d4f6018402bdce29c28b31fba0bd 100755 (executable)
@@ -54,7 +54,22 @@ namespace Novell.Directory.Ldap.Extensions
        /// </summary>
        public class ListReplicasRequest:LdapExtendedOperation
        {
-               
+               static ListReplicasRequest() 
+               {
+                       /*
+                               * Register the extendedresponse class which is returned by the
+                               * server in response to a ListReplicasRequest
+                               */
+                       try
+                       {
+                               LdapExtendedResponse.register(ReplicationConstants.LIST_REPLICAS_RES, System.Type.GetType("Novell.Directory.Ldap.Extensions.ListReplicasResponse"));
+                       }
+                       catch (System.Exception e)
+                       {
+                               System.Console.Error.WriteLine("Could not register Extended Response -" + " Class not found");
+                       }
+               }
+
                /// <summary>  Constructs an extended operation object for listing replicas.
                /// 
                /// </summary>
@@ -66,7 +81,6 @@ namespace Novell.Directory.Ldap.Extensions
                /// </exception>
                public ListReplicasRequest(System.String serverName):base(ReplicationConstants.LIST_REPLICAS_REQ, null)
                {
-                       
                        try
                        {
                                
index 9fa0398434a3b6aef9875fc3d5534449423dc485..65274033a5aeb6f335554f936766f47ef3e2e3ed 100755 (executable)
@@ -59,6 +59,22 @@ namespace Novell.Directory.Ldap.Extensions
        /// </summary>
        public class PartitionEntryCountRequest:LdapExtendedOperation
        {
+
+               static PartitionEntryCountRequest() 
+               {
+                       /*
+                               * Register the extendedresponse class which is returned by the
+                               * server in response to a ListReplicasRequest
+                               */
+                       try
+                       {
+                               LdapExtendedResponse.register(ReplicationConstants.NAMING_CONTEXT_COUNT_RES, System.Type.GetType("Novell.Directory.Ldap.Extensions.PartitionEntryCountResponse"));
+                       }
+                       catch (System.Exception e)
+                       {
+                               System.Console.Error.WriteLine("Could not register Extended Response -" + " Class not found");
+                       }
+               }
                
                /// <summary>  Constructs an extended operation object for counting entries
                /// in a naming context.
index e3093df87e6e33aa665e5a17ddd5c5e22c0cfaa5..52f4a567e950d82a77a1f79767552f136a0b5636 100755 (executable)
@@ -1,50 +1,22 @@
-/******************************************************************************
-* The MIT License
-* Copyright (c) 2003 Novell Inc.  www.novell.com
-* 
-* Permission is hereby granted, free of charge, to any person obtaining  a copy
-* of this software and associated documentation files (the Software), to deal
-* in the Software without restriction, including  without limitation the rights
-* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
-* copies of the Software, and to  permit persons to whom the Software is 
-* furnished to do so, subject to the following conditions:
-* 
-* The above copyright notice and this permission notice shall be included in 
-* all copies or substantial portions of the Software.
-* 
-* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
-* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
-* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
-* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-* SOFTWARE.
-*******************************************************************************/
-//
-// Novell.Directory.Ldap.Utilclass.ExtResponseFactory.cs
-//
-// Author:
-//   Sunil Kumar (Sunilk@novell.com)
-//
-// (C) 2003 Novell, Inc (http://www.novell.com)
-//
 
 using System;
 using Novell.Directory.Ldap;
 using Novell.Directory.Ldap.Extensions;
 using Novell.Directory.Ldap.Rfc2251;
 
+
 namespace Novell.Directory.Ldap.Utilclass
 {
+       
        /// <summary> 
        /// Takes an LdapExtendedResponse and returns an object
        /// (that implements the base class ParsedExtendedResponse)
        /// based on the OID.
        /// 
-       /// You can then call methods defined in the child
+       /// <p>You can then call methods defined in the child
        /// class to parse the contents of the response.  The methods available
        /// depend on the child class. All child classes inherit from the
-       /// ParsedExtendedResponse.
+       /// ParsedExtendedResponse.</p>
        /// 
        /// </summary>
        public class ExtResponseFactory
@@ -56,62 +28,68 @@ namespace Novell.Directory.Ldap.Utilclass
                /// </summary>
                /// <param name="inResponse">  The LdapExtendedReponse object as returned by the
                /// extendedOperation method in the LdapConnection object.
-               /// 
                /// </param>
                /// <returns> An object of base class LdapExtendedResponse.  The actual child
                /// class of this returned object depends on the operation being
                /// performed.
-               /// 
                /// </returns>
-               /// <exception> LdapException A general exception which includes an error message
-               /// and an Ldap error code.
-               /// </exception>
                
                static public LdapExtendedResponse convertToExtendedResponse(RfcLdapMessage inResponse)
                {
                        
                        LdapExtendedResponse tempResponse = new LdapExtendedResponse(inResponse);
-                       
                        // Get the oid stored in the Extended response
                        System.String inOID = tempResponse.ID;
                        
-                       if ((System.Object) inOID == null)
-                               return tempResponse;
-                       // Is this an OID we support, if yes then build the
-                       // detailed LdapExtendedResponse object
+                       RespExtensionSet regExtResponses = LdapExtendedResponse.RegisteredResponses;
                        try
                        {
-                               if (inOID.Equals(ReplicationConstants.NAMING_CONTEXT_COUNT_RES))
-                               {
-                                       return new PartitionEntryCountResponse(inResponse);
-                               }
-                               if (inOID.Equals(ReplicationConstants.GET_IDENTITY_NAME_RES))
+                               System.Type extRespClass = regExtResponses.findResponseExtension(inOID);
+                               if (extRespClass == null)
                                {
-                                       return new GetBindDNResponse(inResponse);
-                               }
-                               if (inOID.Equals(ReplicationConstants.GET_EFFECTIVE_PRIVILEGES_RES))
-                               {
-                                       return new GetEffectivePrivilegesResponse(inResponse);
-                               }
-                               if (inOID.Equals(ReplicationConstants.GET_REPLICA_INFO_RES))
-                               {
-                                       return new GetReplicaInfoResponse(inResponse);
+                                       return tempResponse;
                                }
-                               if (inOID.Equals(ReplicationConstants.LIST_REPLICAS_RES))
+                               System.Type[] argsClass = new System.Type[]{typeof(RfcLdapMessage)};
+                               System.Object[] args = new System.Object[]{inResponse};
+                               System.Exception ex;
+                               try
                                {
-                                       return new ListReplicasResponse(inResponse);
+                                       System.Reflection.ConstructorInfo extConstructor = extRespClass.GetConstructor(argsClass);
+                                       try
+                                       {
+                                               System.Object resp = null;
+                                               resp = extConstructor.Invoke(args);
+                                               return (LdapExtendedResponse) resp;
+                                       }
+                                       catch (System.UnauthorizedAccessException e)
+                                       {
+                                               ex = e;
+                                       }
+                                       catch (System.Reflection.TargetInvocationException e)
+                                       {
+                                               ex = e;
+                                       }
+                                       catch (System.Exception e)
+                                       {
+                                               // Could not create the ResponseControl object
+                                               // All possible exceptions are ignored. We fall through
+                                               // and create a default LdapControl object
+                                               ex = e;
+                                       }
                                }
-                               if (inOID.Equals(ReplicationConstants.GET_REPLICATION_FILTER_RES))
+                               catch (System.MethodAccessException e)
                                {
-                                       return new GetReplicationFilterResponse(inResponse);
+                                       // bad class was specified, fall through and return a
+                                       // default  LdapExtendedResponse object
+                                       ex = e;
                                }
-                               else
-                                       return tempResponse;
                        }
-                       catch (System.IO.IOException ioe)
+                       catch (System.FieldAccessException e)
                        {
-                               throw new LdapException(ExceptionMessages.DECODING_ERROR, LdapException.DECODING_ERROR, (System.String) null);
                        }
+                       // If we get here we did not have a registered extendedresponse
+                       // for this oid.  Return a default LdapExtendedResponse object.
+                       return tempResponse;
                }
        }
-}
+}
\ No newline at end of file
index 11ed067bc819588d6b3eec545492537127839fb9..c0d02f05bdfc7966f09472b4cad50eb76595e550 100755 (executable)
@@ -1,7 +1,9 @@
 Novell.Directory.Ldap/AssemblyInfo.cs
+Novell.Directory.Ldap/SupportClass.cs
 Novell.Directory.Ldap.Utilclass/Base64.cs
 Novell.Directory.Ldap.Utilclass/DN.cs
 Novell.Directory.Ldap.Utilclass/RDN.cs
+Novell.Directory.Ldap.Utilclass/RespExtensionSet.cs
 Novell.Directory.Ldap.Utilclass/BindProperties.cs
 Novell.Directory.Ldap.Utilclass/ReferralInfo.cs
 Novell.Directory.Ldap.Utilclass/ArrayEnumeration.cs
@@ -81,7 +83,6 @@ Novell.Directory.Ldap.Rfc2251/RfcLdapMessage.cs
 Novell.Directory.Ldap.Rfc2251/RfcUnbindRequest.cs
 Novell.Directory.Ldap.Rfc2251/RfcExtendedRequest.cs
 Novell.Directory.Ldap.Rfc2251/RfcExtendedResponse.cs
-Novell.Directory.Ldap/SupportClass.cs
 Novell.Directory.Ldap/LdapConnection.cs
 Novell.Directory.Ldap/LdapAuthHandler.cs
 Novell.Directory.Ldap/LdapBindHandler.cs
@@ -92,6 +93,7 @@ Novell.Directory.Ldap/LdapCompareAttrNames.cs
 Novell.Directory.Ldap/LdapCompareRequest.cs
 Novell.Directory.Ldap/LdapModification.cs
 Novell.Directory.Ldap/LdapAddRequest.cs
+Novell.Directory.Ldap/LdapDSConstants.cs
 Novell.Directory.Ldap/LdapResponseQueue.cs
 Novell.Directory.Ldap/LdapDeleteRequest.cs
 Novell.Directory.Ldap/LdapLocalException.cs
index a69d2eef172f0dc5a5b27a3a47f6339e708cbfd3..31de852965341734f106f5ff7b91d1d373031353 100755 (executable)
@@ -32,6 +32,7 @@
 using System;
 using Novell.Directory.Ldap.Rfc2251;
 using Novell.Directory.Ldap.Asn1;
+using RespExtensionSet = Novell.Directory.Ldap.Utilclass.RespExtensionSet;
 
 namespace Novell.Directory.Ldap
 {
@@ -61,6 +62,23 @@ namespace Novell.Directory.Ldap
                        }
                        
                }
+
+               static LdapExtendedResponse()
+               {
+                       registeredResponses = new RespExtensionSet();
+               }
+
+               public static RespExtensionSet RegisteredResponses
+               {
+                       /* package */
+                       
+                       get
+                       {
+                               return registeredResponses;
+                       }
+                       
+               }
+
                /// <summary> Returns the value part of the response in raw bytes.
                /// 
                /// </summary>
@@ -79,6 +97,7 @@ namespace Novell.Directory.Ldap
                        }
                        
                }
+               private static RespExtensionSet registeredResponses;
                
                /// <summary> Creates an LdapExtendedResponse object which encapsulates
                /// a server response to an asynchronous extended operation request.
@@ -90,5 +109,25 @@ namespace Novell.Directory.Ldap
                public LdapExtendedResponse(RfcLdapMessage message):base(message)
                {
                }
+
+               /// <summary> Registers a class to be instantiated on receipt of a extendedresponse
+               /// with the given OID.
+               /// 
+               /// <p>Any previous registration for the OID is overridden. The 
+               /// extendedResponseClass object MUST be an extension of 
+               /// LDAPExtendedResponse. </p>
+               /// 
+               /// </summary>
+               /// <param name="oid">           The object identifier of the control.
+               /// </param>
+               /// <param name="extendedResponseClass"> A class which can instantiate an 
+               /// LDAPExtendedResponse.
+               /// </param>
+               public static void  register(System.String oid, System.Type extendedResponseClass)
+               {
+                       registeredResponses.registerResponseExtension(oid, extendedResponseClass);
+                       return ;
+               }
+
        }
 }