public abstract class AbstractFallbackRequestAndResponseControlDirContextProcessor extends AbstractRequestControlDirContextProcessor
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(); } }
Modifier and Type | Field and Description |
---|---|
protected boolean |
critical |
protected String |
defaultRequestControl |
protected String |
defaultResponseControl |
protected String |
fallbackRequestControl |
protected String |
fallbackResponseControl |
protected Class<?> |
requestControlClass |
protected Class<?> |
responseControlClass |
log
Constructor and Description |
---|
AbstractFallbackRequestAndResponseControlDirContextProcessor() |
Modifier and Type | Method and Description |
---|---|
Control |
createRequestControl(Class<?>[] paramTypes,
Object[] params)
Creates a request control using the constructor parameters given in
params . |
protected abstract void |
handleResponse(Object control) |
protected Object |
invokeMethod(String method,
Class<?> clazz,
Object control)
Utility method for invoking a method on a Control.
|
protected void |
loadControlClasses() |
void |
postProcess(DirContext ctx)
Perform post-processing on the supplied
DirContext . |
void |
setCritical(boolean critical)
Set whether this control should be indicated as critical.
|
void |
setRequestControlClass(Class<?> requestControlClass) |
void |
setResponseControlClass(Class<?> responseControlClass)
Set the class of the expected ResponseControl for the sorted result
response.
|
createRequestControl, isReplaceSameControlEnabled, preProcess, setReplaceSameControlEnabled
protected Class<?> responseControlClass
protected Class<?> requestControlClass
protected boolean critical
protected String defaultRequestControl
protected String defaultResponseControl
protected String fallbackRequestControl
protected String fallbackResponseControl
public AbstractFallbackRequestAndResponseControlDirContextProcessor()
protected void loadControlClasses()
public void setResponseControlClass(Class<?> responseControlClass)
responseControlClass
- Class of the expected response control.public void setRequestControlClass(Class<?> requestControlClass)
protected Object invokeMethod(String method, Class<?> clazz, Object control)
method
- name of method to invokeclazz
- Class of the object that the method should be invoked oncontrol
- Instance that the method should be invoked onpublic Control createRequestControl(Class<?>[] paramTypes, Object[] params)
params
.paramTypes
- Types of the constructor parametersparams
- Actual constructor parameterspublic void postProcess(DirContext ctx) throws NamingException
DirContextProcessor
DirContext
.ctx
- the DirContext
instance.NamingException
- if thrown by the underlying operation.public void setCritical(boolean critical)
critical
- whether the control is critical.protected abstract void handleResponse(Object control)