directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r807194 - in /directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema: ./ parsers/ registries/
Date Mon, 24 Aug 2009 12:56:02 GMT
Author: elecharny
Date: Mon Aug 24 12:56:01 2009
New Revision: 807194

URL: http://svn.apache.org/viewvc?rev=807194&view=rev
Log:
Modified the DSR classes

Modified:
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/DITStructureRule.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parsers/DITStructureRuleDescription.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DITStructureRuleRegistry.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/MatchingRuleUseRegistry.java

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/DITStructureRule.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/DITStructureRule.java?rev=807194&r1=807193&r2=807194&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/DITStructureRule.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/DITStructureRule.java
Mon Aug 24 12:56:01 2009
@@ -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,108 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public interface DITStructureRule extends SchemaObject
+public class DITStructureRule extends SchemaObject
 {
+    /** 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
      */
-    NameForm getNameForm() throws NamingException;
+    public String getForm()
+    {
+        return form;
+    }
 
 
     /**
-     * Gets a collection of all the superior StructureRules. The difference with
-     * getSuperClass is this method will resolve the entire superior class
-     * chain.
+     * Sets the associated NameForm's OID
+     *
+     * @param form The NameForm's OID
+     */
+    public void setForm( String form )
+    {
+        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 )
+    {
+        this.ruleId = ruleId;
+    }
+
+
+    /**
+     * @return The list of superiors RuleIDs
+     */
+    public List<Integer> getSuperRules()
+    {
+        return superRules;
+    }
+
+
+    /**
+     * 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 )
+    {
+        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
      */
-    DITStructureRule[] getSuperClasses() throws NamingException;
+    public String getOid()
+    {
+        throw new NotImplementedException(); 
+    }
 }

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parsers/DITStructureRuleDescription.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parsers/DITStructureRuleDescription.java?rev=807194&r1=807193&r2=807194&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parsers/DITStructureRuleDescription.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parsers/DITStructureRuleDescription.java
Mon Aug 24 12:56:01 2009
@@ -63,7 +63,7 @@
 
 
     /**
-     *  @return The associated NameForm' OID
+     *  @return The associated NameForm's OID
      */
     public String getForm()
     {

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DITStructureRuleRegistry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DITStructureRuleRegistry.java?rev=807194&r1=807193&r2=807194&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DITStructureRuleRegistry.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DITStructureRuleRegistry.java
Mon Aug 24 12:56:01 2009
@@ -21,10 +21,17 @@
 
 
 import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 import javax.naming.NamingException;
 
 import org.apache.directory.shared.ldap.schema.DITStructureRule;
+import org.apache.directory.shared.ldap.schema.SchemaObject;
+import org.apache.directory.shared.ldap.schema.SchemaObjectType;
+import org.apache.directory.shared.ldap.schema.parsers.DITStructureRuleDescription;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -33,79 +40,273 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public interface DITStructureRuleRegistry extends SchemaObjectRegistry<DITStructureRule>
+public class DITStructureRuleRegistry extends SchemaObjectRegistry<DITStructureRule, DITStructureRuleDescription>
 {
+    /** static class logger */
+    private static final Logger LOG = LoggerFactory.getLogger( DITStructureRuleRegistry.class
);
+
+    /** A speedup for debug */
+    private static final boolean DEBUG = LOG.isDebugEnabled();
+    
+    /** a map of DITStructureRule looked up by RuleId */
+    protected final Map<Integer, DITStructureRule> byRuleId;
+    
+    /** maps an RuleId to a DITStructureRuleDescription Description */
+    private final Map<Integer, DITStructureRuleDescription> ruleIdToDescription;
+    
     /**
-     * Registers a DITStructureRule with this registry.
-     * 
-     * @param dITStructureRule the dITStructureRule to register
-     * @throws NamingException if the DITStructureRule is already registered
-     * or the registration operation is not supported
+     * Creates a new default NormalizerRegistry instance.
      */
-    void register( DITStructureRule dITStructureRule ) throws NamingException;
+    public DITStructureRuleRegistry()
+    {
+        super( SchemaObjectType.DIT_STRUCTURE_RULE );
+        byRuleId = new ConcurrentHashMap<Integer, DITStructureRule>();
+        ruleIdToDescription = new ConcurrentHashMap<Integer, DITStructureRuleDescription>();
+    }
 
 
     /**
-     * Looks up an dITStructureRule using a composite key composed of the
-     * nameForm object identifier with a DOT and the rule id of the 
-     * DITStructureRule appended to it.  If the name form object identifier
-     * is 1.2.3.4 and the rule identifier is 5 then the OID used for the 
-     * lookup is 1.2.3.4.5.
+     * Checks to see if an DITStructureRule exists in the registry, by its
+     * ruleId. 
      * 
-     * @param id the nameForm object identifier with rule identifier appended
-     * @return the DITStructureRule instance for the id
-     * @throws NamingException if the DITStructureRule does not exist
+     * @param oid the object identifier or name of the DITStructureRule
+     * @return true if a DITStructureRule definition exists for the ruleId, false
+     * otherwise
      */
-    DITStructureRule lookup( String id ) throws NamingException;
+    public boolean contains( int ruleId )
+    {
+        return byRuleId.containsKey( ruleId );
+    }
 
+    
+    /**
+     * Gets an iterator over the registered descriptions in the registry.
+     *
+     * @return an Iterator of descriptions
+     */
+    public Iterator<DITStructureRuleDescription> descriptionsIterator()
+    {
+        return ruleIdToDescription.values().iterator();
+    }
 
+    
     /**
-     * Looks up an dITStructureRule by its unique Object IDentifier or by its
-     * name.
-     * 
-     * @param ruleId the rule identifier for the DITStructureRule
-     * @return the DITStructureRule instance for rule identifier
-     * @throws NamingException if the DITStructureRule does not exist
+     * Gets an iterator over the registered descriptions in the registry.
+     *
+     * @return an Iterator of descriptions
      */
-    DITStructureRule lookup( Integer ruleId ) throws NamingException;
+    public Iterator<DITStructureRule> iterator()
+    {
+        return byRuleId.values().iterator();
+    }
+    
+    
+    /**
+     * Gets an iterator over the registered ruleId in the registry.
+     *
+     * @return an Iterator of ruleId
+     */
+    public Iterator<Integer> ruleIdIterator()
+    {
+        return byRuleId.keySet().iterator();
+    }
+    
+    
+    /**
+     * Gets the name of the schema this schema object is associated with.
+     *
+     * @param id the object identifier or the name
+     * @return the schema name
+     * @throws NamingException if the schema object does not exist
+     */
+    public String getSchemaName( int ruleId ) throws NamingException
+    {
+        DITStructureRule ditStructureRule = byRuleId.get( ruleId );
+
+        if ( ditStructureRule != null )
+        {
+            return ditStructureRule.getSchemaName();
+        }
+        
+        String msg = "RuleId " + ruleId + " not found in ruleId to schema name map!";
+        LOG.warn( msg );
+        throw new NamingException( msg );
+    }
 
+    
+    /**
+     * Registers a new DITStructureRule with this registry.
+     *
+     * @param ditStructureRule the DITStructureRule to register
+     * @throws NamingException if the DITStructureRule is already registered or
+     * the registration operation is not supported
+     */
+    public void register( DITStructureRule ditStructureRule ) throws NamingException
+    {
+        int ruleId = ditStructureRule.getRuleId();
+        
+        if ( byRuleId.containsKey( ruleId ) )
+        {
+            String msg = "DITStructureRule with RuleId " + ruleId + " already registered!";
+            LOG.warn( msg );
+            throw new NamingException( msg );
+        }
+
+        byRuleId.put( ruleId, ditStructureRule );
+        
+        if ( LOG.isDebugEnabled() )
+        {
+            LOG.debug( "registered {} for OID {}", ditStructureRule, ruleId );
+        }
+    }
 
+    
     /**
-     * Checks to see if an dITStructureRule exists using the object identifier
-     * of the nameForm appended with the rule identifier of the DITStructureRule.
-     * 
-     * @param id the object identifier of the nameForm with the rule Id appended
-     * @return true if an dITStructureRule definition exists for the id, false
-     * otherwise
+     * Registers a new DITStructureRule with this registry.
+     *
+     * @param ditStructureRuleDescription the DITStructureRuleDescription to register
+     * @param ditStructureRule the DITStructureRule to register
+     * @throws NamingException if the DITStructureRule is already registered or
+     * the registration operation is not supported
      */
-    boolean hasDITStructureRule( String id );
+    public void register( DITStructureRuleDescription ditStructureRuleDescription, DITStructureRule
ditStructureRule ) throws NamingException
+    {
+        int ruleId = ditStructureRule.getRuleId();
+        
+        if ( byRuleId.containsKey( ruleId ) )
+        {
+            String msg = "DITStructureRule with RuleId " + ruleId + " already registered!";
+            LOG.warn( msg );
+            throw new NamingException( msg );
+        }
+
+        byRuleId.put( ruleId, ditStructureRule );
+        
+        // Stores the description
+        ruleIdToDescription.put( ruleId, ditStructureRuleDescription );
+
+        if ( LOG.isDebugEnabled() )
+        {
+            LOG.debug( "registered {} with ruleId {}", ditStructureRuleDescription, ruleId
);
+        }
+    }
 
 
+    
+    
+    
+    
+    
+    
+    
     /**
-     * Checks to see if an dITStructureRule exists using the rule identifier.
+     * Looks up an dITStructureRule by its unique Object IDentifier or by its
+     * name.
      * 
-     * @param ruleId the rule identifier for the DITStructureRule.
-     * @return true if an dITStructureRule definition exists for the id, false
-     * otherwise
+     * @param ruleId the rule identifier for the DITStructureRule
+     * @return the DITStructureRule instance for rule identifier
+     * @throws NamingException if the DITStructureRule does not exist
      */
-    boolean hasDITStructureRule( Integer ruleId );
+    public DITStructureRule lookup( int ruleId ) throws NamingException
+    {
+        DITStructureRule ditStructureRule = byRuleId.get( ruleId );
+
+        if ( ditStructureRule == null )
+        {
+            String msg = "DITStructureRule for ruleId " + ruleId + " does not exist!";
+            LOG.debug( msg );
+            throw new NamingException( msg );
+        }
+
+        if ( DEBUG )
+        {
+            LOG.debug( "Found {} with ruleId: {}", ditStructureRule, ruleId );
+        }
+        
+        return ditStructureRule;
+    }
+
 
-    
     /**
      * Unregisters a DITStructureRule using it's rule identifier. 
      * 
      * @param ruleId the rule identifier for the DITStructureRule to unregister
      * @throws NamingException if no such DITStructureRule exists
      */
-    void unregister( Integer ruleId ) throws NamingException;
+    public void unregister( int ruleId ) throws NamingException
+    {
+        DITStructureRule ditStructureRule = byRuleId.remove( ruleId );
+        
+        ruleIdToDescription.remove( ruleId );
+
+        if ( DEBUG )
+        {
+            LOG.debug( "Removed {} with ruleId {} from the registry", ditStructureRule, ruleId
);
+        }
+    }
     
     
     /**
-     * Gets the schema name for a DITStructureRule using the rule identifier. 
+     * Unregisters all DITStructureRules defined for a specific schema from
+     * this registry.
      * 
-     * @param ruleId the rule identifier for the DITStructureRule
-     * @return the schema name for the DITStructureRule
-     * @throws NamingException if no such rule could be found
+     * @param schemaName the name of the schema whose syntaxCheckers will be removed from
+     */
+    public void unregisterSchemaElements( String schemaName )
+    {
+        if ( schemaName == null )
+        {
+            return;
+        }
+        
+        // Loop on all the SchemaObjects stored and remove those associated
+        // with the give schemaName
+        for ( DITStructureRule ditStructureRule : this )
+        {
+            if ( schemaName.equalsIgnoreCase( ditStructureRule.getSchemaName() ) )
+            {
+                int ruleId = ditStructureRule.getRuleId();
+                SchemaObject removed = byRuleId.remove( ruleId );
+                
+                // Also remove the description if any
+                ruleIdToDescription.remove( ruleId );
+
+                if ( DEBUG )
+                {
+                    LOG.debug( "Removed {} with ruleId {} from the registry", removed, ruleId
);
+                }
+            }
+        }
+    }
+
+    
+    /**
+     * Modify all the DITStructureRule using a schemaName when this name changes.
+     *
+     * @param originalSchemaName The original Schema name
+     * @param newSchemaName The new Schema name
      */
-    String getSchemaName( Integer ruleId ) throws NamingException;
+    public void renameSchema( String originalSchemaName, String newSchemaName )
+    {
+        // Loop on all the SchemaObjects stored and remove those associated
+        // with the give schemaName
+        for ( DITStructureRule ditStructureRule : this )
+        {
+            if ( originalSchemaName.equalsIgnoreCase( ditStructureRule.getSchemaName() )
)
+            {
+                ditStructureRule.setSchemaName( newSchemaName );
+                SchemaObject description = ruleIdToDescription.get( ditStructureRule.getRuleId()
);
+                
+                if ( description != null )
+                {
+                    description.setSchemaName( newSchemaName );
+                }
+
+                if ( DEBUG )
+                {
+                    LOG.debug( "Renamed {} schemaName to {}", ditStructureRule, newSchemaName
);
+                }
+            }
+        }
+    }
 }

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/MatchingRuleUseRegistry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/MatchingRuleUseRegistry.java?rev=807194&r1=807193&r2=807194&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/MatchingRuleUseRegistry.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/MatchingRuleUseRegistry.java
Mon Aug 24 12:56:01 2009
@@ -20,11 +20,9 @@
 package org.apache.directory.shared.ldap.schema.registries;
 
 
-import java.util.Iterator;
-
-import javax.naming.NamingException;
-
 import org.apache.directory.shared.ldap.schema.MatchingRuleUse;
+import org.apache.directory.shared.ldap.schema.SchemaObjectType;
+import org.apache.directory.shared.ldap.schema.parsers.MatchingRuleUseDescription;
 
 
 /**
@@ -35,34 +33,13 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public interface MatchingRuleUseRegistry extends SchemaObjectRegistry<MatchingRuleUse>
+public class MatchingRuleUseRegistry extends SchemaObjectRegistry<MatchingRuleUse, MatchingRuleUseDescription>
 {
     /**
-     * Registers a MatchingRuleUse with this registry.
-     *
-     * @param matchingRuleUse the matchingRuleUse to register
-     * @throws NamingException if the MatchingRuleUse is already registered or
-     * the registration operation is not supported
-     */
-    void register( MatchingRuleUse matchingRuleUse ) throws NamingException;
-
-
-    /**
-     * Looks up an matchingRuleUse by its name.
-     * 
-     * @param name the name of the matchingRuleUse
-     * @return the MatchingRuleUse instance for the name
-     * @throws NamingException if the MatchingRuleUse does not exist
-     */
-    MatchingRuleUse lookup( String name ) throws NamingException;
-
-    
-    /**
-     * Checks to see if an matchingRuleUse exists.
-     * 
-     * @param name the name of the matchingRuleUse
-     * @return true if an matchingRuleUse definition exists for the name, false
-     * otherwise
+     * Creates a new default MatchingRuleUseRegistry instance.
      */
-    boolean hasMatchingRuleUse( String name );
+    public MatchingRuleUseRegistry()
+    {
+        super( SchemaObjectType.MATCHING_RULE_USE );
+    }
 }



Mime
View raw message