directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r1064745 - /directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemamanager/SchemaEditorSchemaLoaderUtils.java
Date Fri, 28 Jan 2011 15:52:17 GMT
Author: pamarcelot
Date: Fri Jan 28 15:52:17 2011
New Revision: 1064745

URL: http://svn.apache.org/viewvc?rev=1064745&view=rev
Log:
Added conversion code for ObjectClass.

Modified:
    directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemamanager/SchemaEditorSchemaLoaderUtils.java

Modified: directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemamanager/SchemaEditorSchemaLoaderUtils.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemamanager/SchemaEditorSchemaLoaderUtils.java?rev=1064745&r1=1064744&r2=1064745&view=diff
==============================================================================
--- directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemamanager/SchemaEditorSchemaLoaderUtils.java
(original)
+++ directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemamanager/SchemaEditorSchemaLoaderUtils.java
Fri Jan 28 15:52:17 2011
@@ -32,6 +32,8 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.name.Dn;
 import org.apache.directory.shared.ldap.model.name.Rdn;
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
+import org.apache.directory.shared.ldap.model.schema.ObjectClass;
+import org.apache.directory.shared.ldap.model.schema.ObjectClassTypeEnum;
 import org.apache.directory.shared.ldap.model.schema.SchemaObject;
 import org.apache.directory.shared.ldap.model.schema.UsageEnum;
 import org.apache.directory.shared.util.Strings;
@@ -113,6 +115,42 @@ public class SchemaEditorSchemaLoaderUti
 
 
     /**
+     * Converts the given object class to an equivalent entry representation.
+     *
+     * @param objectClass
+     *      the object class
+     * @return
+     *      the object class converted to an equivalent entry representation
+     * @throws LdapException
+     */
+    public Entry toEntry( ObjectClass objectClass ) throws LdapException
+    {
+        // Creating a blank entry
+        Entry entry = new DefaultEntry();
+
+        // Setting calculated DN
+        entry.setDn( getDn( objectClass, SchemaConstants.OBJECT_CLASSES_PATH ) );
+
+        // Values common to all schema objects
+        addSchemaObjectValues( objectClass, SchemaConstants.META_OBJECT_CLASS_OC, entry );
+
+        // Superiors value
+        addSuperiorsValue( objectClass, entry );
+
+        // Class type value
+        addClassTypeValue( objectClass, entry );
+
+        // Musts value
+        addMustsValue( objectClass, entry );
+
+        // Mays value
+        addMaysValue( objectClass, entry );
+
+        return entry;
+    }
+
+
+    /**
      * Returns the DN for the given schema object in the given object path.
      *
      * @param schemaObject
@@ -159,7 +197,7 @@ public class SchemaEditorSchemaLoaderUti
         // Description
         addDescriptionValue( schemaObject, entry );
 
-        // Obsolete (only if true)
+        // Obsolete
         addObsoleteValue( schemaObject, entry );
     }
 
@@ -452,4 +490,99 @@ public class SchemaEditorSchemaLoaderUti
             entry.add( attribute );
         }
     }
+
+
+    /**
+     * Adds the superiors value.
+     *
+     * @param objectClass
+     *      the object class
+     * @param entry
+     *      the entry
+     * @throws LdapException
+     */
+    private void addSuperiorsValue( ObjectClass objectClass, Entry entry ) throws LdapException
+    {
+        List<String> superiors = objectClass.getSuperiorOids();
+        if ( ( superiors != null ) && ( superiors.size() > 0 ) )
+        {
+            EntryAttribute attribute = new DefaultEntryAttribute( "m-supObjectClass" );
+            entry.add( attribute );
+
+            for ( String superior : superiors )
+            {
+                attribute.add( superior );
+            }
+        }
+    }
+
+
+    /**
+     * Adds class type value.
+     *
+     * @param objectClass
+     *      the object class
+     * @param entry
+     *      the entry
+     * @throws LdapException
+     */
+    private void addClassTypeValue( ObjectClass objectClass, Entry entry ) throws LdapException
+    {
+        ObjectClassTypeEnum classType = objectClass.getType();
+        if ( classType != ObjectClassTypeEnum.STRUCTURAL )
+        {
+            EntryAttribute attribute = new DefaultEntryAttribute( "m-typeObjectClass", classType.toString()
);
+            entry.add( attribute );
+        }
+    }
+
+
+    /**
+     * Adds musts value.
+     *
+     * @param objectClass
+     *      the object class
+     * @param entry
+     *      the entry
+     * @throws LdapException
+     */
+    private void addMustsValue( ObjectClass objectClass, Entry entry ) throws LdapException
+    {
+        List<String> musts = objectClass.getMustAttributeTypeOids();
+        if ( ( musts != null ) && ( musts.size() > 0 ) )
+        {
+            EntryAttribute attribute = new DefaultEntryAttribute( "m-must" );
+            entry.add( attribute );
+
+            for ( String must : musts )
+            {
+                attribute.add( must );
+            }
+        }
+    }
+
+
+    /**
+     * Adds mays value.
+     *
+     * @param objectClass
+     *      the object class
+     * @param entry
+     *      the entry
+     * @throws LdapException
+     */
+    private void addMaysValue( ObjectClass objectClass, Entry entry ) throws LdapException
+    {
+        List<String> mays = objectClass.getMayAttributeTypeOids();
+        if ( ( mays != null ) && ( mays.size() > 0 ) )
+        {
+            EntryAttribute attribute = new DefaultEntryAttribute( "m-may" );
+            entry.add( attribute );
+
+            for ( String may : mays )
+            {
+                attribute.add( may );
+            }
+        }
+    }
 }



Mime
View raw message