Search in sources :

Example 1 with ObjectClassDefinition

use of com.unboundid.ldap.sdk.schema.ObjectClassDefinition in project zm-mailbox by Zimbra.

the class UBIDLdapSchema method getObjectClasses.

@Override
public List<ZObjectClassDefinition> getObjectClasses() throws LdapException {
    List<ZObjectClassDefinition> ocList = new ArrayList<ZObjectClassDefinition>();
    Set<ObjectClassDefinition> ocs = schema.getObjectClasses();
    for (ObjectClassDefinition oc : ocs) {
        UBIDObjectClassDefinition ubidOC = new UBIDObjectClassDefinition(oc);
        ocList.add(ubidOC);
    }
    Comparator comparator = new Comparator<UBIDObjectClassDefinition>() {

        public int compare(UBIDObjectClassDefinition first, UBIDObjectClassDefinition second) {
            return first.getName().compareTo(second.getName());
        }
    };
    Collections.sort(ocList, comparator);
    return ocList;
}
Also used : ArrayList(java.util.ArrayList) ObjectClassDefinition(com.unboundid.ldap.sdk.schema.ObjectClassDefinition) Comparator(java.util.Comparator)

Example 2 with ObjectClassDefinition

use of com.unboundid.ldap.sdk.schema.ObjectClassDefinition in project oxCore by GluuFederation.

the class SchemaService method getObjectClassesByAttribute.

/**
 * Determine object classes by attribute name
 *
 * @param schemaEntry
 *            Schema
 * @param OBJECT_CLASS
 *            Object class name
 * @return List of object classes
 */
public Set<String> getObjectClassesByAttribute(SchemaEntry schemaEntry, String attributeType) {
    if ((schemaEntry == null) || StringHelper.isEmpty(attributeType)) {
        return null;
    }
    String lowerCaseAttributeType = StringHelper.toLowerCase(attributeType);
    Set<String> resultObjectClasses = new HashSet<String>();
    for (String objectClassDefinition : schemaEntry.getObjectClasses()) {
        ObjectClassDefinition definition;
        try {
            definition = new ObjectClassDefinition(objectClassDefinition);
            Set<String> objectClassAttributeTypes = new HashSet<String>();
            for (String name : definition.getOptionalAttributes()) {
                objectClassAttributeTypes.add(StringHelper.toLowerCase(name));
            }
            for (String name : definition.getRequiredAttributes()) {
                objectClassAttributeTypes.add(StringHelper.toLowerCase(name));
            }
            if (objectClassAttributeTypes.contains(lowerCaseAttributeType)) {
                String objectClassType = definition.getNameOrOID();
                resultObjectClasses.add(objectClassType);
            }
        } catch (Exception ex) {
            log.error("Failed to parse LDAP object class definition: '{}'", ex, objectClassDefinition);
        }
    }
    return resultObjectClasses;
}
Also used : InvalidSchemaUpdateException(org.xdi.util.exception.InvalidSchemaUpdateException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) ObjectClassDefinition(com.unboundid.ldap.sdk.schema.ObjectClassDefinition)

Example 3 with ObjectClassDefinition

use of com.unboundid.ldap.sdk.schema.ObjectClassDefinition in project oxCore by GluuFederation.

the class SchemaService method getObjectClassesAttributes.

/**
 * Get all attribute names by specified object classes
 *
 * @param schemaEntry
 *            Schema
 * @param OBJECT_CLASS
 *            Object class name
 * @return Object class schema definition string
 */
public Set<String> getObjectClassesAttributes(SchemaEntry schemaEntry, String[] objectClasses) {
    if ((schemaEntry == null) || (objectClasses == null)) {
        return null;
    }
    Map<String, ObjectClassDefinition> objectClassDefinitions = new HashMap<String, ObjectClassDefinition>();
    for (String objectClassDefinition : schemaEntry.getObjectClasses()) {
        ObjectClassDefinition definition;
        try {
            definition = new ObjectClassDefinition(objectClassDefinition);
            for (String name : definition.getNames()) {
                objectClassDefinitions.put(StringHelper.toLowerCase(name), definition);
            }
        } catch (Exception ex) {
            log.error("Failed to parse LDAP object class definition: '{}'", ex, objectClassDefinition);
        }
    }
    Set<ObjectClassDefinition> resultObjectClassDefinitions = getSuperiorClasses(objectClassDefinitions, objectClasses, true);
    Set<String> resultAttributes = getAttributes(resultObjectClassDefinitions, true, true);
    return resultAttributes;
}
Also used : HashMap(java.util.HashMap) InvalidSchemaUpdateException(org.xdi.util.exception.InvalidSchemaUpdateException) ObjectClassDefinition(com.unboundid.ldap.sdk.schema.ObjectClassDefinition)

Example 4 with ObjectClassDefinition

use of com.unboundid.ldap.sdk.schema.ObjectClassDefinition in project oxCore by GluuFederation.

the class SchemaService method getSuperiorClasses.

private static void getSuperiorClasses(final Map<String, ObjectClassDefinition> objectClassDefinitions, final ObjectClassDefinition objectClassDefinition, final Set<ObjectClassDefinition> resultObjectClassDefinitions) {
    for (final String superiorClass : objectClassDefinition.getSuperiorClasses()) {
        final ObjectClassDefinition superiorObjectClassDefinition = objectClassDefinitions.get(StringHelper.toLowerCase(superiorClass));
        if (superiorObjectClassDefinition != null) {
            resultObjectClassDefinitions.add(superiorObjectClassDefinition);
            getSuperiorClasses(objectClassDefinitions, superiorObjectClassDefinition, resultObjectClassDefinitions);
        }
    }
}
Also used : ObjectClassDefinition(com.unboundid.ldap.sdk.schema.ObjectClassDefinition)

Aggregations

ObjectClassDefinition (com.unboundid.ldap.sdk.schema.ObjectClassDefinition)4 InvalidSchemaUpdateException (org.xdi.util.exception.InvalidSchemaUpdateException)2 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1