use of org.apache.directory.api.ldap.codec.api.ExtendedOperationFactory in project directory-ldap-api by apache.
the class DefaultLdapCodecService method toJndi.
/**
* {@inheritDoc}
*/
@Override
public javax.naming.ldap.ExtendedRequest toJndi(final ExtendedRequest modelRequest) throws EncoderException {
final String oid = modelRequest.getRequestName();
final byte[] value;
if (modelRequest instanceof ExtendedRequestDecorator) {
ExtendedRequestDecorator<?> decorator = (ExtendedRequestDecorator<?>) modelRequest;
value = decorator.getRequestValue();
} else {
// have to ask the factory to decorate for us - can't do it ourselves
ExtendedOperationFactory extendedRequestFactory = extendedOperationFactories.get(modelRequest.getRequestName());
ExtendedRequestDecorator<?> decorator = (ExtendedRequestDecorator<?>) extendedRequestFactory.decorate(modelRequest);
value = decorator.getRequestValue();
}
return new javax.naming.ldap.ExtendedRequest() {
private static final long serialVersionUID = -4160980385909987475L;
@Override
public String getID() {
return oid;
}
@Override
public byte[] getEncodedValue() {
return value;
}
@Override
public javax.naming.ldap.ExtendedResponse createExtendedResponse(String id, byte[] berValue, int offset, int length) throws NamingException {
ExtendedOperationFactory factory = extendedOperationFactories.get(modelRequest.getRequestName());
try {
final ExtendedResponseDecorator<?> resp = (ExtendedResponseDecorator<?>) factory.newResponse(berValue);
return new javax.naming.ldap.ExtendedResponse() {
private static final long serialVersionUID = -7686354122066100703L;
@Override
public String getID() {
return oid;
}
@Override
public byte[] getEncodedValue() {
return resp.getResponseValue();
}
};
} catch (DecoderException de) {
NamingException ne = new NamingException("Unable to decode encoded response value: " + Strings.dumpBytes(berValue));
ne.setRootCause(de);
throw ne;
}
}
};
}
use of org.apache.directory.api.ldap.codec.api.ExtendedOperationFactory in project directory-ldap-api by apache.
the class DefaultLdapCodecService method decorate.
/**
* {@inheritDoc}
*/
@Override
public ExtendedRequestDecorator<?> decorate(ExtendedRequest decoratedMessage) {
ExtendedRequestDecorator<?> req;
ExtendedOperationFactory extendedRequestFactory = extendedOperationFactories.get(decoratedMessage.getRequestName());
if (extendedRequestFactory != null) {
req = (ExtendedRequestDecorator<?>) extendedRequestFactory.decorate(decoratedMessage);
} else {
req = new ExtendedRequestDecorator<>(this, decoratedMessage);
}
return req;
}
use of org.apache.directory.api.ldap.codec.api.ExtendedOperationFactory in project directory-ldap-api by apache.
the class StandaloneLdapApiService method loadExtendedOperation.
/**
* Loads an of extended operations from its FQCN
*/
private void loadExtendedOperation(String extendedOperationFQCN) throws Exception {
if (getExtendedOperationFactories().containsKey(extendedOperationFQCN)) {
LOG.debug("Factory for extended operation {} was already loaded", extendedOperationFQCN);
return;
}
Class<?>[] types = new Class<?>[] { LdapApiService.class };
// note, trimming whitespace doesn't hurt as it is a class name and
// helps DI containers that use xml config as xml ignores whitespace
@SuppressWarnings("unchecked") Class<? extends ExtendedOperationFactory> clazz = (Class<? extends ExtendedOperationFactory>) Class.forName(extendedOperationFQCN.trim());
Constructor<?> constructor = clazz.getConstructor(types);
ExtendedOperationFactory factory = (ExtendedOperationFactory) constructor.newInstance(new Object[] { this });
getExtendedOperationFactories().put(factory.getOid(), factory);
LOG.info("Registered pre-bundled extended operation factory: {}", factory.getOid());
}
use of org.apache.directory.api.ldap.codec.api.ExtendedOperationFactory in project directory-ldap-api by apache.
the class DefaultLdapCodecService method newExtendedResponse.
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public <E extends ExtendedResponse> E newExtendedResponse(String responseName, int messageId, byte[] serializedResponse) throws DecoderException {
ExtendedResponseDecorator<ExtendedResponse> resp;
ExtendedOperationFactory extendedRequestFactory = extendedOperationFactories.get(responseName);
if (extendedRequestFactory != null) {
resp = (ExtendedResponseDecorator<ExtendedResponse>) extendedRequestFactory.newResponse(serializedResponse);
} else {
resp = new ExtendedResponseDecorator(this, new ExtendedResponseImpl(responseName));
resp.setResponseValue(serializedResponse);
resp.setResponseName(responseName);
}
resp.setMessageId(messageId);
return (E) resp;
}
use of org.apache.directory.api.ldap.codec.api.ExtendedOperationFactory in project directory-ldap-api by apache.
the class DefaultLdapCodecService method newExtendedRequest.
/**
* {@inheritDoc}
*/
@Override
public ExtendedRequest newExtendedRequest(String oid, byte[] value) {
ExtendedRequest req;
ExtendedOperationFactory extendedRequestFactory = extendedOperationFactories.get(oid);
if (extendedRequestFactory != null) {
req = extendedRequestFactory.newRequest(value);
} else {
ExtendedRequestDecorator<ExtendedRequest> decorator = new ExtendedRequestDecorator(this, new ExtendedRequestImpl());
decorator.setRequestName(oid);
decorator.setRequestValue(value);
req = decorator;
}
return req;
}
Aggregations