Search in sources :

Example 1 with ExtendedOperationFactory

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;
            }
        }
    };
}
Also used : ExtendedOperationFactory(org.apache.directory.api.ldap.codec.api.ExtendedOperationFactory) ExtendedRequestDecorator(org.apache.directory.api.ldap.codec.decorators.ExtendedRequestDecorator) DecoderException(org.apache.directory.api.asn1.DecoderException) ExtendedResponse(org.apache.directory.api.ldap.model.message.ExtendedResponse) ExtendedRequest(org.apache.directory.api.ldap.model.message.ExtendedRequest) ExtendedResponseDecorator(org.apache.directory.api.ldap.codec.decorators.ExtendedResponseDecorator) NamingException(javax.naming.NamingException)

Example 2 with ExtendedOperationFactory

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;
}
Also used : ExtendedOperationFactory(org.apache.directory.api.ldap.codec.api.ExtendedOperationFactory)

Example 3 with ExtendedOperationFactory

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());
}
Also used : LdapApiService(org.apache.directory.api.ldap.codec.api.LdapApiService) ExtendedOperationFactory(org.apache.directory.api.ldap.codec.api.ExtendedOperationFactory)

Example 4 with ExtendedOperationFactory

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;
}
Also used : ExtendedResponse(org.apache.directory.api.ldap.model.message.ExtendedResponse) ExtendedOperationFactory(org.apache.directory.api.ldap.codec.api.ExtendedOperationFactory) ExtendedResponseImpl(org.apache.directory.api.ldap.model.message.ExtendedResponseImpl) ExtendedResponseDecorator(org.apache.directory.api.ldap.codec.decorators.ExtendedResponseDecorator)

Example 5 with ExtendedOperationFactory

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;
}
Also used : ExtendedRequestDecorator(org.apache.directory.api.ldap.codec.decorators.ExtendedRequestDecorator) ExtendedRequestImpl(org.apache.directory.api.ldap.model.message.ExtendedRequestImpl) ExtendedOperationFactory(org.apache.directory.api.ldap.codec.api.ExtendedOperationFactory) ExtendedRequest(org.apache.directory.api.ldap.model.message.ExtendedRequest)

Aggregations

ExtendedOperationFactory (org.apache.directory.api.ldap.codec.api.ExtendedOperationFactory)5 ExtendedRequestDecorator (org.apache.directory.api.ldap.codec.decorators.ExtendedRequestDecorator)2 ExtendedResponseDecorator (org.apache.directory.api.ldap.codec.decorators.ExtendedResponseDecorator)2 ExtendedRequest (org.apache.directory.api.ldap.model.message.ExtendedRequest)2 ExtendedResponse (org.apache.directory.api.ldap.model.message.ExtendedResponse)2 NamingException (javax.naming.NamingException)1 DecoderException (org.apache.directory.api.asn1.DecoderException)1 LdapApiService (org.apache.directory.api.ldap.codec.api.LdapApiService)1 ExtendedRequestImpl (org.apache.directory.api.ldap.model.message.ExtendedRequestImpl)1 ExtendedResponseImpl (org.apache.directory.api.ldap.model.message.ExtendedResponseImpl)1