directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r896579 [4/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...
Date Wed, 06 Jan 2010 17:52:31 GMT
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AttributeType.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AttributeType.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AttributeType.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AttributeType.java Wed Jan  6 17:52:15 2010
@@ -20,8 +20,19 @@
 package org.apache.directory.shared.ldap.schema;
 
 
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
 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.Registries;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 
 /**
  * An attributeType specification. attributeType specifications describe the
@@ -129,15 +140,623 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public interface AttributeType extends SchemaObject
+public class AttributeType extends AbstractSchemaObject implements Cloneable
 {
+    /** A logger for this class */
+    private static final Logger LOG = LoggerFactory.getLogger( AttributeType.class );
+
+    /** The serialVersionUID */
+    public static final long serialVersionUID = 1L;
+
+    /** The syntax OID associated with this AttributeType */
+    private String syntaxOid;
+
+    /** The syntax associated with the syntaxID */
+    private LdapSyntax syntax;
+
+    /** The equality OID associated with this AttributeType */
+    private String equalityOid;
+
+    /** The equality MatchingRule associated with the equalityID */
+    private MatchingRule equality;
+
+    /** The substring OID associated with this AttributeType */
+    private String substringOid;
+
+    /** The substring MatchingRule associated with the substringID */
+    private MatchingRule substring;
+
+    /** The ordering OID associated with this AttributeType */
+    private String orderingOid;
+
+    /** The ordering MatchingRule associated with the orderingID */
+    private MatchingRule ordering;
+
+    /** The superior AttributeType OID */
+    private String superiorOid;
+
+    /** The superior AttributeType */
+    private AttributeType superior;
+
+    /** whether or not this type is single valued */
+    private boolean isSingleValued = false;
+
+    /** whether or not this type is a collective attribute */
+    private boolean isCollective = false;
+
+    /** whether or not this type can be modified by directory users */
+    private boolean canUserModify = true;
+
+    /** the usage for this attributeType */
+    private UsageEnum usage = UsageEnum.USER_APPLICATIONS;
+
+    /** the length of this attribute in bytes */
+    private int syntaxLength = 0;
+
+
+    /**
+     * Creates a AttributeType object using a unique OID.
+     * 
+     * @param oid the OID for this AttributeType
+     */
+    public AttributeType( String oid )
+    {
+        super( SchemaObjectType.ATTRIBUTE_TYPE, oid );
+    }
+
+
+    /**
+     * Build the Superior AttributeType reference for an AttributeType
+     */
+    private boolean buildSuperior( List<Throwable> errors, Registries registries )
+    {
+        AttributeType superior = null;
+        AttributeTypeRegistry attributeTypeRegistry = registries.getAttributeTypeRegistry();
+
+        if ( superiorOid != null )
+        {
+            // This AT has a superior
+            try
+            {
+                superior = attributeTypeRegistry.lookup( superiorOid );
+            }
+            catch ( Exception e )
+            {
+                // Not allowed.
+                String msg = "Cannot find the SUPERIOR object " + superiorOid
+                    + " while building cross-references for the " + getName() + " AttributeType.";
+
+                Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                errors.add( error );
+                LOG.info( msg );
+
+                // Get out now
+                return false;
+            }
+
+            if ( superior != null )
+            {
+                this.superior = superior;
+
+                // Recursively update the superior if not already done. We don't recurse
+                // if the superior's superior is not null, as it means it has already been
+                // handled.
+                if ( superior.getSuperior() == null )
+                {
+                    registries.buildReference( errors, superior );
+                }
+
+                // Update the descendant MAP
+                try
+                {
+                    attributeTypeRegistry.registerDescendants( this, superior );
+                }
+                catch ( NamingException ne )
+                {
+                    errors.add( ne );
+                    LOG.info( ne.getMessage() );
+                    return false;
+                }
+
+                // Check for cycles now
+                Set<String> superiors = new HashSet<String>();
+                superiors.add( oid );
+                AttributeType tmp = superior;
+                boolean isOk = true;
+
+                while ( tmp != null )
+                {
+                    if ( superiors.contains( tmp.getOid() ) )
+                    {
+                        // There is a cycle : bad bad bad !
+                        // Not allowed.
+                        String msg = "A cycle has been detected in the superior hierarchyOid"
+                            + " while building cross-references for the " + getName() + " AttributeType.";
+
+                        Throwable error = new LdapSchemaViolationException( msg,
+                            ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                        errors.add( error );
+                        LOG.info( msg );
+                        isOk = false;
+
+                        break;
+                    }
+                    else
+                    {
+                        superiors.add( tmp.getOid() );
+                        tmp = tmp.getSuperior();
+                    }
+                }
+
+                superiors.clear();
+
+                return isOk;
+            }
+            else
+            {
+                // Not allowed.
+                String msg = "Cannot find the SUPERIOR object " + superiorOid
+                    + " while building cross-references for the " + getName() + " AttributeType.";
+
+                Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                errors.add( error );
+                LOG.info( msg );
+
+                // Get out now
+                return false;
+            }
+        }
+        else
+        {
+            // No superior, just return
+            return true;
+        }
+    }
+
+
+    /**
+     * Build the SYNTAX reference for an AttributeType
+     */
+    private void buildSyntax( List<Throwable> errors, Registries registries )
+    {
+        if ( syntaxOid != null )
+        {
+            LdapSyntax syntax = null;
+
+            try
+            {
+                syntax = registries.getLdapSyntaxRegistry().lookup( syntaxOid );
+            }
+            catch ( NamingException ne )
+            {
+                // Not allowed.
+                String msg = "Cannot find a Syntax object " + syntaxOid + " while building cross-references for the "
+                    + getName() + " AttributeType.";
+
+                Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                errors.add( error );
+                LOG.info( msg );
+                return;
+            }
+
+            if ( syntax != null )
+            {
+                // Update the Syntax reference
+                this.syntax = syntax;
+            }
+            else
+            {
+                // Not allowed.
+                String msg = "Cannot find a Syntax object " + syntaxOid + " while building cross-references for the "
+                    + getName() + " AttributeType.";
+
+                Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                errors.add( error );
+                LOG.info( msg );
+                return;
+            }
+        }
+        else
+        {
+            // We inherit from the superior's syntax, if any
+            if ( superior != null )
+            {
+                this.syntax = superior.getSyntax();
+                this.syntaxOid = this.syntax.getOid();
+            }
+            else
+            {
+                // Not allowed.
+                String msg = "The AttributeType " + getName() + " must have "
+                    + "a syntax OID or a superior, it does not have any.";
+
+                Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                errors.add( error );
+                LOG.info( msg );
+                return;
+            }
+        }
+    }
+
+
+    /**
+     * Build the EQUALITY MR reference for an AttributeType
+     */
+    private void buildEquality( List<Throwable> errors, Registries registries )
+    {
+        // The equality MR. It can be null
+        if ( equalityOid != null )
+        {
+            MatchingRule equality = null;
+
+            try
+            {
+                equality = registries.getMatchingRuleRegistry().lookup( equalityOid );
+            }
+            catch ( NamingException ne )
+            {
+                // Not allowed.
+                String msg = "Cannot find an Equality MatchingRule object for " + equalityOid
+                    + " while building cross-references for the " + getName() + " AttributeType.";
+
+                Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                errors.add( error );
+                LOG.info( msg );
+                return;
+            }
+
+            if ( equality != null )
+            {
+                this.equality = equality;
+            }
+            else
+            {
+                // Not allowed.
+                String msg = "Cannot find an EQUALITY MatchingRule instance for " + equalityOid
+                    + " while building cross-references for the " + getName() + " AttributeType.";
+
+                Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                errors.add( error );
+                LOG.info( msg );
+            }
+        }
+        else
+        {
+            // If the AT has a superior, take its Equality MR if any
+            if ( ( superior != null ) && ( superior.getEquality() != null ) )
+            {
+                this.equality = superior.getEquality();
+                this.equalityOid = this.equality.getOid();
+            }
+        }
+    }
+
+
+    /**
+     * Build the ORDERING MR reference for an AttributeType
+     */
+    private void buildOrdering( List<Throwable> errors, Registries registries )
+    {
+        if ( orderingOid != null )
+        {
+            MatchingRule ordering = null;
+
+            try
+            {
+                ordering = registries.getMatchingRuleRegistry().lookup( orderingOid );
+            }
+            catch ( NamingException ne )
+            {
+                // Not allowed.
+                String msg = "Cannot find a Ordering MatchingRule object for " + orderingOid
+                    + " while building cross-references for the " + getName() + " AttributeType.";
+
+                Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                errors.add( error );
+                LOG.info( msg );
+                return;
+            }
+
+            if ( ordering != null )
+            {
+                this.ordering = ordering;
+            }
+            else
+            {
+                // Not allowed.
+                String msg = "Cannot find an ORDERING MatchingRule instance for " + orderingOid
+                    + " while building cross-references for the " + getName() + " AttributeType.";
+
+                Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                errors.add( error );
+                LOG.info( msg );
+            }
+        }
+        else
+        {
+            // If the AT has a superior, take its Ordering MR if any
+            if ( ( superior != null ) && ( superior.getOrdering() != null ) )
+            {
+                this.ordering = superior.getOrdering();
+                this.orderingOid = this.ordering.getOid();
+            }
+        }
+    }
+
+
+    /**
+     * Build the SUBSTR MR reference for an AttributeType
+     */
+    private void buildSubstring( List<Throwable> errors, Registries registries )
+    {
+        // The Substring MR. It can be null
+        if ( substringOid != null )
+        {
+            MatchingRule substring = null;
+
+            try
+            {
+                substring = registries.getMatchingRuleRegistry().lookup( substringOid );
+            }
+            catch ( NamingException ne )
+            {
+                // Not allowed.
+                String msg = "Cannot find a SUBSTR MatchingRule object for " + substringOid
+                    + " while building cross-references for the " + getName() + " AttributeType.";
+
+                Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                errors.add( error );
+                LOG.info( msg );
+                return;
+            }
+
+            if ( substring != null )
+            {
+                this.substring = substring;
+            }
+            else
+            {
+                // Not allowed.
+                String msg = "Cannot find a SUBSTR MatchingRule instance for " + substringOid
+                    + " while building cross-references for the " + getName() + " AttributeType.";
+
+                Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                errors.add( error );
+                LOG.info( msg );
+                return;
+            }
+        }
+        else
+        {
+            // If the AT has a superior, take its Substring MR if any
+            if ( ( superior != null ) && ( superior.getSubstring() != null ) )
+            {
+                this.substring = superior.getSubstring();
+                this.substringOid = this.substring.getOid();
+            }
+        }
+    }
+
+
+    /**
+     * Check the constraints for the Usage field.
+     */
+    private void checkUsage( List<Throwable> errors, Registries registries )
+    {
+        // Check that the AT usage is the same that its superior
+        if ( ( superior != null ) && ( usage != superior.getUsage() ) )
+        {
+            // This is an error
+            String msg = "The attributeType " + getName() + " must have the same USAGE than its superior";
+
+            Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+            errors.add( error );
+            LOG.info( msg );
+            return;
+        }
+
+        // Now, check that the AttributeType's USAGE does not conflict
+        if ( !isUserModifiable() && ( usage == UsageEnum.USER_APPLICATIONS ) )
+        {
+            // Cannot have a not user modifiable AT which is not an operational AT
+            String msg = "The attributeType " + getName() + " is a USER-APPLICATION attribute, "
+                + "it must be USER-MODIFIABLE";
+
+            Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+            errors.add( error );
+            LOG.info( msg );
+        }
+    }
+
+
+    /**
+     * Check the constraints for the Collective field.
+     */
+    private void checkCollective( List<Throwable> errors, Registries registries )
+    {
+        if ( superior != null )
+        {
+            if ( superior.isCollective() )
+            {
+                // An AttributeType will be collective if its superior is collective
+                this.isCollective = true;
+            }
+        }
+
+        if ( isCollective() && ( usage != UsageEnum.USER_APPLICATIONS ) )
+        {
+            // An AttributeType which is collective must be a USER attributeType
+            String msg = "The attributeType " + getName() + " is a COLLECTIVE AttributeType, "
+                + ", it must be a USER-APPLICATION attributeType too.";
+
+            Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+            errors.add( error );
+            LOG.info( msg );
+        }
+    }
+
+
+    /**
+     * Inject the attributeType into the registries, updating the references to
+     * other SchemaObject.
+     * 
+     * If one of the referenced SchemaObject does not exist (SUP, EQUALITY, ORDERING, SUBSTR, SYNTAX), 
+     * an exception is thrown.
+     *
+     * @param registries The Registries
+     * @exception If the AttributeType is not valid 
+     */
+    public void addToRegistries( List<Throwable> errors, Registries registries ) throws NamingException
+    {
+        if ( registries != null )
+        {
+            AttributeTypeRegistry attributeTypeRegistry = registries.getAttributeTypeRegistry();
+
+            // The superior
+            if ( !buildSuperior( errors, registries ) )
+            {
+                // We have had errors, let's stop here as we need a correct superior to continue
+                return;
+            }
+
+            // The Syntax
+            buildSyntax( errors, registries );
+
+            // The EQUALITY matching rule
+            buildEquality( errors, registries );
+
+            // The ORDERING matching rule
+            buildOrdering( errors, registries );
+
+            // The SUBSTR matching rule
+            buildSubstring( errors, registries );
+
+            // Check the USAGE
+            checkUsage( errors, registries );
+
+            // Check the COLLECTIVE element
+            checkCollective( errors, registries );
+
+            // Inject the attributeType into the oid/normalizer map
+            attributeTypeRegistry.addMappingFor( this );
+
+            // Register this AttributeType into the Descendant map
+            attributeTypeRegistry.registerDescendants( this, superior );
+
+            /**
+             * Add the AT references (using and usedBy) : 
+             * AT -> MR (for EQUALITY, ORDERING and SUBSTR)
+             * AT -> S
+             * AT -> AT
+             */
+            if ( equality != null )
+            {
+                registries.addReference( this, equality );
+            }
+
+            if ( ordering != null )
+            {
+                registries.addReference( this, ordering );
+            }
+
+            if ( substring != null )
+            {
+                registries.addReference( this, substring );
+            }
+
+            if ( syntax != null )
+            {
+                registries.addReference( this, syntax );
+            }
+
+            if ( superior != null )
+            {
+                registries.addReference( this, superior );
+            }
+        }
+    }
+
+
+    /**
+     * Remove the attributeType from the registries, updating the references to
+     * other SchemaObject.
+     * 
+     * If one of the referenced SchemaObject does not exist (SUP, EQUALITY, ORDERING, SUBSTR, SYNTAX), 
+     * an exception is thrown.
+     *
+     * @param registries The Registries
+     * @exception If the AttributeType is not valid 
+     */
+    public void removeFromRegistries( List<Throwable> errors, Registries registries ) throws NamingException
+    {
+        if ( registries != null )
+        {
+            AttributeTypeRegistry attributeTypeRegistry = registries.getAttributeTypeRegistry();
+
+            // Remove the attributeType from the oid/normalizer map
+            attributeTypeRegistry.removeMappingFor( this );
+
+            // Unregister this AttributeType into the Descendant map
+            attributeTypeRegistry.unregisterDescendants( this, superior );
+
+            /**
+             * Remove the AT references (using and usedBy) : 
+             * AT -> MR (for EQUALITY, ORDERING and SUBSTR)
+             * AT -> S
+             * AT -> AT
+             */
+            if ( equality != null )
+            {
+                registries.delReference( this, equality );
+            }
+
+            if ( ordering != null )
+            {
+                registries.delReference( this, ordering );
+            }
+
+            if ( substring != null )
+            {
+                registries.delReference( this, substring );
+            }
+
+            if ( syntax != null )
+            {
+                registries.delReference( this, syntax );
+            }
+
+            if ( superior != null )
+            {
+                registries.delReference( this, superior );
+            }
+        }
+    }
+
+
     /**
      * Gets whether or not this AttributeType is single-valued.
      * 
      * @return true if only one value can exist for this AttributeType, false
      *         otherwise
      */
-    boolean isSingleValue();
+    public boolean isSingleValued()
+    {
+        return isSingleValued;
+    }
+
+
+    /**
+     * Tells if this AttributeType is Single Valued or not
+     *
+     * @param singleValue True if the AttributeType is single-valued
+     */
+    public void setSingleValued( boolean singleValued )
+    {
+        if ( !isReadOnly )
+        {
+            this.isSingleValued = singleValued;
+        }
+    }
 
 
     /**
@@ -145,7 +764,24 @@
      * 
      * @return true if users can modify it, false if only the directory can.
      */
-    boolean isCanUserModify();
+    public boolean isUserModifiable()
+    {
+        return canUserModify;
+    }
+
+
+    /**
+     * Tells if this AttributeType can be modified by a user or not
+     *
+     * @param canUserModify The flag to set
+     */
+    public void setUserModifiable( boolean canUserModify )
+    {
+        if ( !isReadOnly )
+        {
+            this.canUserModify = canUserModify;
+        }
+    }
 
 
     /**
@@ -153,7 +789,35 @@
      * 
      * @return true if the attribute is collective, false otherwise
      */
-    boolean isCollective();
+    public boolean isCollective()
+    {
+        return isCollective;
+    }
+
+
+    /**
+     * Updates the collective flag
+     *
+     * @param collective The new value to set
+     */
+    public void updateCollective( boolean collective )
+    {
+        this.isCollective = collective;
+    }
+
+
+    /**
+     * Sets the collective flag
+     *
+     * @param collective The new value to set
+     */
+    public void setCollective( boolean collective )
+    {
+        if ( !isReadOnly )
+        {
+            this.isCollective = collective;
+        }
+    }
 
 
     /**
@@ -161,65 +825,490 @@
      * 
      * @return a type safe UsageEnum
      */
-    UsageEnum getUsage();
+    public UsageEnum getUsage()
+    {
+        return usage;
+    }
+
+
+    /**
+     * Sets the AttributeType usage, one of :<br>
+     * <li>USER_APPLICATIONS
+     * <li>DIRECTORY_OPERATION
+     * <li>DISTRIBUTED_OPERATION
+     * <li>DSA_OPERATION
+     * <br>
+     * @see UsageEnum
+     * @param usage The AttributeType usage
+     */
+    public void setUsage( UsageEnum usage )
+    {
+        if ( !isReadOnly )
+        {
+            this.usage = usage;
+        }
+    }
+
+
+    /**
+     * Updates the AttributeType usage, one of :<br>
+     * <li>USER_APPLICATIONS
+     * <li>DIRECTORY_OPERATION
+     * <li>DISTRIBUTED_OPERATION
+     * <li>DSA_OPERATION
+     * <br>
+     * @see UsageEnum
+     * @param usage The AttributeType usage
+     */
+    public void updateUsage( UsageEnum usage )
+    {
+        this.usage = usage;
+    }
+
+
+    /**
+     * Gets a length limit for this AttributeType.
+     * 
+     * @return the length of the attribute
+     */
+    public int getSyntaxLength()
+    {
+        return syntaxLength;
+    }
+
+
+    /**
+     * Sets the length limit of this AttributeType based on its associated
+     * syntax.
+     * 
+     * @param length the new length to set
+     */
+    public void setSyntaxLength( int length )
+    {
+        if ( !isReadOnly )
+        {
+            this.syntaxLength = length;
+        }
+    }
 
 
     /**
-     * Gets the name of the superior class for this AttributeType.
+     * Gets the the superior AttributeType of this AttributeType.
      * 
-     * @return the super class for this AttributeType
-     * @throws NamingException
-     *             if there is a failure to resolve the superior
+     * @return the superior AttributeType for this AttributeType
      */
-    AttributeType getSuperior() throws NamingException, NamingException;
+    public AttributeType getSuperior()
+    {
+        return superior;
+    }
 
 
     /**
-     * The Syntax for this AttributeType's values.
+     * Gets the OID of the superior AttributeType for this AttributeType.
+     * 
+     * @return The OID of the superior AttributeType for this AttributeType.
+     */
+    public String getSuperiorOid()
+    {
+        return superiorOid;
+    }
+
+
+    /**
+     * Gets the Name of the superior AttributeType for this AttributeType.
+     * 
+     * @return The Name of the superior AttributeType for this AttributeType.
+     */
+    public String getSuperiorName()
+    {
+        if ( superior != null )
+        {
+            return superior.getName();
+        }
+        else
+        {
+            return superiorOid;
+        }
+    }
+
+
+    /**
+     * Sets the superior AttributeType OID of this AttributeType
+     *
+     * @param superiorOid The superior AttributeType OID of this AttributeType
+     */
+    public void setSuperiorOid( String superiorOid )
+    {
+        if ( !isReadOnly )
+        {
+            this.superiorOid = superiorOid;
+        }
+    }
+
+
+    /**
+     * Sets the superior for this AttributeType
+     *
+     * @param superior The superior for this AttributeType
+     */
+    public void setSuperior( AttributeType superior )
+    {
+        if ( !isReadOnly )
+        {
+            this.superior = superior;
+            this.superiorOid = superior.getOid();
+        }
+    }
+
+
+    /**
+     * Sets the superior oid for this AttributeType
+     *
+     * @param superior The superior oid for this AttributeType
+     */
+    public void setSuperior( String superiorOid )
+    {
+        if ( !isReadOnly )
+        {
+            this.superiorOid = superiorOid;
+        }
+    }
+
+
+    /**
+     * Update the associated Superior AttributeType, even if the SchemaObject is readOnly
+     *
+     * @param superior The superior for this AttributeType
+     */
+    public void updateSuperior( AttributeType superior )
+    {
+        this.superior = superior;
+        this.superiorOid = superior.getOid();
+    }
+
+
+    /**
+     * Gets the Syntax for this AttributeType's values.
      * 
      * @return the value syntax
-     * @throws NamingException
-     *             if there is a failure to resolve the syntax
      */
-    Syntax getSyntax() throws NamingException;
+    public LdapSyntax getSyntax()
+    {
+        return syntax;
+    }
 
 
     /**
-     * Gets a length limit for this AttributeType.
+     * Gets the Syntax name for this AttributeType's values.
      * 
-     * @return the length of the attribute
+     * @return the value syntax name
+     */
+    public String getSyntaxName()
+    {
+        if ( syntax != null )
+        {
+            return syntax.getName();
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+
+    /**
+     * Gets the Syntax OID for this AttributeType's values.
+     * 
+     * @return the value syntax's OID
+     */
+    public String getSyntaxOid()
+    {
+        return syntaxOid;
+    }
+
+
+    /**
+     * Sets the Syntax OID for this AttributeType
+     *
+     * @param superiorOid The syntax OID for this AttributeType
+     */
+    public void setSyntaxOid( String syntaxOid )
+    {
+        if ( !isReadOnly )
+        {
+            this.syntaxOid = syntaxOid;
+        }
+    }
+
+
+    /**
+     * Sets the Syntax for this AttributeType
+     *
+     * @param syntax The Syntax for this AttributeType
+     */
+    public void setSyntax( LdapSyntax syntax )
+    {
+        if ( !isReadOnly )
+        {
+            this.syntax = syntax;
+            this.syntaxOid = syntax.getOid();
+        }
+    }
+
+
+    /**
+     * Update the associated Syntax, even if the SchemaObject is readOnly
+     *
+     * @param syntax The Syntax for this AttributeType
      */
-    int getLength();
+    public void updateSyntax( LdapSyntax syntax )
+    {
+        this.syntax = syntax;
+        this.syntaxOid = syntax.getOid();
+    }
 
 
     /**
      * Gets the MatchingRule for this AttributeType used for equality matching.
      * 
      * @return the equality matching rule
-     * @throws NamingException
-     *             if there is a failure to resolve the matchingRule
      */
-    MatchingRule getEquality() throws NamingException;
+    public MatchingRule getEquality()
+    {
+        return equality;
+    }
+
+
+    /**
+     * Gets the Equality OID for this AttributeType's values.
+     * 
+     * @return the value Equality's OID
+     */
+    public String getEqualityOid()
+    {
+        return equalityOid;
+    }
+
+
+    /**
+     * Gets the Equality Name for this AttributeType's values.
+     * 
+     * @return the value Equality's Name
+     */
+    public String getEqualityName()
+    {
+        if ( equality != null )
+        {
+            return equality.getName();
+        }
+        else
+        {
+            return equalityOid;
+        }
+    }
+
+
+    /**
+     * Sets the Equality OID for this AttributeType
+     *
+     * @param equalityOid The Equality OID for this AttributeType
+     */
+    public void setEqualityOid( String equalityOid )
+    {
+        if ( !isReadOnly )
+        {
+            this.equalityOid = equalityOid;
+        }
+    }
+
+
+    /**
+     * Sets the Equality MR for this AttributeType
+     *
+     * @param equality The Equality MR for this AttributeType
+     */
+    public void setEquality( MatchingRule equality )
+    {
+        if ( !isReadOnly )
+        {
+            this.equality = equality;
+            this.equalityOid = equality.getOid();
+        }
+    }
+
+
+    /**
+     * Update the associated Equality MatchingRule, even if the SchemaObject is readOnly
+     *
+     * @param equality The Equality MR for this AttributeType
+     */
+    public void updateEquality( MatchingRule equality )
+    {
+        this.equality = equality;
+        this.equalityOid = equality.getOid();
+    }
+
+
+    /**
+     * Gets the MatchingRule for this AttributeType used for Ordering matching.
+     * 
+     * @return the Ordering matching rule
+     */
+    public MatchingRule getOrdering()
+    {
+        return ordering;
+    }
+
+
+    /**
+     * Gets the MatchingRule name for this AttributeType used for Ordering matching.
+     * 
+     * @return the Ordering matching rule name
+     */
+    public String getOrderingName()
+    {
+        if ( ordering != null )
+        {
+            return ordering.getName();
+        }
+        else
+        {
+            return orderingOid;
+        }
+    }
+
+
+    /**
+     * Gets the Ordering OID for this AttributeType's values.
+     * 
+     * @return the value Equality's OID
+     */
+    public String getOrderingOid()
+    {
+        return orderingOid;
+    }
+
+
+    /**
+     * Sets the Ordering OID for this AttributeType
+     *
+     * @param orderingOid The Ordering OID for this AttributeType
+     */
+    public void setOrderingOid( String orderingOid )
+    {
+        if ( !isReadOnly )
+        {
+            this.orderingOid = orderingOid;
+        }
+    }
+
+
+    /**
+     * Sets the Ordering MR for this AttributeType
+     *
+     * @param ordering The Ordering MR for this AttributeType
+     */
+    public void setOrdering( MatchingRule ordering )
+    {
+        if ( !isReadOnly )
+        {
+            this.ordering = ordering;
+            this.orderingOid = ordering.getOid();
+        }
+    }
+
+
+    /**
+     * Update the associated Ordering MatchingRule, even if the SchemaObject is readOnly
+     *
+     * @param ordering The Ordering MR for this AttributeType
+     */
+    public void updateOrdering( MatchingRule ordering )
+    {
+        this.ordering = ordering;
+        this.orderingOid = ordering.getOid();
+    }
+
+
+    /**
+     * Gets the MatchingRule for this AttributeType used for Substr matching.
+     * 
+     * @return the Substr matching rule
+     */
+    public MatchingRule getSubstring()
+    {
+        return substring;
+    }
 
 
     /**
-     * Gets the MatchingRule for this AttributeType used for ordering.
+     * Gets the MatchingRule name for this AttributeType used for Substring matching.
      * 
-     * @return the ordering matching rule
-     * @throws NamingException
-     *             if there is a failure to resolve the matchingRule
+     * @return the Substring matching rule name
      */
-    MatchingRule getOrdering() throws NamingException;
+    public String getSubstringName()
+    {
+        if ( substring != null )
+        {
+            return substring.getName();
+        }
+        else
+        {
+            return substringOid;
+        }
+    }
 
 
     /**
-     * Gets the MatchingRule for this AttributeType used for substring matching.
+     * Gets the Substr OID for this AttributeType's values.
      * 
-     * @return the substring matching rule
-     * @throws NamingException
-     *             if there is a failure to resolve the matchingRule
+     * @return the value Substr's OID
+     */
+    public String getSubstringOid()
+    {
+        return substringOid;
+    }
+
+
+    /**
+     * Sets the Substr OID for this AttributeType
+     *
+     * @param substrOid The Substr OID for this AttributeType
+     */
+    public void setSubstringOid( String substrOid )
+    {
+        if ( !isReadOnly )
+        {
+            this.substringOid = substrOid;
+        }
+    }
+
+
+    /**
+     * Sets the Substr MR for this AttributeType
+     *
+     * @param substring The Substr MR for this AttributeType
+     */
+    public void setSubstring( MatchingRule substring )
+    {
+        if ( !isReadOnly )
+        {
+            this.substring = substring;
+            this.substringOid = substring.getOid();
+        }
+    }
+
+
+    /**
+     * Update the associated Substring MatchingRule, even if the SchemaObject is readOnly
+     *
+     * @param substring The Substr MR for this AttributeType
      */
-    MatchingRule getSubstr() throws NamingException;
+    public void updateSubstring( MatchingRule substring )
+    {
+        this.substring = substring;
+        this.substringOid = substring.getOid();
+    }
 
 
     /**
@@ -227,10 +1316,17 @@
      * attributeType.
      *
      * @param descendant the perspective descendant to check
-     * @return true if the descendant is truely a derived from this AttributeType
-     * @throws NamingException if there are problems resolving superior types
+     * @return true if the descendant is truly a derived from this AttributeType
      */
-    boolean isAncestorOf( AttributeType descendant ) throws NamingException;
+    public boolean isAncestorOf( AttributeType descendant )
+    {
+        if ( ( descendant == null ) || this.equals( descendant ) )
+        {
+            return false;
+        }
+
+        return isAncestorOrEqual( this, descendant );
+    }
 
 
     /**
@@ -238,8 +1334,267 @@
      * attributeType.
      *
      * @param ancestor the perspective ancestor to check
-     * @return true if this AttributeType truely descends from the ancestor
-     * @throws NamingException if there are problems resolving superior types
+     * @return true if this AttributeType truly descends from the ancestor
+     */
+    public boolean isDescendantOf( AttributeType ancestor )
+    {
+        if ( ( ancestor == null ) || equals( ancestor ) )
+        {
+            return false;
+        }
+
+        return isAncestorOrEqual( ancestor, this );
+    }
+
+
+    /**
+     * Recursive method which checks to see if a descendant is really an ancestor or if the two
+     * are equal.
+     *
+     * @param ancestor the possible ancestor of the descendant
+     * @param descendant the possible descendant of the ancestor
+     * @return true if the ancestor equals the descendant or if the descendant is really
+     * a subtype of the ancestor. otherwise false
+     */
+    private boolean isAncestorOrEqual( AttributeType ancestor, AttributeType descendant )
+    {
+        if ( ( ancestor == null ) || ( descendant == null ) )
+        {
+            return false;
+        }
+
+        if ( ancestor.equals( descendant ) )
+        {
+            return true;
+        }
+
+        return isAncestorOrEqual( ancestor, descendant.getSuperior() );
+    }
+
+
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        return objectType + " " + DescriptionUtils.getDescription( this );
+    }
+
+
+    /**
+     * Copy an AttributeType
+     */
+    public AttributeType copy()
+    {
+        AttributeType copy = new AttributeType( oid );
+
+        // Copy the SchemaObject common data
+        copy.copy( this );
+
+        // Copy the canUserModify flag
+        copy.canUserModify = canUserModify;
+
+        // Copy the isCollective flag
+        copy.isCollective = isCollective;
+
+        // Copy the isSingleValue flag
+        copy.isSingleValued = isSingleValued;
+
+        // Copy the USAGE type
+        copy.usage = usage;
+
+        // All the references to other Registries object are set to null,
+        // all the OIDs are copied
+        // The EQUALITY MR
+        copy.equality = null;
+        copy.equalityOid = equalityOid;
+
+        // The ORDERING MR
+        copy.ordering = null;
+        copy.orderingOid = orderingOid;
+
+        // The SUBSTR MR
+        copy.substring = null;
+        copy.substringOid = substringOid;
+
+        // The SUP AT
+        copy.superior = null;
+        copy.superiorOid = superiorOid;
+
+        // The SYNTAX
+        copy.syntax = null;
+        copy.syntaxOid = syntaxOid;
+        copy.syntaxLength = syntaxLength;
+
+        return copy;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void clear()
+    {
+        // Clear the common elements
+        super.clear();
+
+        // Clear the references
+        equality = null;
+        ordering = null;
+        substring = null;
+        superior = null;
+        syntax = null;
+    }
+
+
+    /**
+     * @see Object#equals(Object)
      */
-    boolean isDescendantOf( AttributeType ancestor ) throws NamingException;
+    public boolean equals( Object o )
+    {
+        if ( !super.equals( o ) )
+        {
+            return false;
+        }
+
+        if ( !( o instanceof AttributeType ) )
+        {
+            return false;
+        }
+
+        AttributeType that = ( AttributeType ) o;
+
+        // The COLLECTIVE
+        if ( isCollective != that.isCollective )
+        {
+            return false;
+        }
+
+        // The SINGLE_VALUE
+        if ( isSingleValued != that.isSingleValued )
+        {
+            return false;
+        }
+
+        // The NO_USER_MODIFICATION
+        if ( canUserModify != that.canUserModify )
+        {
+            return false;
+        }
+
+        // The USAGE
+        if ( usage != that.usage )
+        {
+            return false;
+        }
+
+        // The equality
+        if ( !compareOid( equalityOid, that.equalityOid ) )
+        {
+            return false;
+        }
+
+        if ( equality != null )
+        {
+            if ( !equality.equals( that.equality ) )
+            {
+                return false;
+            }
+        }
+        else
+        {
+            if ( that.equality != null )
+            {
+                return false;
+            }
+        }
+
+        // The ordering
+        if ( !compareOid( orderingOid, that.orderingOid ) )
+        {
+            return false;
+        }
+
+        if ( ordering != null )
+        {
+            if ( !ordering.equals( that.ordering ) )
+            {
+                return false;
+            }
+        }
+        else
+        {
+            if ( that.ordering != null )
+            {
+                return false;
+            }
+        }
+
+        // The substring
+        if ( !compareOid( substringOid, that.substringOid ) )
+        {
+            return false;
+        }
+
+        if ( substring != null )
+        {
+            if ( !substring.equals( that.substring ) )
+            {
+                return false;
+            }
+        }
+        else
+        {
+            if ( that.substring != null )
+            {
+                return false;
+            }
+        }
+
+        // The superior
+        if ( !compareOid( superiorOid, that.superiorOid ) )
+        {
+            return false;
+        }
+
+        if ( superior != null )
+        {
+            if ( !superior.equals( that.superior ) )
+            {
+                return false;
+            }
+        }
+        else
+        {
+            if ( that.superior != null )
+            {
+                return false;
+            }
+        }
+
+        // The syntax
+        if ( !compareOid( syntaxOid, that.syntaxOid ) )
+        {
+            return false;
+        }
+
+        if ( syntaxLength != that.syntaxLength )
+        {
+            return false;
+        }
+
+        if ( syntax == null )
+        {
+            return that.syntax == null;
+        }
+
+        if ( syntax.equals( that.syntax ) )
+        {
+            return syntaxLength == that.syntaxLength;
+        }
+        else
+        {
+            return false;
+        }
+    }
 }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/DITContentRule.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/DITContentRule.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/DITContentRule.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/DITContentRule.java Wed Jan  6 17:52:15 2010
@@ -20,8 +20,15 @@
 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.schema.registries.AttributeTypeRegistry;
+import org.apache.directory.shared.ldap.schema.registries.ObjectClassRegistry;
+import org.apache.directory.shared.ldap.schema.registries.Registries;
+
 
 /**
  * A ditContentRule specification. ditContentRules identify the content of
@@ -109,59 +116,553 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public interface DITContentRule extends SchemaObject
+public class DITContentRule extends AbstractSchemaObject
 {
+    /** The serialVersionUID */
+    public static final long serialVersionUID = 1L;
+
+    /** The list of Auxiliary ObjectClass OIDs entries may belong to */
+    private List<String> auxObjectClassOids;
+
+    /** The list of Auxiliary ObjectClass entries may belong to */
+    private List<ObjectClass> auxObjectClasses;
+
+    /** 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;
+
+    /** The list of precluded AttributeType OIDs */
+    private List<String> notAttributeTypeOids;
+
+    /** The list of precluded AttributeTypes */
+    private List<AttributeType> notAttributeTypes;
+
+
     /**
-     * Gets the STRUCTURAL ObjectClass this DITContentRule specifies attributes
-     * for.
+     * Creates a DITContentRule object using a unique OID.
      * 
-     * @return the ObjectClass this DITContentRule specifies attributes for
-     * @throws NamingException
-     *             if there is a failure resolving the object
+     * @param oid the OID for this DITContentRule
      */
-    ObjectClass getObjectClass() throws NamingException;
+    public DITContentRule( String oid )
+    {
+        super( SchemaObjectType.DIT_CONTENT_RULE, oid );
+
+        mayAttributeTypeOids = new ArrayList<String>();
+        mustAttributeTypeOids = new ArrayList<String>();
+        notAttributeTypeOids = new ArrayList<String>();
+        auxObjectClassOids = new ArrayList<String>();
+
+        mayAttributeTypes = new ArrayList<AttributeType>();
+        mustAttributeTypes = new ArrayList<AttributeType>();
+        notAttributeTypes = new ArrayList<AttributeType>();
+        auxObjectClasses = new ArrayList<ObjectClass>();
+    }
 
 
     /**
-     * Gets all the AUXILIARY ObjectClasses this DITContentRule specifies for
-     * the given STRUCTURAL objectClass.
-     * 
-     * @return the extra AUXILIARY ObjectClasses
-     * @throws NamingException
-     *             if there is a failure resolving the object
+     * @return the auxObjectClassOids
      */
-    ObjectClass[] getAuxObjectClasses() throws NamingException;
+    public List<String> getAuxObjectClassOids()
+    {
+        return auxObjectClassOids;
+    }
 
 
     /**
-     * Gets all the AttributeTypes of the "must" attribute names this
-     * DITContentRule specifies for the given STRUCTURAL objectClass.
-     * 
-     * @return the AttributeTypes of attributes that must be included in entries
-     * @throws NamingException
-     *             if there is a failure resolving the object
+     * Add an Auxiliary ObjectClass Oid
+     *
+     * @param oid The ObjectClass oid
      */
-    AttributeType[] getMustNames() throws NamingException;
+    public void addAuxObjectClassOidOids( String oid )
+    {
+        if ( !isReadOnly )
+        {
+            auxObjectClassOids.add( oid );
+        }
+    }
 
 
     /**
-     * Gets all the AttributeTypes of the "may" attribute names this
-     * DITContentRule specifies for the given STRUCTURAL objectClass.
-     * 
-     * @return the AttributeTypes of attributes that may be included in entries
-     * @throws NamingException
-     *             if there is a failure resolving the object
+     * Add an Auxiliary ObjectClass
+     *
+     * @param oid The ObjectClass
      */
-    AttributeType[] getMayNames() throws NamingException;
+    public void addAuxObjectClasses( ObjectClass objectClass )
+    {
+        if ( !isReadOnly )
+        {
+            if ( !auxObjectClassOids.contains( objectClass.getOid() ) )
+            {
+                auxObjectClasses.add( objectClass );
+                auxObjectClassOids.add( objectClass.getOid() );
+            }
+        }
+    }
 
 
     /**
-     * Gets all the AttributeTypes of the "not" attribute names this
-     * DITContentRule specifies for the given STRUCTURAL objectClass.
-     * 
-     * @return the AttributeTypes of attributes that are excluded in entries
-     * @throws NamingException
-     *             if there is a failure resolving the object
+     * @param auxObjectClassOids the auxObjectClassOids to set
+     */
+    public void setAuxObjectClassOids( List<String> auxObjectClassOids )
+    {
+        if ( !isReadOnly )
+        {
+            this.auxObjectClassOids = auxObjectClassOids;
+        }
+    }
+
+
+    /**
+     * @param auxObjectClasses the auxObjectClasses to set
+     */
+    public void setAuxObjectClasses( List<ObjectClass> auxObjectClasses )
+    {
+        if ( !isReadOnly )
+        {
+            this.auxObjectClasses = auxObjectClasses;
+
+            // update the OIDS now
+            auxObjectClassOids.clear();
+
+            for ( ObjectClass oc : auxObjectClasses )
+            {
+                auxObjectClassOids.add( oc.getOid() );
+            }
+        }
+    }
+
+
+    /**
+     * @return the auxObjectClasses
+     */
+    public List<ObjectClass> getAuxObjectClasses()
+    {
+        return auxObjectClasses;
+    }
+
+
+    /**
+     * @return the mayAttributeTypeOids
+     */
+    public List<String> getMayAttributeTypeOids()
+    {
+        return mayAttributeTypeOids;
+    }
+
+
+    /**
+     * Add an allowed AttributeType
+     *
+     * @param oid The attributeType oid
+     */
+    public void addMayAttributeTypeOids( String oid )
+    {
+        if ( !isReadOnly )
+        {
+            mayAttributeTypeOids.add( oid );
+        }
+    }
+
+
+    /**
+     * Add an allowed AttributeType
+     *
+     * @param attributeType The attributeType
+     */
+    public void addMayAttributeTypes( AttributeType attributeType )
+    {
+        if ( !isReadOnly )
+        {
+            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() );
+            }
+        }
+    }
+
+
+    /**
+     * @return the mayAttributeTypes
+     */
+    public List<AttributeType> getMayAttributeTypes()
+    {
+        return mayAttributeTypes;
+    }
+
+
+    /**
+     * @return the mustAttributeTypeOids
+     */
+    public List<String> getMustAttributeTypeOids()
+    {
+        return mustAttributeTypeOids;
+    }
+
+
+    /**
+     * Add a required AttributeType OID
+     *
+     * @param oid The attributeType OID
+     */
+    public void addMustAttributeTypeOids( String oid )
+    {
+        if ( !isReadOnly )
+        {
+            mustAttributeTypeOids.add( oid );
+        }
+    }
+
+
+    /**
+     * Add a required AttributeType
+     *
+     * @param attributeType The attributeType
+     */
+    public void addMustAttributeTypes( AttributeType attributeType )
+    {
+        if ( !isReadOnly )
+        {
+            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 mayAttributeTypes 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() );
+            }
+        }
+    }
+
+
+    /**
+     * @return the mustAttributeTypes
+     */
+    public List<AttributeType> getMustAttributeTypes()
+    {
+        return mustAttributeTypes;
+    }
+
+
+    /**
+     * @return the notAttributeTypeOids
+     */
+    public List<String> getNotAttributeTypeOids()
+    {
+        return notAttributeTypeOids;
+    }
+
+
+    /**
+     * Add a precluded AttributeType
+     *
+     * @param oid The attributeType oid
+     */
+    public void addNotAttributeTypeOids( String oid )
+    {
+        if ( !isReadOnly )
+        {
+            notAttributeTypeOids.add( oid );
+        }
+    }
+
+
+    /**
+     * Add a precluded AttributeType
+     *
+     * @param attributeType The attributeType
+     */
+    public void addNotAttributeTypes( AttributeType attributeType )
+    {
+        if ( !isReadOnly )
+        {
+            if ( !notAttributeTypeOids.contains( attributeType.getOid() ) )
+            {
+                notAttributeTypes.add( attributeType );
+                notAttributeTypeOids.add( attributeType.getOid() );
+            }
+        }
+    }
+
+
+    /**
+     * @param notAttributeTypeOids the notAttributeTypeOids to set
+     */
+    public void setNotAttributeTypeOids( List<String> notAttributeTypeOids )
+    {
+        if ( !isReadOnly )
+        {
+            this.notAttributeTypeOids = notAttributeTypeOids;
+        }
+    }
+
+
+    /**
+     * Sets the list of precluded AttributeTypes
+     *
+     * @param mayAttributeTypes the list of precluded AttributeTypes
+     */
+    public void setNotAttributeTypes( List<AttributeType> notAttributeTypes )
+    {
+        if ( !isReadOnly )
+        {
+            this.notAttributeTypes = notAttributeTypes;
+
+            // update the OIDS now
+            notAttributeTypeOids.clear();
+
+            for ( AttributeType not : notAttributeTypes )
+            {
+                notAttributeTypeOids.add( not.getOid() );
+            }
+        }
+    }
+
+
+    /**
+     * @return the notAttributeTypes
+     */
+    public List<AttributeType> getNotAttributeTypes()
+    {
+        return notAttributeTypes;
+    }
+
+
+    /**
+     * Inject the DITContentRule into the registries, updating the references to
+     * other SchemaObject
+     *
+     * @param registries The Registries
+     * @exception If the addition failed
+     */
+    public void addToRegistries( Registries registries ) throws NamingException
+    {
+        if ( registries != null )
+        {
+            AttributeTypeRegistry atRegistry = registries.getAttributeTypeRegistry();
+            ObjectClassRegistry ocRegistry = registries.getObjectClassRegistry();
+
+            if ( mayAttributeTypeOids != null )
+            {
+                mayAttributeTypes = new ArrayList<AttributeType>( mayAttributeTypeOids.size() );
+
+                for ( String oid : mayAttributeTypeOids )
+                {
+                    mayAttributeTypes.add( atRegistry.lookup( oid ) );
+                }
+            }
+
+            if ( mustAttributeTypeOids != null )
+            {
+                mustAttributeTypes = new ArrayList<AttributeType>( mustAttributeTypeOids.size() );
+
+                for ( String oid : mustAttributeTypeOids )
+                {
+                    mustAttributeTypes.add( atRegistry.lookup( oid ) );
+                }
+            }
+
+            if ( notAttributeTypeOids != null )
+            {
+                notAttributeTypes = new ArrayList<AttributeType>( notAttributeTypeOids.size() );
+
+                for ( String oid : notAttributeTypeOids )
+                {
+                    notAttributeTypes.add( atRegistry.lookup( oid ) );
+                }
+            }
+
+            if ( auxObjectClassOids != null )
+            {
+                auxObjectClasses = new ArrayList<ObjectClass>( auxObjectClassOids.size() );
+
+                for ( String oid : auxObjectClassOids )
+                {
+                    auxObjectClasses.add( ocRegistry.lookup( oid ) );
+                }
+            }
+        }
+    }
+
+
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        return objectType + " " + DescriptionUtils.getDescription( this );
+    }
+
+
+    /**
+     * Copy a DITContentRule
+     */
+    public DITContentRule copy()
+    {
+        DITContentRule copy = new DITContentRule( oid );
+
+        // Copy the SchemaObject common data
+        copy.copy( this );
+
+        // copy the AUX ObjectClasses OIDs
+        copy.auxObjectClassOids = new ArrayList<String>();
+
+        for ( String oid : auxObjectClassOids )
+        {
+            copy.auxObjectClassOids.add( oid );
+        }
+
+        // copy the AUX ObjectClasses ( will be empty )
+        copy.auxObjectClasses = new ArrayList<ObjectClass>();
+
+        // Clone the MAY AttributeTypes OIDs
+        copy.mayAttributeTypeOids = new ArrayList<String>();
+
+        for ( String oid : mayAttributeTypeOids )
+        {
+            copy.mayAttributeTypeOids.add( oid );
+        }
+
+        // Clone the MAY AttributeTypes ( will be empty )
+        copy.mayAttributeTypes = new ArrayList<AttributeType>();
+
+        // Clone the MUST AttributeTypes OIDs
+        copy.mustAttributeTypeOids = new ArrayList<String>();
+
+        for ( String oid : mustAttributeTypeOids )
+        {
+            copy.mustAttributeTypeOids.add( oid );
+        }
+
+        // Clone the MUST AttributeTypes ( will be empty )
+        copy.mustAttributeTypes = new ArrayList<AttributeType>();
+
+        // Clone the NOT AttributeTypes OIDs
+        copy.notAttributeTypeOids = new ArrayList<String>();
+
+        for ( String oid : notAttributeTypeOids )
+        {
+            copy.notAttributeTypeOids.add( oid );
+        }
+
+        // Clone the NOT AttributeTypes ( will be empty )
+        copy.notAttributeTypes = new ArrayList<AttributeType>();
+
+        return copy;
+    }
+
+
+    /**
+     * @see Object#equals(Object)
+     */
+    public boolean equals( Object o )
+    {
+        if ( !super.equals( o ) )
+        {
+            return false;
+        }
+
+        if ( !( o instanceof DITContentRule ) )
+        {
+            return false;
+        }
+
+        DITContentRule that = ( DITContentRule ) o;
+
+        // TODO : complete the check
+        return true;
+    }
+
+
+    /**
+     * {@inheritDoc}
      */
