You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2008/03/26 00:05:38 UTC

svn commit: r641069 [2/4] - in /directory/studio/trunk: aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/valueeditors/ ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/ ldapbrowser-common/src/...

Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/Attribute.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/Attribute.java?rev=641069&r1=641068&r2=641069&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/Attribute.java (original)
+++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/Attribute.java Tue Mar 25 16:05:04 2008
@@ -25,6 +25,7 @@
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.directory.shared.ldap.schema.syntax.AttributeTypeDescription;
 import org.apache.directory.studio.connection.core.Connection;
 import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
 import org.apache.directory.studio.ldapbrowser.core.events.EmptyValueAddedEvent;
@@ -40,7 +41,6 @@
 import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
 import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
 import org.apache.directory.studio.ldapbrowser.core.model.IValue;
-import org.apache.directory.studio.ldapbrowser.core.model.schema.AttributeTypeDescription;
 import org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils;
 import org.eclipse.search.ui.ISearchPageScoreComputer;
 
@@ -184,7 +184,7 @@
      */
     public boolean isBinary()
     {
-        return getAttributeTypeDescription().isBinary();
+        return SchemaUtils.isBinary( getAttributeTypeDescription(), getEntry().getBrowserConnection().getSchema() );
     }
 
 

Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/DummyEntry.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/DummyEntry.java?rev=641069&r1=641068&r2=641069&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/DummyEntry.java (original)
+++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/DummyEntry.java Tue Mar 25 16:05:04 2008
@@ -27,8 +27,11 @@
 import java.util.List;
 import java.util.Map;
 
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.name.Rdn;
+import org.apache.directory.shared.ldap.schema.ObjectClassTypeEnum;
+import org.apache.directory.shared.ldap.schema.syntax.ObjectClassDescription;
 import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin;
 import org.apache.directory.studio.ldapbrowser.core.events.AttributeAddedEvent;
 import org.apache.directory.studio.ldapbrowser.core.events.AttributeDeletedEvent;
@@ -39,7 +42,6 @@
 import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
 import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
 import org.apache.directory.studio.ldapbrowser.core.model.URL;
-import org.apache.directory.studio.ldapbrowser.core.model.schema.ObjectClassDescription;
 import org.apache.directory.studio.ldapbrowser.core.model.schema.Subschema;
 
 
@@ -314,7 +316,7 @@
      */
     public boolean isAlias()
     {
-        return Arrays.asList( getSubschema().getObjectClassNames() ).contains( ObjectClassDescription.OC_ALIAS );
+        return Arrays.asList( getSubschema().getObjectClassNames() ).contains( SchemaConstants.ALIAS_OC );
     }
 
 
