You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2007/10/01 16:03:10 UTC

svn commit: r580962 - /directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/hierarchy/HierarchyManager.java

Author: pamarcelot
Date: Mon Oct  1 07:03:05 2007
New Revision: 580962

URL: http://svn.apache.org/viewvc?rev=580962&view=rev
Log:
Code formatting and Javadoc.

Modified:
    directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/hierarchy/HierarchyManager.java

Modified: directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/hierarchy/HierarchyManager.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/hierarchy/HierarchyManager.java?rev=580962&r1=580961&r2=580962&view=diff
==============================================================================
--- directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/hierarchy/HierarchyManager.java (original)
+++ directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/hierarchy/HierarchyManager.java Mon Oct  1 07:03:05 2007
@@ -48,6 +48,7 @@
     /** The SchemaHandler */
     private SchemaHandler schemaHandler;
 
+    /** The RootObject of the Hierarchy */
     private RootObject root;
 
 
@@ -60,75 +61,70 @@
         parentsMap = new MultiValueMap();
         childrenMap = new MultiValueMap();
 
+        // Getting the SchemaHandler
         schemaHandler = Activator.getDefault().getSchemaHandler();
 
+        // Loading the complete Schema
         loadSchema();
     }
 
 
     /**
-     * Loads the Schema.
+     * Adds an attribute type.
+     *
+     * @param at
+     *      the attribute type
      */
-    private void loadSchema()
-    {
-        if ( schemaHandler != null )
-        {
-            // Creating the root element
-            root = new RootObject();
-
-            // Looping on the schemas
-            for ( Schema schema : schemaHandler.getSchemas() )
-            {
-                // Looping on the attribute types
-                for ( AttributeTypeImpl at : schema.getAttributeTypes() )
-                {
-                    addAttributeType( at );
-                }
-
-                // Looping on the object classes
-                for ( ObjectClassImpl oc : schema.getObjectClasses() )
-                {
-                    addObjectClass( oc );
-                }
-            }
-        }
-    }
-
-
     private void addAttributeType( AttributeTypeImpl at )
     {
+        // Checking Aliases and OID
         checkAliasesAndOID( at );
 
         String superiorName = at.getSuperiorName();
         if ( superiorName != null )
+        // The attribute type has a superior
         {
             AttributeTypeImpl superior = schemaHandler.getAttributeType( superiorName );
-            if ( superior == null )
+            if ( superior != null )
+            // The superior attribute type object exists
             {
-                parentsMap.put( at, superiorName.toLowerCase() );
-                childrenMap.put( superiorName.toLowerCase(), at );
-                childrenMap.put( root, at );
+                parentsMap.put( at, superior );
+                childrenMap.put( superior, at );
             }
             else
+            // The superior attribute type object does not exist
             {
-                parentsMap.put( at, superior );
-                childrenMap.put( superior, at );
+                // Then, its parent is the name of its superior and
+                // it becomes the children of it and the RootObject
+                parentsMap.put( at, superiorName.toLowerCase() );
+                childrenMap.put( superiorName.toLowerCase(), at );
+                childrenMap.put( root, at );
             }
         }
         else
+        // The attribute type does not have a superior
         {
+            // Then, its parent is the RootObject
             parentsMap.put( at, root );
             childrenMap.put( root, at );
         }
     }
 
 
+    /**
+     * Adds an object class.
+     *
+     * @param oc
+     *      the object class
+     */
     private void addObjectClass( ObjectClassImpl oc )
     {
+        // Checking Aliases and OID
         checkAliasesAndOID( oc );
 
         String[] superClasseNames = oc.getSuperClassesNames();
         if ( ( superClasseNames != null ) && ( superClasseNames.length > 0 ) )
+        // The object class has one or more superiors
         {
             for ( String superClassName : superClasseNames )
             {
@@ -147,10 +143,13 @@
             }
         }
         else
+        // The object class does not have any declared superior
+        // Then, it is a child of the "top (2.5.6.0)" object class
+        // (Unless it is the "top (2.5.6.0)" object class itself)
         {
             ObjectClassImpl topOC = schemaHandler.getObjectClass( "2.5.6.0" );
-
             if ( oc.equals( topOC ) )
+            // The given object class is the "top (2.5.6.0)" object class
             {
                 parentsMap.put( oc, root );
                 childrenMap.put( root, oc );
@@ -158,11 +157,13 @@
             else
             {
                 if ( topOC != null )
+                // The "top (2.5.6.0)" object class exists
                 {
                     parentsMap.put( oc, topOC );
                     childrenMap.put( topOC, oc );
                 }
                 else
+                // The "top (2.5.6.0)" object class does not exist
                 {
                     parentsMap.put( oc, "2.5.6.0" );
                     childrenMap.put( "2.5.6.0", oc );
@@ -172,6 +173,61 @@
     }
 
 
+    /**
+     * This method is called when an attribute type is added.
+     *
+     * @param at
+     *      the added attribute type
+     */
+    public void attributeTypeAdded( AttributeTypeImpl at )
+    {
+        addAttributeType( at );
+    }
+
+
+    /**
+     * This method is called when an attribute type is modified.
+     *
+     * @param at
+     *      the modified attribute type
+     */
+    public void attributeTypeModified( AttributeTypeImpl at )
+    {
+        // Removing the attribute type
+        List<Object> parents = getParents( at );
+        if ( parents != null )
+        {
+            for ( Object parent : parents )
+            {
+                childrenMap.remove( parent, at );
+            }
+
+            parentsMap.remove( at );
+        }
+
+        // Adding the attribute type again
+        addAttributeType( at );
+    }
+
+
+    /**
+     * This method is called when an attribute type is removed.
+     *
+     * @param at
+     *      the removed attribute type
+     */
+    public void attributeTypeRemoved( AttributeTypeImpl at )
+    {
+        removeAttributeType( at );
+    }
+
+
+    /**
+     * Checks the Aliases and OID of an attribute type or an object class.
+     *
+     * @param object
+     *      an attribute type or an object class.
+     */
     private void checkAliasesAndOID( SchemaObject object )
     {
         // Aliases
@@ -180,6 +236,7 @@
         {
             for ( String alias : aliases )
             {
+                // Looking for children objects for this alias value
                 @SuppressWarnings("unchecked")
                 List<Object> children = ( List<Object> ) childrenMap.get( alias.toLowerCase() );
                 if ( children != null )
@@ -199,28 +256,31 @@
         String oid = object.getOid();
         if ( oid != null )
         {
+            // Looking for children objects for this OID value
             @SuppressWarnings("unchecked")
             List<Object> children = ( List<Object> ) childrenMap.get( oid.toLowerCase() );
             if ( children != null )
             {
                 for ( Object value : children )
                 {
-                    childrenMap.remove( oid.toLowerCase(), value );
                     childrenMap.put( object, value );
-                    parentsMap.remove( value, object );
+                    parentsMap.remove( value, oid.toLowerCase() );
                     parentsMap.put( value, object );
                 }
+                childrenMap.remove( oid.toLowerCase() );
             }
         }
     }
 
 
-    public RootObject getRootObject()
-    {
-        return root;
-    }
-
-
+    /**
+     * Gets the children of the given object.
+     *
+     * @param o
+     *      the object
+     * @return
+     *      the children of the given object
+     */
     @SuppressWarnings("unchecked")
     public List<Object> getChildren( Object o )
     {
@@ -228,6 +288,14 @@
     }
 
 
+    /**
+     * Gets the parents of the given object.
+     *
+     * @param o
+     *      the object
+     * @return
+     *      the parents of the given object
+     */
     @SuppressWarnings("unchecked")
     public List<Object> getParents( Object o )
     {
@@ -235,38 +303,92 @@
     }
 
 
-    public void attributeTypeAdded( AttributeTypeImpl at )
+    /**
+     * Gets the RootObject of the Hierarchy.
+     *
+     * @return
+     *      the RootObject of the Hierarchy
+     */
+    public RootObject getRootObject()
     {
-        addAttributeType( at );
+        return root;
     }
 
 
-    public void attributeTypeModified( AttributeTypeImpl at )
+    /**
+     * Loads the Schema.
+     */
+    private void loadSchema()
     {
-        List<Object> parents = getParents( at );
-        if ( parents != null )
+        if ( schemaHandler != null )
         {
-            for ( Object parent : parents )
+            // Creating the root element
+            root = new RootObject();
+
+            // Looping on the schemas
+            for ( Schema schema : schemaHandler.getSchemas() )
             {
-                childrenMap.remove( parent, at );
-            }
+                // Looping on the attribute types
+                for ( AttributeTypeImpl at : schema.getAttributeTypes() )
+                {
+                    addAttributeType( at );
+                }
 
-            parentsMap.remove( at );
+                // Looping on the object classes
+                for ( ObjectClassImpl oc : schema.getObjectClasses() )
+                {
+                    addObjectClass( oc );
+                }
+            }
         }
+    }
 
-        //        removeAttributeType( at );
-        addAttributeType( at );
+
+    /**
+     * This method is called when an object class is added.
+     *
+     * @param oc
+     *      the added object class
+     */
+    public void objectClassAdded( ObjectClassImpl oc )
+    {
+        addObjectClass( oc );
     }
 
 
-    public void attributeTypeRemoved( AttributeTypeImpl at )
+    /**
+     * This method is called when an object class is modified.
+     *
+     * @param oc
+     *      the modified object class
+     */
+    public void objectClassModified( ObjectClassImpl oc )
     {
-        removeAttributeType( at );
+        // TODO implement
+    }
+
+
+    /**
+     * This method is called when an object class is removed.
+     *
+     * @param oc
+     *      the removed object class
+     */
+    public void objectClassRemoved( ObjectClassImpl oc )
+    {
+        // TODO implement
     }
 
 
+    /**
+     * Removes an attribute type.
+     *
+     * @param at
+     *      the attribute type
+     */
     private void removeAttributeType( AttributeTypeImpl at )
     {
+        // Removing the attribute type as child of its superior
         String superiorName = at.getSuperiorName();
         if ( ( superiorName != null ) && ( !"".equals( superiorName ) ) )
         {
@@ -285,6 +407,7 @@
             childrenMap.remove( root, at );
         }
 
+        // Attaching each child (if there are children) to the RootObject
         List<Object> children = getChildren( at );
         if ( children != null )
         {
@@ -310,28 +433,26 @@
     }
 
 
-    public void objectClassAdded( ObjectClassImpl oc )
-    {
-    }
-
-
-    public void objectClassModified( ObjectClassImpl oc )
-    {
-    }
-
-
-    public void objectClassRemoved( ObjectClassImpl oc )
-    {
-    }
-
-
+    /**
+     * This method is called when a schema is added.
+     *
+     * @param schema
+     *      the added schema
+     */
     public void schemaAdded( Schema schema )
     {
+        // TODO implement
     }
 
 
+    /**
+     * This method is called when a schema is removed.
+     *
+     * @param schema
+     *      the removed schema
+     */
     public void schemaRemoved( Schema schema )
     {
+        // TODO implement
     }
-
 }