-    AttributeType[] getNotNames() throws NamingException;
+    public void clear()
+    {
+        // Clear the common elements
+        super.clear();
+
+        // Clear the references
+        auxObjectClasses.clear();
+        auxObjectClassOids.clear();
+        mayAttributeTypes.clear();
+        mayAttributeTypeOids.clear();
+        mustAttributeTypes.clear();
+        mustAttributeTypeOids.clear();
+        notAttributeTypes.clear();
+        notAttributeTypeOids.clear();
+    }
 }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/DITStructureRule.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/DITStructureRule.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/DITStructureRule.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/DITStructureRule.java Wed Jan  6 17:52:15 2010
@@ -20,7 +20,10 @@
 package org.apache.directory.shared.ldap.schema;
 
 
-import javax.naming.NamingException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.shared.ldap.NotImplementedException;
 
 
 /**
@@ -77,35 +80,187 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public interface DITStructureRule extends SchemaObject
+public class DITStructureRule extends AbstractSchemaObject
 {
+    /** The serialVersionUID */
+    private static final long serialVersionUID = 1L;
+
+    /** The rule ID. A DSR does not have an OID */
+    private int ruleId;
+
+    /** The associated NameForm */
+    private String form;
+
+    /** The list of superiors rules */
+    private List<Integer> superRules;
+
+
     /**
-     * Gets the rule identifier for this DITStructureRule.
-     * 
-     * @return the rule identifier 
+     * Creates a new instance of DITStructureRule
      */
