Exemplo n.º 1
0
        /// <summary> Used to Convert an RfcLdapMessage object to the appropriate
        /// LdapExtendedResponse object depending on the operation being performed.
        ///
        /// </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>

        static public LdapExtendedResponse convertToExtendedResponse(RfcLdapMessage inResponse)
        {
            LdapExtendedResponse tempResponse = new LdapExtendedResponse(inResponse);
            // Get the oid stored in the Extended response
            string inOID = tempResponse.ID;

            RespExtensionSet regExtResponses = LdapExtendedResponse.RegisteredResponses;

            try
            {
                Type extRespClass = regExtResponses.findResponseExtension(inOID);
                if (extRespClass == null)
                {
                    return(tempResponse);
                }
                Type[]    argsClass = new Type[] { typeof(RfcLdapMessage) };
                object[]  args      = new object[] { inResponse };
                Exception ex;
                try
                {
                    ConstructorInfo extConstructor = extRespClass.GetConstructor(argsClass);
                    try
                    {
                        object resp = null;
                        resp = extConstructor.Invoke(args);
                        return((LdapExtendedResponse)resp);
                    }
                    catch (UnauthorizedAccessException e)
                    {
                        ex = e;
                    }
                    catch (TargetInvocationException e)
                    {
                        ex = e;
                    }
                    catch (Exception e)
                    {
                        // Could not create the ResponseControl object
                        // All possible exceptions are ignored. We fall through
                        // and create a default LdapControl object
                        ex = e;
                    }
                }
                catch (MethodAccessException e)
                {
                    // bad class was specified, fall through and return a
                    // default  LdapExtendedResponse object
                    ex = e;
                }
            }
            catch (FieldAccessException e)
            {
            }
            // If we get here we did not have a registered extendedresponse
            // for this oid.  Return a default LdapExtendedResponse object.
            return(tempResponse);
        }
        /**
         * Used to Convert an RfcLDAPMessage object to the appropriate
         * LDAPIntermediateResponse object depending on the operation being performed.
         *
         * @param inResponse   The LDAPIntermediateResponse object as returned by the
         *                     extendedOperation method in the LDAPConnection object.
         * <br><br>
         * @return An object of base class LDAPIntermediateResponse.  The actual child
         *         class of this returned object depends on the operation being
         *         performed.
         *
         * @exception LDAPException A general exception which includes an error message
         *                          and an LDAP error code.
         */

        static public LdapIntermediateResponse convertToIntermediateResponse(RfcLdapMessage inResponse)
        //          throws LDAPException
        {
            LdapIntermediateResponse tempResponse = new LdapIntermediateResponse(inResponse);
            // Get the oid stored in the Extended response
            string inOID = tempResponse.getID();

            RespExtensionSet regExtResponses = LdapIntermediateResponse.getRegisteredResponses();

            try
            {
                Type extRespClass = regExtResponses.findResponseExtension(inOID);
                if (extRespClass == null)
                {
                    return(tempResponse);
                }

                Type[]    argsClass = new Type[] { typeof(RfcLdapMessage) };
                object[]  args      = { inResponse };
                Exception ex;
                try
                {
                    ConstructorInfo extConstructor = extRespClass.GetConstructor(argsClass);

                    try
                    {
                        object resp = null;
                        resp = extConstructor.Invoke(args);
                        return((LdapIntermediateResponse)resp);
                    }
                    catch (UnauthorizedAccessException e)
                    {
                        ex = e;
                    }
                    catch (TargetInvocationException e)
                    {
                        ex = e;
                    }
                }
                catch (MissingMethodException e)
                {
                    // bad class was specified, fall through and return a
                    // default  LDAPIntermediateResponse object
                    ex = e;
                }
            }
            catch (MissingFieldException e)
            {
                // No match with the OID
                // Do nothing. Fall through and construct a default LDAPControl object.
            }
            // If we get here we did not have a registered extendedresponse
            // for this oid.  Return a default LDAPIntermediateResponse object.
            return(tempResponse);
        }