use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class AddRequestDecorator method addAttributeType.
/**
* Create a new attributeValue
*
* @param type The attribute's name (called 'type' in the grammar)
* @throws LdapException If the value is invalid
*/
public void addAttributeType(String type) throws LdapException {
// do not create a new attribute if we have seen this attributeType before
if (getDecorated().getEntry().get(type) != null) {
currentAttribute = getDecorated().getEntry().get(type);
return;
}
// fix this to use AttributeImpl(type.getString().toLowerCase())
currentAttribute = new DefaultAttribute(type);
getDecorated().getEntry().put(currentAttribute);
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SearchResultEntryDsml method addAttribute.
/**
* Create a new attribute
*
* @param type The attribute's type
* @throws LdapException If we can't add the new attributeType
*/
public void addAttribute(String type) throws LdapException {
currentAttribute = new DefaultAttribute(type);
getDecorated().getEntry().put(currentAttribute);
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class ModifyRequestDsml method addAttributeTypeAndValues.
/**
* Add a new attributeTypeAndValue
*
* @param type The attribute's name
*/
public void addAttributeTypeAndValues(String type) {
currentAttribute = new DefaultAttribute(type);
Modification modification = new DefaultModification(currentOperation, currentAttribute);
getDecorated().addModification(modification);
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class LdifAnonymizer method anonymizeAva.
/**
* Anonymize an AVA
*/
private Ava anonymizeAva(Ava ava) throws LdapInvalidDnException, LdapInvalidAttributeValueException {
Value value = ava.getValue();
AttributeType attributeType = ava.getAttributeType();
Value anonymizedValue = valueMap.get(value);
Ava anonymizedAva;
if (anonymizedValue == null) {
Attribute attribute = new DefaultAttribute(attributeType);
attribute.add(value);
Anonymizer anonymizer = attributeAnonymizers.get(attribute.getAttributeType().getOid());
if (value.isHumanReadable()) {
if (anonymizer == null) {
anonymizedAva = new Ava(schemaManager, ava.getType(), value.getValue());
} else {
Attribute anonymizedAttribute = anonymizer.anonymize(valueMap, valueSet, attribute);
anonymizedAva = new Ava(schemaManager, ava.getType(), anonymizedAttribute.getString());
}
} else {
if (anonymizer == null) {
anonymizedAva = new Ava(schemaManager, ava.getType(), value.getBytes());
} else {
Attribute anonymizedAttribute = anonymizer.anonymize(valueMap, valueSet, attribute);
anonymizedAva = new Ava(schemaManager, ava.getType(), anonymizedAttribute.getBytes());
}
}
} else {
if (value.isHumanReadable()) {
anonymizedAva = new Ava(schemaManager, ava.getType(), anonymizedValue.getValue());
} else {
anonymizedAva = new Ava(schemaManager, ava.getType(), anonymizedValue.getBytes());
}
}
return anonymizedAva;
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeSerializationTest method testEntryAttributeNoBinaryValueSerialization.
@Test
public void testEntryAttributeNoBinaryValueSerialization() throws IOException, ClassNotFoundException, LdapInvalidAttributeValueException, LdapInvalidAttributeValueException {
Attribute attribute1 = new DefaultAttribute(userCertificate);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(baos);
attribute1.writeExternal(out);
ObjectInputStream in = null;
byte[] data = baos.toByteArray();
in = new ObjectInputStream(new ByteArrayInputStream(data));
Attribute attribute2 = new DefaultAttribute(userCertificate);
attribute2.readExternal(in);
attribute2.apply(userCertificate);
assertEquals(attribute1, attribute2);
}
Aggregations