You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2010/01/06 18:52:31 UTC
svn commit: r896579 [6/14] - in /directory/shared/trunk: ./ ldap/
ldap/src/main/antlr/ ldap/src/main/java/org/apache/directory/shared/ldap/
ldap/src/main/java/org/apache/directory/shared/ldap/codec/
ldap/src/main/java/org/apache/directory/shared/ldap/c...
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectClass.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectClass.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectClass.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectClass.java Wed Jan 6 17:52:15 2010
@@ -20,8 +20,17 @@
package org.apache.directory.shared.ldap.schema;
+import java.util.ArrayList;
+import java.util.List;
+
import javax.naming.NamingException;
+import org.apache.directory.shared.ldap.exception.LdapSchemaViolationException;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.schema.registries.AttributeTypeRegistry;
+import org.apache.directory.shared.ldap.schema.registries.ObjectClassRegistry;
+import org.apache.directory.shared.ldap.schema.registries.Registries;
+
/**
* An objectClass definition.
@@ -67,16 +76,667 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$
*/
-public interface ObjectClass extends SchemaObject
+public class ObjectClass extends AbstractSchemaObject
{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
+ /** The ObjectClass type : ABSTRACT, AUXILIARY or STRUCTURAL */
+ private ObjectClassTypeEnum objectClassType = ObjectClassTypeEnum.STRUCTURAL;
+
+ /** The ObjectClass superior OIDs */
+ private List<String> superiorOids;
+
+ /** The ObjectClass superiors */
+ private List<ObjectClass> superiors;
+
+ /** The list of allowed AttributeType OIDs */
+ private List<String> mayAttributeTypeOids;
+
+ /** The list of allowed AttributeTypes */
+ private List<AttributeType> mayAttributeTypes;
+
+ /** The list of required AttributeType OIDs */
+ private List<String> mustAttributeTypeOids;
+
+ /** The list of required AttributeTypes */
+ private List<AttributeType> mustAttributeTypes;
+
+
+ /**
+ * Creates a new instance of MatchingRuleUseDescription
+ * @param oid the OID for this objectClass
+ */
+ public ObjectClass( String oid )
+ {
+ super( SchemaObjectType.OBJECT_CLASS, oid );
+
+ mayAttributeTypeOids = new ArrayList<String>();
+ mustAttributeTypeOids = new ArrayList<String>();
+ superiorOids = new ArrayList<String>();
+
+ mayAttributeTypes = new ArrayList<AttributeType>();
+ mustAttributeTypes = new ArrayList<AttributeType>();
+ superiors = new ArrayList<ObjectClass>();
+ objectClassType = ObjectClassTypeEnum.STRUCTURAL;
+ }
+
+
+ private void buildSuperiors( List<Throwable> errors, Registries registries )
+ {
+ ObjectClassRegistry ocRegistry = registries.getObjectClassRegistry();
+
+ if ( superiorOids != null )
+ {
+ superiors = new ArrayList<ObjectClass>( superiorOids.size() );
+
+ for ( String superiorName : superiorOids )
+ {
+ try
+ {
+ ObjectClass superior = ocRegistry.lookup( ocRegistry.getOidByName( superiorName ) );
+
+ // Before adding the superior, check that the ObjectClass type is consistent
+ switch ( objectClassType )
+ {
+ case ABSTRACT:
+ if ( superior.objectClassType != ObjectClassTypeEnum.ABSTRACT )
+ {
+ // An ABSTRACT OC can only inherit from ABSTRACT OCs
+ String msg = "Cannot register the SchemaOject " + oid + ", an ABSTRACT ObjectClass "
+ + "cannot inherit from an " + superior.getObjectType() + " ObjectClass :/n "
+ + superior;
+
+ Throwable error = new LdapSchemaViolationException( msg,
+ ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+ errors.add( error );
+ return;
+ }
+
+ break;
+
+ case AUXILIARY:
+ if ( superior.objectClassType == ObjectClassTypeEnum.STRUCTURAL )
+ {
+ // An AUXILIARY OC can only inherit from STRUCTURAL OCs
+ String msg = "Cannot register the SchemaOject " + oid + ", an AUXILIARY ObjectClass "
+ + "cannot inherit from a STRUCTURAL ObjectClass :/n " + superior;
+
+ Throwable error = new LdapSchemaViolationException( msg,
+ ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+ errors.add( error );
+ return;
+ }
+
+ break;
+
+ case STRUCTURAL:
+ if ( superior.objectClassType == ObjectClassTypeEnum.AUXILIARY )
+ {
+ // A STRUCTURAL OC can only inherit from AUXILIARY OCs
+ String msg = "Cannot register the SchemaOject " + oid + ", a STRUCTURAL ObjectClass "
+ + "cannot inherit from an AUXILIARY ObjectClass :/n " + superior;
+
+ Throwable error = new LdapSchemaViolationException( msg,
+ ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+ errors.add( error );
+ return;
+ }
+
+ break;
+ }
+
+ superiors.add( superior );
+ }
+ catch ( NamingException ne )
+ {
+ // Cannot find the OC
+ String msg = "Cannot register the SchemaOject " + oid + ", the given SUPERIOR does not exist : "
+ + superiorName;
+
+ Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+ errors.add( error );
+ return;
+ }
+ }
+ }
+ }
+
+
+ private void buildMay( List<Throwable> errors, Registries registries )
+ {
+ AttributeTypeRegistry atRegistry = registries.getAttributeTypeRegistry();
+
+ if ( mayAttributeTypeOids != null )
+ {
+ mayAttributeTypes = new ArrayList<AttributeType>( mayAttributeTypeOids.size() );
+
+ for ( String mayAttributeTypeName : mayAttributeTypeOids )
+ {
+ try
+ {
+ AttributeType attributeType = atRegistry.lookup( mayAttributeTypeName );
+
+ if ( mayAttributeTypes.contains( attributeType ) )
+ {
+ // Already registered : this is an error
+ String msg = "Cannot register the SchemaOject " + oid
+ + ", there are some duplicate AT in the MAY : " + mayAttributeTypeName;
+
+ Throwable error = new LdapSchemaViolationException( msg,
+ ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+ errors.add( error );
+ break;
+ }
+
+ mayAttributeTypes.add( attributeType );
+ }
+ catch ( NamingException ne )
+ {
+ // Cannot find the AT
+ String msg = "Cannot register the SchemaOject " + oid
+ + ", the AT we want to add to MAY does not exist : " + mayAttributeTypeName;
+
+ Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+ errors.add( error );
+ break;
+ }
+ }
+ }
+ }
+
+
+ private void buildMust( List<Throwable> errors, Registries registries )
+ {
+ AttributeTypeRegistry atRegistry = registries.getAttributeTypeRegistry();
+
+ if ( mustAttributeTypeOids != null )
+ {
+ mustAttributeTypes = new ArrayList<AttributeType>( mustAttributeTypeOids.size() );
+
+ for ( String mustAttributeTypeName : mustAttributeTypeOids )
+ {
+ try
+ {
+ AttributeType attributeType = atRegistry.lookup( mustAttributeTypeName );
+
+ if ( mustAttributeTypes.contains( attributeType ) )
+ {
+ // Already registered : this is an error
+ String msg = "Cannot register the SchemaOject " + oid
+ + ", there are some duplicate AT in the MUST : " + mustAttributeTypeName;
+
+ Throwable error = new LdapSchemaViolationException( msg,
+ ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+ errors.add( error );
+ break;
+ }
+
+ // Check that the MUST AT is not also present in the MAY AT
+ if ( mayAttributeTypes.contains( attributeType ) )
+ {
+ // Already registered : this is an error
+ String msg = "Cannot register the SchemaOject " + oid
+ + ", there are some duplicate AT in MAY and MUST : " + mustAttributeTypeName;
+
+ Throwable error = new LdapSchemaViolationException( msg,
+ ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+ errors.add( error );
+ break;
+ }
+
+ mustAttributeTypes.add( attributeType );
+ }
+ catch ( NamingException ne )
+ {
+ // Cannot find the AT
+ String msg = "Cannot register the SchemaOject " + oid
+ + ", the AT we want to add to MUST does not exist : " + mustAttributeTypeName;
+
+ Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+ errors.add( error );
+ break;
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Inject the ObjectClass into the registries, updating the references to
+ * other SchemaObject
+ *
+ * @param errors The errors we got while adding the ObjectClass to the registries
+ * @param registries The Registries
+ * @throws Exception on failure
+ *
+ */
+ public void addToRegistries( List<Throwable> errors, Registries registries ) throws NamingException
+ {
+ if ( registries != null )
+ {
+ // The superiors
+ buildSuperiors( errors, registries );
+
+ // The MAY AttributeTypes
+ buildMay( errors, registries );
+
+ // The MUST AttributeTypes
+ buildMust( errors, registries );
+
+ /**
+ * Add the OC references (using and usedBy) :
+ * OC -> AT (MAY and MUST)
+ * OC -> OC (SUPERIORS)
+ */
+ for ( AttributeType mayAttributeType : mayAttributeTypes )
+ {
+ registries.addReference( this, mayAttributeType );
+ }
+
+ for ( AttributeType mustAttributeType : mustAttributeTypes )
+ {
+ registries.addReference( this, mustAttributeType );
+ }
+
+ for ( ObjectClass superiorObjectClass : superiors )
+ {
+ registries.addReference( this, superiorObjectClass );
+ }
+ }
+ }
+
+
+ /**
+ * Remove the ObjectClass from the registries, updating the references to
+ * other SchemaObject.
+ *
+ * If one of the referenced SchemaObject does not exist (SUPERIORS, MAY, MUST),
+ * an exception is thrown.
+ *
+ * @param errors The errors we got while removing the ObjectClass from the registries
+ * @param registries The Registries
+ * @exception If the ObjectClass is not valid
+ */
+ public void removeFromRegistries( List<Throwable> errors, Registries registries ) throws NamingException
+ {
+ if ( registries != null )
+ {
+ ObjectClassRegistry objectClassRegistry = registries.getObjectClassRegistry();
+
+ // Unregister this ObjectClass into the Descendant map
+ objectClassRegistry.unregisterDescendants( this, superiors );
+
+ /**
+ * Remove the OC references (using and usedBy) :
+ * OC -> AT (for MAY and MUST)
+ * OC -> OC
+ */
+ if ( mayAttributeTypes != null )
+ {
+ for ( AttributeType may : mayAttributeTypes )
+ {
+ registries.delReference( this, may );
+ }
+ }
+
+ if ( mustAttributeTypes != null )
+ {
+ for ( AttributeType must : mustAttributeTypes )
+ {
+ registries.delReference( this, must );
+ }
+ }
+
+ if ( superiors != null )
+ {
+ for ( ObjectClass superior : superiors )
+ {
+ registries.delReference( this, superior );
+ }
+ }
+ }
+ }
+
+
+ /**
+ * @return the mayAttributeTypeOids
+ */
+ public List<String> getMayAttributeTypeOids()
+ {
+ return mayAttributeTypeOids;
+ }
+
+
+ /**
+ * @return the mayAttributeTypes
+ */
+ public List<AttributeType> getMayAttributeTypes()
+ {
+ return mayAttributeTypes;
+ }
+
+
+ /**
+ * Add some allowed AttributeType
+ *
+ * @param oids The attributeType oids
+ */
+ public void addMayAttributeTypeOids( String... oids )
+ {
+ if ( !isReadOnly )
+ {
+ for ( String oid : oids )
+ {
+ mayAttributeTypeOids.add( oid );
+ }
+ }
+ }
+
+
+ /**
+ * Add some allowed AttributeTypes
+ *
+ * @param attributeTypes The attributeTypes
+ */
+ public void addMayAttributeTypes( AttributeType... attributeTypes )
+ {
+ if ( !isReadOnly )
+ {
+ for ( AttributeType attributeType : attributeTypes )
+ {
+ if ( !mayAttributeTypeOids.contains( attributeType.getOid() ) )
+ {
+ mayAttributeTypes.add( attributeType );
+ mayAttributeTypeOids.add( attributeType.getOid() );
+ }
+ }
+ }
+ }
+
+
+ /**
+ * @param mayAttributeTypeOids the mayAttributeTypeOids to set
+ */
+ public void setMayAttributeTypeOids( List<String> mayAttributeTypeOids )
+ {
+ if ( !isReadOnly )
+ {
+ this.mayAttributeTypeOids = mayAttributeTypeOids;
+ }
+ }
+
+
+ /**
+ * Sets the list of allowed AttributeTypes
+ *
+ * @param mayAttributeTypes the list of allowed AttributeTypes
+ */
+ public void setMayAttributeTypes( List<AttributeType> mayAttributeTypes )
+ {
+ if ( !isReadOnly )
+ {
+ this.mayAttributeTypes = mayAttributeTypes;
+
+ // update the OIDS now
+ mayAttributeTypeOids.clear();
+
+ for ( AttributeType may : mayAttributeTypes )
+ {
+ mayAttributeTypeOids.add( may.getOid() );
+ }
+ }
+ }
+
+
+ /**
+ * Update the associated MAY AttributeType, even if the SchemaObject is readOnly
+ *
+ * @param mayAttributeTypes the list of allowed AttributeTypes
+ */
+ public void updateMayAttributeTypes( List<AttributeType> mayAttributeTypes )
+ {
+ this.mayAttributeTypes.clear();
+ this.mayAttributeTypes.addAll( mayAttributeTypes );
+
+ // update the OIDS now
+ mayAttributeTypeOids.clear();
+
+ for ( AttributeType may : mayAttributeTypes )
+ {
+ mayAttributeTypeOids.add( may.getOid() );
+ }
+ }
+
+
+ /**
+ * @return the mustAttributeTypeOids
+ */
+ public List<String> getMustAttributeTypeOids()
+ {
+ return mustAttributeTypeOids;
+ }
+
+
+ /**
+ * @return the mustAttributeTypes
+ */
+ public List<AttributeType> getMustAttributeTypes()
+ {
+ return mustAttributeTypes;
+ }
+
+
+ /**
+ * Add some required AttributeType OIDs
+ *
+ * @param oid The attributeType OIDs
+ */
+ public void addMustAttributeTypeOids( String... oids )
+ {
+ if ( !isReadOnly )
+ {
+ for ( String oid : oids )
+ {
+ mustAttributeTypeOids.add( oid );
+ }
+ }
+ }
+
+
+ /**
+ * Add some required AttributeTypes
+ *
+ * @param attributeTypes The attributeTypse
+ */
+ public void addMustAttributeTypes( AttributeType... attributeTypes )
+ {
+ if ( !isReadOnly )
+ {
+ for ( AttributeType attributeType : attributeTypes )
+ {
+ if ( !mustAttributeTypeOids.contains( attributeType.getOid() ) )
+ {
+ mustAttributeTypes.add( attributeType );
+ mustAttributeTypeOids.add( attributeType.getOid() );
+ }
+ }
+ }
+ }
+
+
+ /**
+ * @param mustAttributeTypeOids the mustAttributeTypeOids to set
+ */
+ public void setMustAttributeTypeOids( List<String> mustAttributeTypeOids )
+ {
+ if ( !isReadOnly )
+ {
+ this.mustAttributeTypeOids = mustAttributeTypeOids;
+ }
+ }
+
+
+ /**
+ * Sets the list of required AttributeTypes
+ *
+ * @param mustAttributeTypes the list of required AttributeTypes
+ */
+ public void setMustAttributeTypes( List<AttributeType> mustAttributeTypes )
+ {
+ if ( !isReadOnly )
+ {
+ this.mustAttributeTypes = mustAttributeTypes;
+
+ // update the OIDS now
+ mustAttributeTypeOids.clear();
+
+ for ( AttributeType may : mustAttributeTypes )
+ {
+ mustAttributeTypeOids.add( may.getOid() );
+ }
+ }
+ }
+
+
+ /**
+ * Update the associated MUST AttributeType, even if the SchemaObject is readOnly
+ *
+ * @param mayAttributeTypes the list of allowed AttributeTypes
+ */
+ public void updateMustAttributeTypes( List<AttributeType> mustAttributeTypes )
+ {
+ this.mustAttributeTypes.clear();
+ this.mustAttributeTypes.addAll( mustAttributeTypes );
+
+ // update the OIDS now
+ mustAttributeTypeOids.clear();
+
+ for ( AttributeType must : mustAttributeTypes )
+ {
+ mustAttributeTypeOids.add( must.getOid() );
+ }
+ }
+
+
/**
* Gets the superclasses of this ObjectClass.
*
* @return the superclasses
- * @throws NamingException
- * if there is a failure resolving the object
+ * @throws NamingException if there is a failure resolving the object
+ */
+ public List<ObjectClass> getSuperiors()
+ {
+ return superiors;
+ }
+
+
+ /**
+ * Gets the superclasses OIDsof this ObjectClass.
+ *
+ * @return the superclasses OIDs
+ */
+ public List<String> getSuperiorOids()
+ {
+ return superiorOids;
+ }
+
+
+ /**
+ * Add some superior ObjectClass OIDs
+ *
+ * @param oids The superior ObjectClass OIDs
+ */
+ public void addSuperiorOids( String... oids )
+ {
+ if ( !isReadOnly )
+ {
+ for ( String oid : oids )
+ {
+ if ( !superiorOids.contains( oid ) )
+ {
+ superiorOids.add( oid );
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Add some superior ObjectClasses
+ *
+ * @param objectClasses The superior ObjectClasses
+ */
+ public void addSuperior( ObjectClass... objectClasses )
+ {
+ if ( !isReadOnly )
+ {
+ for ( ObjectClass objectClass : objectClasses )
+ {
+ if ( !superiorOids.contains( objectClass.getOid() ) )
+ {
+ superiorOids.add( objectClass.getOid() );
+ superiors.add( objectClass );
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Sets the superior object classes
+ *
+ * @param superiors the object classes to set
+ */
+ public void setSuperiors( List<ObjectClass> superiors )
+ {
+ if ( !isReadOnly )
+ {
+ this.superiors = superiors;
+
+ // update the OIDS now
+ superiorOids.clear();
+
+ for ( ObjectClass oc : superiors )
+ {
+ superiorOids.add( oc.getOid() );
+ }
+ }
+ }
+
+
+ /**
+ * Update the associated SUPERIORS ObjectClasses, even if the SchemaObject is readOnly
+ *
+ * @param superiors the object classes to set
+ */
+ public void updateSuperiors( List<ObjectClass> superiors )
+ {
+ this.superiors.clear();
+ this.superiors.addAll( superiors );
+
+ // update the OIDS now
+ superiorOids.clear();
+
+ for ( ObjectClass oc : superiors )
+ {
+ superiorOids.add( oc.getOid() );
+ }
+ }
+
+
+ /**
+ * Sets the superior object class OIDs
+ *
+ * @param superiorOids the object class OIDs to set
*/
- ObjectClass[] getSuperClasses() throws NamingException;
+ public void setSuperiorOids( List<String> superiorOids )
+ {
+ if ( !isReadOnly )
+ {
+ this.superiorOids = superiorOids;
+ }
+ }
/**
@@ -84,53 +744,303 @@
*
* @return the ObjectClass type as an enum
*/
- ObjectClassTypeEnum getType();
-
-
+ public ObjectClassTypeEnum getType()
+ {
+ return objectClassType;
+ }
+
+
+ /**
+ * Set the ObjectClass type, one of ABSTRACT, AUXILIARY or STRUCTURAL.
+ *
+ * @param objectClassType The ObjectClassType value
+ */
+ public void setType( ObjectClassTypeEnum objectClassType )
+ {
+ if ( !isReadOnly )
+ {
+ this.objectClassType = objectClassType;
+ }
+ }
+
+
/**
* Tells if the current ObjectClass is STRUCTURAL
*
* @return <code>true</code> if the ObjectClass is STRUCTURAL
*/
- boolean isStructural();
-
+ public boolean isStructural()
+ {
+ return objectClassType == ObjectClassTypeEnum.STRUCTURAL;
+ }
+
/**
* Tells if the current ObjectClass is ABSTRACT
*
* @return <code>true</code> if the ObjectClass is ABSTRACT
*/
- boolean isAbstract();
-
+ public boolean isAbstract()
+ {
+ return objectClassType == ObjectClassTypeEnum.ABSTRACT;
+ }
+
/**
* Tells if the current ObjectClass is AUXILIARY
*
* @return <code>true</code> if the ObjectClass is AUXILIARY
*/
- boolean isAuxiliary();
+ public boolean isAuxiliary()
+ {
+ return objectClassType == ObjectClassTypeEnum.AUXILIARY;
+ }
/**
- * Gets the AttributeTypes whose attributes must be present within an entry
- * of this ObjectClass.
- *
- * @return the AttributeTypes of attributes that must be within entries of
- * this ObjectClass
- * @throws NamingException
- * if there is a failure resolving the object
+ * @see Object#toString()
*/
- AttributeType[] getMustList() throws NamingException;
+ public String toString()
+ {
+ return objectType + " " + DescriptionUtils.getDescription( this );
+ }
/**
- * Gets the AttributeTypes whose attributes may be present within an entry
- * of this ObjectClass.
- *
- * @return the AttributeTypes of attributes that may be within entries of
- * this ObjectClass
- * @throws NamingException
- * if there is a failure resolving the object
+ * Copy an ObjectClass
+ */
+ public ObjectClass copy()
+ {
+ ObjectClass copy = new ObjectClass( oid );
+
+ // Copy the SchemaObject common data
+ copy.copy( this );
+
+ // Copy the ObjectClass type
+ copy.objectClassType = objectClassType;
+
+ // Copy the Superiors ObjectClasses OIDs
+ copy.superiorOids = new ArrayList<String>();
+
+ for ( String oid : superiorOids )
+ {
+ copy.superiorOids.add( oid );
+ }
+
+ // Copy the Superiors ObjectClasses ( will be empty )
+ copy.superiors = new ArrayList<ObjectClass>();
+
+ // Copy the MAY AttributeTypes OIDs
+ copy.mayAttributeTypeOids = new ArrayList<String>();
+
+ for ( String oid : mayAttributeTypeOids )
+ {
+ copy.mayAttributeTypeOids.add( oid );
+ }
+
+ // Copy the MAY AttributeTypes ( will be empty )
+ copy.mayAttributeTypes = new ArrayList<AttributeType>();
+
+ // Copy the MUST AttributeTypes OIDs
+ copy.mustAttributeTypeOids = new ArrayList<String>();
+
+ for ( String oid : mustAttributeTypeOids )
+ {
+ copy.mustAttributeTypeOids.add( oid );
+ }
+
+ // Copy the MUST AttributeTypes ( will be empty )
+ copy.mustAttributeTypes = new ArrayList<AttributeType>();
+
+ return copy;
+ }
+
+
+ /**
+ * @see Object#equals(Object)
*/
- AttributeType[] getMayList() throws NamingException;
+ public boolean equals( Object o )
+ {
+ if ( !super.equals( o ) )
+ {
+ return false;
+ }
+
+ if ( !( o instanceof ObjectClass ) )
+ {
+ return false;
+ }
+
+ ObjectClass that = ( ObjectClass ) o;
+
+ // The ObjectClassType
+ if ( objectClassType != that.objectClassType )
+ {
+ return false;
+ }
+
+ // The Superiors OIDs
+ if ( superiorOids.size() != that.superiorOids.size() )
+ {
+ return false;
+ }
+
+ // One way
+ for ( String oid : superiorOids )
+ {
+ if ( !that.superiorOids.contains( oid ) )
+ {
+ return false;
+ }
+ }
+
+ // The other way
+ for ( String oid : that.superiorOids )
+ {
+ if ( !superiorOids.contains( oid ) )
+ {
+ return false;
+ }
+ }
+
+ // The Superiors
+ if ( superiors.size() != that.superiors.size() )
+ {
+ return false;
+ }
+
+ // One way
+ for ( ObjectClass oid : superiors )
+ {
+ if ( !that.superiors.contains( oid ) )
+ {
+ return false;
+ }
+ }
+
+ // The other way
+ for ( ObjectClass oid : that.superiors )
+ {
+ if ( !superiors.contains( oid ) )
+ {
+ return false;
+ }
+ }
+
+ // The MAY OIDs
+ if ( mayAttributeTypeOids.size() != that.mayAttributeTypeOids.size() )
+ {
+ return false;
+ }
+
+ // One way
+ for ( String oid : mayAttributeTypeOids )
+ {
+ if ( !that.mayAttributeTypeOids.contains( oid ) )
+ {
+ return false;
+ }
+ }
+
+ // The other way
+ for ( String oid : that.mayAttributeTypeOids )
+ {
+ if ( !mayAttributeTypeOids.contains( oid ) )
+ {
+ return false;
+ }
+ }
+
+ // The MAY
+ if ( mayAttributeTypes.size() != that.mayAttributeTypes.size() )
+ {
+ return false;
+ }
+
+ // One way
+ for ( AttributeType oid : mayAttributeTypes )
+ {
+ if ( !that.mayAttributeTypes.contains( oid ) )
+ {
+ return false;
+ }
+ }
+
+ // The other way
+ for ( AttributeType oid : that.mayAttributeTypes )
+ {
+ if ( !mayAttributeTypes.contains( oid ) )
+ {
+ return false;
+ }
+ }
+
+ // The MUST OIDs
+ if ( mustAttributeTypeOids.size() != that.mustAttributeTypeOids.size() )
+ {
+ return false;
+ }
+
+ // One way
+ for ( String oid : mustAttributeTypeOids )
+ {
+ if ( !that.mustAttributeTypeOids.contains( oid ) )
+ {
+ return false;
+ }
+ }
+
+ // The other way
+ for ( String oid : that.mustAttributeTypeOids )
+ {
+ if ( !mustAttributeTypeOids.contains( oid ) )
+ {
+ return false;
+ }
+ }
+
+ // The MUST
+ if ( mustAttributeTypes.size() != that.mustAttributeTypes.size() )
+ {
+ return false;
+ }
+
+ // One way
+ for ( AttributeType oid : mustAttributeTypes )
+ {
+ if ( !that.mustAttributeTypes.contains( oid ) )
+ {
+ return false;
+ }
+ }
+
+ // The other way
+ for ( AttributeType oid : that.mustAttributeTypes )
+ {
+ if ( !mustAttributeTypes.contains( oid ) )
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void clear()
+ {
+ // Clear the common elements
+ super.clear();
+
+ // Clear the references
+ mayAttributeTypes.clear();
+ mayAttributeTypeOids.clear();
+ mustAttributeTypes.clear();
+ mustAttributeTypeOids.clear();
+ superiors.clear();
+ superiorOids.clear();
+ }
}
\ No newline at end of file
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaObject.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaObject.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaObject.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaObject.java Wed Jan 6 17:52:15 2010
@@ -19,30 +19,56 @@
*/
package org.apache.directory.shared.ldap.schema;
+
import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.NamingException;
+
+import org.apache.directory.shared.ldap.schema.registries.Registries;
/**
- * Most schema objects have some common attributes. This super interface
- * represents the minimum set of properties exposed by a SchemaObject.
- *
+ * Most schema objects have some common attributes. This class
+ * contains the minimum set of properties exposed by a SchemaObject.<br>
+ * We have 11 types of SchemaObjects :
+ * <li> AttributeType
+ * <li> DitCOntentRule
+ * <li> DitStructureRule
+ * <li> LdapComparator (specific to ADS)
+ * <li> LdapSyntaxe
+ * <li> MatchingRule
+ * <li> MatchingRuleUse
+ * <li> NameForm
+ * <li> Normalizer (specific to ADS)
+ * <li> ObjectClass
+ * <li> SyntaxChecker (specific to ADS)
+ * <br>
+ * <br>
+ * This class provides accessors and setters for the following attributes,
+ * which are common to all those SchemaObjects :
+ * <li>oid : The numeric OID
+ * <li>description : The SchemaObject description
+ * <li>obsolete : Tells if the schema object is obsolete
+ * <li>extensions : The extensions, a key/Values map
+ * <li>schemaObjectType : The SchemaObject type (see upper)
+ * <li>schema : The schema the SchemaObject is associated with (it's an extension).
+ * Can be null
+ * <li>isEnabled : The SchemaObject status (it's related to the schema status)
+ * <li>isReadOnly : Tells if the SchemaObject can be modified or not
+ * <br><br>
+ * Some of those attributes are not used by some Schema elements, even if they should
+ * have been used. Here is the list :
+ * <b>name</b> : LdapSyntax, Comparator, Normalizer, SyntaxChecker
+ * <b>numericOid</b> : DitStructureRule,
+ * <b>obsolete</b> : LdapSyntax, Comparator, Normalizer, SyntaxChecker
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$
*/
public interface SchemaObject extends Serializable
{
/**
- * Gets whether or not this SchemaObject has been inactivated. All
- * SchemaObjects except Syntaxes allow for this parameter within their
- * definition. For Syntaxes this property should always return false in
- * which case it is never included in the description.
- *
- * @return true if inactive, false if active
- */
- boolean isObsolete();
-
-
- /**
* Gets usually what is the numeric object identifier assigned to this
* SchemaObject. All schema objects except for MatchingRuleUses have an OID
* assigned specifically to then. A MatchingRuleUse's OID really is the OID
@@ -56,37 +82,211 @@
/**
- * Gets short names for this SchemaObject if any exists for it.
+ * A special method used when renaming an SchemaObject: we may have to
+ * change it's OID
+ * @param oid The new OID
+ */
+ void setOid( String oid );
+
+
+ /**
+ * Gets short names for this SchemaObject if any exists for it, otherwise,
+ * returns an empty list.
*
* @return the names for this SchemaObject
*/
- String[] getNamesRef();
+ List<String> getNames();
/**
* Gets the first name in the set of short names for this SchemaObject if
* any exists for it.
*
- * @return the first of the names for this SchemaObject or null if one does
- * not exist
+ * @return the first of the names for this SchemaObject or the oid
+ * if one does not exist
*/
String getName();
/**
+ * Inject this SchemaObject into the given registries, updating the references to
+ * other SchemaObject
+ *
+ * @param errors The errors we got
+ * @param registries The Registries
+ */
+ void addToRegistries( List<Throwable> errors, Registries registries ) throws NamingException;
+
+
+ /**
+ * Remove this SchemaObject from the given registries, updating the references to
+ * other SchemaObject
+ *
+ * @param errors The errors we got
+ * @param registries The Registries
+ */
+ void removeFromRegistries( List<Throwable> errors, Registries registries ) throws NamingException;
+
+
+ /**
+ * Add a new name to the list of names for this SchemaObject. The name
+ * is lowercased and trimmed.
+ *
+ * @param names The names to add
+ */
+ void addName( String... names );
+
+
+ /**
+ * Sets the list of names for this SchemaObject. The names are
+ * lowercased and trimmed.
+ *
+ * @param names The list of names. Can be empty
+ */
+ void setNames( List<String> names );
+
+
+ /**
* Gets a short description about this SchemaObject.
*
* @return a short description about this SchemaObject
*/
- String getDescription();
-
-
+ public String getDescription();
+
+
+ /**
+ * Sets the SchemaObject's description
+ *
+ * @param description The SchemaObject's description
+ */
+ public void setDescription( String description );
+
+
+ /**
+ * Gets the SchemaObject specification.
+ *
+ * @return the SchemaObject specification
+ */
+ public String getSpecification();
+
+
+ /**
+ * Sets the SchemaObject's specification
+ *
+ * @param specification The SchemaObject's specification
+ */
+ void setSpecification( String specification );
+
+
+ /**
+ * Tells if this SchemaObject is enabled.
+ *
+ * @param schemaEnabled the associated schema status
+ * @return true if the SchemaObject is enabled, or if it depends on
+ * an enabled schema
+ */
+ boolean isEnabled();
+
+
+ /**
+ * Tells if this SchemaObject is disabled.
+ *
+ * @return true if the SchemaObject is disabled
+ */
+ boolean isDisabled();
+
+
+ /**
+ * Sets the SchemaObject state, either enabled or disabled.
+ *
+ * @param enabled The current SchemaObject state
+ */
+ void setEnabled( boolean enabled );
+
+
+ /**
+ * Tells if this SchemaObject is ReadOnly.
+ *
+ * @return true if the SchemaObject is not modifiable
+ */
+ boolean isReadOnly();
+
+
+ /**
+ * Sets the SchemaObject readOnly flag
+ *
+ * @param enabled The current SchemaObject ReadOnly status
+ */
+ void setReadOnly( boolean isReadOnly );
+
+
+ /**
+ * Gets whether or not this SchemaObject has been inactivated. All
+ * SchemaObjects except Syntaxes allow for this parameter within their
+ * definition. For Syntaxes this property should always return false in
+ * which case it is never included in the description.
+ *
+ * @return true if inactive, false if active
+ */
+ boolean isObsolete();
+
+
+ /**
+ * Sets the Obsolete flag.
+ *
+ * @param obsolete The Obsolete flag state
+ */
+ void setObsolete( boolean obsolete );
+
+
+ /**
+ * @return The SchemaObject extensions, as a Map of [extension, values]
+ */
+ Map<String, List<String>> getExtensions();
+
+
+ /**
+ * Add an extension with its values
+ * @param key The extension key
+ * @param values The associated values
+ */
+ void addExtension( String key, List<String> values );
+
+
+ /**
+ * Add an extensions with their values. (Actually do a copy)
+ *
+ * @param key The extension key
+ * @param values The associated values
+ */
+ void setExtensions( Map<String, List<String>> extensions );
+
+
+ /**
+ * The SchemaObject type :
+ * <li> AttributeType
+ * <li> DitCOntentRule
+ * <li> DitStructureRule
+ * <li> LdapComparator (specific to ADS)
+ * <li> LdapSyntaxe
+ * <li> MatchingRule
+ * <li> MatchingRuleUse
+ * <li> NameForm
+ * <li> Normalizer (specific to ADS)
+ * <li> ObjectClass
+ * <li> SyntaxChecker (specific to ADS)
+ *
+ * @return the SchemaObject type
+ */
+ SchemaObjectType getObjectType();
+
+
/**
* Gets the name of the schema this SchemaObject is associated with.
*
* @return the name of the schema associated with this schemaObject
*/
- String getSchema();
+ String getSchemaName();
/**
@@ -94,5 +294,58 @@
*
* @param schemaName the new schema name
*/
- void setSchema( String schemaName );
+ void setSchemaName( String schemaName );
+
+
+ /**
+ * @see Object#hashCode()
+ */
+ int hashCode();
+
+
+ /**
+ * @see Object#equals(Object)
+ */
+ boolean equals( Object o1 );
+
+
+ /**
+ * Register the given SchemaObject into the given registries' globalOidRegistry
+ *
+ * @param schemaObject the SchemaObject we want to register
+ * @param registries The registries in which we want it to be stored
+ * @throws NamingException If the OID is invalid
+ */
+ void registerOid( SchemaObject schemaObject, Registries registries ) throws NamingException;
+
+
+ /**
+ * Copy the current SchemaObject on place
+ *
+ * @return The copied SchemaObject
+ */
+ SchemaObject copy();
+
+
+ /**
+ * Copy a SchemaObject.
+ *
+ * @return A copy of the current SchemaObject
+ */
+ SchemaObject copy( SchemaObject original );
+
+
+ /**
+ * Clear the current SchemaObject : remove all the references to other objects,
+ * and all the Maps.
+ */
+ void clear();
+
+
+ /**
+ * Inject the Registries into the SchemaObject
+ *
+ * @param registries The Registries
+ */
+ void setRegistries( Registries registries );
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaUtils.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaUtils.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaUtils.java Wed Jan 6 17:52:15 2010
@@ -28,13 +28,11 @@
import javax.naming.NamingException;
+import org.apache.directory.shared.ldap.constants.MetaSchemaConstants;
import org.apache.directory.shared.ldap.entry.Entry;
import org.apache.directory.shared.ldap.entry.EntryAttribute;
import org.apache.directory.shared.ldap.entry.Modification;
import org.apache.directory.shared.ldap.entry.Value;
-import org.apache.directory.shared.ldap.schema.parsers.AbstractAdsSchemaDescription;
-import org.apache.directory.shared.ldap.schema.parsers.AbstractSchemaDescription;
-import org.apache.directory.shared.ldap.schema.parsers.AttributeTypeDescription;
import org.apache.directory.shared.ldap.util.StringTools;
@@ -135,23 +133,25 @@
* the quoted description strings to render
* @return the same string buffer that was given for call chaining
*/
- public static StringBuffer render( StringBuffer buf, String[] qdescrs )
+ public static StringBuffer render( StringBuffer buf, List<String> qdescrs )
{
- if ( qdescrs == null || qdescrs.length == 0 )
+ if ( ( qdescrs == null ) || ( qdescrs.size() == 0 ) )
{
return buf;
}
- else if ( qdescrs.length == 1 )
+ else if ( qdescrs.size() == 1 )
{
- buf.append( "'" ).append( qdescrs[0] ).append( "'" );
+ buf.append( "'" ).append( qdescrs.get( 0 ) ).append( "'" );
}
else
{
buf.append( "( " );
- for ( int ii = 0; ii < qdescrs.length; ii++ )
+
+ for ( String qdescr : qdescrs )
{
- buf.append( "'" ).append( qdescrs[ii] ).append( "' " );
+ buf.append( "'" ).append( qdescr ).append( "' " );
}
+
buf.append( ")" );
}
@@ -166,7 +166,7 @@
* the quoted description strings to render
* @return the string buffer the qdescrs are rendered into
*/
- public static StringBuffer render( String[] qdescrs )
+ public static StringBuffer render( List<String> qdescrs )
{
StringBuffer buf = new StringBuffer();
return render( buf, qdescrs );
@@ -345,10 +345,10 @@
StringBuffer buf = new StringBuffer();
buf.append( "( " ).append( oc.getOid() );
- if ( oc.getNamesRef() != null && oc.getNamesRef().length > 0 )
+ if ( oc.getNames() != null && oc.getNames().size() > 0 )
{
buf.append( " NAME " );
- render( buf, oc.getNamesRef() ).append( " " );
+ render( buf, oc.getNames() ).append( " " );
}
else
{
@@ -365,10 +365,10 @@
buf.append( " OBSOLETE " );
}
- if ( oc.getSuperClasses() != null && oc.getSuperClasses().length > 0 )
+ if ( ( oc.getSuperiorOids() != null ) && ( oc.getSuperiorOids().size() > 0 ) )
{
buf.append( "SUP " );
- render( buf, oc.getSuperClasses() );
+ render( buf, oc.getSuperiorOids() );
}
if ( oc.getType() != null )
@@ -376,20 +376,20 @@
buf.append( " " ).append( oc.getType() );
}
- if ( oc.getMustList() != null && oc.getMustList().length > 0 )
+ if ( ( oc.getMustAttributeTypeOids() != null ) && ( oc.getMustAttributeTypeOids().size() > 0 ) )
{
buf.append( " MUST " );
- render( buf, oc.getMustList() );
+ render( buf, oc.getMustAttributeTypeOids() );
}
- if ( oc.getMayList() != null && oc.getMayList().length > 0 )
+ if ( ( oc.getMayAttributeTypeOids() != null ) && ( oc.getMayAttributeTypeOids().size() > 0 ) )
{
buf.append( " MAY " );
- render( buf, oc.getMayList() );
+ render( buf, oc.getMayAttributeTypeOids() );
}
buf.append( " X-SCHEMA '" );
- buf.append( oc.getSchema() );
+ buf.append( oc.getSchemaName() );
buf.append( "'" );
// @todo extensions are not presently supported and skipped
@@ -464,10 +464,10 @@
StringBuffer buf = new StringBuffer();
buf.append( "( " ).append( at.getOid() );
- if ( at.getNamesRef() != null && at.getNamesRef().length > 0 )
+ if ( at.getNames() != null && at.getNames().size() > 0 )
{
buf.append( " NAME " );
- render( buf, at.getNamesRef() ).append( " " );
+ render( buf, at.getNames() ).append( " " );
}
else
{
@@ -499,22 +499,22 @@
buf.append( " ORDERING " ).append( at.getOrdering().getName() );
}
- if ( at.getSubstr() != null )
+ if ( at.getSubstring() != null )
{
- buf.append( " SUBSTR " ).append( at.getSubstr().getName() );
+ buf.append( " SUBSTR " ).append( at.getSubstring().getName() );
}
if ( at.getSyntax() != null )
{
buf.append( " SYNTAX " ).append( at.getSyntax().getOid() );
- if ( at.getLength() > 0 )
+ if ( at.getSyntaxLength() > 0 )
{
- buf.append( "{" ).append( at.getLength() ).append( "}" );
+ buf.append( "{" ).append( at.getSyntaxLength() ).append( "}" );
}
}
- if ( at.isSingleValue() )
+ if ( at.isSingleValued() )
{
buf.append( " SINGLE-VALUE" );
}
@@ -524,7 +524,7 @@
buf.append( " COLLECTIVE" );
}
- if ( !at.isCanUserModify() )
+ if ( !at.isUserModifiable() )
{
buf.append( " NO-USER-MODIFICATION" );
}
@@ -535,7 +535,7 @@
}
buf.append( " X-SCHEMA '" );
- buf.append( at.getSchema() );
+ buf.append( at.getSchemaName() );
buf.append( "'" );
// @todo extensions are not presently supported and skipped
@@ -605,83 +605,83 @@
* @return the StringBuffer containing the rendered attributeType description
* @throws NamingException if there are problems accessing the objects
* associated with the attribute type.
- */
- public static StringBuffer render( AttributeTypeDescription atd )
+ *
+ public static StringBuffer render( AttributeType attributeType )
{
StringBuffer buf = new StringBuffer();
- buf.append( "( " ).append( atd.getNumericOid() );
+ buf.append( "( " ).append( attributeType.getOid() );
- if ( atd.getNames() != null && atd.getNames().size() > 0 )
+ if ( attributeType.getNames() != null && attributeType.getNames().size() > 0 )
{
buf.append( " NAME " );
- render( buf, atd.getNames().toArray( new String[atd.getNames().size()] ) ).append( " " );
+ render( buf, attributeType.getNames() ).append( " " );
}
else
{
buf.append( " " );
}
- if ( atd.getDescription() != null )
+ if ( attributeType.getDescription() != null )
{
- buf.append( "DESC " ).append( "'" ).append( atd.getDescription() ).append( "' " );
+ buf.append( "DESC " ).append( "'" ).append( attributeType.getDescription() ).append( "' " );
}
- if ( atd.isObsolete() )
+ if ( attributeType.isObsolete() )
{
buf.append( " OBSOLETE" );
}
- if ( atd.getSuperType() != null )
+ if ( attributeType.getSupOid() != null )
{
- buf.append( " SUP " ).append( atd.getSuperType() );
+ buf.append( " SUP " ).append( attributeType.getSupOid() );
}
- if ( atd.getEqualityMatchingRule() != null )
+ if ( attributeType.getEqualityOid() != null )
{
- buf.append( " EQUALITY " ).append( atd.getEqualityMatchingRule() );
+ buf.append( " EQUALITY " ).append( attributeType.getEqualityOid() );
}
- if ( atd.getOrderingMatchingRule() != null )
+ if ( attributeType.getOrderingOid() != null )
{
- buf.append( " ORDERING " ).append( atd.getOrderingMatchingRule() );
+ buf.append( " ORDERING " ).append( attributeType.getOrderingOid() );
}
- if ( atd.getSubstringsMatchingRule() != null )
+ if ( attributeType.getSubstrOid() != null )
{
- buf.append( " SUBSTR " ).append( atd.getSubstringsMatchingRule() );
+ buf.append( " SUBSTR " ).append( attributeType.getSubstrOid() );
}
- if ( atd.getSyntax() != null )
+ if ( attributeType.getSyntax() != null )
{
- buf.append( " SYNTAX " ).append( atd.getSyntax() );
+ buf.append( " SYNTAX " ).append( attributeType.getSyntax() );
- if ( atd.getSyntaxLength() > 0 )
+ if ( attributeType.getLength() > 0 )
{
- buf.append( "{" ).append( atd.getSyntaxLength() ).append( "}" );
+ buf.append( "{" ).append( attributeType.getLength() ).append( "}" );
}
}
- if ( atd.isSingleValued() )
+ if ( attributeType.isSingleValue() )
{
buf.append( " SINGLE-VALUE" );
}
- if ( atd.isCollective() )
+ if ( attributeType.isCollective() )
{
buf.append( " COLLECTIVE" );
}
- if ( !atd.isUserModifiable() )
+ if ( !attributeType.isCanUserModify() )
{
buf.append( " NO-USER-MODIFICATION" );
}
- if ( atd.getUsage() != null )
+ if ( attributeType.getUsage() != null )
{
- buf.append( " USAGE " ).append( UsageEnum.render( atd.getUsage() ) );
+ buf.append( " USAGE " ).append( UsageEnum.render( attributeType.getUsage() ) );
}
- return buf.append( render( atd.getExtensions() ) ).append( ")" );
+ return buf.append( render( attributeType.getExtensions() ) ).append( ")" );
}
@@ -787,10 +787,10 @@
StringBuffer buf = new StringBuffer();
buf.append( "( " ).append( mr.getOid() );
- if ( mr.getNamesRef() != null && mr.getNamesRef().length > 0 )
+ if ( mr.getNames() != null && mr.getNames().size() > 0 )
{
buf.append( " NAME " );
- render( buf, mr.getNamesRef() ).append( " " );
+ render( buf, mr.getNames() ).append( " " );
}
else
{
@@ -813,7 +813,7 @@
}
buf.append( " X-SCHEMA '" );
- buf.append( mr.getSchema() );
+ buf.append( mr.getSchemaName() );
buf.append( "'" );
// @todo extensions are not presently supported and skipped
@@ -848,7 +848,7 @@
* @param syntax the Syntax to render the description for
* @return the StringBuffer containing the rendered syntax description
*/
- public static StringBuffer render( Syntax syntax )
+ public static StringBuffer render( LdapSyntax syntax )
{
StringBuffer buf = new StringBuffer();
buf.append( "( " ).append( syntax.getOid() ).append( " " );
@@ -859,7 +859,7 @@
}
buf.append( " X-SCHEMA '" );
- buf.append( syntax.getSchema() );
+ buf.append( syntax.getSchemaName() );
if ( syntax.isHumanReadable() )
{
@@ -886,7 +886,7 @@
{
StringBuffer buf = new StringBuffer();
buf.append( "( " ).append( mru.getOid() ).append( " NAME " );
- render( buf, mru.getNamesRef() ).append( " " );
+ render( buf, mru.getNames() ).append( " " );
if ( mru.getDescription() != null )
{
@@ -894,7 +894,7 @@
}
buf.append( " X-SCHEMA '" );
- buf.append( mru.getSchema() );
+ buf.append( mru.getSchemaName() );
buf.append( "'" );
// @todo extensions are not presently supported and skipped
@@ -913,7 +913,7 @@
{
StringBuffer buf = new StringBuffer();
buf.append( "( " ).append( dcr.getOid() ).append( " NAME " );
- render( buf, dcr.getNamesRef() ).append( " " );
+ render( buf, dcr.getNames() ).append( " " );
if ( dcr.getDescription() != null )
{
@@ -921,7 +921,7 @@
}
buf.append( " X-SCHEMA '" );
- buf.append( dcr.getSchema() );
+ buf.append( dcr.getSchemaName() );
buf.append( "'" );
// @todo extensions are not presently supported and skipped
@@ -940,7 +940,7 @@
{
StringBuffer buf = new StringBuffer();
buf.append( "( " ).append( dsr.getOid() ).append( " NAME " );
- render( buf, dsr.getNamesRef() ).append( " " );
+ render( buf, dsr.getNames() ).append( " " );
if ( dsr.getDescription() != null )
{
@@ -948,7 +948,7 @@
}
buf.append( " X-SCHEMA '" );
- buf.append( dsr.getSchema() );
+ buf.append( dsr.getSchemaName() );
buf.append( "' )" );
return buf;
@@ -962,7 +962,7 @@
{
StringBuffer buf = new StringBuffer();
buf.append( "( " ).append( nf.getOid() ).append( " NAME " );
- render( buf, nf.getNamesRef() ).append( " " );
+ render( buf, nf.getNames() ).append( " " );
if ( nf.getDescription() != null )
{
@@ -970,7 +970,7 @@
}
buf.append( " X-SCHEMA '" );
- buf.append( nf.getSchema() );
+ buf.append( nf.getSchemaName() );
buf.append( "' )" );
return buf;
@@ -985,10 +985,10 @@
* @param description The description to transform to a String
* @return
*/
- public static String render( AbstractAdsSchemaDescription description )
+ public static String render( LoadableSchemaObject description )
{
StringBuilder buf = new StringBuilder();
- buf.append( "( " ).append( description.getNumericOid() ).append( " " );
+ buf.append( "( " ).append( description.getOid() ).append( " " );
if ( description.getDescription() != null )
{
@@ -997,26 +997,26 @@
buf.append( "FQCN " ).append( description.getFqcn() ).append( " " );
- if ( description.getBytecode() != null )
+ if ( !StringTools.isEmpty( description.getBytecode() ) )
{
buf.append( "BYTECODE " ).append( description.getBytecode() );
}
buf.append( " X-SCHEMA '" );
- buf.append( getSchema( description ) );
+ buf.append( getSchemaName( description ) );
buf.append( "' )" );
return buf.toString();
}
- private static String getSchema( AbstractSchemaDescription desc )
+ private static String getSchemaName( SchemaObject desc )
{
- List<String> values = desc.getExtensions().get( "X-SCHEMA" );
+ List<String> values = desc.getExtensions().get( MetaSchemaConstants.X_SCHEMA );
if ( values == null || values.size() == 0 )
{
- return "other";
+ return MetaSchemaConstants.SCHEMA_OTHER;
}
return values.get( 0 );
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SyntaxChecker.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SyntaxChecker.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SyntaxChecker.java Wed Jan 6 17:52:15 2010
@@ -22,6 +22,9 @@
import javax.naming.NamingException;
+import org.apache.directory.shared.ldap.exception.LdapInvalidAttributeValueException;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+
/**
* Used to validate values of a particular syntax. This interface does not
@@ -31,14 +34,29 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
*/
-public interface SyntaxChecker
+public abstract class SyntaxChecker extends LoadableSchemaObject
{
+ /** The serialversionUID */
+ private static final long serialVersionUID = 1L;
+
/**
- * Gets the OID of the attribute syntax.
- *
- * @return the object identifier of the Syntax this SyntaxChecker validates
+ * The SyntaxChecker base constructor
+ * @param oid The associated OID
+ */
+ protected SyntaxChecker( String oid )
+ {
+ super( SchemaObjectType.SYNTAX_CHECKER, oid );
+ }
+
+
+ /**
+ * The SyntaxChecker default constructor where the oid is set after
+ * instantiation.
*/
- String getSyntaxOid();
+ protected SyntaxChecker()
+ {
+ super( SchemaObjectType.SYNTAX_CHECKER );
+ }
/**
@@ -47,7 +65,7 @@
* @param value the value of some attribute with the syntax
* @return true if the value is in the valid syntax, false otherwise
*/
- boolean isValidSyntax( Object value );
+ public abstract boolean isValidSyntax( Object value );
/**
@@ -57,5 +75,34 @@
* @param value the value of some attribute with the syntax
* @throws NamingException if the value does not conform to the attribute syntax.
*/
- void assertSyntax( Object value ) throws NamingException;
+ public void assertSyntax( Object value ) throws NamingException
+ {
+ if ( !isValidSyntax( value ) )
+ {
+ throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+ }
+ }
+
+
+ /**
+ * @see Object#equals()
+ */
+ public boolean equals( Object o )
+ {
+ if ( !super.equals( o ) )
+ {
+ return false;
+ }
+
+ return o instanceof SyntaxChecker;
+ }
+
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString()
+ {
+ return objectType + " " + DescriptionUtils.getDescription( this );
+ }
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/UsageEnum.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/UsageEnum.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/UsageEnum.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/UsageEnum.java Wed Jan 6 17:52:15 2010
@@ -119,7 +119,7 @@
{
if ( usage == null)
{
- return "";
+ return "userApplications";
}
switch ( usage )
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/BooleanComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/BooleanComparator.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/BooleanComparator.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/BooleanComparator.java Wed Jan 6 17:52:15 2010
@@ -19,8 +19,10 @@
*/
package org.apache.directory.shared.ldap.schema.comparators;
+import org.apache.directory.shared.ldap.schema.LdapComparator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-import java.util.Comparator;
/**
* A class for the BooleanComparator matchingRule (RFC 4517, par. 4.2.2)
@@ -28,17 +30,34 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev: 437007 $
*/
-public class BooleanComparator implements Comparator<Object>
+public class BooleanComparator extends LdapComparator<String>
{
+ /** A logger for this class */
+ private static final Logger LOG = LoggerFactory.getLogger( BooleanComparator.class );
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The BooleanComparator constructor. Its OID is the BooleanMatch matching
+ * rule OID.
+ */
+ public BooleanComparator( String oid )
+ {
+ super( oid );
+ }
+
/**
* Implementation of the Compare method
*/
- public int compare( Object backendValue, Object assertValue )
+ public int compare( String b1, String b2 )
{
+ LOG.debug( "comparing boolean objects '{}' with '{}'", b1, b2 );
+
// First, shortcut the process by comparing
// references. If they are equals, then o1 and o2
// reference the same object
- if ( backendValue == assertValue )
+ if ( b1 == b2 )
{
return 0;
}
@@ -46,16 +65,11 @@
// Then, deal with one of o1 or o2 being null
// Both can't be null, because then they would
// have been catched by the previous test
- if ( ( backendValue == null ) || ( assertValue == null ) )
+ if ( ( b1 == null ) || ( b2 == null ) )
{
- return ( backendValue == null ? -1 : 1 );
+ return ( b1 == null ? -1 : 1 );
}
- // Both object must be stored as String for boolean
- // values. If this is not the case, we have a pb...
- // However, the method will then throw a ClassCastException
- String b1 = (String)backendValue;
-
// The boolean should have been stored as 'TRUE' or 'FALSE'
// into the server, and the compare method will be called
// with normalized booleans, so no need to uppercase them.
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/ByteArrayComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/ByteArrayComparator.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/ByteArrayComparator.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/ByteArrayComparator.java Wed Jan 6 17:52:15 2010
@@ -20,7 +20,10 @@
package org.apache.directory.shared.ldap.schema.comparators;
-import java.util.Comparator;
+import org.apache.directory.shared.ldap.schema.LdapComparator;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
@@ -29,16 +32,31 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$
*/
-public class ByteArrayComparator implements Comparator<byte[]>
+public class ByteArrayComparator extends LdapComparator<byte[]>
{
- /** A static instance of this comparator */
- public static final Comparator<byte[]> INSTANCE = new ByteArrayComparator();
+ /** A logger for this class */
+ private static final Logger LOG = LoggerFactory.getLogger( ByteArrayComparator.class );
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The ByteArrayComparator constructor. Its OID is the OctetStringMatch matching
+ * rule OID.
+ */
+ public ByteArrayComparator( String oid )
+ {
+ super( oid );
+ }
/**
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
public int compare( byte[] b1, byte[] b2 )
{
+ LOG.debug( "comparing OctetString objects '{}' with '{}'",
+ StringTools.dumpBytes( b1 ), StringTools.dumpBytes( b2 ) );
+
// -------------------------------------------------------------------
// Handle some basis cases
// -------------------------------------------------------------------
@@ -55,13 +73,13 @@
if ( b1.length == b2.length )
{
- for ( int ii = 0; ii < b1.length; ii++ )
+ for ( int i = 0; i < b1.length; i++ )
{
- if ( b1[ii] > b2[ii] )
+ if ( b1[i] > b2[i] )
{
return 1;
}
- else if ( b1[ii] < b2[ii] )
+ else if ( b1[i] < b2[i] )
{
return -1;
}
@@ -71,13 +89,14 @@
}
int minLength = Math.min( b1.length, b2.length );
- for ( int ii = 0; ii < minLength; ii++ )
+
+ for ( int i = 0; i < minLength; i++ )
{
- if ( b1[ii] > b2[ii] )
+ if ( b1[i] > b2[i] )
{
return 1;
}
- else if ( b1[ii] < b2[ii] )
+ else if ( b1[i] < b2[i] )
{
return -1;
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/ComparableComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/ComparableComparator.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/ComparableComparator.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/ComparableComparator.java Wed Jan 6 17:52:15 2010
@@ -20,9 +20,12 @@
package org.apache.directory.shared.ldap.schema.comparators;
-import java.io.Serializable;
import java.util.Comparator;
+import org.apache.directory.shared.ldap.schema.LdapComparator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* Compares two objects taking into account that one might be a Comparable.
@@ -30,10 +33,22 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$
*/
-public class ComparableComparator implements Comparator, Serializable
+public class ComparableComparator<T> extends LdapComparator<Comparable<T>>
{
- private static final long serialVersionUID = -5295278271807198471L;
+ /** A logger for this class */
+ private static final Logger LOG = LoggerFactory.getLogger( ComparableComparator.class );
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The BooleanComparator constructor. Its OID is the BooleanMatch matching
+ * rule OID.
+ */
+ public ComparableComparator( String oid )
+ {
+ super( oid );
+ }
/**
* Compares two objects taking into account that one may be a Comparable. If
@@ -45,14 +60,16 @@
*
* @see Comparator#compare(Object, Object)
*/
- public int compare( Object o1, Object o2 )
+ public int compare( Comparable<T> o1, Comparable<T> o2 )
{
+ LOG.debug( "comparing objects '{}' with '{}'", o1, o2 );
+
if ( ( o1 == null ) && ( o2 == null ) )
{
return 0;
}
- if ( o1 instanceof Comparable )
+ if ( o1 instanceof Comparable<?> )
{
if ( o2 == null )
{
@@ -60,7 +77,7 @@
}
else
{
- return ( ( Comparable ) o1 ).compareTo( o2 );
+ return o1.compareTo( ( T ) o2 );
}
}
@@ -68,7 +85,7 @@
{
return 1;
}
- else if ( o2 instanceof Comparable )
+ else if ( o2 instanceof Comparable<?> )
{
if ( o1 == null )
{
@@ -76,7 +93,7 @@
}
else
{
- return -( ( Comparable ) o2 ).compareTo( o1 );
+ return - o2.compareTo( ( T ) o1 );
}
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/CsnComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/CsnComparator.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/CsnComparator.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/CsnComparator.java Wed Jan 6 17:52:15 2010
@@ -20,9 +20,10 @@
package org.apache.directory.shared.ldap.schema.comparators;
-import java.util.Comparator;
-
import org.apache.directory.shared.ldap.csn.Csn;
+import org.apache.directory.shared.ldap.schema.LdapComparator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
@@ -37,21 +38,34 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$
*/
-public class CsnComparator implements Comparator<String>
+public class CsnComparator extends LdapComparator<String>
{
- /** A static instance of this comparator */
- public static final Comparator<String> INSTANCE = new CsnComparator();
-
-
+ /** A logger for this class */
+ private static final Logger LOG = LoggerFactory.getLogger( CsnComparator.class );
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The CsnComparator constructor. Its OID is the CsnMatch matching
+ * rule OID.
+ */
+ public CsnComparator( String oid )
+ {
+ super( oid );
+ }
+
+
/**
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
public int compare( String csnStr1, String csnStr2 )
{
+ LOG.debug( "comparing CSN objects '{}' with '{}'", csnStr1, csnStr2 );
+
// -------------------------------------------------------------------
// Handle some basis cases
// -------------------------------------------------------------------
-
if ( csnStr1 == null )
{
return ( csnStr2 == null ) ? 0 : -1;
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/CsnSidComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/CsnSidComparator.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/CsnSidComparator.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/CsnSidComparator.java Wed Jan 6 17:52:15 2010
@@ -20,7 +20,9 @@
package org.apache.directory.shared.ldap.schema.comparators;
-import java.util.Comparator;
+import org.apache.directory.shared.ldap.schema.LdapComparator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
@@ -31,10 +33,22 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$
*/
-public class CsnSidComparator implements Comparator<String>
+public class CsnSidComparator extends LdapComparator<String>
{
- /** A static instance of this comparator */
- public static final Comparator<String> INSTANCE = new CsnSidComparator();
+ /** A logger for this class */
+ private static final Logger LOG = LoggerFactory.getLogger( CsnSidComparator.class );
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The CsnSidComparator constructor. Its OID is the CsnSidMatch matching
+ * rule OID.
+ */
+ public CsnSidComparator( String oid )
+ {
+ super( oid );
+ }
/**
@@ -42,10 +56,11 @@
*/
public int compare( String sidStr1, String sidStr2 )
{
+ LOG.debug( "comparing CSN SID objects '{}' with '{}'", sidStr1, sidStr2 );
+
// -------------------------------------------------------------------
// Handle some basis cases
// -------------------------------------------------------------------
-
if ( sidStr1 == null )
{
return ( sidStr2 == null ) ? 0 : -1;
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/IntegerOrderingComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/IntegerOrderingComparator.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/IntegerOrderingComparator.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/IntegerOrderingComparator.java Wed Jan 6 17:52:15 2010
@@ -20,7 +20,9 @@
package org.apache.directory.shared.ldap.schema.comparators;
-import java.util.Comparator;
+import org.apache.directory.shared.ldap.schema.LdapComparator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* A class for the IntegerOrderingComparator matchingRule (RFC 4517, par. 4.2.20)
@@ -28,13 +30,31 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev: 437007 $
*/
-public class IntegerOrderingComparator implements Comparator<Object>
+public class IntegerOrderingComparator extends LdapComparator<String>
{
+ /** A logger for this class */
+ private static final Logger LOG = LoggerFactory.getLogger( IntegerOrderingComparator.class );
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The IntegerOrderingComparator constructor. Its OID is the IntegerOrderingMatch matching
+ * rule OID.
+ */
+ public IntegerOrderingComparator( String oid )
+ {
+ super( oid );
+ }
+
+
/**
* Implementation of the Compare method
*/
- public int compare( Object backendValue, Object assertValue )
+ public int compare( String backendValue, String assertValue )
{
+ LOG.debug( "comparing IntegerOrdering objects '{}' with '{}'", backendValue, assertValue );
+
// First, shortcut the process by comparing
// references. If they are equals, then o1 and o2
// reference the same object
@@ -54,8 +74,8 @@
// Both object must be stored as String for boolean
// values. If this is not the case, we have a pb...
// However, the method will then throw a ClassCastException
- int b1 = Integer.parseInt( (String)backendValue );
- int b2 = Integer.parseInt( (String)assertValue );
+ long b1 = Long.parseLong( backendValue );
+ long b2 = Long.parseLong( assertValue );
if ( b1 == b2 )
{
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/NormalizingComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/NormalizingComparator.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/NormalizingComparator.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/NormalizingComparator.java Wed Jan 6 17:52:15 2010
@@ -21,9 +21,10 @@
import java.util.Comparator;
+
import javax.naming.NamingException;
-import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.schema.LdapComparator;
import org.apache.directory.shared.ldap.schema.Normalizer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -36,15 +37,19 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$
*/
-public class NormalizingComparator implements Comparator
+/* no qualifier*/ class NormalizingComparator extends LdapComparator<String>
{
- private static final Logger log = LoggerFactory.getLogger( NormalizingComparator.class );
+ /** A logger for this class */
+ private static final Logger LOG = LoggerFactory.getLogger( NormalizingComparator.class );
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
/** the Normalizer to normalize values with before comparing */
private Normalizer normalizer;
/** the underlying comparator to use for comparisons */
- private Comparator<Object> comparator;
+ private LdapComparator<String> comparator;
/**
@@ -53,8 +58,9 @@
* @param normalizer the Normalizer to normalize values with before comparing
* @param comparator the underlying comparator to use for comparisons
*/
- public NormalizingComparator( Normalizer normalizer, Comparator<Object> comparator )
+ public NormalizingComparator( String oid, Normalizer normalizer, LdapComparator<String> comparator )
{
+ super( oid );
this.normalizer = normalizer;
this.comparator = comparator;
}
@@ -66,31 +72,46 @@
*
* @see Comparator#compare(Object, Object)
*/
- public int compare( Object o1, Object o2 )
+ public int compare( String o1, String o2 )
{
- Object n1;
- Object n2;
+ String n1;
+ String n2;
try
{
- n1 = normalizer.normalize( (String)o1 );
+ n1 = normalizer.normalize( o1 );
}
catch ( NamingException e )
{
- log.warn( "Failed to normalize: " + o1, e );
+ LOG.warn( "Failed to normalize: " + o1, e );
n1 = o1;
}
try
{
- n2 = normalizer.normalize( (String)o2 );
+ n2 = normalizer.normalize( o2 );
}
catch ( NamingException e )
{
- log.warn( "Failed to normalize: " + o2, e );
+ LOG.warn( "Failed to normalize: " + o2, e );
n2 = o2;
}
return comparator.compare( n1, n2 );
}
+
+
+ /**
+ * Makes sure we update the oid property of the contained normalizer and
+ * comparator.
+ *
+ * @param oid the object identifier
+ */
+ @Override
+ public void setOid( String oid )
+ {
+ super.setOid( oid );
+ normalizer.setOid( oid );
+ comparator.setOid( oid );
+ }
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/ObjectIdentifierComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/ObjectIdentifierComparator.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/ObjectIdentifierComparator.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/ObjectIdentifierComparator.java Wed Jan 6 17:52:15 2010
@@ -20,8 +20,9 @@
package org.apache.directory.shared.ldap.schema.comparators;
-import java.io.Serializable;
-import java.util.Comparator;
+import org.apache.directory.shared.ldap.schema.LdapComparator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
@@ -30,13 +31,35 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$
*/
-public class ObjectIdentifierComparator implements Comparator, Serializable
+public class ObjectIdentifierComparator extends LdapComparator<Object>
{
- private static final long serialVersionUID = -2374941241008282707L;
+ /** A logger for this class */
+ private static final Logger LOG = LoggerFactory.getLogger( ObjectIdentifierComparator.class );
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The ObjectIdentifierComparator constructor. Its OID is the ObjectIdentifierMatch matching
+ * rule OID.
+ */
+ public ObjectIdentifierComparator( String oid )
+ {
+ super( oid );
+ }
+
+
+ /**
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+ */
public int compare( Object o1, Object o2 )
{
+ LOG.debug( "comparing ObjectIdentifier objects '{}' with '{}'", o1, o2 );
+
+ // -------------------------------------------------------------------
+ // Handle some basis cases
+ // -------------------------------------------------------------------
if ( o1 == null )
{
return ( o2 == null ) ? 0 : -1;
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/StringComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/StringComparator.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/StringComparator.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/StringComparator.java Wed Jan 6 17:52:15 2010
@@ -20,7 +20,9 @@
package org.apache.directory.shared.ldap.schema.comparators;
-import java.util.Comparator;
+import org.apache.directory.shared.ldap.schema.LdapComparator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
@@ -29,20 +31,33 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$
*/
-public class StringComparator implements Comparator<String>
+public class StringComparator extends LdapComparator<String>
{
- /** A static instance of this comparator */
- public static final Comparator<String> INSTANCE = new StringComparator();
+ /** A logger for this class */
+ private static final Logger LOG = LoggerFactory.getLogger( StringComparator.class );
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The StringComparator constructor. Its OID is the StringMatch matching
+ * rule OID.
+ */
+ public StringComparator( String oid )
+ {
+ super( oid );
+ }
/**
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
public int compare( String s1, String s2 )
{
+ LOG.debug( "comparing String objects '{}' with '{}'", s1, s2 );
+
// -------------------------------------------------------------------
// Handle some basis cases
// -------------------------------------------------------------------
-
if ( s1 == null )
{
return ( s2 == null ) ? 0 : -1;
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/TelephoneNumberComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/TelephoneNumberComparator.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/TelephoneNumberComparator.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/TelephoneNumberComparator.java Wed Jan 6 17:52:15 2010
@@ -20,7 +20,9 @@
package org.apache.directory.shared.ldap.schema.comparators;
-import java.util.Comparator;
+import org.apache.directory.shared.ldap.schema.LdapComparator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
@@ -32,11 +34,23 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$
*/
-public class TelephoneNumberComparator implements Comparator<String>
+public class TelephoneNumberComparator extends LdapComparator<String>
{
- /** A static instance of this comparator */
- public static final Comparator<String> INSTANCE = new TelephoneNumberComparator();
-
+ /** A logger for this class */
+ private static final Logger LOG = LoggerFactory.getLogger( TelephoneNumberComparator.class );
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The TelephoneNumberComparator constructor. Its OID is the TelephoneNumberMatch matching
+ * rule OID.
+ */
+ public TelephoneNumberComparator( String oid )
+ {
+ super( oid );
+ }
+
/**
* Remove all spaces and '-' from the telephone number
@@ -65,10 +79,11 @@
*/
public int compare( String telephoneNumber1, String telephoneNumber2 )
{
+ LOG.debug( "comparing TelephoneNumber objects '{}' with '{}'", telephoneNumber1, telephoneNumber2 );
+
// -------------------------------------------------------------------
// Handle some basis cases
// -------------------------------------------------------------------
-
if ( telephoneNumber1 == null )
{
return ( telephoneNumber2 == null ) ? 0 : -1;
@@ -82,9 +97,9 @@
// -------------------------------------------------------------------
// Remove all spaces and '-'
// -------------------------------------------------------------------
- telephoneNumber1 = strip( telephoneNumber1 );
- telephoneNumber2 = strip( telephoneNumber2 );
+ String strippedTelephoneNumber1 = strip( telephoneNumber1 );
+ String strippedTelephoneNumber2 = strip( telephoneNumber2 );
- return ( telephoneNumber1.compareToIgnoreCase( telephoneNumber2 ) );
+ return ( strippedTelephoneNumber1.compareToIgnoreCase( strippedTelephoneNumber2 ) );
}
}