Class LDAPSchema
- java.lang.Object
-
- netscape.ldap.LDAPSchema
-
- All Implemented Interfaces:
java.io.Serializable
public class LDAPSchema extends java.lang.Object implements java.io.SerializableThis object represents the schema of an LDAP v3 server. You can use thefetchSchemamethod to retrieve the schema used by a server. (The server must support LDAP v3 and the capability to retrieve the schema over the LDAP protocol.)After you retrieve the schema, you can use this object to get the object class, attribute type, and matching rule descriptions in the schema. You can also add your own object classes, attribute types, and matching rules to the schema.
To remove any object classes, attribute types, and matching rules that you added, call the
removemethods of theLDAPObjectClassSchema,LDAPAttributeSchema, andLDAPMatchingRuleSchemaclasses. (This method is inherited from theLDAPSchemaElementclass.)The following class is an example of an LDAP client that can fetch the schema, get and print object class descriptions and attribute type descriptions, and add object classes and attribute types to the schema over the LDAP protocol.
import netscape.ldap.*; public class TestSchema { public static void main( String[] args ) { String HOSTNAME = "ldap.netscape.com"; int PORT_NUMBER = DEFAULT_PORT; String ROOT_DN = "cn=Directory Manager"; String ROOT_PASSWORD = "23skidoo"; LDAPConnection ld = new LDAPConnection(); // Construct a newIf you are using the Netscape Directory Server 3.0, you can also verify that the class and attribute type have been added through the directory server manager (go to Schema | Edit or View Attributes or Schema | Edit or View Object Classes).LDAPSchemaobject to get the schema. LDAPSchema dirSchema = new LDAPSchema(); try { // Connect to the server. ld.connect( HOSTNAME, PORT_NUMBER ); // Get the schema from the directory. dirSchema.fetchSchema( ld ); // Get and print the inetOrgPerson object class description. LDAPObjectClassSchema objClass = dirSchema.getObjectClass( "inetOrgPerson" ); if ( objClass != null ) { System.out.println("inetOrgPerson := "+objClass.toString()); } // Get and print the definition of the userPassword attribute. LDAPAttributeSchema attrType = dirSchema.getAttribute( "userpassword" ); if ( attrType != null ) { System.out.println("userPassword := " + attrType.toString()); } // Create a new object class definition. String[] requiredAttrs = {"cn", "mail"}; String[] optionalAttrs = {"sn", "phoneNumber"}; LDAPObjectClassSchema newObjClass = new LDAPObjectClassSchema( "newInetOrgPerson", "1.2.3.4.5.6.7", "top", "Experiment", requiredAttrs, optionalAttrs ); // Authenticate as root DN to get permissions to edit the schema. ld.authenticate( ROOT_DN, ROOT_PASSWORD ); // Add the new object class to the schema. newObjClass.add( ld ); // Create a new attribute type "hairColor". LDAPAttributeSchema newAttrType = new LDAPAttributeSchema( "hairColor", "1.2.3.4.5.4.3.2.1", "Blonde, red, etc", LDAPAttributeSchema.cis, false ); // Add a custom qualifier newObjClass.setQualifier( "X-OWNER", "John Jacobson" ); // Add the new attribute type to the schema. newAttrType.add( ld ); // Fetch the schema again to verify that changes were made. dirSchema.fetchSchema( ld ); // Get and print the new attribute type. newAttrType = dirSchema.getAttribute( "hairColor" ); if ( newAttrType != null ) { System.out.println("hairColor := " + newAttrType.toString()); } // Get and print the new object class. newObjClass = dirSchema.getObjectClass( "newInetOrgPerson" ); if ( newObjClass != null ) { System.out.println("newInetOrgPerson := " +newObjClass.toString()); } ld.disconnect(); } catch ( Exception e ) { System.err.println( e.toString() ); System.exit( 1 ); } System.exit( 0 ); } }To remove the classes and attribute types added by the example, see the examples under the
LDAPSchemaElementclass.- Version:
- 1.0
- Author:
- Rob Weltman
- See Also:
LDAPAttributeSchema,LDAPObjectClassSchema,LDAPMatchingRuleSchema,LDAPSchemaElement, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description LDAPSchema()Constructs a newLDAPSchemaobject.LDAPSchema(LDAPEntry entry)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAttribute(LDAPAttributeSchema attrSchema)Add an attribute type schema definition to the current schema.voidaddDITContentRule(LDAPDITContentRuleSchema rule)Add a content rule definition to the current schema.voidaddDITStructureRule(LDAPDITStructureRuleSchema rule)Add a structure rule definition to the current schema.voidaddMatchingRule(LDAPMatchingRuleSchema matchSchema)Add a matching rule schema definition to the current schema.voidaddNameForm(LDAPNameFormSchema nameForm)Add a name form definition to the current schema.voidaddObjectClass(LDAPObjectClassSchema objectSchema)Adds an object class schema definition to the current schema.voidaddSyntax(LDAPSyntaxSchema syntaxSchema)Add a syntax schema definition to the current schema.voidfetchSchema(LDAPConnection ld)Retrieve the entire schema from the root of a Directory Server.voidfetchSchema(LDAPConnection ld, java.lang.String dn)Retrieve the schema for a specific entry.LDAPAttributeSchemagetAttribute(java.lang.String name)Gets the definition of the attribute type with the specified name.java.util.Enumeration<java.lang.String>getAttributeNames()Get an enumeration of the names of the attribute types in this schema.java.util.Enumeration<LDAPAttributeSchema>getAttributes()Gets an enumeration ofthe attribute type definitions in this schema.LDAPDITContentRuleSchemagetDITContentRule(java.lang.String name)Gets the definition of a content rule with the specified name.java.util.Enumeration<java.lang.String>getDITContentRuleNames()Get an enumeration of the names of the content rules in this schema.java.util.Enumeration<LDAPDITContentRuleSchema>getDITContentRules()Get an enumeration of the content rules in this schema.LDAPDITStructureRuleSchemagetDITStructureRule(int ID)Gets the definition of a structure rule with the specified name.LDAPDITStructureRuleSchemagetDITStructureRule(java.lang.String name)Gets the definition of a structure rule with the specified name.java.util.Enumeration<java.lang.String>getDITStructureRuleNames()Get an enumeration of the names of the structure rules in this schema.java.util.Enumeration<LDAPDITStructureRuleSchema>getDITStructureRules()Get an enumeration of the structure rules in this schema.LDAPMatchingRuleSchemagetMatchingRule(java.lang.String name)Gets the definition of a matching rule with the specified name.java.util.Enumeration<java.lang.String>getMatchingRuleNames()Get an enumeration of the names of the matching rules in this schema.java.util.Enumeration<LDAPMatchingRuleSchema>getMatchingRules()Gets an enumeration ofthe matching rule definitions in this schema.LDAPNameFormSchemagetNameForm(java.lang.String name)Gets the definition of a name form with the specified name.java.util.Enumeration<java.lang.String>getNameFormNames()Get an enumeration of the names of the name forms in this schema.java.util.Enumeration<LDAPNameFormSchema>getNameForms()Get an enumeration of the name forms in this schema.LDAPObjectClassSchemagetObjectClass(java.lang.String name)Gets the definition of the object class with the specified name.java.util.Enumeration<LDAPObjectClassSchema>getObjectClasses()Gets an enumeration ofthe object class definitions in this schema.java.util.Enumeration<java.lang.String>getObjectClassNames()Get an enumeration of the names of the object classes in this schema.LDAPSyntaxSchemagetSyntax(java.lang.String name)Gets the definition of a syntax with the specified name.java.util.Enumeration<LDAPSyntaxSchema>getSyntaxes()Get an enumeration of the syntaxes in this schema.java.util.Enumeration<java.lang.String>getSyntaxNames()Get an enumeration of the names of the syntaxes in this schema.protected voidinitialize(LDAPEntry entry)Extract all schema elements from subschema entrystatic voidmain(java.lang.String[] args)Fetch the schema from the LDAP server at the specified host and port, and print out the schema (including descriptions of its object classes, attribute types, and matching rules).java.lang.StringtoString()Displays the schema (including the descriptions of its object classes, attribute types, and matching rules) in an easily readable format (not the same as the format expected by an LDAP server).
-
-
-
Constructor Detail
-
LDAPSchema
public LDAPSchema()
Constructs a newLDAPSchemaobject. Once you construct the object, you can get the schema by callingfetchSchema.You can also print out the schema by using the
mainmethod. For example, you can enter the following command:java netscape.ldap.LDAPSchema myhost.mydomain.com 389
Note that you need to callfetchSchemato get the schema from the server. Constructing the object does not fetch the schema.
-
LDAPSchema
public LDAPSchema(LDAPEntry entry)
-
-
Method Detail
-
addObjectClass
public void addObjectClass(LDAPObjectClassSchema objectSchema)
Adds an object class schema definition to the current schema. You can also add object class schema definitions by calling theaddmethod of your newly constructedLDAPObjectClassSchemaobject.To remove an object class schema definition that you have added, call the
getObjectClassmethod to get theLDAPObjectClassSchemaobject representing your object class and call theremovemethod.NOTE: For information on the
addandremovemethods ofLDAPObjectClassSchema, see the documentation forLDAPSchemaElement. (These methods are inherited fromLDAPSchemaElement.)- Parameters:
objectSchema-LDAPObjectClassSchemaobject representing the object class schema definition to add- See Also:
LDAPObjectClassSchema,LDAPSchemaElement.add(netscape.ldap.LDAPConnection, java.lang.String),LDAPSchemaElement.remove(netscape.ldap.LDAPConnection, java.lang.String)
-
addAttribute
public void addAttribute(LDAPAttributeSchema attrSchema)
Add an attribute type schema definition to the current schema. You can also add attribute type schema definitions by calling theaddmethod of your newly constructedLDAPAttributeSchemaobject.To remove an attribute type schema definition that you have added, call the
getAttributemethod to get theLDAPAttributeSchemaobject representing your attribute type and call theremovemethod.NOTE: For information on the
addandremovemethods ofLDAPAttributeSchema, see the documentation forLDAPSchemaElement. (These methods are inherited fromLDAPSchemaElement.)- Parameters:
attrSchema-LDAPAttributeSchemaobject representing the attribute type schema definition to add- See Also:
LDAPAttributeSchema,LDAPSchemaElement.add(netscape.ldap.LDAPConnection, java.lang.String),LDAPSchemaElement.remove(netscape.ldap.LDAPConnection, java.lang.String)
-
addMatchingRule
public void addMatchingRule(LDAPMatchingRuleSchema matchSchema)
Add a matching rule schema definition to the current schema. You can also add matching rule schema definitions by calling theaddmethod of your newly constructedLDAPMatchingRuleSchemaobject.To remove an attribute type schema definition that you have added, call the
getMatchingRulemethod to get theLDAPMatchingRuleSchemaobject representing your matching rule and call theremovemethod.NOTE: For information on the
addandremovemethods ofLDAPMatchingRuleSchema, see the documentation forLDAPSchemaElement. (These methods are inherited fromLDAPSchemaElement.)- Parameters:
matchSchema-LDAPMatchingRuleSchemaobject representing the matching rule schema definition to add- See Also:
LDAPMatchingRuleSchema,LDAPSchemaElement.add(netscape.ldap.LDAPConnection, java.lang.String),LDAPSchemaElement.remove(netscape.ldap.LDAPConnection, java.lang.String)
-
addSyntax
public void addSyntax(LDAPSyntaxSchema syntaxSchema)
Add a syntax schema definition to the current schema. You can also add syntax schema definitions by calling theaddmethod of your newly constructedLDAPSyntaxSchemaobject.To remove a syntax schema definition that you have added, call the
getSyntaxmethod to get theLDAPSyntaxSchemaobject representing your syntax type and call theremovemethod.NOTE: For information on the
addandremovemethods ofLDAPSyntaxSchema, see the documentation forLDAPSchemaElement. (These methods are inherited fromLDAPSchemaElement.)- Parameters:
syntaxSchema-LDAPSyntaxSchemaobject representing the syntax schema definition to add- See Also:
LDAPSyntaxSchema,LDAPSchemaElement.add(netscape.ldap.LDAPConnection, java.lang.String),LDAPSchemaElement.remove(netscape.ldap.LDAPConnection, java.lang.String)
-
addDITStructureRule
public void addDITStructureRule(LDAPDITStructureRuleSchema rule)
Add a structure rule definition to the current schema. You can also add structure rule definitions by calling theaddmethod of your newly constructedLDAPDITStructureRuleSchemaobject.To remove a structure rule definition that you have added, call the
getDITStructureRulemethod to get theLDAPDITStructureRuleSchemaobject representing your rule and call theremovemethod.NOTE: For information on the
addandremovemethods ofLDAPSyntaxSchema, see the documentation forLDAPSchemaElement. (These methods are inherited fromLDAPSchemaElement.)- Parameters:
rule-LDAPDITStructureRuleSchemaobject representing the structure rule definition to add- See Also:
LDAPDITStructureRuleSchema,LDAPSchemaElement.add(netscape.ldap.LDAPConnection, java.lang.String),LDAPSchemaElement.remove(netscape.ldap.LDAPConnection, java.lang.String)
-
addDITContentRule
public void addDITContentRule(LDAPDITContentRuleSchema rule)
Add a content rule definition to the current schema. You can also add content rule definitions by calling theaddmethod of your newly constructedLDAPDITContentRuleSchemaobject.To remove a content rule definition that you have added, call the
getDITContentRulemethod to get theLDAPDITContentRuleSchemaobject representing your rule and call theremovemethod.NOTE: For information on the
addandremovemethods ofLDAPSyntaxSchema, see the documentation forLDAPSchemaElement. (These methods are inherited fromLDAPSchemaElement.)- Parameters:
rule-LDAPDITContentRuleSchemaobject representing the content rule definition to add- See Also:
LDAPDITContentRuleSchema,LDAPSchemaElement.add(netscape.ldap.LDAPConnection, java.lang.String),LDAPSchemaElement.remove(netscape.ldap.LDAPConnection, java.lang.String)
-
addNameForm
public void addNameForm(LDAPNameFormSchema nameForm)
Add a name form definition to the current schema. You can also add name form definitions by calling theaddmethod of your newly constructedLDAPNameFormSchemaobject.To remove a name form definition that you have added, call the
getNameFormmethod to get theLDAPNameFormSchemaobject representing your nameForm type and call theremovemethod.NOTE: For information on the
addandremovemethods ofLDAPNameFormSchema, see the documentation forLDAPSchemaElement. (These methods are inherited fromLDAPSchemaElement.)- Parameters:
nameForm-LDAPNameFormSchemaobject representing the name form definition to add- See Also:
LDAPNameFormSchema,LDAPSchemaElement.add(netscape.ldap.LDAPConnection, java.lang.String),LDAPSchemaElement.remove(netscape.ldap.LDAPConnection, java.lang.String)
-
getObjectClasses
public java.util.Enumeration<LDAPObjectClassSchema> getObjectClasses()
Gets an enumeration ofthe object class definitions in this schema.- Returns:
- an enumeration of object class definitions.
-
getAttributes
public java.util.Enumeration<LDAPAttributeSchema> getAttributes()
Gets an enumeration ofthe attribute type definitions in this schema.- Returns:
- an enumeration of attribute type definitions.
-
getMatchingRules
public java.util.Enumeration<LDAPMatchingRuleSchema> getMatchingRules()
Gets an enumeration ofthe matching rule definitions in this schema.- Returns:
- an enumeration of matching rule definitions.
-
getSyntaxes
public java.util.Enumeration<LDAPSyntaxSchema> getSyntaxes()
Get an enumeration of the syntaxes in this schema.- Returns:
- an enumeration of syntax objects
-
getDITStructureRules
public java.util.Enumeration<LDAPDITStructureRuleSchema> getDITStructureRules()
Get an enumeration of the structure rules in this schema.- Returns:
- an enumeration of structure rule objects
-
getDITContentRules
public java.util.Enumeration<LDAPDITContentRuleSchema> getDITContentRules()
Get an enumeration of the content rules in this schema.- Returns:
- an enumeration of content rule objects
-
getNameForms
public java.util.Enumeration<LDAPNameFormSchema> getNameForms()
Get an enumeration of the name forms in this schema.- Returns:
- an enumeration of name form objects
-
getObjectClass
public LDAPObjectClassSchema getObjectClass(java.lang.String name)
Gets the definition of the object class with the specified name.- Parameters:
name- name of the object class to find- Returns:
- an
LDAPObjectClassSchemaobject representing the object class definition, ornullif not found.
-
getAttribute
public LDAPAttributeSchema getAttribute(java.lang.String name)
Gets the definition of the attribute type with the specified name.- Parameters:
name- name of the attribute type to find- Returns:
- an
LDAPAttributeSchemaobject representing the attribute type definition, ornullif not found.
-
getMatchingRule
public LDAPMatchingRuleSchema getMatchingRule(java.lang.String name)
Gets the definition of a matching rule with the specified name.- Parameters:
name- name of the matching rule to find- Returns:
- an
LDAPMatchingRuleSchemaobject representing the matching rule definition, ornullif not found.
-
getSyntax
public LDAPSyntaxSchema getSyntax(java.lang.String name)
Gets the definition of a syntax with the specified name.- Parameters:
name- name of the syntax to find- Returns:
- an
LDAPSyntaxSchemaobject representing the syntax definition, ornullif not found.
-
getDITStructureRule
public LDAPDITStructureRuleSchema getDITStructureRule(java.lang.String name)
Gets the definition of a structure rule with the specified name.- Parameters:
name- name of the rule to find- Returns:
- an
LDAPDITStructureRuleSchemaobject representing the rule, ornullif not found.
-
getDITStructureRule
public LDAPDITStructureRuleSchema getDITStructureRule(int ID)
Gets the definition of a structure rule with the specified name.- Parameters:
ID- ID of the rule to find- Returns:
- an
LDAPDITStructureRuleSchemaobject representing the rule, ornullif not found.
-
getDITContentRule
public LDAPDITContentRuleSchema getDITContentRule(java.lang.String name)
Gets the definition of a content rule with the specified name.- Parameters:
name- name of the rule to find- Returns:
- an
LDAPDITContentRuleSchemaobject representing the rule, ornullif not found.
-
getNameForm
public LDAPNameFormSchema getNameForm(java.lang.String name)
Gets the definition of a name form with the specified name.- Parameters:
name- name of the name form to find- Returns:
- an
LDAPNameFormSchemaobject representing the syntax definition, ornullif not found.
-
getObjectClassNames
public java.util.Enumeration<java.lang.String> getObjectClassNames()
Get an enumeration of the names of the object classes in this schema.- Returns:
- an enumeration of object class names (all lower-case).
-
getAttributeNames
public java.util.Enumeration<java.lang.String> getAttributeNames()
Get an enumeration of the names of the attribute types in this schema.- Returns:
- an enumeration of attribute names (all lower-case).
-
getMatchingRuleNames
public java.util.Enumeration<java.lang.String> getMatchingRuleNames()
Get an enumeration of the names of the matching rules in this schema.- Returns:
- an enumeration of matching rule names (all lower-case).
-
getSyntaxNames
public java.util.Enumeration<java.lang.String> getSyntaxNames()
Get an enumeration of the names of the syntaxes in this schema.- Returns:
- an enumeration of syntax names (all lower-case).
-
getDITStructureRuleNames
public java.util.Enumeration<java.lang.String> getDITStructureRuleNames()
Get an enumeration of the names of the structure rules in this schema.- Returns:
- an enumeration of names of the structure rule objects
-
getDITContentRuleNames
public java.util.Enumeration<java.lang.String> getDITContentRuleNames()
Get an enumeration of the names of the content rules in this schema.- Returns:
- an enumeration of names of the content rule objects
-
getNameFormNames
public java.util.Enumeration<java.lang.String> getNameFormNames()
Get an enumeration of the names of the name forms in this schema.- Returns:
- an enumeration of names of name form objects
-
fetchSchema
public void fetchSchema(LDAPConnection ld, java.lang.String dn) throws LDAPException
Retrieve the schema for a specific entry.- Parameters:
ld- an active connection to a Directory Serverdn- the entry for which to fetch schema- Throws:
LDAPException- on failure.
-
initialize
protected void initialize(LDAPEntry entry)
Extract all schema elements from subschema entry- Parameters:
entry- entry containing schema definitions
-
fetchSchema
public void fetchSchema(LDAPConnection ld) throws LDAPException
Retrieve the entire schema from the root of a Directory Server.- Parameters:
ld- an active connection to a Directory Server- Throws:
LDAPException- on failure.
-
toString
public java.lang.String toString()
Displays the schema (including the descriptions of its object classes, attribute types, and matching rules) in an easily readable format (not the same as the format expected by an LDAP server).- Overrides:
toStringin classjava.lang.Object- Returns:
- a string containing the schema in printable format.
-
main
public static void main(java.lang.String[] args)
Fetch the schema from the LDAP server at the specified host and port, and print out the schema (including descriptions of its object classes, attribute types, and matching rules). The schema is printed in an easily readable format (not the same as the format expected by an LDAP server). For example, you can enter the following command to print the schema:java netscape.ldap.LDAPSchema myhost.mydomain.com 389
- Parameters:
args- the host name and the port number of the LDAP server (for example,netscape.ldap.LDAPSchema directory.netscape.com 389)
-
-