-    Integer getRuleId();
-    
-    
+    public DITStructureRule( int ruleId )
+    {
+        super( SchemaObjectType.DIT_STRUCTURE_RULE, null );
+        this.ruleId = ruleId;
+        form = null;
+        superRules = new ArrayList<Integer>();
+    }
+
+
     /**
-     * The nameForm associating this ditStructureRule with a structural
-     * objectClass.
-     * 
-     * @return the nameForm for the structural objectClass
-     * @throws NamingException
-     *             if there is a failure resolving the object
+     *  @return The associated NameForm's OID
+     */
+    public String getForm()
+    {
+        return form;
+    }
+
+
+    /**
+     * Sets the associated NameForm's OID
+     *
+     * @param form The NameForm's OID
+     */
+    public void setForm( String form )
+    {
+        if ( !isReadOnly )
+        {
+            this.form = form;
+        }
+    }
+
+
+    /**
+     * @return The Rule ID
+     */
+    public int getRuleId()
+    {
+        return ruleId;
+    }
+
+
+    /**
+     * Sets the rule identifier of this DIT structure rule;
+     *
+     * @param ruleId the rule identifier of this DIT structure rule;
+     */
+    public void setRuleId( int ruleId )
+    {
+        if ( !isReadOnly )
+        {
+            this.ruleId = ruleId;
+        }
+    }
+
+
+    /**
+     * @return The list of superiors RuleIDs
      */
