use of org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator in project directory-ldap-api by apache.
the class StoreModifyRequestAttributeValue method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<ModifyRequestDecorator> container) {
ModifyRequestDecorator modifyRequestDecorator = container.getMessage();
TLV tlv = container.getCurrentTLV();
// Store the value. It can't be null
byte[] value = Strings.EMPTY_BYTES;
try {
if (tlv.getLength() == 0) {
modifyRequestDecorator.addAttributeValue("");
} else {
value = tlv.getValue().getData();
if (container.isBinary(modifyRequestDecorator.getCurrentAttributeType())) {
modifyRequestDecorator.addAttributeValue(value);
} else {
modifyRequestDecorator.addAttributeValue(Strings.utf8ToString((byte[]) value));
}
}
} catch (LdapException le) {
// Just swallow the exception, it can't occur here
}
// We can have an END transition
container.setGrammarEndAllowed(true);
if (IS_DEBUG) {
LOG.debug("Value modified : {}", value);
}
}
use of org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator in project directory-ldap-api by apache.
the class MessageDecorator method getDecorator.
/**
* Gets the decorator associated with a given message
*
* @param codec The LdapApiService to use
* @param decoratedMessage The message to decorate
* @return The decorator instance
*/
public static MessageDecorator<? extends Message> getDecorator(LdapApiService codec, Message decoratedMessage) {
if (decoratedMessage instanceof MessageDecorator) {
return (MessageDecorator<?>) decoratedMessage;
}
MessageDecorator<?> decorator;
switch(decoratedMessage.getType()) {
case ABANDON_REQUEST:
decorator = new AbandonRequestDecorator(codec, (AbandonRequest) decoratedMessage);
break;
case ADD_REQUEST:
decorator = new AddRequestDecorator(codec, (AddRequest) decoratedMessage);
break;
case ADD_RESPONSE:
decorator = new AddResponseDecorator(codec, (AddResponse) decoratedMessage);
break;
case BIND_REQUEST:
decorator = new BindRequestDecorator(codec, (BindRequest) decoratedMessage);
break;
case BIND_RESPONSE:
decorator = new BindResponseDecorator(codec, (BindResponse) decoratedMessage);
break;
case COMPARE_REQUEST:
decorator = new CompareRequestDecorator(codec, (CompareRequest) decoratedMessage);
break;
case COMPARE_RESPONSE:
decorator = new CompareResponseDecorator(codec, (CompareResponse) decoratedMessage);
break;
case DEL_REQUEST:
decorator = new DeleteRequestDecorator(codec, (DeleteRequest) decoratedMessage);
break;
case DEL_RESPONSE:
decorator = new DeleteResponseDecorator(codec, (DeleteResponse) decoratedMessage);
break;
case EXTENDED_REQUEST:
decorator = codec.decorate((ExtendedRequest) decoratedMessage);
break;
case EXTENDED_RESPONSE:
decorator = codec.decorate((ExtendedResponse) decoratedMessage);
break;
case INTERMEDIATE_RESPONSE:
decorator = new IntermediateResponseDecorator(codec, (IntermediateResponse) decoratedMessage);
break;
case MODIFY_REQUEST:
decorator = new ModifyRequestDecorator(codec, (ModifyRequest) decoratedMessage);
break;
case MODIFY_RESPONSE:
decorator = new ModifyResponseDecorator(codec, (ModifyResponse) decoratedMessage);
break;
case MODIFYDN_REQUEST:
decorator = new ModifyDnRequestDecorator(codec, (ModifyDnRequest) decoratedMessage);
break;
case MODIFYDN_RESPONSE:
decorator = new ModifyDnResponseDecorator(codec, (ModifyDnResponse) decoratedMessage);
break;
case SEARCH_REQUEST:
decorator = new SearchRequestDecorator(codec, (SearchRequest) decoratedMessage);
break;
case SEARCH_RESULT_DONE:
decorator = new SearchResultDoneDecorator(codec, (SearchResultDone) decoratedMessage);
break;
case SEARCH_RESULT_ENTRY:
decorator = new SearchResultEntryDecorator(codec, (SearchResultEntry) decoratedMessage);
break;
case SEARCH_RESULT_REFERENCE:
decorator = new SearchResultReferenceDecorator(codec, (SearchResultReference) decoratedMessage);
break;
case UNBIND_REQUEST:
decorator = new UnbindRequestDecorator(codec, (UnbindRequest) decoratedMessage);
break;
default:
return null;
}
Map<String, Control> controls = decoratedMessage.getControls();
if (controls != null) {
for (Control control : controls.values()) {
decorator.addControl(control);
}
}
return decorator;
}
use of org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator in project directory-ldap-api by apache.
the class InitModifyRequest method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<ModifyRequestDecorator> container) {
// Now, we can allocate the ModifyRequest Object
ModifyRequest internalModifyRequest = new ModifyRequestImpl();
internalModifyRequest.setMessageId(container.getMessageId());
ModifyRequestDecorator modifyRequestDecorator = new ModifyRequestDecorator(container.getLdapCodecService(), internalModifyRequest);
container.setMessage(modifyRequestDecorator);
}
use of org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator in project directory-ldap-api by apache.
the class StoreModifyRequestObjectName method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<ModifyRequestDecorator> container) throws DecoderException {
ModifyRequestDecorator modifyRequestDecorator = container.getMessage();
ModifyRequest modifyRequest = modifyRequestDecorator.getDecorated();
TLV tlv = container.getCurrentTLV();
Dn object = Dn.EMPTY_DN;
// Store the value.
if (tlv.getLength() == 0) {
(modifyRequestDecorator.getDecorated()).setName(object);
} else {
byte[] dnBytes = tlv.getValue().getData();
String dnStr = Strings.utf8ToString(dnBytes);
try {
object = new Dn(dnStr);
} catch (LdapInvalidDnException ine) {
String msg = "Invalid Dn given : " + dnStr + " (" + Strings.dumpBytes(dnBytes) + ") is invalid";
LOG.error("{} : {}", msg, ine.getMessage());
ModifyResponseImpl response = new ModifyResponseImpl(modifyRequest.getMessageId());
throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, Dn.EMPTY_DN, ine);
}
modifyRequest.setName(object);
}
if (IS_DEBUG) {
LOG.debug("Modification of Dn {}", modifyRequest.getName());
}
}
use of org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator in project directory-ldap-api by apache.
the class StoreOperationType method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<ModifyRequestDecorator> container) throws DecoderException {
ModifyRequestDecorator modifyRequestDecorator = container.getMessage();
TLV tlv = container.getCurrentTLV();
// Decode the operation type
int operation = 0;
try {
operation = IntegerDecoder.parse(tlv.getValue(), 0, 2);
} catch (IntegerDecoderException ide) {
String msg = I18n.err(I18n.ERR_04082, Strings.dumpBytes(tlv.getValue().getData()));
LOG.error(msg);
// This will generate a PROTOCOL_ERROR
throw new DecoderException(msg, ide);
}
// Store the current operation.
modifyRequestDecorator.setCurrentOperation(operation);
if (IS_DEBUG) {
switch(operation) {
case LdapCodecConstants.OPERATION_ADD:
LOG.debug("Modification operation : ADD");
break;
case LdapCodecConstants.OPERATION_DELETE:
LOG.debug("Modification operation : DELETE");
break;
case LdapCodecConstants.OPERATION_REPLACE:
LOG.debug("Modification operation : REPLACE");
break;
default:
LOG.debug("Modification operation : UNKNOWN");
}
}
}
Aggregations