@@ -361,7 +363,7 @@
         for ( String ocValue : ocValues )
         {
             ObjectClassDescription ocd = this.getBrowserConnection().getSchema().getObjectClassDescription( ocValue );
-            if ( ocd.isStructural() )
+            if ( ocd.getKind() == ObjectClassTypeEnum.STRUCTURAL )
             {
                 structuralObjectClassAvailable = true;
                 break;
@@ -402,7 +404,7 @@
      */
     public boolean isReferral()
     {
-        return Arrays.asList( getSubschema().getObjectClassNames() ).contains( ObjectClassDescription.OC_REFERRAL );
+        return Arrays.asList( getSubschema().getObjectClassNames() ).contains( SchemaConstants.REFERRAL_OC );
     }
 
 
@@ -411,7 +413,7 @@
      */
     public boolean isSubentry()
     {
-        return Arrays.asList( this.getSubschema().getObjectClassNames() ).contains( ObjectClassDescription.OC_SUBENTRY );
+        return Arrays.asList( this.getSubschema().getObjectClassNames() ).contains( SchemaConstants.SUBENTRY_OC );
     }
 
 

Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/BinaryAttribute.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/BinaryAttribute.java?rev=641069&r1=641068&r2=641069&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/BinaryAttribute.java (original)
+++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/BinaryAttribute.java Tue Mar 25 16:05:04 2008
@@ -21,29 +21,53 @@
 package org.apache.directory.studio.ldapbrowser.core.model.schema;
 
 
+/**
+ * Bean class to store the numeric OID or the name of a binary attribute.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class BinaryAttribute
 {
 
     private String attributeNumericOidOrName;
 
 
+    /**
+     * Creates a new instance of BinaryAttribute.
+     */
     public BinaryAttribute()
     {
     }
 
 
+    /**
+     * Creates a new instance of BinaryAttribute.
+     * 
+     * @param attributeNumericOidOrName the attribute numeric oid or name
+     */
     public BinaryAttribute( String attributeNumericOidOrName )
     {
         this.attributeNumericOidOrName = attributeNumericOidOrName;
     }
 
 
+    /**
+     * Gets the attribute numeric OID or name.
+     * 
+     * @return the attribute numeric OID or name
+     */
     public String getAttributeNumericOidOrName()
     {
         return attributeNumericOidOrName;
     }
 
 
+    /**
+     * Sets the attribute numeric OID or name.
+     * 
+     * @param attributeNumericOidOrName the new attribute numeric OID or name
+     */
     public void setAttributeNumericOidOrName( String attributeNumericOidOrName )
     {
         this.attributeNumericOidOrName = attributeNumericOidOrName;

Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/Schema.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/Schema.java?rev=641069&r1=641068&r2=641069&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/Schema.java (original)
+++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/Schema.java Tue Mar 25 16:05:04 2008
@@ -24,24 +24,31 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
-import java.io.Serializable;
-import java.io.StringReader;
 import java.io.Writer;
 import java.net.URL;
 import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.schema.UsageEnum;
+import org.apache.directory.shared.ldap.schema.syntax.AttributeTypeDescription;
+import org.apache.directory.shared.ldap.schema.syntax.LdapSyntaxDescription;
+import org.apache.directory.shared.ldap.schema.syntax.MatchingRuleDescription;
+import org.apache.directory.shared.ldap.schema.syntax.MatchingRuleUseDescription;
+import org.apache.directory.shared.ldap.schema.syntax.ObjectClassDescription;
+import org.apache.directory.shared.ldap.schema.syntax.parser.AttributeTypeDescriptionSchemaParser;
+import org.apache.directory.shared.ldap.schema.syntax.parser.LdapSyntaxDescriptionSchemaParser;
+import org.apache.directory.shared.ldap.schema.syntax.parser.MatchingRuleDescriptionSchemaParser;
+import org.apache.directory.shared.ldap.schema.syntax.parser.MatchingRuleUseDescriptionSchemaParser;
+import org.apache.directory.shared.ldap.schema.syntax.parser.ObjectClassDescriptionSchemaParser;
 import org.apache.directory.studio.ldapbrowser.core.model.AttributeDescription;
 import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
-import org.apache.directory.studio.ldapbrowser.core.model.schema.parser.SchemaLexer;
-import org.apache.directory.studio.ldapbrowser.core.model.schema.parser.SchemaParser;
 import org.apache.directory.studio.ldifparser.LdifFormatParameters;
 import org.apache.directory.studio.ldifparser.model.LdifEnumeration;
 import org.apache.directory.studio.ldifparser.model.container.LdifContainer;
@@ -50,13 +57,17 @@
 import org.apache.directory.studio.ldifparser.parser.LdifParser;
 
 
-public class Schema implements Serializable
+/**
+ * The schema is the central access point to all schema information.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class Schema
 {
 
-    private static final long serialVersionUID = 2439355717760227167L;
-
     public static final String SCHEMA_FILTER = "(objectClass=subschema)";
-    
+
     public static final String SCHEMA_ATTRIBUTE_OBJECTCLASSES = "objectClasses";
 
     public static final String SCHEMA_ATTRIBUTE_ATTRIBUTETYPES = "attributeTypes";
@@ -67,6 +78,18 @@
 
     public static final String SCHEMA_ATTRIBUTE_MATCHINGRULEUSE = "matchingRuleUse";
 
+    public static final String RAW_SCHEMA_DEFINITION_LDIF_VALUE = "RAW_SCHEMA_DEFINITION_LDIF_VALUE";
+
+    public static final String DN_SYNTAX_OID = "1.3.6.1.4.1.1466.115.121.1.12";
+
+    public static final LdapSyntaxDescription DUMMY_LDAP_SYNTAX;
+    static
+    {
+        DUMMY_LDAP_SYNTAX = new LdapSyntaxDescription();
+        DUMMY_LDAP_SYNTAX.setNumericOid( "" );
+        DUMMY_LDAP_SYNTAX.setDescription( "" );
+    }
+
     public static final Schema DEFAULT_SCHEMA;
     static
     {
@@ -74,8 +97,7 @@
 
         try
         {
-            URL url = Schema.class.getClassLoader().getResource(
-                "default_schema.ldif" );
+            URL url = Schema.class.getClassLoader().getResource( "default_schema.ldif" );
             InputStream is = url.openStream();
             Reader reader = new InputStreamReader( is );
 
@@ -103,41 +125,35 @@
 
     private LdapDN dn;
 
-    private String[] objectClasses;
-
     private String createTimestamp;
 
     private String modifyTimestamp;
 
-    private Map ocdMapByName;
-
-    private Map atdMapByName;
+    private Map<String, ObjectClassDescription> ocdMapByNameOrNumericOid;
 
-    private Map lsdMapByNumericOID;
+    private Map<String, AttributeTypeDescription> atdMapByNameOrNumericOid;
 
-    private Map mrdMapByName;
+    private Map<String, LdapSyntaxDescription> lsdMapByNumericOid;
 
-    private Map mrdMapByNumericOID;
+    private Map<String, MatchingRuleDescription> mrdMapByNameOrNumericOid;
 
-    private Map mrudMapByName;
-
-    private Map mrudMapByNumericOID;
+    private Map<String, MatchingRuleUseDescription> mrudMapByNameOrNumericOid;
 
 
+    /**
+     * Creates a new instance of Schema.
+     */
     public Schema()
     {
         this.schemaRecord = null;
         this.dn = null;
-        this.objectClasses = new String[0];
         this.createTimestamp = null;
         this.modifyTimestamp = null;
-        this.ocdMapByName = new HashMap();
-        this.atdMapByName = new HashMap();
-        this.lsdMapByNumericOID = new HashMap();
-        this.mrdMapByName = new HashMap();
-        this.mrdMapByNumericOID = new HashMap();
-        this.mrudMapByName = new HashMap();
-        this.mrudMapByNumericOID = new HashMap();
+        this.ocdMapByNameOrNumericOid = new HashMap<String, ObjectClassDescription>();
+        this.atdMapByNameOrNumericOid = new HashMap<String, AttributeTypeDescription>();
+        this.lsdMapByNumericOid = new HashMap<String, LdapSyntaxDescription>();
+        this.mrdMapByNameOrNumericOid = new HashMap<String, MatchingRuleDescription>();
+        this.mrudMapByNameOrNumericOid = new HashMap<String, MatchingRuleUseDescription>();
     }
 
 
@@ -145,7 +161,7 @@
      * Loads all schema elements from the given reader. The input must be in
      * LDIF format.
      * 
-     * @param reader
+     * @param reader the reader
      */
     public void loadFromLdif( Reader reader )
     {
@@ -159,7 +175,7 @@
                 if ( container instanceof LdifContentRecord )
                 {
                     LdifContentRecord schemaRecord = ( LdifContentRecord ) container;
-                    this.parseSchemaRecord( schemaRecord );
+                    parseSchemaRecord( schemaRecord );
                 }
             }
         }
@@ -170,11 +186,16 @@
     }
 
 
+    /**
+     * Load all schema elements from the given schema record.
+     * 
+     * @param schemaRecord the schema record
+     */
     public void loadFromRecord( LdifContentRecord schemaRecord )
     {
         try
         {
-            this.parseSchemaRecord( schemaRecord );
+            parseSchemaRecord( schemaRecord );
         }
         catch ( Exception e )
         {
@@ -192,7 +213,7 @@
     {
         try
         {
-            writer.write( this.getSchemaRecord().toFormattedString( LdifFormatParameters.DEFAULT ) );
+            writer.write( getSchemaRecord().toFormattedString( LdifFormatParameters.DEFAULT ) );
         }
         catch ( Exception e )
         {
@@ -201,11 +222,17 @@
     }
 
 
+    /**
+     * Parses the schema record.
+     * 
+     * @param schemaRecord the schema record
+     * 
+     * @throws Exception the exception
+     */
     private void parseSchemaRecord( LdifContentRecord schemaRecord ) throws Exception
     {
-
-        this.setSchemaRecord( schemaRecord );
-        this.setDn( new LdapDN( schemaRecord.getDnLine().getValueAsString() ) );
+        setSchemaRecord( schemaRecord );
+        setDn( new LdapDN( schemaRecord.getDnLine().getValueAsString() ) );
 
         LdifAttrValLine[] lines = schemaRecord.getAttrVals();
         for ( int i = 0; i < lines.length; i++ )
@@ -213,54 +240,53 @@
             LdifAttrValLine line = lines[i];
             String attributeName = line.getUnfoldedAttributeDescription();
             String value = line.getValueAsString();
-
-            SchemaLexer lexer = new SchemaLexer( new StringReader( value ) );
-            SchemaParser parser = new SchemaParser( lexer );
+            List<String> ldifValues = new ArrayList<String>( 1 );
+            ldifValues.add( value );
 
             try
             {
                 if ( attributeName.equalsIgnoreCase( Schema.SCHEMA_ATTRIBUTE_OBJECTCLASSES ) )
                 {
-                    ObjectClassDescription ocd = parser.objectClassDescription();
-                    ocd.setSchema( this );
-                    ocd.setLine( line );
-                    this.addObjectClassDescription( ocd );
+                    ObjectClassDescription ocd = new ObjectClassDescriptionSchemaParser()
+                        .parseObjectClassDescription( value );
+                    ocd.addExtension( RAW_SCHEMA_DEFINITION_LDIF_VALUE, ldifValues );
+                    addObjectClassDescription( ocd );
                 }
                 else if ( attributeName.equalsIgnoreCase( Schema.SCHEMA_ATTRIBUTE_ATTRIBUTETYPES ) )
                 {
-                    AttributeTypeDescription atd = parser.attributeTypeDescription();
-                    atd.setSchema( this );
-                    atd.setLine( line );
-                    this.addAttributeTypeDescription( atd );
+                    AttributeTypeDescription atd = new AttributeTypeDescriptionSchemaParser()
+                        .parseAttributeTypeDescription( value );
+                    atd.addExtension( RAW_SCHEMA_DEFINITION_LDIF_VALUE, ldifValues );
+                    addAttributeTypeDescription( atd );
                 }
                 else if ( attributeName.equalsIgnoreCase( Schema.SCHEMA_ATTRIBUTE_LDAPSYNTAXES ) )
                 {
-                    LdapSyntaxDescription lsd = parser.syntaxDescription();
-                    lsd.setSchema( this );
-                    lsd.setLine( line );
-                    this.addLdapSyntaxDescription( lsd );
+                    LdapSyntaxDescription lsd = new LdapSyntaxDescriptionSchemaParser()
+                        .parseLdapSyntaxDescription( value );
+                    lsd.addExtension( RAW_SCHEMA_DEFINITION_LDIF_VALUE, ldifValues );
+                    addLdapSyntaxDescription( lsd );
                 }
                 else if ( attributeName.equalsIgnoreCase( Schema.SCHEMA_ATTRIBUTE_MATCHINGRULES ) )
                 {
-                    MatchingRuleDescription mrd = parser.matchingRuleDescription();
-                    mrd.setSchema( this );
-                    mrd.setLine( line );
-                    this.addMatchingRuleDescription( mrd );
+                    MatchingRuleDescription mrd = new MatchingRuleDescriptionSchemaParser()
+                        .parseMatchingRuleDescription( value );
+                    mrd.addExtension( RAW_SCHEMA_DEFINITION_LDIF_VALUE, ldifValues );
+                    addMatchingRuleDescription( mrd );
                 }
                 else if ( attributeName.equalsIgnoreCase( Schema.SCHEMA_ATTRIBUTE_MATCHINGRULEUSE ) )
                 {
-                    MatchingRuleUseDescription mrud = parser.matchingRuleUseDescription();
-                    mrud.setSchema( this );
-                    mrud.setLine( line );
-                    this.addMatchingRuleUseDescription( mrud );
+                    MatchingRuleUseDescription mrud = new MatchingRuleUseDescriptionSchemaParser()
+                        .parseMatchingRuleUseDescription( value );
+                    mrud.addExtension( RAW_SCHEMA_DEFINITION_LDIF_VALUE, ldifValues );
+                    addMatchingRuleUseDescription( mrud );
                 }
                 else if ( attributeName.equalsIgnoreCase( IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP ) )
                 {
-                    this.setCreateTimestamp( value );
+                    setCreateTimestamp( value );
                 }
                 else if ( attributeName.equalsIgnoreCase( IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP ) )
                 {
-                    this.setModifyTimestamp( value );
+                    setModifyTimestamp( value );
                 }
             }
             catch ( Exception e )
@@ -272,14 +298,16 @@
 
         // set extensibleObject may attributes
         ObjectClassDescription extensibleObjectOcd = this
-            .getObjectClassDescription( ObjectClassDescription.EXTENSIBLEOBJECT_OBJECTCLASSNAME );
-        AttributeTypeDescription[] userAtds = SchemaUtils.getUserAttributeDescriptions( this );
-        String[] attributeTypeDescriptionNames = SchemaUtils.getAttributeTypeDescriptionNames( userAtds );
-        extensibleObjectOcd.setMayAttributeTypeDescriptionNames( attributeTypeDescriptionNames );
+            .getObjectClassDescription( SchemaConstants.EXTENSIBLE_OBJECT_OC );
+        Collection<AttributeTypeDescription> userAtds = SchemaUtils.getUserAttributeDescriptions( this );
+        Collection<String> atdNames = SchemaUtils.getNames( userAtds );
+        List<String> atdNames2 = new ArrayList<String>( atdNames );
+        extensibleObjectOcd.setMayAttributeTypes( atdNames2 );
     }
 
 
     /**
+     * Gets the schema record.
      * 
      * @return the schema record when the schema was created using the
      *         loadFromLdif() method, null otherwise
@@ -290,6 +318,11 @@
     }
 
 
+    /**
+     * Sets the schema record.
+     * 
+     * @param schemaRecord the new schema record
+     */
     public void setSchemaRecord( LdifContentRecord schemaRecord )
     {
         this.schemaRecord = schemaRecord;
@@ -297,8 +330,9 @@
 
 
     /**
+     * Gets the DN of the schema record, may be null.
      * 
-     * @return the dn of the schema record, may be null
+     * @return the DN of the schema record, may be null
      */
     public LdapDN getDn()
     {
@@ -306,6 +340,11 @@
     }
 
 
+    /**
+     * Sets the DN.
+     * 
+     * @param dn the new DN
+     */
     public void setDn( LdapDN dn )
     {
         this.dn = dn;
@@ -313,6 +352,7 @@
 
 
     /**
+     * Gets the create timestamp of the schema record, may be null.
      * 
      * @return the create timestamp of the schema record, may be null
      */
@@ -322,6 +362,11 @@
     }
 
 
+    /**
+     * Sets the creates the timestamp.
+     * 
+     * @param createTimestamp the new creates the timestamp
+     */
     public void setCreateTimestamp( String createTimestamp )
     {
         this.createTimestamp = createTimestamp;
@@ -329,6 +374,7 @@
 
 
     /**
+     * Gets the modify timestamp of the schema record, may be null.
      * 
      * @return the modify timestamp of the schema record, may be null
      */
@@ -338,566 +384,410 @@
     }
 
 
-    public void setModifyTimestamp( String modifyTimestamp )
-    {
-        this.modifyTimestamp = modifyTimestamp;
-    }
-
-
     /**
+     * Sets the modify timestamp.
      * 
-     * @return the object classes of the schema record, may be an empty
-     *         array.
+     * @param modifyTimestamp the new modify timestamp
      */
-    public String[] getObjectClasses()
+    public void setModifyTimestamp( String modifyTimestamp )
     {
-        return objectClasses;
+        this.modifyTimestamp = modifyTimestamp;
     }
 
 
-    public void setObjectClasses( String[] objectClasses )
-    {
-        this.objectClasses = objectClasses;
-    }
-
+    ////////////////////// Object Class Description //////////////////////
 
     /**
+     * Adds the object class description.
      * 
-     * @return a Map of name to attribute type description
+     * @param ocd the object class description
      */
-    Map getAtdMapByName()
-    {
-        return atdMapByName;
-    }
-
-
-    void setAtdMapByName( Map atdMapByName )
+    private void addObjectClassDescription( ObjectClassDescription ocd )
     {
-        this.atdMapByName = atdMapByName;
-    }
-
-
-    public void addAttributeTypeDescription( AttributeTypeDescription atd )
-    {
-        if ( atd.getNames() != null && atd.getNames().length > 0 )
+        if ( ocd.getNumericOid() != null )
         {
-            for ( int i = 0; i < atd.getNames().length; i++ )
-            {
-                this.atdMapByName.put( atd.getNames()[i].toLowerCase(), atd );
-            }
+            ocdMapByNameOrNumericOid.put( ocd.getNumericOid().toLowerCase(), ocd );
         }
-        if ( atd.getNumericOID() != null )
+        if ( ocd.getNames() != null && !ocd.getNames().isEmpty() )
         {
-            this.atdMapByName.put( atd.getNumericOID().toLowerCase(), atd );
+            for ( String ocdName : ocd.getNames() )
+            {
+                ocdMapByNameOrNumericOid.put( ocdName.toLowerCase(), ocd );
+            }
         }
     }
 
 
     /**
+     * Gets the object class descriptions.
      * 
-     * @return an array of all attribute type description names
+     * @return the object class descriptions
      */
-    public String[] getAttributeTypeDescriptionNames()
+    public Collection<ObjectClassDescription> getObjectClassDescriptions()
     {
-        Set set = new HashSet();
-        for ( Iterator it = this.atdMapByName.values().iterator(); it.hasNext(); )
-        {
-            AttributeTypeDescription atd = ( AttributeTypeDescription ) it.next();
-            for ( int i = 0; i < atd.getNames().length; i++ )
-            {
-                set.add( atd.getNames()[i] );
-            }
-        }
-        return ( String[] ) set.toArray( new String[set.size()] );
-    }
-
-
-    public AttributeTypeDescription[] getAttributeTypeDescriptions()
-    {
-        Set set = new HashSet();
-        for ( Iterator it = this.atdMapByName.values().iterator(); it.hasNext(); )
-        {
-            AttributeTypeDescription atd = ( AttributeTypeDescription ) it.next();
-            set.add( atd );
-        }
-        return ( AttributeTypeDescription[] ) set.toArray( new AttributeTypeDescription[set.size()] );
+        Set<ObjectClassDescription> set = new HashSet<ObjectClassDescription>( ocdMapByNameOrNumericOid.values() );
+        return set;
     }
 
 
     /**
+     * Checks if an object class descriptions with the given name or OID exists.
      * 
-     * @return a Map of oid to syntax description
+     * @param nameOrOid the name numeric OID of the object class description
+     * 
+     * @return true if an object class description with the given name
+     *         or OID exists.
      */
-    public Map getLsdMapByNumericOID()
-    {
-        return lsdMapByNumericOID;
-    }
-
-
-    public void setLsdMapByNumericOID( Map lsdMapByNumericOID )
-    {
-        this.lsdMapByNumericOID = lsdMapByNumericOID;
-    }
-
-
-    public void addLdapSyntaxDescription( LdapSyntaxDescription lsd )
+    public boolean hasObjectClassDescription( String nameOrOid )
     {
-        if ( lsd.getNumericOID() != null )
-        {
-            this.lsdMapByNumericOID.put( lsd.getNumericOID().toLowerCase(), lsd );
-        }
+        return ocdMapByNameOrNumericOid.containsKey( nameOrOid.toLowerCase() );
     }
 
 
     /**
+     * Returns the object class description of the given name. If no such
+     * object exists the default or a dummy object class description is
+     * returned.
      * 
-     * @return an array of all syntax description oids
+     * @param nameOrOid the name numeric OID of the object class description
+     * 
+     * @return the object class description, or the default or a dummy
      */
-    public String[] getLdapSyntaxDescriptionOids()
+    public ObjectClassDescription getObjectClassDescription( String nameOrOid )
     {
-        Set set = new HashSet();
-        for ( Iterator it = this.lsdMapByNumericOID.values().iterator(); it.hasNext(); )
+        if ( ocdMapByNameOrNumericOid.containsKey( nameOrOid.toLowerCase() ) )
         {
-            LdapSyntaxDescription lsd = ( LdapSyntaxDescription ) it.next();
-            set.add( lsd.getNumericOID() );
+            return ocdMapByNameOrNumericOid.get( nameOrOid.toLowerCase() );
         }
-        return ( String[] ) set.toArray( new String[set.size()] );
-    }
-
-
-    public LdapSyntaxDescription[] getLdapSyntaxDescriptions()
-    {
-        Set set = new HashSet();
-        for ( Iterator it = this.lsdMapByNumericOID.values().iterator(); it.hasNext(); )
+        else if ( !isDefault() )
         {
-            LdapSyntaxDescription lsd = ( LdapSyntaxDescription ) it.next();
-            set.add( lsd );
+            return DEFAULT_SCHEMA.getObjectClassDescription( nameOrOid );
+        }
+        else
+        {
+            // DUMMY
+            List<String> names = new ArrayList<String>();
+            names.add( nameOrOid );
+            ObjectClassDescription ocd = new ObjectClassDescription();
+            ocd.setNumericOid( nameOrOid );
+            ocd.setNames( names );
+            return ocd;
         }
-        return ( LdapSyntaxDescription[] ) set.toArray( new LdapSyntaxDescription[set.size()] );
-    }
-
-
-    /**
-     * 
-     * @return a Map of name to matching rule description
-     */
-    public Map getMrdMapByName()
-    {
-        return mrdMapByName;
     }
 
 
-    public void setMrdMapByName( Map mrdMapByName )
-    {
-        this.mrdMapByName = mrdMapByName;
-    }
+    ////////////////////// Attribute Type Description //////////////////////
 
-    
     /**
+     * Adds the attribute type description.
      * 
-     * @return an array of all matching rule description names
+     * @param atd the attribute type description
      */
-    public String[] getMatchingRuleDescriptionNames()
+    private void addAttributeTypeDescription( AttributeTypeDescription atd )
     {
-        Set set = new HashSet();
-        for ( Iterator it = this.mrdMapByName.values().iterator(); it.hasNext(); )
+        if ( atd.getNumericOid() != null )
         {
-            MatchingRuleDescription mrd = ( MatchingRuleDescription ) it.next();
-            for ( int i = 0; i < mrd.getNames().length; i++ )
-            {
-                set.add( mrd.getNames()[i] );
-            }
+            atdMapByNameOrNumericOid.put( atd.getNumericOid().toLowerCase(), atd );
         }
-        return ( String[] ) set.toArray( new String[set.size()] );
-    }
-
-
-    public MatchingRuleDescription[] getMatchingRuleDescriptions()
-    {
-        Set set = new HashSet();
-        for ( Iterator it = this.mrdMapByName.values().iterator(); it.hasNext(); )
-        {
-            MatchingRuleDescription mrd = ( MatchingRuleDescription ) it.next();
-            set.add( mrd );
-        }
-        return ( MatchingRuleDescription[] ) set.toArray( new MatchingRuleDescription[set.size()] );
-    }
-
-    public void addMatchingRuleDescription( MatchingRuleDescription mrd )
-    {
-        if ( mrd.getNames() != null && mrd.getNames().length > 0 )
+        if ( atd.getNames() != null && !atd.getNames().isEmpty() )
         {
-            for ( int i = 0; i < mrd.getNames().length; i++ )
+            for ( String atdName : atd.getNames() )
             {
-                this.mrdMapByName.put( mrd.getNames()[i].toLowerCase(), mrd );
+                atdMapByNameOrNumericOid.put( atdName.toLowerCase(), atd );
             }
         }
-        if ( mrd.getNumericOID() != null )
-        {
-            this.mrdMapByNumericOID.put( mrd.getNumericOID().toLowerCase(), mrd );
-        }
     }
 
 
     /**
+     * Gets the attribute type descriptions.
      * 
-     * @return a Map of oid to matching rule description
+     * @return the attribute type descriptions
      */
-    public Map getMrdMapByNumericOID()
-    {
-        return mrdMapByNumericOID;
-    }
-
-
-    public void setMrdMapByNumericOID( Map mrdMapByNumericOID )
+    public Collection<AttributeTypeDescription> getAttributeTypeDescriptions()
     {
-        this.mrdMapByNumericOID = mrdMapByNumericOID;
+        Set<AttributeTypeDescription> set = new HashSet<AttributeTypeDescription>( atdMapByNameOrNumericOid.values() );
+        return set;
     }
 
 
     /**
+     * Checks if an attribute type descriptions with the given name or OID exists.
      * 
-     * @return a Map of name to matching rule use description
-     */
-    public Map getMrudMapByName()
-    {
-        return mrudMapByName;
-    }
-
-
-    public void setMrudMapByName( Map mrudMapByName )
-    {
-        this.mrudMapByName = mrudMapByName;
-    }
-
-
-    public void addMatchingRuleUseDescription( MatchingRuleUseDescription mrud )
-    {
-        if ( mrud.getNames() != null && mrud.getNames().length > 0 )
-        {
-            for ( int i = 0; i < mrud.getNames().length; i++ )
-            {
-                this.mrudMapByName.put( mrud.getNames()[i].toLowerCase(), mrud );
-            }
-        }
-        if ( mrud.getNumericOID() != null )
-        {
-            this.mrudMapByNumericOID.put( mrud.getNumericOID().toLowerCase(), mrud );
-        }
-    }
-
-
-    /**
+     * @param nameOrOid the name numeric OID of the attribute type description
      * 
-     * @return a Map of oid to matching rule use description
+     * @return true if an attribute type description with the given name
+     *         or OID exists.
      */
-    public Map getMrudMapByNumericOID()
-    {
-        return mrudMapByNumericOID;
-    }
-
-
-    public void setMrduMapByNumericOID( Map mrudMapByNumericOID )
+    public boolean hasAttributeTypeDescription( String nameOrOid )
     {
-        this.mrudMapByNumericOID = mrudMapByNumericOID;
+        return atdMapByNameOrNumericOid.containsKey( nameOrOid.toLowerCase() );
     }
 
 
     /**
+     * Returns the attribute type description of the given name. If no such
+     * object exists the default or a dummy attribute type description is
+     * returned.
+     * 
+     * @param nameOrOid the name numeric OID of the attribute type description
      * 
-     * @return a Map of name to object class description
+     * @return the attribute type description, or the default or a dummy
      */
-    Map getOcdMapByName()
+    public AttributeTypeDescription getAttributeTypeDescription( String nameOrOid )
     {
-        return ocdMapByName;
-    }
-
-
-    void setOcdMapByName( Map ocdMapByName )
-    {
-        this.ocdMapByName = ocdMapByName;
-    }
-
+        AttributeDescription ad = new AttributeDescription( nameOrOid );
+        String attributeType = ad.getParsedAttributeType();
 
-    public void addObjectClassDescription( ObjectClassDescription ocd )
-    {
-        if ( ocd.getNames() != null && ocd.getNames().length > 0 )
+        if ( atdMapByNameOrNumericOid.containsKey( attributeType.toLowerCase() ) )
         {
-            for ( int i = 0; i < ocd.getNames().length; i++ )
-            {
-                this.ocdMapByName.put( ocd.getNames()[i].toLowerCase(), ocd );
-            }
+            return atdMapByNameOrNumericOid.get( attributeType.toLowerCase() );
         }
-        if ( ocd.getNumericOID() != null )
+        else if ( !isDefault() )
         {
-            this.ocdMapByName.put( ocd.getNumericOID().toLowerCase(), ocd );
+            return DEFAULT_SCHEMA.getAttributeTypeDescription( attributeType );
+        }
+        else
+        {
+            // DUMMY
+            List<String> attributeTypes = new ArrayList<String>();
+            attributeTypes.add( attributeType );
+            AttributeTypeDescription atd = new AttributeTypeDescription();
+            atd.setNumericOid( attributeType );
+            atd.setNames( attributeTypes );
+            atd.setUserModifiable( false );
+            atd.setUsage( UsageEnum.USER_APPLICATIONS );
+            return atd;
         }
     }
 
 
+    //////////////////////// LDAP Syntax Description ////////////////////////
+
     /**
+     * Adds the LDAP syntax description.
      * 
-     * @return an array of all object class names
+     * @param lsd the LDAP syntax description
      */
-    public String[] getObjectClassDescriptionNames()
+    private void addLdapSyntaxDescription( LdapSyntaxDescription lsd )
     {
-        Set set = new HashSet();
-        for ( Iterator it = this.ocdMapByName.values().iterator(); it.hasNext(); )
+        if ( lsd.getNumericOid() != null )
         {
-            ObjectClassDescription ocd = ( ObjectClassDescription ) it.next();
-            for ( int i = 0; i < ocd.getNames().length; i++ )
-            {
-                set.add( ocd.getNames()[i] );
-            }
+            lsdMapByNumericOid.put( lsd.getNumericOid().toLowerCase(), lsd );
         }
-        return ( String[] ) set.toArray( new String[set.size()] );
     }
 
 
-    public ObjectClassDescription[] getObjectClassDescriptions()
+    /**
+     * Gets the LDAP syntax descriptions.
+     * 
+     * @return the LDAP syntax descriptions
+     */
+    public Collection<LdapSyntaxDescription> getLdapSyntaxDescriptions()
     {
-        Set set = new HashSet();
-        for ( Iterator it = this.ocdMapByName.values().iterator(); it.hasNext(); )
-        {
-            ObjectClassDescription ocd = ( ObjectClassDescription ) it.next();
-            set.add( ocd );
-        }
-        return ( ObjectClassDescription[] ) set.toArray( new ObjectClassDescription[set.size()] );
+        Set<LdapSyntaxDescription> set = new HashSet<LdapSyntaxDescription>( lsdMapByNumericOid.values() );
+        return set;
     }
 
 
     /**
+     * Checks if an LDAP syntax descriptions with the given OID exists.
      * 
-     * @param name
-     * @return true if a object class description with the given name
-     *         exists.
+     * @param numericOid the numeric OID of the LDAP syntax description
+     * 
+     * @return true if an LDAP syntax description with the given OID exists.
      */
-    public boolean hasObjectClassDescription( String name )
+    public boolean hasLdapSyntaxDescription( String numericOid )
     {
-        return this.ocdMapByName.containsKey( name.toLowerCase() );
+        return lsdMapByNumericOid.containsKey( numericOid.toLowerCase() );
     }
 
 
     /**
-     * Returns the object class description of the given name. If no such
-     * object exists the default or a dummy object class description is
-     * returned.
+     * Returns the syntax description of the given OID. If no such object
+     * exists the default or a dummy syntax description is returned.
+     * 
+     * @param numericOid the numeric OID of the LDAP syntax description
      * 
-     * @param name
-     *                the object class name
-     * @return the object class description, the default or a dummy
+     * @return the attribute type description or the default or a dummy
      */
-    public ObjectClassDescription getObjectClassDescription( String name )
+    public LdapSyntaxDescription getLdapSyntaxDescription( String numericOid )
     {
-        if ( this.ocdMapByName.containsKey( name.toLowerCase() ) )
+        if ( numericOid == null )
+        {
+            return DUMMY_LDAP_SYNTAX;
+        }
+        else if ( lsdMapByNumericOid.containsKey( numericOid.toLowerCase() ) )
         {
-            return ( ObjectClassDescription ) this.ocdMapByName.get( name.toLowerCase() );
+            return lsdMapByNumericOid.get( numericOid.toLowerCase() );
         }
-        else if ( !this.isDefault() )
+        else if ( !isDefault() )
         {
-            return DEFAULT_SCHEMA.getObjectClassDescription( name );
+            return DEFAULT_SCHEMA.getLdapSyntaxDescription( numericOid );
         }
         else
         {
             // DUMMY
-            ObjectClassDescription ocd = new ObjectClassDescription();
-            ocd.setSchema( this );
-            ocd.setNumericOID( name );
-            ocd.setNames( new String[]
-                { name } );
-            return ocd;
+            LdapSyntaxDescription lsd = new LdapSyntaxDescription();
+            lsd.setNumericOid( numericOid );
+            return lsd;
         }
     }
 
 
+    ////////////////////////// Matching Rule Description //////////////////////////
+
     /**
+     * Adds the matching rule description.
      * 
-     * @param name
-     * @return true if a attribute type description with the given name
-     *         exists.
+     * @param mrud the matching rule description
      */
-    public boolean hasAttributeTypeDescription( String name )
+    private void addMatchingRuleDescription( MatchingRuleDescription mrd )
     {
-        return this.atdMapByName.containsKey( name.toLowerCase() );
+        if ( mrd.getNumericOid() != null )
+        {
+            mrdMapByNameOrNumericOid.put( mrd.getNumericOid().toLowerCase(), mrd );
+        }
+        if ( mrd.getNames() != null && !mrd.getNames().isEmpty() )
+        {
+            for ( String mrdName : mrd.getNames() )
+            {
+                mrdMapByNameOrNumericOid.put( mrdName.toLowerCase(), mrd );
+            }
+        }
     }
 
 
     /**
-     * Returns the attribute type description of the given name. If no such
-     * object exists the default or a dummy attribute type description is
-     * returned.
+     * Gets the matching rule descriptions.
      * 
-     * @param description
-     *                the attribute description
-     * @return the attribute type description, or the default or a dummy
+     * @return the matching rule descriptions
      */
-    public AttributeTypeDescription getAttributeTypeDescription( String description )
+    public Collection<MatchingRuleDescription> getMatchingRuleDescriptions()
     {
-        AttributeDescription ad = new AttributeDescription( description );
-        String attributeType = ad.getParsedAttributeType();
-
-        if ( this.atdMapByName.containsKey( attributeType.toLowerCase() ) )
-        {
-            return ( AttributeTypeDescription ) this.atdMapByName.get( attributeType.toLowerCase() );
-        }
-        else if ( !this.isDefault() )
-        {
-            return DEFAULT_SCHEMA.getAttributeTypeDescription( attributeType );
-        }
-        else
-        {
-            // DUMMY
-            AttributeTypeDescription atd = new AttributeTypeDescription();
-            atd.setSchema( this );
-            atd.setNumericOID( attributeType );
-            atd.setNames( new String[]
-                { attributeType } );
-            atd.setNoUserModification( true );
-            atd.setUsage( "" );
-            return atd;
-        }
+        Set<MatchingRuleDescription> set = new HashSet<MatchingRuleDescription>( mrdMapByNameOrNumericOid.values() );
+        return set;
     }
 
 
     /**
+     * Checks if an matching rule descriptions with the given name or OID exists.
+     * 
+     * @param nameOrOid the name numeric OID of the matching rule description
      * 
-     * @param name
-     * @return true if a syntax description with the given name exists.
+     * @return true if a matching rule description with the given name
+     *         or OID exists.
      */
-    public boolean hasLdapSyntaxDescription( String numericOID )
+    public boolean hasMatchingRuleDescription( String nameOrOid )
     {
-        return this.lsdMapByNumericOID.containsKey( numericOID.toLowerCase() );
+        return mrdMapByNameOrNumericOid.containsKey( nameOrOid.toLowerCase() );
     }
 
 
     /**
-     * Returns the syntax description of the given name. If no such object
-     * exists the default or a dummy syntax description is returned.
+     * Returns the matching rule description of the given name or OID. If no
+     * such object exists the default or a dummy matching rule description
+     * is returned.
      * 
-     * @param name
-     *                the attribute name
-     * @return the attribute type description, or the default or a dummy
+     * @param nameOrOid the name or numeric OID of the matching rule description
+     * 
+     * @return the matching rule description or the default or a dummy
      */
-    public LdapSyntaxDescription getLdapSyntaxDescription( String numericOID )
+    public MatchingRuleDescription getMatchingRuleDescription( String nameOrOid )
     {
-        if ( this.lsdMapByNumericOID.containsKey( numericOID.toLowerCase() ) )
+        if ( mrdMapByNameOrNumericOid.containsKey( nameOrOid.toLowerCase() ) )
         {
-            return ( LdapSyntaxDescription ) this.lsdMapByNumericOID.get( numericOID.toLowerCase() );
+            return mrdMapByNameOrNumericOid.get( nameOrOid.toLowerCase() );
         }
-        else if ( !this.isDefault() )
+        else if ( !isDefault() )
         {
-            return DEFAULT_SCHEMA.getLdapSyntaxDescription( numericOID );
+            return DEFAULT_SCHEMA.getMatchingRuleDescription( nameOrOid );
         }
         else
         {
             // DUMMY
-            LdapSyntaxDescription lsd = new LdapSyntaxDescription();
-            lsd.setSchema( this );
-            lsd.setNumericOID( numericOID );
-            return lsd;
+            MatchingRuleDescription mrd = new MatchingRuleDescription();
+            mrd.setNumericOid( nameOrOid );
+            return mrd;
         }
     }
 
 
+    //////////////////////// Matching Rule Use Description ////////////////////////
+
     /**
+     * Adds the matching rule use description.
      * 
-     * @param name
-     * @return true if a matching rule description with the given name or
-     *         oid exists.
+     * @param mrud the matching rule use description
      */
-    public boolean hasMatchingRuleDescription( String nameOrOID )
+    private void addMatchingRuleUseDescription( MatchingRuleUseDescription mrud )
     {
-        return this.mrdMapByName.containsKey( nameOrOID.toLowerCase() )
-            || this.mrdMapByNumericOID.containsKey( nameOrOID.toLowerCase() );
+        if ( mrud.getNumericOid() != null )
+        {
+            mrudMapByNameOrNumericOid.put( mrud.getNumericOid().toLowerCase(), mrud );
+        }
+        if ( mrud.getNames() != null && !mrud.getNames().isEmpty() )
+        {
+            for ( String mrudName : mrud.getNames() )
+            {
+                mrudMapByNameOrNumericOid.put( mrudName.toLowerCase(), mrud );
+            }
+        }
     }
 
 
     /**
-     * Returns the matching rule description of the given name or oid. If no
-     * such object exists the default or a dummy matching rule description
-     * is returned.
+     * Gets the matching rule use descriptions.
      * 
-     * @param name
-     *                the matching rule
-     * @return the matching rule description, or the default or a dummy
+     * @return the matching rule use descriptions
      */
-    public MatchingRuleDescription getMatchingRuleDescription( String nameOrOID )
+    public Collection<MatchingRuleUseDescription> getMatchingRuleUseDescriptions()
     {
-        if ( this.mrdMapByName.containsKey( nameOrOID.toLowerCase() ) )
-        {
-            return ( MatchingRuleDescription ) this.mrdMapByName.get( nameOrOID.toLowerCase() );
-        }
-        else if ( this.mrdMapByNumericOID.containsKey( nameOrOID.toLowerCase() ) )
-        {
-            return ( MatchingRuleDescription ) this.mrdMapByNumericOID.get( nameOrOID.toLowerCase() );
-        }
-        else if ( !this.isDefault() )
-        {
-            return DEFAULT_SCHEMA.getMatchingRuleDescription( nameOrOID );
-        }
-        else
-        {
-            // DUMMY
-            MatchingRuleDescription mrd = new MatchingRuleDescription();
-            mrd.setSchema( this );
-            mrd.setNumericOID( nameOrOID );
-            return mrd;
-        }
+        Set<MatchingRuleUseDescription> set = new HashSet<MatchingRuleUseDescription>( mrudMapByNameOrNumericOid.values() );
+        return set;
     }
 
 
     /**
+     * Checks if an matching rule use descriptions with the given name or OID exists.
+     * 
+     * @param nameOrOid the name numeric OID of the matching rule use description
      * 
-     * @param name
      * @return true if a matching rule use description with the given name
-     *         or oid exists.
+     *         or OID exists.
      */
-    public boolean hasMatchingRuleUseDescription( String nameOrOID )
+    public boolean hasMatchingRuleUseDescription( String nameOrOid )
     {
-        return this.mrudMapByName.containsKey( nameOrOID.toLowerCase() )
-            || this.mrudMapByNumericOID.containsKey( nameOrOID.toLowerCase() );
+        return mrudMapByNameOrNumericOid.containsKey( nameOrOid.toLowerCase() );
     }
 
 
     /**
-     * Returns the matching rule description of the given name or oid. If no
-     * such object exists the default or a dummy matching rule description
+     * Returns the matching rule use description of the given name or OID. If no
+     * such object exists the default or a dummy matching rule use description
      * is returned.
      * 
-     * @param name
-     *                the matching rule
-     * @return the matching rule description, or the default or a dummy
+     * @param nameOrOid the name or numeric OID of the matching rule use description
+     * 
+     * @return the matching rule use description or the default or a dummy
      */
-    public MatchingRuleUseDescription getMatchingRuleUseDescription( String nameOrOID )
+    public MatchingRuleUseDescription getMatchingRuleUseDescription( String nameOrOid )
     {
-        if ( this.mrudMapByName.containsKey( nameOrOID.toLowerCase() ) )
-        {
-            return ( MatchingRuleUseDescription ) this.mrudMapByName.get( nameOrOID.toLowerCase() );
-        }
-        else if ( this.mrudMapByNumericOID.containsKey( nameOrOID.toLowerCase() ) )
+        if ( mrudMapByNameOrNumericOid.containsKey( nameOrOid.toLowerCase() ) )
         {
-            return ( MatchingRuleUseDescription ) this.mrudMapByNumericOID.get( nameOrOID.toLowerCase() );
+            return mrudMapByNameOrNumericOid.get( nameOrOid.toLowerCase() );
         }
-        else if ( !this.isDefault() )
+        else if ( !isDefault() )
         {
-            return DEFAULT_SCHEMA.getMatchingRuleUseDescription( nameOrOID );
+            return DEFAULT_SCHEMA.getMatchingRuleUseDescription( nameOrOid );
         }
         else
         {
             // DUMMY
             MatchingRuleUseDescription mrud = new MatchingRuleUseDescription();
-            mrud.setSchema( this );
-            mrud.setNumericOID( nameOrOID );
+            mrud.setNumericOid( nameOrOid );
             return mrud;
         }
-    }
-
-
-    static String[] addValue( String[] array, String value )
-    {
-        List list = new ArrayList( Arrays.asList( array ) );
-        list.add( value );
-        return ( String[] ) list.toArray( new String[list.size()] );
     }
 
 }

Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/SchemaUtils.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/SchemaUtils.java?rev=641069&r1=641068&r2=641069&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/SchemaUtils.java (original)
+++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/SchemaUtils.java Tue Mar 25 16:05:04 2008
@@ -21,88 +21,182 @@
 package org.apache.directory.studio.ldapbrowser.core.model.schema;
 
 
-import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Comparator;
 import java.util.HashSet;
-import java.util.Iterator;
+import java.util.List;
 import java.util.Set;
+import java.util.TreeSet;
 
+import org.apache.directory.shared.ldap.schema.UsageEnum;
+import org.apache.directory.shared.ldap.schema.syntax.AbstractSchemaDescription;
+import org.apache.directory.shared.ldap.schema.syntax.AttributeTypeDescription;
+import org.apache.directory.shared.ldap.schema.syntax.LdapSyntaxDescription;
+import org.apache.directory.shared.ldap.schema.syntax.MatchingRuleDescription;
+import org.apache.directory.shared.ldap.schema.syntax.MatchingRuleUseDescription;
+import org.apache.directory.shared.ldap.schema.syntax.ObjectClassDescription;
+import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin;
 import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
 
 
+/**
+ * Utility class for Schema.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class SchemaUtils
 {
 
-    public static String[] getAttributeTypeDescriptionNames( AttributeTypeDescription[] atds )
+    private static final Comparator<String> nameAndOidComparator = new Comparator<String>()
     {
+        public int compare( String s1, String s2 )
+        {
+            if ( s1.matches( "[0-9\\.]+" ) && !s2.matches( "[0-9\\.]+" ) )
+            {
+                return 1;
+            }
+            else if ( !s1.matches( "[0-9\\.]+" ) && s2.matches( "[0-9\\.]+" ) )
+            {
+                return -1;
+            }
+            else
+            {
+                return s1.compareToIgnoreCase( s2 );
+            }
+        }
+    };
+    
+    private static final Comparator<AbstractSchemaDescription> schemaElementNameComparator = new Comparator<AbstractSchemaDescription>()
+    {
+        public int compare( AbstractSchemaDescription s1, AbstractSchemaDescription s2 )
+        {
+            return SchemaUtils.toString( s1 ).compareToIgnoreCase( SchemaUtils.toString( s2 ) );
+        }
+    };
+    
+    /**
+     * Gets the names of the given schema elements.
+     * 
+     * @param asds the schema elements
+     * 
+     * @return the names
+     */
+    public static Collection<String> getNames( Collection<? extends AbstractSchemaDescription> asds )
+    {
+        Set<String> nameSet = new TreeSet<String>( nameAndOidComparator );
+        for ( AbstractSchemaDescription asd : asds )
+        {
+            nameSet.addAll( asd.getNames() );
+        }
+        return nameSet;
+    }
 
-        Set attributeSet = new HashSet();
-        for ( int i = 0; i < atds.length; i++ )
+    
+    /**
+     * Gets the names of the given schema elements.
+     * 
+     * @param asds the schema elements
+     * 
+     * @return the names
+     */
+    public static String[] getNamesAsArray( Collection<? extends AbstractSchemaDescription> asds )
+    {
+        return getNames( asds ).toArray( new String[0] );
+    }
+    
+
+    /**
+     * Get the numeric OIDs of the given schema descriptions.
+     * 
+     * @return the numeric OIDs of the given schema descriptions
+     */
+    public Collection<String> getNumericOids( Collection<? extends AbstractSchemaDescription> descritpions )
+    {
+        Set<String> oids = new HashSet<String>();
+        for ( AbstractSchemaDescription asd : descritpions )
         {
-            AttributeTypeDescription atd = atds[i];
-            attributeSet.addAll( Arrays.asList( atd.getNames() ) );
+            oids.add( asd.getNumericOid() );
+    
         }
+        return oids;
+    }
 
-        String[] attributes = ( String[] ) attributeSet.toArray( new String[0] );
-        Arrays.sort( attributes );
-        return attributes;
 
+    /**
+     * Gets the identifiers of the given schema descriptions.
+     * 
+     * @param asd the the schema description
+     * 
+     * @return the identifiers
+     */
+    public static Collection<String> getLowerCaseIdentifiers( AbstractSchemaDescription asd )
+    {
+        Set<String> identiers = new HashSet<String>();
+        if ( asd.getNumericOid() != null )
+        {
+            identiers.add( asd.getNumericOid().toLowerCase() );
+        }
+        if ( asd.getNames() != null && !asd.getNames().isEmpty() )
+        {
+            for ( String name : asd.getNames() )
+            {
+                if ( name != null )
+                {
+                    identiers.add( name.toLowerCase() );
+                }
+            }
+        }
+        return identiers;
     }
 
 
     /**
+     * Gets all operational attribute type descriptions.
+     * 
+     * @param schema the schema
      * 
      * @return all operational attributes types
      */
-    public static AttributeTypeDescription[] getOperationalAttributeDescriptions( Schema schema )
+    public static Collection<AttributeTypeDescription> getOperationalAttributeDescriptions( Schema schema )
     {
-        Set operationalAttributeSet = new HashSet();
-        for ( Iterator it = schema.getAtdMapByName().values().iterator(); it.hasNext(); )
+        Set<AttributeTypeDescription> operationalAtds = new HashSet<AttributeTypeDescription>();
+        for ( AttributeTypeDescription atd : schema.getAttributeTypeDescriptions() )
         {
-            AttributeTypeDescription atd = ( AttributeTypeDescription ) it.next();
             if ( isOperational( atd ) )
             {
-                operationalAttributeSet.add( atd );
+                operationalAtds.add( atd );
             }
         }
-
-        AttributeTypeDescription[] operationalAttributes = ( AttributeTypeDescription[] ) operationalAttributeSet
-            .toArray( new AttributeTypeDescription[0] );
-        return operationalAttributes;
+        return operationalAtds;
     }
 
 
     /**
+     * Gets all user (non-operational) attribute type descriptions.
      * 
-     * @return all user attributes types
+     * @param schema the schema
+     * 
+     * @return all user attributes type descriptions
      */
-    public static AttributeTypeDescription[] getUserAttributeDescriptions( Schema schema )
+    public static Collection<AttributeTypeDescription> getUserAttributeDescriptions( Schema schema )
     {
-        Set userAttributeSet = new HashSet();
-        for ( Iterator it = schema.getAtdMapByName().values().iterator(); it.hasNext(); )
+        Set<AttributeTypeDescription> userAtds = new HashSet<AttributeTypeDescription>();
+        for ( AttributeTypeDescription atd : schema.getAttributeTypeDescriptions() )
         {
-            AttributeTypeDescription atd = ( AttributeTypeDescription ) it.next();
             if ( !isOperational( atd ) )
             {
-                userAttributeSet.add( atd );
+                userAtds.add( atd );
             }
         }
-
-        AttributeTypeDescription[] userAttributes = ( AttributeTypeDescription[] ) userAttributeSet
-            .toArray( new AttributeTypeDescription[0] );
-        return userAttributes;
+        return userAtds;
     }
 
 
     public static boolean isOperational( AttributeTypeDescription atd )
     {
-        return atd.isNoUserModification()
-            || !AttributeTypeDescription.ATTRIBUTE_USAGE_USER_APPLICATIONS.equalsIgnoreCase( atd.getUsage() );
-
-        // atd.isNoUserModification()
-        // ||
-        // AttributeTypeDescription.ATTRIBUTE_USAGE_DIRECTORY_OPERATION.equalsIgnoreCase(atd.getUsage())
-        // ||
-        // AttributeTypeDescription.ATTRIBUTE_USAGE_DSA_OPERATION.equalsIgnoreCase(atd.getUsage());
+        return !atd.isUserModifiable() || atd.getUsage() != UsageEnum.USER_APPLICATIONS;
     }
 
 
@@ -114,7 +208,7 @@
             return false;
         }
 
-        if ( atd.isNoUserModification() )
+        if ( !atd.isUserModifiable() )
         {
             return false;
         }
@@ -138,13 +232,13 @@
         for ( int i = 0; i < nonModifyableAttributes.length; i++ )
         {
             String att = nonModifyableAttributes[i];
-            if ( att.equalsIgnoreCase( atd.getNumericOID() ) )
+            if ( att.equalsIgnoreCase( atd.getNumericOid() ) )
             {
                 return false;
             }
-            for ( int n = 0; n < atd.getNames().length; n++ )
+            for ( String name : atd.getNames() )
             {
-                if ( att.equalsIgnoreCase( atd.getNames()[n] ) )
+                if ( att.equalsIgnoreCase( name ) )
                 {
                     return false;
                 }
@@ -153,5 +247,557 @@
 
         return true;
     }
+
+
+    ////////////////////////////////////////////////////////
+    /**
+     * Checks the pre-defined and user-defined binary syntax OIDs. If this
+     * syntax OID is defined as binary, false is returned..
+     * 
+     * @param lsd the LDAP syntax description
+     * 
+     * @return false if the syntax is defined as binary
+     */
+    public static boolean isString( LdapSyntaxDescription lsd )
+    {
+        return !isBinary( lsd );
+    }
+
+
+    /**
+     * Checks the pre-defined and user-defined binary syntax OIDs. If this
+     * syntax OID is defined as binary, true is returned..
+     * 
+     * @param lsd the LDAP syntax description
+     * 
+     * @return true if the syntax is defined as binary
+     */
+    public static boolean isBinary( LdapSyntaxDescription lsd )
+    {
+        // check user-defined binary syntaxes
+        Set<String> binarySyntaxOids = BrowserCorePlugin.getDefault().getCorePreferences()
+            .getUpperCasedBinarySyntaxOids();
+        return binarySyntaxOids.contains( lsd.getNumericOid().toUpperCase() );
+    }
+
+
+    /**
+     * Checks the pre-defined and user-defined binary attribute types. If this
+     * attribute type is defined as binary, false is returned..
+     * 
+     * @param atd the attribute type description
+     * @param schema the schema
+     * 
+     * @return false if the attribute type is defined as binary
+     */
+    public static boolean isString( AttributeTypeDescription atd, Schema schema )
+    {
+        return !isBinary( atd, schema );
+    }
+
+
+    /**
+     * Checks the pre-defined and user-defined binary attribute types. If this
+     * attribute type is defined as binary, true is returned..
+     * 
+     * @param atd the attribute type description
+     * @param schema the schema
+     * 
+     * @return true if the attribute type is defined as binary
+     */
+    public static boolean isBinary( AttributeTypeDescription atd, Schema schema )
+    {
+        // check user-defined binary attribute types
+        Set<String> binaryAttributeOidsAndNames = BrowserCorePlugin.getDefault().getCorePreferences()
+            .getUpperCasedBinaryAttributeOidsAndNames();
+        if ( binaryAttributeOidsAndNames.contains( atd.getNumericOid().toUpperCase() ) )
+        {
+            return true;
+        }
+        for ( String name : atd.getNames() )
+        {
+            if ( binaryAttributeOidsAndNames.contains( name.toUpperCase() ) )
+            {
+                return true;
+            }
+        }
+
+        // check user-defined binary syntaxes
+        String syntax = getSyntaxNumericOidTransitive( atd, schema );
+        if ( syntax != null && schema.hasLdapSyntaxDescription( syntax ) )
+        {
+            LdapSyntaxDescription lsd = schema.getLdapSyntaxDescription( syntax );
+            return isBinary( lsd );
+        }
+
+        return false;
+    }
+
+
+    /**
+     * Gets all attribute type descriptions using the given syntax description.
+     * 
+     * @param lsd the LDAP syntax description
+     * @param schema the schema
+     * 
+     * @return all attribute type description using this syntax description
+     */
+    public static Collection<AttributeTypeDescription> getUsedFromAttributeTypeDescriptions( LdapSyntaxDescription lsd,
+        Schema schema )
+    {
+        Set<AttributeTypeDescription> usedFroms = new TreeSet<AttributeTypeDescription>( schemaElementNameComparator );
+        for ( AttributeTypeDescription atd : schema.getAttributeTypeDescriptions() )
+        {
+            String syntax = getSyntaxNumericOidTransitive( atd, schema );
+            if ( syntax != null && lsd.getNumericOid() != null
+                && syntax.toLowerCase().equals( lsd.getNumericOid().toLowerCase() ) )
+            {
+                usedFroms.add( atd );
+            }
+        }
+        return usedFroms;
+    }
+
+
+    /**
+     * Gets all attribute type descriptions using the given matching rule description.
+     * 
+     * @param mrd the matching rule description
+     * @param schema the schema
+     * 
+     * @return all attribute type descriptions using this matching rule for
+     * equality, substring or ordering matching
+     */
+    public static Collection<AttributeTypeDescription> getUsedFromAttributeTypeDescriptions( MatchingRuleDescription mrd,
+        Schema schema )
+    {
+        Set<AttributeTypeDescription> usedFromSet = new TreeSet<AttributeTypeDescription>( schemaElementNameComparator );
+        for ( AttributeTypeDescription atd : schema.getAttributeTypeDescriptions() )
+        {
+            Collection<String> lowerCaseIdentifiers = getLowerCaseIdentifiers( mrd );
+            String emr = getEqualityMatchingRuleNameOrNumericOidTransitive( atd, schema );
+            String smr = getSubstringMatchingRuleNameOrNumericOidTransitive( atd, schema );
+            String omr = getOrderingMatchingRuleNameOrNumericOidTransitive( atd, schema );
+            if ( emr != null && lowerCaseIdentifiers.contains( emr.toLowerCase() ) )
+            {
+                usedFromSet.add( atd );
+            }
+            if ( smr != null && lowerCaseIdentifiers.contains( smr.toLowerCase() ) )
+            {
+                usedFromSet.add( atd );
+            }
+            if ( omr != null && lowerCaseIdentifiers.contains( omr.toLowerCase() ) )
+            {
+                usedFromSet.add( atd );
+            }
+        }
+        return usedFromSet;
+    }
+
+
+    /**
+     * Gets the equality matching rule description name or OID of the given or the
+     * superior attribute type description.
+     * 
+     * @param atd the attribute type description
+     * @param schema the schema
+     * 
+     * @return the equality matching rule description name or OID of the given or the
+     *         superior attribute type description, may be null
+     */
+    public static String getEqualityMatchingRuleNameOrNumericOidTransitive( AttributeTypeDescription atd, Schema schema )
+    {
+        if ( atd.getEqualityMatchingRule() != null )
+        {
+            return atd.getEqualityMatchingRule();
+        }
+
+        if ( atd.getSuperType() != null && schema.hasAttributeTypeDescription( atd.getSuperType() ) )
+        {
+            AttributeTypeDescription superior = schema.getAttributeTypeDescription( atd.getSuperType() );
+            return getEqualityMatchingRuleNameOrNumericOidTransitive( superior, schema );
+        }
+
+        return null;
+    }
+
+
+    /**
+     * Gets the substring matching rule description name or OID of the given or the
+     * superior attribute type description.
+     * 
+     * @param atd the attribute type description
+     * @param schema the schema
+     * 
+     * @return the substring matching rule description name or OID of the given or the
+     *         superior attribute type description, may be null
+     */
+    public static String getSubstringMatchingRuleNameOrNumericOidTransitive( AttributeTypeDescription atd, Schema schema )
+    {
+        if ( atd.getSubstringsMatchingRule() != null )
+        {
+            return atd.getSubstringsMatchingRule();
+        }
+
+        if ( atd.getSuperType() != null && schema.hasAttributeTypeDescription( atd.getSuperType() ) )
+        {
+            AttributeTypeDescription superior = schema.getAttributeTypeDescription( atd.getSuperType() );
+            return getSubstringMatchingRuleNameOrNumericOidTransitive( superior, schema );
+        }
+
+        return null;
+    }
+
+
+    /**
+     * Gets the ordering matching rule description name or OID of the given or the
+     * superior attribute type description.
+     * 
+     * @param atd the attribute type description
+     * @param schema the schema
+     * 
+     * @return the ordering matching rule description name or OID of the given or the
+     *         superior attribute type description, may be null
+     */
+    public static String getOrderingMatchingRuleNameOrNumericOidTransitive( AttributeTypeDescription atd, Schema schema )
+    {
+        if ( atd.getOrderingMatchingRule() != null )
+        {
+            return atd.getOrderingMatchingRule();
+        }
+
+        if ( atd.getSuperType() != null && schema.hasAttributeTypeDescription( atd.getSuperType() ) )
+        {
+            AttributeTypeDescription superior = schema.getAttributeTypeDescription( atd.getSuperType() );
+            return getOrderingMatchingRuleNameOrNumericOidTransitive( superior, schema );
+        }
+
+        return null;
+    }
+
+
+    /**
+     * Gets the syntax description OID of the given or the
+     * superior attribute type description.
+     * 
+     * @param atd the attribute type description
+     * @param schema the schema
+     * 
+     * @return the syntax description OID of the given or the
+     *         superior attribute type description, may be null
+     */
+    public static String getSyntaxNumericOidTransitive( AttributeTypeDescription atd, Schema schema )
+    {
+        if ( atd.getSyntax() != null )
+        {
+            return atd.getSyntax();
+        }
+
+        if ( atd.getSuperType() != null && schema.hasAttributeTypeDescription( atd.getSuperType() ) )
+        {
+            AttributeTypeDescription superior = schema.getAttributeTypeDescription( atd.getSuperType() );
+            return getSyntaxNumericOidTransitive( superior, schema );
+        }
+
+        return null;
+    }
+
+    
+    /**
+     * Gets the syntax length of the given or the
+     * superior attribute type description.
+     * 
+     * @param atd the attribute type description
+     * @param schema the schema
+     * 
+     * @return the syntax length of the given or the
+     *         superior attribute type description, may be null
+     */
+    public static int getSyntaxLengthTransitive( AttributeTypeDescription atd, Schema schema )
+    {
+        if ( atd.getSyntaxLength() != -1 )
+        {
+            return atd.getSyntaxLength();
+        }
+
+        if ( atd.getSuperType() != null && schema.hasAttributeTypeDescription( atd.getSuperType() ) )
+        {
+            AttributeTypeDescription superior = schema.getAttributeTypeDescription( atd.getSuperType() );
+            return getSyntaxLengthTransitive( superior, schema );
+        }
+
+        return -1;
+    }
+    
+    
+    /**
+     * Gets all matching rule description names the given attribute type
+     * description applies to according to the schema's matchin rul use
+     * descritpions.
+     * 
+     * @param atd the attribute type description
+     * @param schema the schema
+     * 
+     * @return all matching rule description names this attribute type
+     *         description applies to according to the schema's matching 
+     *         rule use descriptions
+     */
+    public static Collection<String> getOtherMatchingRuleDescriptionNames( AttributeTypeDescription atd, Schema schema )
+    {
+        Set<String> otherMatchingRules = new TreeSet<String>( nameAndOidComparator ); 
+        for ( MatchingRuleUseDescription mrud : schema.getMatchingRuleUseDescriptions() )
+        {
+            Collection<String> atdSet = toLowerCaseSet( mrud.getApplicableAttributes() );
+            if ( atdSet.removeAll( getLowerCaseIdentifiers( atd ) ) )
+            {
+                otherMatchingRules.addAll( mrud.getNames() );
+            }
+        }
+        return otherMatchingRules;
+    }
+    
+    
+    /**
+     * Gets all attribute type descriptions using the given attribute type
+     * descriptions as superior.
+     * 
+     * @param atd the attribute type description
+     * @param schema the schema
+     * 
+     * @return all attribute type descriptions using this attribute type
+     *         description as superior
+     */
+    public static Collection<AttributeTypeDescription> getDerivedAttributeTypeDescriptions( AttributeTypeDescription atd, Schema schema )
+    {
+        Set<AttributeTypeDescription> derivedAtds = new TreeSet<AttributeTypeDescription>( schemaElementNameComparator );
+        for ( AttributeTypeDescription derivedAtd : schema.getAttributeTypeDescriptions() )
+        {
+            String superType = derivedAtd.getSuperType();
+            if ( superType != null && getLowerCaseIdentifiers( atd ).contains( superType.toLowerCase() ) )
+            {
+                derivedAtds.add( derivedAtd );
+            }
+        }
+        return derivedAtds;
+    }
+    
+    /**
+     * Gets all object class description using the given attribute type
+     * description as must attribute.
+     * 
+     * @param atd the attribute type description
+     * @param schema the schema
+     * 
+     * @return all object class description using the given attribute type
+     *         description as must attribute
+     */
+    public static Collection<ObjectClassDescription> getUsedAsMust( AttributeTypeDescription atd, Schema schema )
+    {
+        Collection<String> lowerCaseIdentifiers = getLowerCaseIdentifiers( atd );
+        Set<ObjectClassDescription> ocds = new TreeSet<ObjectClassDescription>( schemaElementNameComparator );
+        for ( ObjectClassDescription ocd : schema.getObjectClassDescriptions() )
+        {
+            Collection<String> mustSet = toLowerCaseSet( getMustAttributeTypeDescriptionNamesTransitive( ocd, schema ) );
+            if ( mustSet.removeAll( lowerCaseIdentifiers ) )
+            {
+                ocds.add( ocd );
+            }
+        }
+        return ocds;
+    }
+
+
+    /**
+     * Gets all object class description using the given attribute type
+     * description as may attribute.
+     * 
+     * @param atd the attribute type description
+     * @param schema the schema
+     * 
+     * @return all object class description using the given attribute type
+     *         description as may attribute
+     */
+    public static Collection<ObjectClassDescription> getUsedAsMay( AttributeTypeDescription atd, Schema schema )
+    {
+        Collection<String> lowerCaseIdentifiers = getLowerCaseIdentifiers( atd );
+        Set<ObjectClassDescription> ocds = new TreeSet<ObjectClassDescription>( schemaElementNameComparator );
+        for ( ObjectClassDescription ocd : schema.getObjectClassDescriptions() )
+        {
+            Collection<String> mustSet = toLowerCaseSet( getMayAttributeTypeDescriptionNamesTransitive( ocd, schema ) );
+            if ( mustSet.removeAll( lowerCaseIdentifiers ) )
+            {
+                ocds.add( ocd );
+            }
+        }
+        return ocds;
+    }
+    
+    
+    
+
+    private static Collection<ObjectClassDescription> getExistingSuperiorObjectClassDescription( ObjectClassDescription ocd, Schema schema )
+    {
+        List<ObjectClassDescription> superiorList = new ArrayList<ObjectClassDescription>();
+        for ( String superior : ocd.getSuperiorObjectClasses() )
+        {
+            if ( schema.hasObjectClassDescription( superior ) )
+            {
+                superiorList.add( schema.getObjectClassDescription( superior ) );
+            }
+        }
+        return superiorList;
+    }
+
+    
+    /**
+     * Gets the superior object class descriptions of the given object class description.
+     * 
+     * @param ocd the bject class descriptio
+     * @param schema the schema
+     * 
+     * @return the superior object class descriptions
+     */
+    public static List<ObjectClassDescription> getSuperiorObjectClassDescriptions( ObjectClassDescription ocd, Schema schema )
+    {
+        List<ObjectClassDescription> superiorList = new ArrayList<ObjectClassDescription>();
+        for ( String superior : ocd.getSuperiorObjectClasses() )
+        {
+            superiorList.add( schema.getObjectClassDescription( superior ) );
+        }
+        return superiorList;
+    }
+    
+    
+    /**
+     * Gets the sub object class descriptions of the given object class description.
+     * 
+     * @param ocd the object class description
+     * @param schema the schema
+     * 
+     * @return the sub object class descriptions
+     */
+    public static List<ObjectClassDescription> getSubObjectClassDescriptions( ObjectClassDescription ocd, Schema schema )
+    {
+        List<ObjectClassDescription> subOcds = new ArrayList<ObjectClassDescription>();
+        for ( ObjectClassDescription testOcd : schema.getObjectClassDescriptions() )
+        {
+            Collection<String> superiorNames = toLowerCaseSet( testOcd.getSuperiorObjectClasses() );
+            if ( superiorNames.removeAll( getLowerCaseIdentifiers( ocd ) ) )
+            {
+                subOcds.add( testOcd );
+            }
+        }
+        return subOcds;
+    }
+    
+    /**
+     * Gets the must attribute type description names of the given
+     * and all superior object class description, transitively.
+     * 
+     * @param ocd the object class description
+     * @param schema the schema
+     * 
+     * @return the must attribute type description names of the given
+     *         and all superior object class description, transitively
+     */
+    public static Collection<String> getMustAttributeTypeDescriptionNamesTransitive( ObjectClassDescription ocd, Schema schema )
+    {
+        Set<String> musts = new TreeSet<String>( nameAndOidComparator ); 
+        musts.addAll( ocd.getMustAttributeTypes() );
+        Collection<ObjectClassDescription> superiors = getExistingSuperiorObjectClassDescription( ocd, schema );
+        for ( ObjectClassDescription superior : superiors )
+        {
+            musts.addAll( getMustAttributeTypeDescriptionNamesTransitive( superior, schema ) );
+        }
+        return musts;
+    }
+    
+    
+    /**
+     * Gets the may attribute type description names of the given
+     * and all superior object class description, transitively.
+     * 
+     * @param ocd the object class description
+     * @param schema the schema
+     * 
+     * @return the may attribute type description names of the given
+     *         and all superior object class description, transitively
+     */
+    public static Collection<String> getMayAttributeTypeDescriptionNamesTransitive( ObjectClassDescription ocd, Schema schema )
+    {
+        Set<String> mays= new TreeSet<String>( nameAndOidComparator ); 
+        mays.addAll( ocd.getMayAttributeTypes() );
+        Collection<ObjectClassDescription> superiors = getExistingSuperiorObjectClassDescription( ocd, schema );
+        for ( ObjectClassDescription superior : superiors )
+        {
+            mays.addAll( getMayAttributeTypeDescriptionNamesTransitive( superior, schema ) );
+        }
+        return mays;
+    }
+
+    /**
+     * Gets the LDIF line of the given schema element, may be null.
+     *
+     * @param asd the schema element
+     * @return the LDIF line of the given schema element, may be null
+     */
+    public static String getLdifLine( AbstractSchemaDescription asd )
+    {
+        List<String> ldifLines = asd.getExtensions().get( Schema.RAW_SCHEMA_DEFINITION_LDIF_VALUE );
+        String ldifLine = ldifLines != null && !ldifLines.isEmpty() ? ldifLines.get( 0 ) : null;
+        return ldifLine;
+    }
+    
+    
+    private static Collection<String> toLowerCaseSet( Collection<String> names )
+    {
+        Set<String> set = new HashSet<String>();
+        if ( names != null )
+        {
+            for ( String name : names )
+            {
+                set.add( name.toLowerCase() );
+            }
+        }
+        return set;
+    }
+    
+    /**
+     * Gets the string representation of the given schema element.
+     * 
+     * @param asd the schema element
+     * 
+     * @return the string representation of the given schema element
+     */
+    public static String toString( AbstractSchemaDescription asd )
+    {
+        StringBuffer sb = new StringBuffer();
+        if ( asd instanceof LdapSyntaxDescription )
+        {
+            if ( asd.getDescription() != null && asd.getDescription().length() > 0 )
+            {
+                sb.append( asd.getDescription() );
+            }
+            else
+            {
+                sb.append( asd.getNumericOid() );
+            }
+        }
+        else
+        {
+            boolean first = true;
+            for ( String name : asd.getNames() )
+            {
+                if ( !first )
+                {
+                    sb.append( ", " );
+                }
+                sb.append( name );
+                first = false;
+            }
+        }
+        return sb.toString();
+    }
+    
 
 }

Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/Subschema.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/Subschema.java?rev=641069&r1=641068&r2=641069&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/Subschema.java (original)
+++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/Subschema.java Tue Mar 25 16:05:04 2008
@@ -26,11 +26,19 @@
 import java.util.Set;
 import java.util.TreeSet;
 
+import org.apache.directory.shared.ldap.schema.syntax.AttributeTypeDescription;
+import org.apache.directory.shared.ldap.schema.syntax.ObjectClassDescription;
 import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
 import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
 import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
 
 
+/**
+ * A subschema represents the schema information for an entry.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class Subschema implements Serializable
 {
 
@@ -40,7 +48,7 @@
 
     private Schema schema;
 
-    private Set allAttributeNameSet;
+    private Set<String> allAttributeNameSet;
 
 
     protected Subschema()
@@ -48,6 +56,11 @@
     }
 
 
+    /**
+     * Creates a new instance of Subschema.
+     * 
+     * @param entry the entry
+     */
     public Subschema( IEntry entry )
     {
         if ( entry.getAttribute( IAttribute.OBJECTCLASS_ATTRIBUTE ) != null )
@@ -62,6 +75,12 @@
     }
 
 
+    /**
+     * Creates a new instance of Subschema.
+     * 
+     * @param objectClassNames the object class names
+     * @param connection the connection
+     */
     public Subschema( String[] objectClassNames, IBrowserConnection connection )
     {
         this.objectClassNames = objectClassNames;
@@ -81,27 +100,25 @@
 
 
     /**
-     * Returns the must attribute names of this and all super object
-     * classes.
+     * Gets the must attribute names of this subschema.
      * 
-     * @return
+     * @return the must attribute names of this subschema
      */
     public String[] getMustAttributeNames()
     {
-        Set mustAttrSet = new TreeSet();
-        for ( int i = 0; i < this.objectClassNames.length; i++ )
+        Set<String> mustAttributeNames = new TreeSet<String>();
+        for ( String objectClassName : objectClassNames )
         {
-            this.fetchMust( this.objectClassNames[i], mustAttrSet );
+            fetchMust( objectClassName, mustAttributeNames );
         }
-        return ( String[] ) mustAttrSet.toArray( new String[0] );
+        return ( String[] ) mustAttributeNames.toArray( new String[0] );
     }
 
 
     /**
-     * Returns the must attribute types of this and all super object
-     * classes.
+     * Gets the must attribute types descriptions of this subschema.
      * 
-     * @return
+     * @return the must attribute types descriptions of this subschema
      */
     public AttributeTypeDescription[] getMustAttributeTypeDescriptions()
     {
@@ -116,43 +133,43 @@
     }
 
 
-    private void fetchMust( String ocName, Set attributeSet )
+    private void fetchMust( String ocName, Set<String> mustAttributeNames )
     {
         // add own must attributes
-        ObjectClassDescription ocd = this.getSchema().getObjectClassDescription( ocName );
-        attributeSet.addAll( Arrays.asList( ocd.getMustAttributeTypeDescriptionNames() ) );
+        ObjectClassDescription ocd = getSchema().getObjectClassDescription( ocName );
+        mustAttributeNames.addAll( ocd.getMustAttributeTypes() );
 
         // add must attributes of super object classes
-        if ( ocd.getSuperiorObjectClassDescriptionNames() != null )
+        if ( ocd.getSuperiorObjectClasses() != null )
         {
-            for ( int k = 0; k < ocd.getSuperiorObjectClassDescriptionNames().length; k++ )
+            for ( String superior : ocd.getSuperiorObjectClasses() )
             {
-                fetchMust( ocd.getSuperiorObjectClassDescriptionNames()[k], attributeSet );
+                fetchMust( superior, mustAttributeNames );
             }
         }
     }
 
 
     /**
-     * Returns the may attribute names of this and all super object classes.
+     * Gets the may attribute names of this subschema.
      * 
-     * @return
+     * @return the may attribute names of this subschema
      */
     public String[] getMayAttributeNames()
     {
-        Set mayAttrSet = new TreeSet();
-        for ( int i = 0; i < this.objectClassNames.length; i++ )
+        Set<String> mayAttrSet = new TreeSet<String>();
+        for ( String objectClassName : objectClassNames )
         {
-            this.fetchMay( this.objectClassNames[i], mayAttrSet );
+            fetchMay( objectClassName, mayAttrSet );
         }
         return ( String[] ) mayAttrSet.toArray( new String[0] );
     }
 
 
     /**
-     * Returns the may attribute types of this and all super object classes.
+     * Gets the may attribute types descriptions of this subschema.
      * 
-     * @return
+     * @return the may attribute types descriptions of this subschema
      */
     public AttributeTypeDescription[] getMayAttributeTypeDescriptions()
     {
@@ -167,28 +184,27 @@
     }
 
 
-    private void fetchMay( String ocName, Set attributeSet )
+    private void fetchMay( String ocName, Set<String> mustAttributeNames )
     {
         // add own may attributes
         ObjectClassDescription ocd = this.getSchema().getObjectClassDescription( ocName );
-        attributeSet.addAll( Arrays.asList( ocd.getMayAttributeTypeDescriptionNames() ) );
+        mustAttributeNames.addAll( ocd.getMayAttributeTypes() );
 
         // add may attributes of super object classes
-        if ( ocd.getSuperiorObjectClassDescriptionNames() != null )
+        if ( ocd.getSuperiorObjectClasses() != null )
         {
-            for ( int k = 0; k < ocd.getSuperiorObjectClassDescriptionNames().length; k++ )
+            for ( String superior : ocd.getSuperiorObjectClasses() )
             {
-                fetchMay( ocd.getSuperiorObjectClassDescriptionNames()[k], attributeSet );
+                fetchMust( superior, mustAttributeNames );
             }
         }
     }
 
 
     /**
-     * Returns the must and may attribute names of this and all super object
-     * classes.
+     * Gets the must and may attribute names of this subschema.
      * 
-     * @return
+     * @return the must and may attribute names of this subschema
      */
     public String[] getAllAttributeNames()
     {
@@ -196,24 +212,27 @@
     }
 
 
-    public Set getAllAttributeNameSet()
+    public Set<String> getAllAttributeNameSet()
     {
-        if ( this.allAttributeNameSet == null )
+        if ( allAttributeNameSet == null )
         {
-            this.allAttributeNameSet = new TreeSet();
-            this.allAttributeNameSet.addAll( Arrays.asList( this.getMustAttributeNames() ) );
-            this.allAttributeNameSet.addAll( Arrays.asList( this.getMayAttributeNames() ) );
+            allAttributeNameSet = new TreeSet<String>();
+            allAttributeNameSet.addAll( Arrays.asList( this.getMustAttributeNames() ) );
+            allAttributeNameSet.addAll( Arrays.asList( this.getMayAttributeNames() ) );
         }
 
-        return this.allAttributeNameSet;
+        return allAttributeNameSet;
     }
 
 
+    /**
+     * Gets the schema.
+     * 
+     * @return the schema
+     */
     private Schema getSchema()
     {
         return schema;
-        // return
-        // BrowserCorePlugin.getDefault().getConnectionManager().getConnection(this.connectionName).getSchema();
     }
 
 }

Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/Utils.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/Utils.java?rev=641069&r1=641068&r2=641069&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/Utils.java (original)
+++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/Utils.java Tue Mar 25 16:05:04 2008
@@ -101,7 +101,7 @@
 
     private static String getOidString( AttributeTypeAndValue atav, Schema schema )
     {
-        String oid = schema != null ? schema.getAttributeTypeDescription( atav.getNormType() ).getNumericOID() : atav
+        String oid = schema != null ? schema.getAttributeTypeDescription( atav.getNormType() ).getNumericOid() : atav
             .getNormType();
         return oid.trim().toLowerCase() + "=" + ( ( String ) atav.getUpValue() ).trim().toLowerCase(); //$NON-NLS-1$
     }