Class Schema

  • All Implemented Interfaces:
    java.io.Serializable

    @NotMutable
    @ThreadSafety(level=COMPLETELY_THREADSAFE)
    public final class Schema
    extends java.lang.Object
    implements java.io.Serializable
    This class provides a data structure for representing a directory server subschema subentry. This includes information about the attribute syntaxes, matching rules, attribute types, object classes, name forms, DIT content rules, DIT structure rules, and matching rule uses defined in the server schema.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String ATTR_ATTRIBUTE_SYNTAX
      The name of the attribute used to hold the attribute syntax definitions.
      static java.lang.String ATTR_ATTRIBUTE_TYPE
      The name of the attribute used to hold the attribute type definitions.
      static java.lang.String ATTR_DIT_CONTENT_RULE
      The name of the attribute used to hold the DIT content rule definitions.
      static java.lang.String ATTR_DIT_STRUCTURE_RULE
      The name of the attribute used to hold the DIT structure rule definitions.
      static java.lang.String ATTR_MATCHING_RULE
      The name of the attribute used to hold the matching rule definitions.
      static java.lang.String ATTR_MATCHING_RULE_USE
      The name of the attribute used to hold the matching rule use definitions.
      static java.lang.String ATTR_NAME_FORM
      The name of the attribute used to hold the name form definitions.
      static java.lang.String ATTR_OBJECT_CLASS
      The name of the attribute used to hold the object class definitions.
      static java.lang.String ATTR_SUBSCHEMA_SUBENTRY
      The name of the attribute used to hold the DN of the subschema subentry with the schema information that governs a specified entry.
    • Constructor Summary

      Constructors 
      Constructor Description
      Schema​(Entry schemaEntry)
      Creates a new schema object by decoding the information in the provided entry.
      Schema​(Entry schemaEntry, java.util.Map<java.lang.String,​LDAPException> unparsableAttributeSyntaxes, java.util.Map<java.lang.String,​LDAPException> unparsableMatchingRules, java.util.Map<java.lang.String,​LDAPException> unparsableAttributeTypes, java.util.Map<java.lang.String,​LDAPException> unparsableObjectClasses, java.util.Map<java.lang.String,​LDAPException> unparsableDITContentRules, java.util.Map<java.lang.String,​LDAPException> unparsableDITStructureRules, java.util.Map<java.lang.String,​LDAPException> unparsableNameForms, java.util.Map<java.lang.String,​LDAPException> unparsableMatchingRuleUses)
      Creates a new schema object by decoding the information in the provided entry, optionally capturing any information about unparsable values in the provided maps.
    • Constructor Detail

      • Schema

        public Schema​(@NotNull
                      Entry schemaEntry)
        Creates a new schema object by decoding the information in the provided entry. Any schema elements that cannot be parsed will be silently ignored.
        Parameters:
        schemaEntry - The schema entry to decode. It must not be null.
      • Schema

        public Schema​(@NotNull
                      Entry schemaEntry,
                      @Nullable
                      java.util.Map<java.lang.String,​LDAPException> unparsableAttributeSyntaxes,
                      @Nullable
                      java.util.Map<java.lang.String,​LDAPException> unparsableMatchingRules,
                      @Nullable
                      java.util.Map<java.lang.String,​LDAPException> unparsableAttributeTypes,
                      @Nullable
                      java.util.Map<java.lang.String,​LDAPException> unparsableObjectClasses,
                      @Nullable
                      java.util.Map<java.lang.String,​LDAPException> unparsableDITContentRules,
                      @Nullable
                      java.util.Map<java.lang.String,​LDAPException> unparsableDITStructureRules,
                      @Nullable
                      java.util.Map<java.lang.String,​LDAPException> unparsableNameForms,
                      @Nullable
                      java.util.Map<java.lang.String,​LDAPException> unparsableMatchingRuleUses)
        Creates a new schema object by decoding the information in the provided entry, optionally capturing any information about unparsable values in the provided maps.
        Parameters:
        schemaEntry - The schema entry to decode. It must not be null.
        unparsableAttributeSyntaxes - A map that will be updated with information about any attribute syntax definitions that cannot be parsed. It may be null if unparsable attribute syntax definitions should be silently ignored.
        unparsableMatchingRules - A map that will be updated with information about any matching rule definitions that cannot be parsed. It may be null if unparsable matching rule definitions should be silently ignored.
        unparsableAttributeTypes - A map that will be updated with information about any attribute type definitions that cannot be parsed. It may be null if unparsable attribute type definitions should be silently ignored.
        unparsableObjectClasses - A map that will be updated with information about any object class definitions that cannot be parsed. It may be null if unparsable object class definitions should be silently ignored.
        unparsableDITContentRules - A map that will be updated with information about any DIT content rule definitions that cannot be parsed. It may be null if unparsable DIT content rule definitions should be silently ignored.
        unparsableDITStructureRules - A map that will be updated with information about any DIT structure rule definitions that cannot be parsed. It may be null if unparsable attribute DIT structure rule definitions should be silently ignored.
        unparsableNameForms - A map that will be updated with information about any name form definitions that cannot be parsed. It may be null if unparsable name form definitions should be silently ignored.
        unparsableMatchingRuleUses - A map that will be updated with information about any matching rule use definitions that cannot be parsed. It may be null if unparsable matching rule use definitions should be silently ignored.
    • Method Detail

      • parseSchemaEntry

        @NotNull
        public static Schema parseSchemaEntry​(@NotNull
                                              Entry schemaEntry)
                                       throws LDAPException
        Parses all schema elements contained in the provided entry. This method differs from the Schema(Entry) constructor in that this method will throw an exception if it encounters any unparsable schema elements, while the constructor will silently ignore them. Alternately, the 'constructor that takes a bunch of maps can be used to
        Parameters:
        schemaEntry - The schema entry to parse. It must not be null.
        Returns:
        The schema entry that was parsed.
        Throws:
        LDAPException - If the provided entry contains any schema element definitions that cannot be parsed.
      • getSchema

        @Nullable
        public static Schema getSchema​(@NotNull
                                       LDAPConnection connection)
                                throws LDAPException
        Retrieves the directory server schema over the provided connection. The root DSE will first be retrieved in order to get its subschemaSubentry DN, and then that entry will be retrieved from the server and its contents decoded as schema elements. This should be sufficient for directories that only provide a single schema, but for directories with multiple schemas it may be necessary to specify the DN of an entry for which to retrieve the subschema subentry. Any unparsable schema elements will be silently ignored.
        Parameters:
        connection - The connection to use in order to retrieve the server schema. It must not be null.
        Returns:
        A decoded representation of the server schema.
        Throws:
        LDAPException - If a problem occurs while obtaining the server schema.
      • getSchema

        @Nullable
        public static Schema getSchema​(@NotNull
                                       LDAPConnection connection,
                                       @Nullable
                                       java.lang.String entryDN)
                                throws LDAPException
        Retrieves the directory server schema that governs the specified entry. In some servers, different portions of the DIT may be served by different schemas, and in such cases it will be necessary to provide the DN of the target entry in order to ensure that the appropriate schema which governs that entry is returned. For servers that support only a single schema, any entry DN (including that of the root DSE) should be sufficient. Any unparsable schema elements will be silently ignored.
        Parameters:
        connection - The connection to use in order to retrieve the server schema. It must not be null.
        entryDN - The DN of the entry for which to retrieve the governing schema. It may be null or an empty string in order to retrieve the schema that governs the server's root DSE.
        Returns:
        A decoded representation of the server schema, or null if it is not available for some reason (e.g., the client does not have permission to read the server schema).
        Throws:
        LDAPException - If a problem occurs while obtaining the server schema.
      • getSchema

        @Nullable
        public static Schema getSchema​(@NotNull
                                       LDAPConnection connection,
                                       @Nullable
                                       java.lang.String entryDN,
                                       boolean throwOnUnparsableElement)
                                throws LDAPException
        Retrieves the directory server schema that governs the specified entry. In some servers, different portions of the DIT may be served by different schemas, and in such cases it will be necessary to provide the DN of the target entry in order to ensure that the appropriate schema which governs that entry is returned. For servers that support only a single schema, any entry DN (including that of the root DSE) should be sufficient. This method may optionally throw an exception if the retrieved schema contains one or more unparsable schema elements.
        Parameters:
        connection - The connection to use in order to retrieve the server schema. It must not be null.
        entryDN - The DN of the entry for which to retrieve the governing schema. It may be null or an empty string in order to retrieve the schema that governs the server's root DSE.
        throwOnUnparsableElement - Indicates whether to throw an exception if the schema entry that is retrieved has one or more unparsable schema elements.
        Returns:
        A decoded representation of the server schema, or null if it is not available for some reason (e.g., the client does not have permission to read the server schema).
        Throws:
        LDAPException - If a problem occurs while obtaining the server schema, or if the schema contains one or more unparsable elements and throwOnUnparsableElement is true.
      • getSchema

        @Nullable
        public static Schema getSchema​(@NotNull
                                       java.lang.String... schemaFiles)
                                throws java.io.IOException,
                                       LDIFException
        Reads schema information from one or more files containing the schema represented in LDIF form, with the definitions represented in the form described in section 4.1 of RFC 4512. Each file should contain a single entry. Any unparsable schema elements will be silently ignored.
        Parameters:
        schemaFiles - The paths to the LDIF files containing the schema information to be read. At least one file must be specified. If multiple files are specified, then they will be processed in the order in which they have been listed.
        Returns:
        The schema read from the specified schema files, or null if none of the files contains any LDIF data to be read.
        Throws:
        java.io.IOException - If a problem occurs while attempting to read from any of the specified files.
        LDIFException - If a problem occurs while attempting to parse the contents of any of the schema files.
      • getSchema

        @Nullable
        public static Schema getSchema​(@NotNull
                                       java.io.File... schemaFiles)
                                throws java.io.IOException,
                                       LDIFException
        Reads schema information from one or more files containing the schema represented in LDIF form, with the definitions represented in the form described in section 4.1 of RFC 4512. Each file should contain a single entry. Any unparsable schema elements will be silently ignored.
        Parameters:
        schemaFiles - The paths to the LDIF files containing the schema information to be read. At least one file must be specified. If multiple files are specified, then they will be processed in the order in which they have been listed.
        Returns:
        The schema read from the specified schema files, or null if none of the files contains any LDIF data to be read.
        Throws:
        java.io.IOException - If a problem occurs while attempting to read from any of the specified files.
        LDIFException - If a problem occurs while attempting to parse the contents of any of the schema files.
      • getSchema

        @Nullable
        public static Schema getSchema​(@NotNull
                                       java.util.List<java.io.File> schemaFiles)
                                throws java.io.IOException,
                                       LDIFException
        Reads schema information from one or more files containing the schema represented in LDIF form, with the definitions represented in the form described in section 4.1 of RFC 4512. Each file should contain a single entry. Any unparsable schema elements will be silently ignored.
        Parameters:
        schemaFiles - The paths to the LDIF files containing the schema information to be read. At least one file must be specified. If multiple files are specified, then they will be processed in the order in which they have been listed.
        Returns:
        The schema read from the specified schema files, or null if none of the files contains any LDIF data to be read.
        Throws:
        java.io.IOException - If a problem occurs while attempting to read from any of the specified files.
        LDIFException - If a problem occurs while attempting to parse the contents of any of the schema files.
      • getSchema

        @Nullable
        public static Schema getSchema​(@NotNull
                                       java.util.List<java.io.File> schemaFiles,
                                       boolean throwOnUnparsableElement)
                                throws java.io.IOException,
                                       LDIFException
        Reads schema information from one or more files containing the schema represented in LDIF form, with the definitions represented in the form described in section 4.1 of RFC 4512. Each file should contain a single entry.
        Parameters:
        schemaFiles - The paths to the LDIF files containing the schema information to be read. At least one file must be specified. If multiple files are specified, then they will be processed in the order in which they have been listed.
        throwOnUnparsableElement - Indicates whether to throw an exception if the schema entry that is retrieved has one or more unparsable schema elements.
        Returns:
        The schema read from the specified schema files, or null if none of the files contains any LDIF data to be read.
        Throws:
        java.io.IOException - If a problem occurs while attempting to read from any of the specified files.
        LDIFException - If a problem occurs while attempting to parse the contents of any of the schema files. If throwOnUnparsableElement is true, then this may also be thrown if any of the schema files contains any unparsable schema elements.
      • getSchema

        @Nullable
        public static Schema getSchema​(@NotNull
                                       java.io.InputStream inputStream)
                                throws java.io.IOException,
                                       LDIFException
        Reads schema information from the provided input stream. The information should be in LDIF form, with the definitions represented in the form described in section 4.1 of RFC 4512. Only a single entry will be read from the input stream, and it will be closed at the end of this method.
        Parameters:
        inputStream - The input stream from which the schema entry will be read. It must not be null, and it will be closed when this method returns.
        Returns:
        The schema read from the provided input stream, or null if the end of the input stream is reached without reading any data.
        Throws:
        java.io.IOException - If a problem is encountered while attempting to read from the provided input stream.
        LDIFException - If a problem occurs while attempting to parse the data read as LDIF.
      • getDefaultStandardSchema

        @NotNull
        public static Schema getDefaultStandardSchema()
                                               throws LDAPException
        Retrieves a schema object that contains definitions for a number of standard attribute types and object classes from LDAP-related RFCs and Internet Drafts.
        Returns:
        A schema object that contains definitions for a number of standard attribute types and object classes from LDAP-related RFCs and Internet Drafts.
        Throws:
        LDAPException - If a problem occurs while attempting to obtain or parse the default standard schema definitions.
      • mergeSchemas

        @Nullable
        public static Schema mergeSchemas​(@NotNull
                                          Schema... schemas)
        Retrieves a schema containing all of the elements of each of the provided schemas.
        Parameters:
        schemas - The schemas to be merged. It must not be null or empty.
        Returns:
        A merged representation of the provided schemas.
      • getSubschemaSubentryDN

        @Nullable
        public static java.lang.String getSubschemaSubentryDN​(@NotNull
                                                              LDAPConnection connection,
                                                              @Nullable
                                                              java.lang.String entryDN)
                                                       throws LDAPException
        Retrieves the value of the subschemaSubentry attribute from the specified entry using the provided connection.
        Parameters:
        connection - The connection to use in order to perform the search. It must not be null.
        entryDN - The DN of the entry from which to retrieve the subschemaSubentry attribute. It may be null or an empty string in order to retrieve the value from the server's root DSE.
        Returns:
        The value of the subschemaSubentry attribute from the specified entry, or null if it is not available for some reason (e.g., the client does not have permission to read the target entry or the subschemaSubentry attribute).
        Throws:
        LDAPException - If a problem occurs while attempting to retrieve the specified entry.
      • getAttributeSyntaxes

        @NotNull
        public java.util.Set<AttributeSyntaxDefinitiongetAttributeSyntaxes()
        Retrieves the set of attribute syntax definitions contained in the server schema.
        Returns:
        The set of attribute syntax definitions contained in the server schema.
      • getAttributeSyntax

        @Nullable
        public AttributeSyntaxDefinition getAttributeSyntax​(@NotNull
                                                            java.lang.String oid)
        Retrieves the attribute syntax with the specified OID from the server schema.
        Parameters:
        oid - The OID of the attribute syntax to retrieve. It must not be null. It may optionally include a minimum upper bound (as may appear when the syntax OID is included in an attribute type definition), but if it does then that portion will be ignored when retrieving the attribute syntax.
        Returns:
        The requested attribute syntax, or null if there is no such syntax defined in the server schema.
      • getAttributeTypes

        @NotNull
        public java.util.Set<AttributeTypeDefinitiongetAttributeTypes()
        Retrieves the set of attribute type definitions contained in the server schema.
        Returns:
        The set of attribute type definitions contained in the server schema.
      • getOperationalAttributeTypes

        @NotNull
        public java.util.Set<AttributeTypeDefinitiongetOperationalAttributeTypes()
        Retrieves the set of operational attribute type definitions (i.e., those definitions with a usage of directoryOperation, distributedOperation, or dSAOperation) contained in the server schema.
        Returns:
        The set of operational attribute type definitions contained in the server schema.
      • getUserAttributeTypes

        @NotNull
        public java.util.Set<AttributeTypeDefinitiongetUserAttributeTypes()
        Retrieves the set of user attribute type definitions (i.e., those definitions with a usage of userApplications) contained in the server schema.
        Returns:
        The set of user attribute type definitions contained in the server schema.
      • getAttributeType

        @Nullable
        public AttributeTypeDefinition getAttributeType​(@NotNull
                                                        java.lang.String name)
        Retrieves the attribute type with the specified name or OID from the server schema.
        Parameters:
        name - The name or OID of the attribute type to retrieve. It must not be null.
        Returns:
        The requested attribute type, or null if there is no such attribute type defined in the server schema.
      • getSubordinateAttributeTypes

        @NotNull
        public java.util.List<AttributeTypeDefinitiongetSubordinateAttributeTypes​(@NotNull
                                                                                    AttributeTypeDefinition d)
        Retrieves a list of all subordinate attribute type definitions for the provided attribute type definition.
        Parameters:
        d - The attribute type definition for which to retrieve all subordinate attribute types. It must not be null.
        Returns:
        A list of all subordinate attribute type definitions for the provided attribute type definition, or an empty list if it does not have any subordinate types or the provided attribute type is not defined in the schema.
      • getDITContentRules

        @NotNull
        public java.util.Set<DITContentRuleDefinitiongetDITContentRules()
        Retrieves the set of DIT content rule definitions contained in the server schema.
        Returns:
        The set of DIT content rule definitions contained in the server schema.
      • getDITContentRule

        @Nullable
        public DITContentRuleDefinition getDITContentRule​(@NotNull
                                                          java.lang.String name)
        Retrieves the DIT content rule with the specified name or OID from the server schema.
        Parameters:
        name - The name or OID of the DIT content rule to retrieve. It must not be null.
        Returns:
        The requested DIT content rule, or null if there is no such rule defined in the server schema.
      • getDITStructureRules

        @NotNull
        public java.util.Set<DITStructureRuleDefinitiongetDITStructureRules()
        Retrieves the set of DIT structure rule definitions contained in the server schema.
        Returns:
        The set of DIT structure rule definitions contained in the server schema.
      • getDITStructureRuleByID

        @Nullable
        public DITStructureRuleDefinition getDITStructureRuleByID​(int ruleID)
        Retrieves the DIT content rule with the specified rule ID from the server schema.
        Parameters:
        ruleID - The rule ID for the DIT structure rule to retrieve.
        Returns:
        The requested DIT structure rule, or null if there is no such rule defined in the server schema.
      • getDITStructureRuleByName

        @Nullable
        public DITStructureRuleDefinition getDITStructureRuleByName​(@NotNull
                                                                    java.lang.String ruleName)
        Retrieves the DIT content rule with the specified name from the server schema.
        Parameters:
        ruleName - The name of the DIT structure rule to retrieve. It must not be null.
        Returns:
        The requested DIT structure rule, or null if there is no such rule defined in the server schema.
      • getDITStructureRuleByNameForm

        @Nullable
        public DITStructureRuleDefinition getDITStructureRuleByNameForm​(@NotNull
                                                                        java.lang.String nameForm)
        Retrieves the DIT content rule associated with the specified name form from the server schema.
        Parameters:
        nameForm - The name or OID of the name form for which to retrieve the associated DIT structure rule.
        Returns:
        The requested DIT structure rule, or null if there is no such rule defined in the server schema.
      • getMatchingRules

        @NotNull
        public java.util.Set<MatchingRuleDefinitiongetMatchingRules()
        Retrieves the set of matching rule definitions contained in the server schema.
        Returns:
        The set of matching rule definitions contained in the server schema.
      • getMatchingRule

        @Nullable
        public MatchingRuleDefinition getMatchingRule​(@NotNull
                                                      java.lang.String name)
        Retrieves the matching rule with the specified name or OID from the server schema.
        Parameters:
        name - The name or OID of the matching rule to retrieve. It must not be null.
        Returns:
        The requested matching rule, or null if there is no such rule defined in the server schema.
      • getMatchingRuleUses

        @NotNull
        public java.util.Set<MatchingRuleUseDefinitiongetMatchingRuleUses()
        Retrieves the set of matching rule use definitions contained in the server schema.
        Returns:
        The set of matching rule use definitions contained in the server schema.
      • getMatchingRuleUse

        @Nullable
        public MatchingRuleUseDefinition getMatchingRuleUse​(@NotNull
                                                            java.lang.String name)
        Retrieves the matching rule use with the specified name or OID from the server schema.
        Parameters:
        name - The name or OID of the matching rule use to retrieve. It must not be null.
        Returns:
        The requested matching rule, or null if there is no such matching rule use defined in the server schema.
      • getNameForms

        @NotNull
        public java.util.Set<NameFormDefinitiongetNameForms()
        Retrieves the set of name form definitions contained in the server schema.
        Returns:
        The set of name form definitions contained in the server schema.
      • getNameFormByName

        @Nullable
        public NameFormDefinition getNameFormByName​(@NotNull
                                                    java.lang.String name)
        Retrieves the name form with the specified name or OID from the server schema.
        Parameters:
        name - The name or OID of the name form to retrieve. It must not be null.
        Returns:
        The requested name form, or null if there is no such rule defined in the server schema.
      • getNameFormByObjectClass

        @NotNull
        public NameFormDefinition getNameFormByObjectClass​(@NotNull
                                                           java.lang.String objectClass)
        Retrieves the name form associated with the specified structural object class from the server schema.
        Parameters:
        objectClass - The name or OID of the structural object class for which to retrieve the associated name form. It must not be null.
        Returns:
        The requested name form, or null if there is no such rule defined in the server schema.
      • getObjectClasses

        @NotNull
        public java.util.Set<ObjectClassDefinitiongetObjectClasses()
        Retrieves the set of object class definitions contained in the server schema.
        Returns:
        The set of object class definitions contained in the server schema.
      • getAbstractObjectClasses

        @NotNull
        public java.util.Set<ObjectClassDefinitiongetAbstractObjectClasses()
        Retrieves the set of abstract object class definitions contained in the server schema.
        Returns:
        The set of abstract object class definitions contained in the server schema.
      • getAuxiliaryObjectClasses

        @NotNull
        public java.util.Set<ObjectClassDefinitiongetAuxiliaryObjectClasses()
        Retrieves the set of auxiliary object class definitions contained in the server schema.
        Returns:
        The set of auxiliary object class definitions contained in the server schema.
      • getStructuralObjectClasses

        @NotNull
        public java.util.Set<ObjectClassDefinitiongetStructuralObjectClasses()
        Retrieves the set of structural object class definitions contained in the server schema.
        Returns:
        The set of structural object class definitions contained in the server schema.
      • getObjectClass

        @Nullable
        public ObjectClassDefinition getObjectClass​(@NotNull
                                                    java.lang.String name)
        Retrieves the object class with the specified name or OID from the server schema.
        Parameters:
        name - The name or OID of the object class to retrieve. It must not be null.
        Returns:
        The requested object class, or null if there is no such class defined in the server schema.
      • hashCode

        public int hashCode()
        Retrieves a hash code for this schema object.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        A hash code for this schema object.
      • equals

        public boolean equals​(@Nullable
                              java.lang.Object o)
        Indicates whether the provided object is equal to this schema object.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        o - The object for which to make the determination.
        Returns:
        true if the provided object is equal to this schema object, or false if not.
      • toString

        @NotNull
        public java.lang.String toString()
        Retrieves a string representation of the associated schema entry.
        Overrides:
        toString in class java.lang.Object
        Returns:
        A string representation of the associated schema entry.