-    NameForm getNameForm() throws NamingException;
+    public List<Integer> getSuperRules()
+    {
+        return superRules;
+    }
 
 
     /**
-     * Gets a collection of all the superior StructureRules. The difference with
-     * getSuperClass is this method will resolve the entire superior class
-     * chain.
+     * Sets the list of superior RuleIds
      * 
-     * @return the chain of StructureRules
-     * @throws NamingException
-     *             if there is a failure resolving the object
+     * @param superRules the list of superior RuleIds
+     */
+    public void setSuperRules( List<Integer> superRules )
+    {
+        if ( !isReadOnly )
+        {
+            this.superRules = superRules;
+        }
+    }
+
+
+    /**
+     * Adds a new superior RuleId
+     *
+     * @param superRule The superior RuleID to add
+     */
+    public void addSuperRule( Integer superRule )
+    {
+        superRules.add( superRule );
+    }
+
+
+    /**
+     * The DSR does not have an OID, so throw an exception
+     */
+    public String getOid()
+    {
+        throw new NotImplementedException();
+    }
+
+
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        return objectType + " " + DescriptionUtils.getDescription( this );
+    }
+
+
+    /**
+     * Copy a DITStructureRule
+     */
+    public DITStructureRule copy()
+    {
+        DITStructureRule copy = new DITStructureRule( ruleId );
+
+        // Copy the SchemaObject common data
+        copy.copy( this );
+
+        // Copy the Superiors rules
+        copy.superRules = new ArrayList<Integer>();
+
+        // Copy the form
+        copy.form = form;
+
+        for ( int ruleId : superRules )
+        {
+            copy.superRules.add( ruleId );
+        }
+
+        return copy;
+    }
+
+
+    /**
+     * @see Object#equals(Object)
+     */
+    public boolean equals( Object o )
+    {
+        if ( !super.equals( o ) )
+        {
+            return false;
+        }
+
+        if ( !( o instanceof DITStructureRule ) )
+        {
+            return false;
+        }
+
+        DITStructureRule that = ( DITStructureRule ) o;
+
+        // TODO : complete the test
+        return true;
+    }
+
+
+    /**
+     * {@inheritDoc}
      */
-    DITStructureRule[] getSuperClasses() throws NamingException;
+    public void clear()
+    {
+        // Clear the common elements
+        super.clear();
+
+        // Clear the references
+        superRules.clear();
+    }
 }



Mime
View raw message