|
LDAPJDK 4.1 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--netscape.ldap.LDAPSchema
This object represents the schema of an LDAP v3 server.
You can use the fetchSchema
method 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 remove
methods of the
LDAPObjectClassSchema
, LDAPAttributeSchema
,
and LDAPMatchingRuleSchema
classes. (This method is
inherited from the LDAPSchemaElement
class.)
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 new LDAPSchema
object 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 );
}
}
If 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).
To remove the classes and attribute types added by the example,
see the examples under the LDAPSchemaElement
class.
LDAPAttributeSchema
,
LDAPObjectClassSchema
,
LDAPMatchingRuleSchema
,
LDAPSchemaElement
, Serialized FormConstructor Summary | |
LDAPSchema()
Constructs a new LDAPSchema object. |
|
LDAPSchema(LDAPEntry entry)
|
Method Summary | |
void |
addAttribute(LDAPAttributeSchema attrSchema)
Add an attribute type schema definition to the current schema. |
void |
addDITContentRule(LDAPDITContentRuleSchema rule)
Add a content rule definition to the current schema. |
void |
addDITStructureRule(LDAPDITStructureRuleSchema rule)
Add a structure rule definition to the current schema. |
void |
addMatchingRule(LDAPMatchingRuleSchema matchSchema)
Add a matching rule schema definition to the current schema. |
void |
addNameForm(LDAPNameFormSchema nameForm)
Add a name form definition to the current schema. |
void |
addObjectClass(LDAPObjectClassSchema objectSchema)
Adds an object class schema definition to the current schema. |
void |
addSyntax(LDAPSyntaxSchema syntaxSchema)
Add a syntax schema definition to the current schema. |
void |
fetchSchema(LDAPConnection ld)
Retrieve the entire schema from the root of a Directory Server. |
void |
fetchSchema(LDAPConnection ld,
java.lang.String dn)
Retrieve the schema for a specific entry. |
LDAPAttributeSchema |
getAttribute(java.lang.String name)
Gets the definition of the attribute type with the specified name. |
java.util.Enumeration |
getAttributeNames()
Get an enumeration of the names of the attribute types in this schema. |
java.util.Enumeration |
getAttributes()
Gets an enumeration ofthe attribute type definitions in this schema. |
LDAPDITContentRuleSchema |
getDITContentRule(java.lang.String name)
Gets the definition of a content rule with the specified name. |
java.util.Enumeration |
getDITContentRuleNames()
Get an enumeration of the names of the content rules in this schema. |
java.util.Enumeration |
getDITContentRules()
Get an enumeration of the content rules in this schema. |
LDAPDITStructureRuleSchema |
getDITStructureRule(int ID)
Gets the definition of a structure rule with the specified name. |
LDAPDITStructureRuleSchema |
getDITStructureRule(java.lang.String name)
Gets the definition of a structure rule with the specified name. |
java.util.Enumeration |
getDITStructureRuleNames()
Get an enumeration of the names of the structure rules in this schema. |
java.util.Enumeration |
getDITStructureRules()
Get an enumeration of the structure rules in this schema. |
LDAPMatchingRuleSchema |
getMatchingRule(java.lang.String name)
Gets the definition of a matching rule with the specified name. |
java.util.Enumeration |
getMatchingRuleNames()
Get an enumeration of the names of the matching rules in this schema. |
java.util.Enumeration |
getMatchingRules()
Gets an enumeration ofthe matching rule definitions in this schema. |
LDAPNameFormSchema |
getNameForm(java.lang.String name)
Gets the definition of a name form with the specified name. |
java.util.Enumeration |
getNameFormNames()
Get an enumeration of the names of the name forms in this schema. |
java.util.Enumeration |
getNameForms()
Get an enumeration of the name forms in this schema. |
LDAPObjectClassSchema |
getObjectClass(java.lang.String name)
Gets the definition of the object class with the specified name. |
java.util.Enumeration |
getObjectClasses()
Gets an enumeration ofthe object class definitions in this schema. |
java.util.Enumeration |
getObjectClassNames()
Get an enumeration of the names of the object classes in this schema. |
LDAPSyntaxSchema |
getSyntax(java.lang.String name)
Gets the definition of a syntax with the specified name. |
java.util.Enumeration |
getSyntaxes()
Get an enumeration of the syntaxes in this schema. |
java.util.Enumeration |
getSyntaxNames()
Get an enumeration of the names of the syntaxes in this schema. |
protected void |
initialize(LDAPEntry entry)
Extract all schema elements from subschema entry |
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). |
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). |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Constructor Detail |
public LDAPSchema()
LDAPSchema
object.
Once you construct the object, you can get
the schema by calling fetchSchema
.
You can also print out the schema by using the
main
method. For example, you can enter
the following command:
java netscape.ldap.LDAPSchema myhost.mydomain.com 389Note that you need to call
fetchSchema
to get the schema from the server. Constructing the
object does not fetch the schema.
fetchSchema(netscape.ldap.LDAPConnection, java.lang.String)
,
main(java.lang.String[])
public LDAPSchema(LDAPEntry entry)
Method Detail |
public void addObjectClass(LDAPObjectClassSchema objectSchema)
add
method of your newly constructed
LDAPObjectClassSchema
object.
To remove an object class schema definition that you have added,
call the getObjectClass
method to get the
LDAPObjectClassSchema
object representing your
object class and call the remove
method.
NOTE: For information on the add
and
remove
methods of LDAPObjectClassSchema
,
see the documentation for LDAPSchemaElement
.
(These methods are inherited from LDAPSchemaElement
.)
objectSchema
- LDAPObjectClassSchema
object
representing the object class schema definition to addLDAPObjectClassSchema
,
LDAPSchemaElement.add(netscape.ldap.LDAPConnection, java.lang.String)
,
LDAPSchemaElement.remove(netscape.ldap.LDAPConnection, java.lang.String)
public void addAttribute(LDAPAttributeSchema attrSchema)
add
method of your newly constructed
LDAPAttributeSchema
object.
To remove an attribute type schema definition that you have added,
call the getAttribute
method to get the
LDAPAttributeSchema
object representing your
attribute type and call the remove
method.
NOTE: For information on the add
and
remove
methods of LDAPAttributeSchema
,
see the documentation for LDAPSchemaElement
.
(These methods are inherited from LDAPSchemaElement
.)
attrSchema
- LDAPAttributeSchema
object
representing the attribute type schema definition to addLDAPAttributeSchema
,
LDAPSchemaElement.add(netscape.ldap.LDAPConnection, java.lang.String)
,
LDAPSchemaElement.remove(netscape.ldap.LDAPConnection, java.lang.String)
public void addMatchingRule(LDAPMatchingRuleSchema matchSchema)
add
method of your newly constructed
LDAPMatchingRuleSchema
object.
To remove an attribute type schema definition that you have added,
call the getMatchingRule
method to get the
LDAPMatchingRuleSchema
object representing your
matching rule and call the remove
method.
NOTE: For information on the add
and
remove
methods of LDAPMatchingRuleSchema
,
see the documentation for LDAPSchemaElement
.
(These methods are inherited from LDAPSchemaElement
.)
matchSchema
- LDAPMatchingRuleSchema
object
representing the matching rule schema definition to addLDAPMatchingRuleSchema
,
LDAPSchemaElement.add(netscape.ldap.LDAPConnection, java.lang.String)
,
LDAPSchemaElement.remove(netscape.ldap.LDAPConnection, java.lang.String)
public void addSyntax(LDAPSyntaxSchema syntaxSchema)
add
method of your newly constructed
LDAPSyntaxSchema
object.
To remove a syntax schema definition that you have added,
call the getSyntax
method to get the
LDAPSyntaxSchema
object representing your
syntax type and call the remove
method.
NOTE: For information on the add
and
remove
methods of LDAPSyntaxSchema
,
see the documentation for LDAPSchemaElement
.
(These methods are inherited from LDAPSchemaElement
.)
syntaxSchema
- LDAPSyntaxSchema
object
representing the syntax schema definition to addLDAPSyntaxSchema
,
LDAPSchemaElement.add(netscape.ldap.LDAPConnection, java.lang.String)
,
LDAPSchemaElement.remove(netscape.ldap.LDAPConnection, java.lang.String)
public void addDITStructureRule(LDAPDITStructureRuleSchema rule)
add
method of your newly constructed
LDAPDITStructureRuleSchema
object.
To remove a structure rule definition that you have added,
call the getDITStructureRule
method to get the
LDAPDITStructureRuleSchema
object representing your
rule and call the remove
method.
NOTE: For information on the add
and
remove
methods of LDAPSyntaxSchema
,
see the documentation for LDAPSchemaElement
.
(These methods are inherited from LDAPSchemaElement
.)
rule
- LDAPDITStructureRuleSchema
object
representing the structure rule definition to addLDAPDITStructureRuleSchema
,
LDAPSchemaElement.add(netscape.ldap.LDAPConnection, java.lang.String)
,
LDAPSchemaElement.remove(netscape.ldap.LDAPConnection, java.lang.String)
public void addDITContentRule(LDAPDITContentRuleSchema rule)
add
method of your newly constructed
LDAPDITContentRuleSchema
object.
To remove a content rule definition that you have added,
call the getDITContentRule
method to get the
LDAPDITContentRuleSchema
object representing your
rule and call the remove
method.
NOTE: For information on the add
and
remove
methods of LDAPSyntaxSchema
,
see the documentation for LDAPSchemaElement
.
(These methods are inherited from LDAPSchemaElement
.)
rule
- LDAPDITContentRuleSchema
object
representing the content rule definition to addLDAPDITContentRuleSchema
,
LDAPSchemaElement.add(netscape.ldap.LDAPConnection, java.lang.String)
,
LDAPSchemaElement.remove(netscape.ldap.LDAPConnection, java.lang.String)
public void addNameForm(LDAPNameFormSchema nameForm)
add
method of your newly constructed
LDAPNameFormSchema
object.
To remove a name form definition that you have added,
call the getNameForm
method to get the
LDAPNameFormSchema
object representing your
nameForm type and call the remove
method.
NOTE: For information on the add
and
remove
methods of LDAPNameFormSchema
,
see the documentation for LDAPSchemaElement
.
(These methods are inherited from LDAPSchemaElement
.)
nameForm
- LDAPNameFormSchema
object
representing the name form definition to addLDAPNameFormSchema
,
LDAPSchemaElement.add(netscape.ldap.LDAPConnection, java.lang.String)
,
LDAPSchemaElement.remove(netscape.ldap.LDAPConnection, java.lang.String)
public java.util.Enumeration getObjectClasses()
public java.util.Enumeration getAttributes()
public java.util.Enumeration getMatchingRules()
public java.util.Enumeration getSyntaxes()
public java.util.Enumeration getDITStructureRules()
public java.util.Enumeration getDITContentRules()
public java.util.Enumeration getNameForms()
public LDAPObjectClassSchema getObjectClass(java.lang.String name)
name
- name of the object class to findLDAPObjectClassSchema
object representing
the object class definition, or null
if not found.public LDAPAttributeSchema getAttribute(java.lang.String name)
name
- name of the attribute type to findLDAPAttributeSchema
object representing
the attribute type definition, or null
if not found.public LDAPMatchingRuleSchema getMatchingRule(java.lang.String name)
name
- name of the matching rule to findLDAPMatchingRuleSchema
object representing
the matching rule definition, or null
if not found.public LDAPSyntaxSchema getSyntax(java.lang.String name)
name
- name of the syntax to findLDAPSyntaxSchema
object representing
the syntax definition, or null
if not found.public LDAPDITStructureRuleSchema getDITStructureRule(java.lang.String name)
name
- name of the rule to findLDAPDITStructureRuleSchema
object representing
the rule, or null
if not found.public LDAPDITStructureRuleSchema getDITStructureRule(int ID)
ID
- ID of the rule to findLDAPDITStructureRuleSchema
object representing
the rule, or null
if not found.public LDAPDITContentRuleSchema getDITContentRule(java.lang.String name)
name
- name of the rule to findLDAPDITContentRuleSchema
object representing
the rule, or null
if not found.public LDAPNameFormSchema getNameForm(java.lang.String name)
name
- name of the name form to findLDAPNameFormSchema
object representing
the syntax definition, or null
if not found.public java.util.Enumeration getObjectClassNames()
public java.util.Enumeration getAttributeNames()
public java.util.Enumeration getMatchingRuleNames()
public java.util.Enumeration getSyntaxNames()
public java.util.Enumeration getDITStructureRuleNames()
public java.util.Enumeration getDITContentRuleNames()
public java.util.Enumeration getNameFormNames()
public void fetchSchema(LDAPConnection ld, java.lang.String dn) throws LDAPException
ld
- an active connection to a Directory Serverdn
- the entry for which to fetch schemaprotected void initialize(LDAPEntry entry)
entry
- entry containing schema definitionspublic void fetchSchema(LDAPConnection ld) throws LDAPException
ld
- an active connection to a Directory Serverpublic java.lang.String toString()
public static void main(java.lang.String[] args)
java netscape.ldap.LDAPSchema myhost.mydomain.com 389
args
- the host name and the port number of the LDAP server
(for example, netscape.ldap.LDAPSchema directory.netscape.com
389
)
|
LDAPJDK 4.1 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |