directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r819572 - in /directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema: SchemaObject.java SchemaWrapper.java registries/Registries.java registries/Schema.java
Date Mon, 28 Sep 2009 15:01:33 GMT
Author: elecharny
Date: Mon Sep 28 15:01:33 2009
New Revision: 819572

URL: http://svn.apache.org/viewvc?rev=819572&view=rev
Log:
Added a Map in the Registries to associate all the SchemaObjects to their Schema, for easier
schema enabling/disabling operations

Added:
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaWrapper.java
Modified:
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaObject.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Schema.java

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaObject.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaObject.java?rev=819572&r1=819571&r2=819572&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaObject.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaObject.java
Mon Sep 28 15:01:33 2009
@@ -451,7 +451,7 @@
      * <li> NameForm
      * <li> Normalizer (specific to ADS)
      * <li> ObjectClass
-     * <li> SynatxChecker (specific to ADS)
+     * <li> SyntaxChecker (specific to ADS)
      * 
      * @return the SchemaObject type
      */

Added: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaWrapper.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaWrapper.java?rev=819572&view=auto
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaWrapper.java
(added)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaWrapper.java
Mon Sep 28 15:01:33 2009
@@ -0,0 +1,100 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.ldap.schema;
+
+/**
+ * A class containing a SchemaObject, used by the global registries. As the hash code
+ * method of the SchemaObjetc class is too complex, we had to define a simplest class
+ * for this purpose, where the hash code is computed using only the SchemaObject
+ * type and its OID.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SchemaWrapper
+{
+    /** The internal schemaObject */
+    private SchemaObject schemaObject;
+    
+    
+    /**
+     * Creates a new instance of SchemaWrapper.
+     *
+     * @param schemaObject The contained SchemaObject
+     */
+    public SchemaWrapper( SchemaObject schemaObject )
+    {
+        this.schemaObject = schemaObject;
+    }
+    
+    /**
+     * Compute the hash code for this wrapper. We only use the object type
+     * and its oid.
+     */
+    public int hashCode()
+    {
+        int h = 37;
+        h += h*17 + schemaObject.getObjectType().getValue();
+        h += h*17 + schemaObject.getOid().hashCode();
+        
+        return h;
+    }
+    
+    
+    /**
+     * @see Object#equals(Object)
+     */
+    public boolean equals( Object o )
+    {
+        if ( o == this )
+        {
+            return true;
+        }
+        
+        if ( !(o instanceof SchemaWrapper ) )
+        {
+            return false;
+        }
+        
+        SchemaObject that = ((SchemaWrapper)o).get();
+        SchemaObject current = get();
+        
+        return ( that.getOid().equals( current.getOid() ) &&
+            ( that.getObjectType() == current.getObjectType() ) );
+    }
+
+    
+    /**
+     *  @return The interned SchemaObject
+     */
+    public SchemaObject get()
+    {
+        return schemaObject;
+    }
+    
+    
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        return schemaObject.toString();
+    }
+}

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java?rev=819572&r1=819571&r2=819572&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java
Mon Sep 28 15:01:33 2009
@@ -19,21 +19,30 @@
  */
 package org.apache.directory.shared.ldap.schema.registries;
 
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
-import java.util.ArrayList;
 import java.util.Map;
-import java.util.HashMap;
+import java.util.Set;
+
 import javax.naming.NamingException;
 
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.DITContentRule;
 import org.apache.directory.shared.ldap.schema.DITStructureRule;
+import org.apache.directory.shared.ldap.schema.LdapComparator;
 import org.apache.directory.shared.ldap.schema.LdapSyntax;
 import org.apache.directory.shared.ldap.schema.MatchingRule;
 import org.apache.directory.shared.ldap.schema.MatchingRuleUse;
 import org.apache.directory.shared.ldap.schema.NameForm;
+import org.apache.directory.shared.ldap.schema.Normalizer;
 import org.apache.directory.shared.ldap.schema.ObjectClass;
+import org.apache.directory.shared.ldap.schema.SchemaObject;
+import org.apache.directory.shared.ldap.schema.SchemaWrapper;
+import org.apache.directory.shared.ldap.schema.SyntaxChecker;
+import org.apache.directory.shared.ldap.util.StringTools;
 
 
 /**
@@ -86,6 +95,9 @@
     /** The LdapSyntax registry */
     protected LdapSyntaxRegistry ldapSyntaxRegistry;
     
