Commit 02f379a2 authored by Sunil Kumar's avatar Sunil Kumar
Browse files

Modified to Add LDAPExtendedResponse.register method

parent 48656b3f
......@@ -19,6 +19,11 @@ import com.novell.ldap.extensions.*;
import com.novell.ldap.rfc2251.*;
import com.novell.ldap.resources.*;
import java.io.IOException;
import com.novell.ldap.client.Debug;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Constructor;
/**
*
* Takes an LDAPExtendedResponse and returns an object
......@@ -50,43 +55,65 @@ public class ExtResponseFactory {
static public LDAPExtendedResponse convertToExtendedResponse(RfcLDAPMessage inResponse)
throws LDAPException {
LDAPExtendedResponse tempResponse = new LDAPExtendedResponse(inResponse);
// Get the oid stored in the Extended response
String inOID = tempResponse.getID();
if (inOID == null)
return tempResponse;
// Is this an OID we support, if yes then build the
// detailed LDAPExtendedResponse object
try {
if (inOID.equals(ReplicationConstants.NAMING_CONTEXT_COUNT_RES)) {
return new PartitionEntryCountResponse(inResponse);
}
if (inOID.equals(ReplicationConstants.GET_IDENTITY_NAME_RES) ) {
return new GetBindDNResponse(inResponse);
}
if (inOID.equals(ReplicationConstants.GET_EFFECTIVE_PRIVILEGES_RES) ) {
return new GetEffectivePrivilegesResponse(inResponse);
RespExtensionSet regExtResponses =
LDAPExtendedResponse.getRegisteredResponses();
try{
Class extRespClass = regExtResponses.findResponseExtension(inOID);
if ( extRespClass == null ){
return tempResponse;
}
if (inOID.equals(ReplicationConstants.GET_REPLICA_INFO_RES) ) {
return new GetReplicaInfoResponse(inResponse);
if( Debug.LDAP_DEBUG) {
Debug.trace( Debug.messages,
"For oid " + inOID + ", found class " + extRespClass.toString());
}
Class[] argsClass = { RfcLDAPMessage.class };
Object[] args = { inResponse };
Exception ex;
try{
Constructor extConstructor =
extRespClass.getConstructor(argsClass);
try{
Object resp = null;
resp = extConstructor.newInstance(args);
return (LDAPExtendedResponse) resp;
}catch(InstantiationException e) {
// Could not create the ResponseControl object
// All possible exceptions are ignored. We fall through
// and create a default LDAPControl object
ex = e;
} catch (IllegalAccessException e) {
ex = e;
} catch (InvocationTargetException e) {
ex = e;
}
} catch (NoSuchMethodException e) {
// bad class was specified, fall through and return a
// default LDAPExtendedResponse object
ex = e;
}
if (inOID.equals(ReplicationConstants.LIST_REPLICAS_RES) ) {
return new ListReplicasResponse(inResponse);
if( Debug.LDAP_DEBUG) {
Debug.trace( Debug.messages,
"Unable to create new instance of child LDAPExtendedResponse");
Debug.trace( Debug.messages,
ex.toString());
}
if (inOID.equals(ReplicationConstants.GET_REPLICATION_FILTER_RES) ) {
return new GetReplicationFilterResponse(inResponse);
} catch (NoSuchFieldException e) {
// No match with the OID
// Do nothing. Fall through and construct a default LDAPControl object.
if( Debug.LDAP_DEBUG) {
Debug.trace( Debug.messages,
"Oid " + inOID + " not registered");
}
else
return tempResponse;
}
catch(IOException ioe) {
throw new LDAPException(
ExceptionMessages.DECODING_ERROR,
LDAPException.DECODING_ERROR,(String) null);
}
// If we get here we did not have a registered extendedresponse
// for this oid. Return a default LDAPExtendedResponse object.
return tempResponse;
}
}
/* **************************************************************************
* $OpenLDAP$
*
* Copyright (C) 1999, 2000, 2001 Novell, Inc. All Rights Reserved.
*
* THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND
* TREATIES. USE, MODIFICATION, AND REDISTRIBUTION OF THIS WORK IS SUBJECT
* TO VERSION 2.0.1 OF THE OPENLDAP PUBLIC LICENSE, A COPY OF WHICH IS
* AVAILABLE AT HTTP://WWW.OPENLDAP.ORG/LICENSE.HTML OR IN THE FILE "LICENSE"
* IN THE TOP-LEVEL DIRECTORY OF THE DISTRIBUTION. ANY USE OR EXPLOITATION
* OF THIS WORK OTHER THAN AS AUTHORIZED IN VERSION 2.0.1 OF THE OPENLDAP
* PUBLIC LICENSE, OR OTHER PRIOR WRITTEN CONSENT FROM NOVELL, COULD SUBJECT
* THE PERPETRATOR TO CRIMINAL AND CIVIL LIABILITY.
***************************************************************************/
package com.novell.ldap.client;
import com.novell.ldap.client.Debug;
import java.util.HashMap;
import java.util.Iterator;
/**
* This class extends the AbstractSet and Implements the Set
* so that it can be used to maintain a list of currently
* registered extended responses.
*/
public class RespExtensionSet extends java.util.AbstractSet
implements java.util.Set
{
private HashMap map;
public RespExtensionSet()
{
super();
map = new HashMap();
return;
}
/* Adds a responseExtension to the current list of registered responses.
*
*/
public final synchronized void registerResponseExtension(String oid, Class extClass)
{
if( Debug.LDAP_DEBUG) {
Debug.trace( Debug.controls, "Registered Extension with OID " + oid
+ " for class " + extClass.toString());
}
if( !this.map.containsKey(oid)){
this.map.put(oid, (Class)extClass);
}
}
/**
* Returns the number of extensions in this set.
*
* @return number of extensions in this set.
*/
public int size(){
return this.map.size();
}
/**
* Returns an iterator over the responses in this set. The responses
* returned from this iterator are not in any particular order.
*
* @return iterator over the responses in this set
*/
public Iterator iterator(){
return this.map.values().iterator();
}
/* Searches the list of registered responses for a mathcing response. We
* search using the OID string. If a match is found we return the
* Class name that was provided to us on registration.
*/
public final synchronized Class findResponseExtension(String searchOID)
throws NoSuchFieldException
{
if( this.map.containsKey(searchOID))
{
return (Class)this.map.get(searchOID);
}
/* The requested extension does not have a registered response class */
if( Debug.LDAP_DEBUG) {
Debug.trace( Debug.controls, "Returned Extension did not match any registered extension.");
}
return null;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment