use of org.apache.directory.api.asn1.EncoderException in project directory-ldap-api by apache.
the class ModifyDnResponseDecorator method encode.
/**
* Encode the ModifyDnResponse message to a PDU.
*
* @param buffer The buffer where to put the PDU
*/
@Override
public ByteBuffer encode(ByteBuffer buffer) throws EncoderException {
try {
// The ModifyResponse Tag
buffer.put(LdapCodecConstants.MODIFY_DN_RESPONSE_TAG);
buffer.put(TLV.getBytes(modifyDnResponseLength));
// The LdapResult
((LdapResultDecorator) getLdapResult()).encode(buffer);
} catch (BufferOverflowException boe) {
throw new EncoderException(I18n.err(I18n.ERR_04005), boe);
}
return buffer;
}
use of org.apache.directory.api.asn1.EncoderException in project directory-ldap-api by apache.
the class ModifyRequestDecorator method encode.
/**
* Encode the ModifyRequest message to a PDU.
* <br>
* ModifyRequest :
* <pre>
* 0x66 LL
* 0x04 LL object
* 0x30 LL modifiations
* 0x30 LL modification sequence
* 0x0A 0x01 operation
* 0x30 LL modification
* 0x04 LL type
* 0x31 LL vals
* 0x04 LL attributeValue
* ...
* 0x04 LL attributeValue
* ...
* 0x30 LL modification sequence
* 0x0A 0x01 operation
* 0x30 LL modification
* 0x04 LL type
* 0x31 LL vals
* 0x04 LL attributeValue
* ...
* 0x04 LL attributeValue
* </pre>
*
* @param buffer The buffer where to put the PDU
* @return The PDU.
*/
@Override
public ByteBuffer encode(ByteBuffer buffer) throws EncoderException {
try {
// The AddRequest Tag
buffer.put(LdapCodecConstants.MODIFY_REQUEST_TAG);
buffer.put(TLV.getBytes(modifyRequestLength));
// The entry
BerValue.encode(buffer, dnBytes);
// The modifications sequence
buffer.put(UniversalTag.SEQUENCE.getValue());
buffer.put(TLV.getBytes(changesLength));
// The modifications list
Collection<Modification> modifications = getModifications();
if ((modifications != null) && (!modifications.isEmpty())) {
int modificationNumber = 0;
// Compute the modifications length
for (Modification modification : modifications) {
// The modification sequence
buffer.put(UniversalTag.SEQUENCE.getValue());
int localModificationSequenceLength = changeLength.get(modificationNumber);
buffer.put(TLV.getBytes(localModificationSequenceLength));
// The operation. The value has to be changed, it's not
// the same value in DirContext and in RFC 2251.
buffer.put(UniversalTag.ENUMERATED.getValue());
buffer.put((byte) 1);
buffer.put((byte) modification.getOperation().getValue());
// The modification
buffer.put(UniversalTag.SEQUENCE.getValue());
int localModificationLength = modificationLength.get(modificationNumber);
buffer.put(TLV.getBytes(localModificationLength));
// The modification type
BerValue.encode(buffer, modification.getAttribute().getUpId());
// The values
buffer.put(UniversalTag.SET.getValue());
int localValuesLength = valuesLength.get(modificationNumber);
buffer.put(TLV.getBytes(localValuesLength));
if (modification.getAttribute().size() != 0) {
for (org.apache.directory.api.ldap.model.entry.Value value : modification.getAttribute()) {
if (value.isHumanReadable()) {
BerValue.encode(buffer, value.getValue());
} else {
BerValue.encode(buffer, value.getBytes());
}
}
}
// Go to the next modification number
modificationNumber++;
}
}
} catch (BufferOverflowException boe) {
throw new EncoderException(I18n.err(I18n.ERR_04005), boe);
}
return buffer;
}
use of org.apache.directory.api.asn1.EncoderException in project directory-ldap-api by apache.
the class ModifyResponseDecorator method encode.
/**
* Encode the ModifyResponse message to a PDU.
*
* @param buffer The buffer where to put the PDU
*/
@Override
public ByteBuffer encode(ByteBuffer buffer) throws EncoderException {
try {
// The ModifyResponse Tag
buffer.put(LdapCodecConstants.MODIFY_RESPONSE_TAG);
buffer.put(TLV.getBytes(modifyResponseLength));
// The LdapResult
((LdapResultDecorator) getLdapResult()).encode(buffer);
} catch (BufferOverflowException boe) {
throw new EncoderException(I18n.err(I18n.ERR_04005), boe);
}
return buffer;
}
use of org.apache.directory.api.asn1.EncoderException in project directory-ldap-api by apache.
the class SearchRequestDecorator method encode.
/**
* Encode the SearchRequest message to a PDU.
* <br>
* SearchRequest :
* <pre>
* 0x63 LL
* 0x04 LL baseObject
* 0x0A 01 scope
* 0x0A 01 derefAliases
* 0x02 0N sizeLimit
* 0x02 0N timeLimit
* 0x01 0x01 typesOnly
* filter.encode()
* 0x30 LL attributeDescriptionList
* 0x04 LL attributeDescription
* ...
* 0x04 LL attributeDescription
* </pre>
*
* @param buffer The buffer where to put the PDU
* @return The PDU.
*/
@Override
public ByteBuffer encode(ByteBuffer buffer) throws EncoderException {
try {
// The SearchRequest Tag
buffer.put(LdapCodecConstants.SEARCH_REQUEST_TAG);
buffer.put(TLV.getBytes(searchRequestLength));
// The baseObject
BerValue.encode(buffer, dnBytes);
// The scope
BerValue.encodeEnumerated(buffer, getScope().getScope());
// The derefAliases
BerValue.encodeEnumerated(buffer, getDerefAliases().getValue());
// The sizeLimit
BerValue.encode(buffer, getSizeLimit());
// The timeLimit
BerValue.encode(buffer, getTimeLimit());
// The typesOnly
BerValue.encode(buffer, getTypesOnly());
// The filter
getCodecFilter().encode(buffer);
// The attributeDescriptionList
buffer.put(UniversalTag.SEQUENCE.getValue());
buffer.put(TLV.getBytes(attributeDescriptionListLength));
if ((getAttributes() != null) && (!getAttributes().isEmpty())) {
// encode each attribute
for (byte[] attributeBytes : attributeNameBytes) {
BerValue.encode(buffer, attributeBytes);
}
}
} catch (BufferOverflowException boe) {
throw new EncoderException(I18n.err(I18n.ERR_04005), boe);
}
return buffer;
}
use of org.apache.directory.api.asn1.EncoderException in project directory-ldap-api by apache.
the class SearchResultEntryDecorator method encode.
/**
* Encode the SearchResultEntry message to a PDU.
* <br>
* SearchResultEntry :
* <pre>
* 0x64 LL
* 0x04 LL objectName
* 0x30 LL attributes
* 0x30 LL partialAttributeList
* 0x04 LL type
* 0x31 LL vals
* 0x04 LL attributeValue
* ...
* 0x04 LL attributeValue
* ...
* 0x30 LL partialAttributeList
* 0x04 LL type
* 0x31 LL vals
* 0x04 LL attributeValue
* ...
* 0x04 LL attributeValue
* </pre>
*
* @param buffer The buffer where to put the PDU
* @return The PDU.
*/
@Override
public ByteBuffer encode(ByteBuffer buffer) throws EncoderException {
try {
// The SearchResultEntry Tag
buffer.put(LdapCodecConstants.SEARCH_RESULT_ENTRY_TAG);
buffer.put(TLV.getBytes(searchResultEntryLength));
// The objectName
BerValue.encode(buffer, objectNameBytes);
// The attributes sequence
buffer.put(UniversalTag.SEQUENCE.getValue());
buffer.put(TLV.getBytes(attributesLength));
// The partial attribute list
Entry entry = getEntry();
if ((entry != null) && (entry.size() != 0)) {
int attributeNumber = 0;
// Compute the attributes length
for (Attribute attribute : entry) {
// The partial attribute list sequence
buffer.put(UniversalTag.SEQUENCE.getValue());
int localAttributeLength = attributeLength.get(attributeNumber);
buffer.put(TLV.getBytes(localAttributeLength));
// The attribute type
BerValue.encode(buffer, attributeIds.get(attributeNumber));
// The values
buffer.put(UniversalTag.SET.getValue());
int localValuesLength = valuesLength.get(attributeNumber);
buffer.put(TLV.getBytes(localValuesLength));
if (attribute.size() > 0) {
for (Value value : attribute) {
BerValue.encode(buffer, value.getBytes());
}
}
// Go to the next attribute number
attributeNumber++;
}
}
} catch (BufferOverflowException boe) {
throw new EncoderException(I18n.err(I18n.ERR_04005), boe);
}
return buffer;
}
Aggregations