+    /** A map storing all the schema objects associated with a schema */
+    private Map<String, Set<SchemaWrapper>> schemaObjectsBySchemaName;
+    
 
     /**
      * Creates a new instance of Registries.
@@ -106,6 +118,7 @@
         ditStructureRuleRegistry = new DITStructureRuleRegistry( oidRegistry );
         matchingRuleUseRegistry = new MatchingRuleUseRegistry( oidRegistry );
         nameFormRegistry = new NameFormRegistry( oidRegistry );
+        schemaObjectsBySchemaName = new HashMap<String, Set<SchemaWrapper>>();
     }
 
     
@@ -649,4 +662,171 @@
 	{
 		return Collections.unmodifiableMap( loadedSchemas );
 	}
+	
+	
+	/**
+	 * @return Gets a reference to the Map associating a schemaName to
+	 * its contained SchemaObjects
+	 */
+	public Map<String, Set<SchemaWrapper>> getObjectBySchemaname()
+	{
+	    return schemaObjectsBySchemaName;
+	}
+	
+	
+	/**
+	 * Create a new schema association with its content
+	 *
+	 * @param schemaName The schema name
+	 */
+	public Set<SchemaWrapper> addSchema( String schemaName )
+	{
+	    Set<SchemaWrapper> content = new HashSet<SchemaWrapper>();
+	    schemaObjectsBySchemaName.put( schemaName, content );
+	    
+	    return content;
+	}
+	
+	
+	public void register( SchemaObject schemaObject ) throws NamingException
+	{
+	    // First call the specific registry's register method
+	    switch ( schemaObject.getObjectType() )
+	    {
+	        case ATTRIBUTE_TYPE : 
+	            attributeTypeRegistry.register( (AttributeType)schemaObject );
+	            break;
+	            
+            case COMPARATOR : 
+                comparatorRegistry.register( (LdapComparator<?>)schemaObject );
+                break;
+                
+            case DIT_CONTENT_RULE : 
+                ditContentRuleRegistry.register( (DITContentRule)schemaObject );
+                break;
+                
+            case DIT_STRUCTURE_RULE : 
+                ditStructureRuleRegistry.register( (DITStructureRule)schemaObject );
+                break;
+                
+            case LDAP_SYNTAX : 
+                ldapSyntaxRegistry.register( (LdapSyntax)schemaObject );
+                break;
+                
+            case MATCHING_RULE : 
+                matchingRuleRegistry.register( (MatchingRule)schemaObject );
+                break;
+                
+            case MATCHING_RULE_USE : 
+                matchingRuleUseRegistry.register( (MatchingRuleUse)schemaObject );
+                break;
+                
+            case NAME_FORM : 
+                nameFormRegistry.register( (NameForm)schemaObject );
+                break;
+                
+            case NORMALIZER : 
+                normalizerRegistry.register( (Normalizer)schemaObject );
+                break;
+                
+            case OBJECT_CLASS : 
+                objectClassRegistry.register( (ObjectClass)schemaObject );
+                break;
+                
+            case SYNTAX_CHECKER : 
+                syntaxCheckerRegistry.register( (SyntaxChecker)schemaObject );
+                break;
+	    }
+	    
+	    // And register the schemaObject within its schema
+	    Set<SchemaWrapper> content = schemaObjectsBySchemaName.get( StringTools.toLowerCase(
schemaObject.getSchemaName() ) );
+	    
+	    if ( content == null )
+	    {
+	        content = new HashSet<SchemaWrapper>();
+	        schemaObjectsBySchemaName.put( StringTools.toLowerCase( schemaObject.getSchemaName()
), content );
+	    }
+	    
+	    SchemaWrapper schemaWrapper = new SchemaWrapper( schemaObject );
+	    
+	    if ( content.contains( schemaWrapper ) )
+	    {
+	        // Already present !
+	        
+	    }
+	    else
+	    {
+	        // Create the association
+	        content.add( schemaWrapper );
+	    }
+	}
+
+
+    public void unregister( SchemaObject schemaObject ) throws NamingException
+    {
+        String oid = schemaObject.getOid();
+        
+        // First call the specific registry's register method
+        switch ( schemaObject.getObjectType() )
+        {
+            case ATTRIBUTE_TYPE : 
+                attributeTypeRegistry.unregister( oid );
+                break;
+                
+            case COMPARATOR : 
+                comparatorRegistry.unregister( oid );
+                break;
+                
+            case DIT_CONTENT_RULE : 
+                ditContentRuleRegistry.unregister( oid );
+                break;
+                
+            case DIT_STRUCTURE_RULE : 
+                ditStructureRuleRegistry.unregister( oid );
+                break;
+                
+            case LDAP_SYNTAX : 
+                ldapSyntaxRegistry.unregister( oid );
+                break;
+                
+            case MATCHING_RULE : 
+                matchingRuleRegistry.unregister( oid );
+                break;
+                
+            case MATCHING_RULE_USE : 
+                matchingRuleUseRegistry.unregister( oid );
+                break;
+                
+            case NAME_FORM : 
+                nameFormRegistry.unregister( oid );
+                break;
+                
+            case NORMALIZER : 
+                normalizerRegistry.unregister( oid );
+                break;
+                
+            case OBJECT_CLASS : 
+                objectClassRegistry.unregister( oid );
+                break;
+                
+            case SYNTAX_CHECKER : 
+                syntaxCheckerRegistry.unregister( oid );
+                break;
+        }
+        
+        // And unregister the schemaObject within its schema
+        Set<SchemaWrapper> content = schemaObjectsBySchemaName.get( StringTools.toLowerCase(
schemaObject.getSchemaName() ) );
+        
+        SchemaWrapper schemaWrapper = new SchemaWrapper( schemaObject );
+        
+        if ( content.contains( schemaWrapper ) )
+        {
+            // remove the schemaObject
+            content.remove( schemaWrapper );
+        }
+        else
+        {
+            // Not present !!
+        }
+    }
 }

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Schema.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Schema.java?rev=819572&r1=819571&r2=819572&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Schema.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Schema.java
Mon Sep 28 15:01:33 2009
@@ -19,6 +19,10 @@
  */
 package org.apache.directory.shared.ldap.schema.registries;
 
+import java.util.Set;
+
+import org.apache.directory.shared.ldap.schema.SchemaWrapper;
+
 
 /**
  * Base schema interface.
@@ -81,4 +85,12 @@
      * @return the String names of schema dependencies
      */
     String[] getDependencies();
+    
+    
+    /**
+     * Gets the set of SchemaObject elements declared in this schema
+     *
+     * @return The Set of associated SchemaObjects
+     */
+    Set<SchemaWrapper> getContent();
 }



Mime
View raw message