Package org.springframework.ldap.control
Class AbstractFallbackRequestAndResponseControlDirContextProcessor
- java.lang.Object
-
- org.springframework.ldap.control.AbstractRequestControlDirContextProcessor
-
- org.springframework.ldap.control.AbstractFallbackRequestAndResponseControlDirContextProcessor
-
- All Implemented Interfaces:
DirContextProcessor
- Direct Known Subclasses:
PagedResultsDirContextProcessor
,SortControlDirContextProcessor
,VirtualListViewControlDirContextProcessor
public abstract class AbstractFallbackRequestAndResponseControlDirContextProcessor extends AbstractRequestControlDirContextProcessor
Convenient base class useful when implementing a standard DirContextProcessor which has a request control and a response control. It handles the loading of the control classes, using fallback implementations specified by the subclass if necessary. It handles the request control constructor invocation; it only needs the constructor arguments to be provided. It also handles most of the work in the post processing of the response control, only delegating to a template method for the actual value retrieval. In short, it makes it easy to implement a custom DirContextProcessor.public class SortControlDirContextProcessor extends AbstractFallbackRequestAndResponseControlDirContextProcessor { String sortKey; private boolean sorted = false; private int resultCode = -1; public SortControlDirContextProcessor(String sortKey) { this.sortKey = sortKey; defaultRequestControl = "javax.naming.ldap.SortControl"; defaultResponseControl = "com.sun.jndi.ldap.ctl.SortControl"; fallbackRequestControl = "javax.naming.ldap.SortResponseControl"; fallbackResponseControl = "com.sun.jndi.ldap.ctl.SortResponseControl"; loadControlClasses(); } public boolean isSorted() { return sorted; } public int getResultCode() { return resultCode; } public Control createRequestControl() { return super.createRequestControl(new Class[] { String[].class, boolean.class }, new Object[] { new String[] { sortKey }, Boolean.valueOf(critical) }); } protected void handleResponse(Object control) { Boolean result = (Boolean) invokeMethod("isSorted", responseControlClass, control); this.sorted = result.booleanValue(); Integer code = (Integer) invokeMethod("getResultCode", responseControlClass, control); resultCode = code.intValue(); } }
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
critical
protected java.lang.String
defaultRequestControl
protected java.lang.String
defaultResponseControl
protected java.lang.String
fallbackRequestControl
protected java.lang.String
fallbackResponseControl
protected java.lang.Class<?>
requestControlClass
protected java.lang.Class<?>
responseControlClass
-
Fields inherited from class org.springframework.ldap.control.AbstractRequestControlDirContextProcessor
log
-
-
Constructor Summary
Constructors Constructor Description AbstractFallbackRequestAndResponseControlDirContextProcessor()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description javax.naming.ldap.Control
createRequestControl(java.lang.Class<?>[] paramTypes, java.lang.Object[] params)
Creates a request control using the constructor parameters given inparams
.protected abstract void
handleResponse(java.lang.Object control)
protected java.lang.Object
invokeMethod(java.lang.String method, java.lang.Class<?> clazz, java.lang.Object control)
Utility method for invoking a method on a Control.protected void
loadControlClasses()
void
postProcess(javax.naming.directory.DirContext ctx)
Perform post-processing on the suppliedDirContext
.void
setCritical(boolean critical)
Set whether this control should be indicated as critical.void
setRequestControlClass(java.lang.Class<?> requestControlClass)
void
setResponseControlClass(java.lang.Class<?> responseControlClass)
Set the class of the expected ResponseControl for the sorted result response.-
Methods inherited from class org.springframework.ldap.control.AbstractRequestControlDirContextProcessor
createRequestControl, isReplaceSameControlEnabled, preProcess, setReplaceSameControlEnabled
-
-
-
-
Field Detail
-
responseControlClass
protected java.lang.Class<?> responseControlClass
-
requestControlClass
protected java.lang.Class<?> requestControlClass
-
critical
protected boolean critical
-
defaultRequestControl
protected java.lang.String defaultRequestControl
-
defaultResponseControl
protected java.lang.String defaultResponseControl
-
fallbackRequestControl
protected java.lang.String fallbackRequestControl
-
fallbackResponseControl
protected java.lang.String fallbackResponseControl
-
-
Method Detail
-
loadControlClasses
protected void loadControlClasses()
-
setResponseControlClass
public void setResponseControlClass(java.lang.Class<?> responseControlClass)
Set the class of the expected ResponseControl for the sorted result response.- Parameters:
responseControlClass
- Class of the expected response control.
-
setRequestControlClass
public void setRequestControlClass(java.lang.Class<?> requestControlClass)
-
invokeMethod
protected java.lang.Object invokeMethod(java.lang.String method, java.lang.Class<?> clazz, java.lang.Object control)
Utility method for invoking a method on a Control.- Parameters:
method
- name of method to invokeclazz
- Class of the object that the method should be invoked oncontrol
- Instance that the method should be invoked on- Returns:
- the invocation result, if any
-
createRequestControl
public javax.naming.ldap.Control createRequestControl(java.lang.Class<?>[] paramTypes, java.lang.Object[] params)
Creates a request control using the constructor parameters given inparams
.- Parameters:
paramTypes
- Types of the constructor parametersparams
- Actual constructor parameters- Returns:
- Control to be used by the DirContextProcessor
-
postProcess
public void postProcess(javax.naming.directory.DirContext ctx) throws javax.naming.NamingException
Description copied from interface:DirContextProcessor
Perform post-processing on the suppliedDirContext
.- Parameters:
ctx
- theDirContext
instance.- Throws:
javax.naming.NamingException
- if thrown by the underlying operation.
-
setCritical
public void setCritical(boolean critical)
Set whether this control should be indicated as critical.- Parameters:
critical
- whether the control is critical.- Since:
- 2.0
-
handleResponse
protected abstract void handleResponse(java.lang.Object control)
-
-