directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1240482 - in /directory: apacheds/trunk/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/ shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/ shared/trunk/ldap/client/api/src/main/java/...
Date Sat, 04 Feb 2012 10:29:08 GMT
Author: elecharny
Date: Sat Feb  4 10:29:07 2012
New Revision: 1240482

URL: http://svn.apache.org/viewvc?rev=1240482&view=rev
Log:
o Moved the AttributesFactory from server to shared, as it will be used by the SSSE loader
too.
o Some stupid modifications done by the formatter while I was looking for some files... (I
thought I have formatted all the files 2 weeks ago, but the formatter seems a bit dumb...)

Added:
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/AttributesFactory.java
Removed:
    directory/apacheds/trunk/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/AttributesFactory.java
Modified:
    directory/apacheds/trunk/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryModifier.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/CramMd5Request.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/Krb5LoginConfiguration.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/NetworkSchemaLoader.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslRequest.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/exception/InvalidConnectionException.java

Modified: directory/apacheds/trunk/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryModifier.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryModifier.java?rev=1240482&r1=1240481&r2=1240482&view=diff
==============================================================================
--- directory/apacheds/trunk/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryModifier.java
(original)
+++ directory/apacheds/trunk/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryModifier.java
Sat Feb  4 10:29:07 2012
@@ -33,6 +33,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
 import org.apache.directory.shared.ldap.model.name.Dn;
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
+import org.apache.directory.shared.ldap.model.schema.AttributesFactory;
 import org.apache.directory.shared.ldap.model.schema.DITContentRule;
 import org.apache.directory.shared.ldap.model.schema.DITStructureRule;
 import org.apache.directory.shared.ldap.model.schema.LdapSyntax;

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/CramMd5Request.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/CramMd5Request.java?rev=1240482&r1=1240481&r2=1240482&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/CramMd5Request.java
(original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/CramMd5Request.java
Sat Feb  4 10:29:07 2012
@@ -26,7 +26,7 @@ import org.apache.directory.shared.ldap.
 
 /**
  * Holds the data required to complete the CRAM-MD5 SASL operation
- *  
+ * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 public class CramMd5Request extends SaslRequest

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/Krb5LoginConfiguration.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/Krb5LoginConfiguration.java?rev=1240482&r1=1240481&r2=1240482&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/Krb5LoginConfiguration.java
(original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/Krb5LoginConfiguration.java
Sat Feb  4 10:29:07 2012
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ * 
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ * 
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.ldap.client.api;
 

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java?rev=1240482&r1=1240481&r2=1240482&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
(original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
Sat Feb  4 10:29:07 2012
@@ -3347,6 +3347,7 @@ public class LdapNetworkConnection exten
 
             // we enable all the schemas so that need not check with server for enabled schemas
             Collection<Schema> schemas = jarSchemaLoader.getAllSchemas();
+            
             for ( Schema s : schemas )
             {
                 s.enable();

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/NetworkSchemaLoader.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/NetworkSchemaLoader.java?rev=1240482&r1=1240481&r2=1240482&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/NetworkSchemaLoader.java
(original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/NetworkSchemaLoader.java
Sat Feb  4 10:29:07 2012
@@ -37,7 +37,7 @@ import org.slf4j.LoggerFactory;
 
 
 /**
- * A schema loader which uses LdapConnection to load schema.
+ * A schema loader which uses LdapConnection to load schema from a ApacheDS serveur
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
@@ -80,6 +80,7 @@ public class NetworkSchemaLoader extends
         List<Entry> schemaEntries = searchSchemaObjects( SCHEMA_BASE, "(objectClass=metaSchema)"
);
 
         LOG.debug( "initializing schemas {}", schemaEntries );
+        
         for ( Entry entry : schemaEntries )
         {
             Schema schema = getSchema( entry );
@@ -94,7 +95,7 @@ public class NetworkSchemaLoader extends
      * @param baseDn the Dn of the schema entry under which the schema objects are present
      *               e.x ou=attributeTypes,cn=apache,ou=schema
      * @param filter optional search filter, if null the default fileter {@link #FILTER}
is used
-     * @return a list of entries of the schema objects 
+     * @return a list of entries of the schema objects
      * @throws LdapException
      */
     private List<Entry> searchSchemaObjects( String baseDn, String filter ) throws
LdapException

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslRequest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslRequest.java?rev=1240482&r1=1240481&r2=1240482&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslRequest.java
(original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslRequest.java
Sat Feb  4 10:29:07 2012
@@ -34,7 +34,7 @@ import org.apache.directory.shared.util.
 
 /**
  * Holds the data required to complete the SASL operation
- *  
+ * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 public abstract class SaslRequest

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/exception/InvalidConnectionException.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/exception/InvalidConnectionException.java?rev=1240482&r1=1240481&r2=1240482&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/exception/InvalidConnectionException.java
(original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/exception/InvalidConnectionException.java
Sat Feb  4 10:29:07 2012
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ * 
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ * 
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.ldap.client.api.exception;
 

Added: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/AttributesFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/AttributesFactory.java?rev=1240482&view=auto
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/AttributesFactory.java
(added)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/AttributesFactory.java
Sat Feb  4 10:29:07 2012
@@ -0,0 +1,434 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ * 
+ */
+package org.apache.directory.shared.ldap.model.schema;
+
+
+import java.util.List;
+
+import org.apache.directory.shared.ldap.model.constants.MetaSchemaConstants;
+import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.model.entry.DefaultAttribute;
+import org.apache.directory.shared.ldap.model.entry.Attribute;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.schema.AttributeType;
+import org.apache.directory.shared.ldap.model.schema.DITContentRule;
+import org.apache.directory.shared.ldap.model.schema.DITStructureRule;
+import org.apache.directory.shared.ldap.model.schema.LdapComparator;
+import org.apache.directory.shared.ldap.model.schema.LdapSyntax;
+import org.apache.directory.shared.ldap.model.schema.MatchingRule;
+import org.apache.directory.shared.ldap.model.schema.MatchingRuleUse;
+import org.apache.directory.shared.ldap.model.schema.NameForm;
+import org.apache.directory.shared.ldap.model.schema.Normalizer;
+import org.apache.directory.shared.ldap.model.schema.ObjectClass;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+import org.apache.directory.shared.ldap.model.schema.SchemaObject;
+import org.apache.directory.shared.ldap.model.schema.SyntaxChecker;
+import org.apache.directory.shared.ldap.model.schema.registries.Schema;
+import org.apache.directory.shared.util.DateUtils;
+
+
+/**
+ * A factory that generates an entry using the meta schema for schema
+ * elements.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AttributesFactory
+{
+    public Entry getAttributes( SchemaObject obj, Schema schema, SchemaManager schemaManager
) throws LdapException
+    {
+        if ( obj instanceof LdapSyntax )
+        {
+            return getAttributes( obj, schema, schemaManager );
+        }
+        else if ( obj instanceof MatchingRule )
+        {
+            return getAttributes( obj, schema, schemaManager );
+        }
+        else if ( obj instanceof AttributeType )
+        {
+            return getAttributes( obj, schema, schemaManager );
+        }
+        else if ( obj instanceof ObjectClass )
+        {
+            return getAttributes( obj, schema, schemaManager );
+        }
+        else if ( obj instanceof MatchingRuleUse )
+        {
+            return getAttributes( obj, schema, schemaManager );
+        }
+        else if ( obj instanceof DITStructureRule )
+        {
+            return getAttributes( obj, schema, schemaManager );
+        }
+        else if ( obj instanceof DITContentRule )
+        {
+            return getAttributes( obj, schema, schemaManager );
+        }
+        else if ( obj instanceof NameForm )
+        {
+            return getAttributes( obj, schema, schemaManager );
+        }
+
+        throw new IllegalArgumentException( "nknown SchemaObject type: " + obj.getClass()
);
+    }
+
+
+    /**
+     * Convert a Schema to Entry
+     * 
+     * @param schema The Schema to convert
+     * @param schemaManager The SchemaManager
+     * @return An Entry containing the converted Schema
+     * @throws LdapException If the conversion failed
+     */
+    public Entry convert( Schema schema, SchemaManager schemaManager ) throws LdapException
+    {
+        Entry entry = new DefaultEntry( schemaManager );
+
+        entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_SCHEMA_OC
);
+        entry.put( SchemaConstants.CN_AT, schema.getSchemaName() );
+        entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
+        entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+
+        if ( schema.isDisabled() )
+        {
+            entry.put( MetaSchemaConstants.M_DISABLED_AT, "TRUE" );
+        }
+
+        String[] dependencies = schema.getDependencies();
+
+        if ( dependencies != null && dependencies.length > 0 )
+        {
+            Attribute attr = new DefaultAttribute(
+                schemaManager.getAttributeType( MetaSchemaConstants.M_DEPENDENCIES_AT ) );
+
+            for ( String dependency : dependencies )
+            {
+                attr.add( dependency );
+            }
+
+            entry.put( attr );
+        }
+
+        return entry;
+    }
+
+
+    public Entry convert( SyntaxChecker syntaxChecker, Schema schema, SchemaManager schemaManager
)
+    {
+        Entry entry = new DefaultEntry( schemaManager );
+
+        entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_SYNTAX_CHECKER_OC
);
+        entry.put( MetaSchemaConstants.M_OID_AT, syntaxChecker.getOid() );
+        entry.put( MetaSchemaConstants.M_FQCN_AT, syntaxChecker.getClass().getName() );
+        entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
+        entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+
+        return entry;
+    }
+
+
+    public Entry convert( LdapSyntax syntax, Schema schema, SchemaManager schemaManager )
throws LdapException
+    {
+        Entry entry = new DefaultEntry( schemaManager );
+
+        entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_SYNTAX_OC
);
+        entry.put( MetaSchemaConstants.X_HUMAN_READABLE_AT, getBoolean( syntax.isHumanReadable()
) );
+        entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
+        entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+        injectCommon( syntax, entry, schemaManager );
+
+        return entry;
+    }
+
+
+    public Entry convert( String oid, Normalizer normalizer, Schema schema, SchemaManager
schemaManager )
+    {
+        Entry entry = new DefaultEntry( schemaManager );
+
+        entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_NORMALIZER_OC
);
+        entry.put( MetaSchemaConstants.M_OID_AT, oid );
+        entry.put( MetaSchemaConstants.M_FQCN_AT, normalizer.getClass().getName() );
+        entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
+        entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+        return entry;
+    }
+
+
+    public Entry convert( String oid, LdapComparator<? super Object> comparator, Schema
schema,
+        SchemaManager schemaManager )
+    {
+        Entry entry = new DefaultEntry( schemaManager );
+
+        entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_COMPARATOR_OC
);
+        entry.put( MetaSchemaConstants.M_OID_AT, oid );
+        entry.put( MetaSchemaConstants.M_FQCN_AT, comparator.getClass().getName() );
+        entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
+        entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+        return entry;
+    }
+
+
+    /**
+     * 
+     * @param matchingRule
+     * @return Attributes
+     * @throws LdapException
+     */
+    public Entry convert( MatchingRule matchingRule, Schema schema, SchemaManager schemaManager
)
+        throws LdapException
+    {
+        Entry entry = new DefaultEntry( schemaManager );
+
+        entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_MATCHING_RULE_OC
);
+        entry.put( MetaSchemaConstants.M_SYNTAX_AT, matchingRule.getSyntaxOid() );
+        entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
+        entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+        injectCommon( matchingRule, entry, schemaManager );
+        return entry;
+    }
+
+
+    public Entry convert( MatchingRuleUse matchingRuleUse, Schema schema, SchemaManager schemaManager
)
+    {
+        Entry entry = new DefaultEntry( schemaManager );
+
+        entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, "" );
+        entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
+        entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+        return entry;
+    }
+
+
+    public Entry convert( DITStructureRule dITStructureRule, Schema schema, SchemaManager
schemaManager )
+    {
+        Entry entry = new DefaultEntry( schemaManager );
+
+        entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, "" );
+        entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
+        entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+        return entry;
+    }
+
+
+    public Entry convert( DITContentRule dITContentRule, Schema schema, SchemaManager schemaManager
)
+    {
+        Entry entry = new DefaultEntry( schemaManager );
+
+        entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, "" );
+        entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
+        entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+        return entry;
+    }
+
+
+    public Entry convert( NameForm nameForm, Schema schema, SchemaManager schemaManager )
+    {
+        Entry entry = new DefaultEntry( schemaManager );
+
+        entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, "" );
+        entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
+        entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+        return entry;
+    }
+
+
+    /**
+     * <pre>
+     *    objectclass ( 1.3.6.1.4.1.18060.0.4.0.3.3
+     *       NAME 'metaAttributeType'
+     *       DESC 'meta definition of the AttributeType object'
+     *       SUP metaTop
+     *       STRUCTURAL
+     *       MUST ( m-name $ m-syntax )
+     *       MAY ( m-supAttributeType $ m-obsolete $ m-equality $ m-ordering $
+     *             m-substr $ m-singleValue $ m-collective $ m-noUserModification $
+     *             m-usage $ m-extensionAttributeType )
+     *    )
+     * </pre>
+     * 
+     * @param attributeType
+     * @return Attributes
+     * @throws LdapException
+     */
+    public Entry convert( AttributeType attributeType, Schema schema, SchemaManager schemaManager
)
+        throws LdapException
+    {
+        Entry entry = new DefaultEntry( schemaManager );
+
+        entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_ATTRIBUTE_TYPE_OC
);
+        entry.put( MetaSchemaConstants.M_SYNTAX_AT, attributeType.getSyntaxOid() );
+        entry.put( MetaSchemaConstants.M_COLLECTIVE_AT, getBoolean( attributeType.isCollective()
) );
+        entry.put( MetaSchemaConstants.M_NO_USER_MODIFICATION_AT, getBoolean( !attributeType.isUserModifiable()
) );
+        entry.put( MetaSchemaConstants.M_SINGLE_VALUE_AT, getBoolean( attributeType.isSingleValued()
) );
+        entry.put( MetaSchemaConstants.M_USAGE_AT, attributeType.getUsage().toString() );
+        entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
+        entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+
+        injectCommon( attributeType, entry, schemaManager );
+
+        String superiorOid = attributeType.getSuperiorOid();
+
+        if ( superiorOid != null )
+        {
+            entry.put( MetaSchemaConstants.M_SUP_ATTRIBUTE_TYPE_AT, superiorOid );
+        }
+
+        if ( attributeType.getEqualityOid() != null )
+        {
+            entry.put( MetaSchemaConstants.M_EQUALITY_AT, attributeType.getEqualityOid()
);
+        }
+
+        if ( attributeType.getSubstringOid() != null )
+        {
+            entry.put( MetaSchemaConstants.M_SUBSTR_AT, attributeType.getSubstringOid() );
+        }
+
+        if ( attributeType.getOrderingOid() != null )
+        {
+            entry.put( MetaSchemaConstants.M_ORDERING_AT, attributeType.getOrderingOid()
);
+        }
+
+        return entry;
+    }
+
+
+    /**
+     * Creates the attributes of an entry representing an objectClass.
+     * 
+     * <pre>
+     *  objectclass ( 1.3.6.1.4.1.18060.0.4.0.3.2
+     *      NAME 'metaObjectClass'
+     *      DESC 'meta definition of the objectclass object'
+     *      SUP metaTop
+     *      STRUCTURAL
+     *      MUST m-oid
+     *      MAY ( m-name $ m-obsolete $ m-supObjectClass $ m-typeObjectClass $ m-must $
+     *            m-may $ m-extensionObjectClass )
+     *  )
+     * </pre>
+     * 
+     * @param objectClass the objectClass to produce a meta schema entry for
+     * @return the attributes of the metaSchema entry representing the objectClass
+     * @throws LdapException if there are any problems
+     */
+    public Entry convert( ObjectClass objectClass, Schema schema, SchemaManager schemaManager
)
+        throws LdapException
+    {
+        Entry entry = new DefaultEntry( schemaManager );
+
+        entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_OBJECT_CLASS_OC
);
+        entry.put( MetaSchemaConstants.M_TYPE_OBJECT_CLASS_AT, objectClass.getType().toString()
);
+        entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
+        entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+
+        injectCommon( objectClass, entry, schemaManager );
+
+        // handle the superior objectClasses
+        if ( objectClass.getSuperiorOids() != null && objectClass.getSuperiorOids().size()
!= 0 )
+        {
+            Attribute attr = new DefaultAttribute(
+                schemaManager.getAttributeType( MetaSchemaConstants.M_SUP_OBJECT_CLASS_AT
) );
+
+            for ( String superior : objectClass.getSuperiorOids() )
+            {
+                attr.add( superior );
+            }
+
+            entry.put( attr );
+        }
+
+        // add the must list
+        if ( objectClass.getMustAttributeTypeOids() != null && objectClass.getMustAttributeTypeOids().size()
!= 0 )
+        {
+            Attribute attr = new DefaultAttribute( schemaManager.getAttributeType( MetaSchemaConstants.M_MUST_AT
) );
+
+            for ( String mustOid : objectClass.getMustAttributeTypeOids() )
+            {
+                attr.add( mustOid );
+            }
+
+            entry.put( attr );
+        }
+
+        // add the may list
+        if ( objectClass.getMayAttributeTypeOids() != null && objectClass.getMayAttributeTypeOids().size()
!= 0 )
+        {
+            Attribute attr = new DefaultAttribute( schemaManager.getAttributeType( MetaSchemaConstants.M_MAY_AT
) );
+
+            for ( String mayOid : objectClass.getMayAttributeTypeOids() )
+            {
+                attr.add( mayOid );
+            }
+
+            entry.put( attr );
+        }
+
+        return entry;
+    }
+
+
+    private final void injectCommon( SchemaObject object, Entry entry, SchemaManager schemaManager
)
+        throws LdapException
+    {
+        injectNames( object.getNames(), entry, schemaManager );
+        entry.put( MetaSchemaConstants.M_OBSOLETE_AT, getBoolean( object.isObsolete() ) );
+        entry.put( MetaSchemaConstants.M_OID_AT, object.getOid() );
+
+        if ( object.getDescription() != null )
+        {
+            entry.put( MetaSchemaConstants.M_DESCRIPTION_AT, object.getDescription() );
+        }
+    }
+
+
+    private final void injectNames( List<String> names, Entry entry, SchemaManager
schemaManager ) throws LdapException
+    {
+        if ( ( names == null ) || ( names.size() == 0 ) )
+        {
+            return;
+        }
+
+        Attribute attr = new DefaultAttribute( schemaManager.getAttributeType( MetaSchemaConstants.M_NAME_AT
) );
+
+        for ( String name : names )
+        {
+            attr.add( name );
+        }
+
+        entry.put( attr );
+    }
+
+
+    private final String getBoolean( boolean value )
+    {
+        if ( value )
+        {
+            return "TRUE";
+        }
+        else
+        {
+            return "FALSE";
+        }
+    }
+}



Mime
View raw message