use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.
the class DefaultAttributeTypeRegistry method unregister.
/**
* {@inheritDoc}
*/
@Override
public AttributeType unregister(String numericOid) throws LdapException {
try {
AttributeType removed = super.unregister(numericOid);
removeMappingFor(removed);
// Deleting an AT which might be used as a superior means we have
// to recursively update the descendant map. We also have to remove
// the at.oid -> descendant relation
oidToDescendantSet.remove(numericOid);
// Now recurse if needed
unregisterDescendants(removed, removed.getSuperior());
return removed;
} catch (LdapException ne) {
throw new LdapNoSuchAttributeException(ne.getMessage(), ne);
}
}
use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.
the class OpenLdapSchemaParser method afterParse.
/**
* Splits parsed schema descriptions and resolved
* object identifier macros.
*
* @throws ParseException the parse exception
*/
private void afterParse() throws ParseException {
objectClasses = new ArrayList<>();
attributeTypes = new ArrayList<>();
objectIdentifierMacros = new HashMap<>();
// split parsed schema descriptions
for (Object obj : schemaDescriptions) {
if (obj instanceof OpenLdapObjectIdentifierMacro) {
OpenLdapObjectIdentifierMacro oid = (OpenLdapObjectIdentifierMacro) obj;
objectIdentifierMacros.put(oid.getName(), oid);
} else if (obj instanceof AttributeType) {
MutableAttributeType attributeType = (MutableAttributeType) obj;
attributeTypes.add(attributeType);
} else if (obj instanceof ObjectClass) {
ObjectClass objectClass = (ObjectClass) obj;
objectClasses.add(objectClass);
}
}
if (isResolveObjectIdentifierMacros()) {
// resolve object identifier macros
for (OpenLdapObjectIdentifierMacro oid : objectIdentifierMacros.values()) {
resolveObjectIdentifierMacro(oid);
}
// apply object identifier macros to object classes
for (ObjectClass objectClass : objectClasses) {
objectClass.setOid(getResolveOid(objectClass.getOid()));
}
// apply object identifier macros to attribute types
for (MutableAttributeType attributeType : attributeTypes) {
attributeType.setOid(getResolveOid(attributeType.getOid()));
attributeType.setSyntaxOid(getResolveOid(attributeType.getSyntaxOid()));
}
}
}
use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.
the class SchemaBinaryAttributeDetector method isBinary.
/**
* {@inheritDoc}
*/
@Override
public boolean isBinary(String attributeId) {
String attrId = Strings.toLowerCaseAscii(attributeId);
if (attrId.endsWith(";binary")) {
return true;
}
if (schemaManager != null) {
AttributeType attributeType = schemaManager.getAttributeType(attrId);
if (attributeType == null) {
return false;
}
LdapSyntax ldapSyntax = attributeType.getSyntax();
return (ldapSyntax != null) && !ldapSyntax.isHumanReadable();
}
return false;
}
use of org.apache.directory.api.ldap.model.schema.AttributeType 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.schema.AttributeType 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