use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.
the class StoreSearchResultAttributeValue method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<SearchResultEntryDecorator> container) {
SearchResultEntryDecorator searchResultEntry = container.getMessage();
TLV tlv = container.getCurrentTLV();
// Store the value
Object value = null;
try {
if (tlv.getLength() == 0) {
searchResultEntry.addAttributeValue("");
LOG.debug("The attribute value is null");
} else {
if (container.isBinary(searchResultEntry.getCurrentAttribute().getId())) {
value = tlv.getValue().getData();
if (IS_DEBUG) {
LOG.debug("Attribute value {}", Strings.dumpBytes((byte[]) value));
}
} else {
value = Strings.utf8ToString(tlv.getValue().getData());
LOG.debug("Attribute value {}", value);
}
searchResultEntry.addAttributeValue(value);
}
} catch (LdapException le) {
// Just swallow the exception, it can't occur here
}
// We can have an END transition
container.setGrammarEndAllowed(true);
}
use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.
the class AttributeUtils method toEntry.
/**
* Convert a BasicAttributes or a AttributesImpl to an Entry
*
* @param attributes the BasicAttributes or AttributesImpl instance to convert
* @param dn The Dn which is needed by the Entry
* @return An instance of a Entry object
*
* @throws LdapException If we get an invalid attribute
*/
public static Entry toEntry(Attributes attributes, Dn dn) throws LdapException {
if (attributes instanceof BasicAttributes) {
try {
Entry entry = new DefaultEntry(dn);
for (NamingEnumeration<? extends javax.naming.directory.Attribute> attrs = attributes.getAll(); attrs.hasMoreElements(); ) {
javax.naming.directory.Attribute attr = attrs.nextElement();
Attribute entryAttribute = toApiAttribute(attr);
if (entryAttribute != null) {
entry.put(entryAttribute);
}
}
return entry;
} catch (LdapException ne) {
throw new LdapInvalidAttributeTypeException(ne.getMessage(), ne);
}
} else {
return null;
}
}
use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.
the class DefaultAttribute method isValid.
/**
* {@inheritDoc}
*/
@Override
public boolean isValid(AttributeType attributeType) throws LdapInvalidAttributeValueException {
LdapSyntax syntax = attributeType.getSyntax();
if (syntax == null) {
return false;
}
SyntaxChecker syntaxChecker = syntax.getSyntaxChecker();
if (syntaxChecker == null) {
return false;
}
// Check that we can have no value for this attributeType
if (values.isEmpty()) {
return syntaxChecker.isValidSyntax(null);
}
// Check that we can't have more than one value if the AT is single-value
if ((attributeType.isSingleValued()) && (values.size() > 1)) {
return false;
}
// Now check the values
for (Value value : values) {
try {
if (!value.isValid(syntaxChecker)) {
return false;
}
} catch (LdapException le) {
return false;
}
}
return true;
}
use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.
the class DefaultEntry method put.
/**
* {@inheritDoc}
*/
public Attribute put(String upId, AttributeType attributeType, byte[]... values) throws LdapException {
if (attributeType == null) {
try {
attributeType = getAttributeType(upId);
} catch (Exception e) {
String message = I18n.err(I18n.ERR_13231_NO_VALID_AT_FOR_THIS_ID);
LOG.error(message);
throw new IllegalArgumentException(message, e);
}
} else {
if (!Strings.isEmpty(upId)) {
AttributeType tempAT = getAttributeType(upId);
if (!tempAT.equals(attributeType)) {
String message = I18n.err(I18n.ERR_13229_ID_INCOMPATIBLE_WITH_AT, upId, attributeType);
LOG.error(message);
throw new IllegalArgumentException(message);
}
} else {
upId = getUpId(upId, attributeType);
}
}
if (attributeType.equals(objectClassAttributeType)) {
String message = I18n.err(I18n.ERR_13227_NON_STRING_VALUE_NOT_ALLOWED);
LOG.error(message);
throw new UnsupportedOperationException(message);
}
Attribute attribute = new DefaultAttribute(upId, attributeType, values);
return attributes.put(attributeType.getOid(), attribute);
}
use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.
the class DefaultEntry method removeAttributes.
/**
* {@inheritDoc}
*/
@Override
public void removeAttributes(String... attributes) {
if (attributes.length == 0) {
return;
}
if (schemaManager == null) {
for (String attribute : attributes) {
Attribute attr = get(attribute);
if (attr != null) {
this.attributes.remove(attr.getId());
} else {
String message = I18n.err(I18n.ERR_13218_AT_DOES_NOT_EXIST, attribute);
LOG.warn(message);
continue;
}
}
} else {
for (String attribute : attributes) {
AttributeType attributeType = null;
try {
attributeType = schemaManager.lookupAttributeTypeRegistry(attribute);
} catch (LdapException ne) {
LOG.warn(I18n.msg(I18n.MSG_13203_MISSING_ATTRIBUTE_IN_ENTRY, attribute));
continue;
}
this.attributes.remove(attributeType.getOid());
}
}
}
Aggregations