directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r1064712 - in /directory/studio/trunk/plugins/schemaeditor: ./ src/main/java/org/apache/directory/studio/schemaeditor/model/schemamanager/
Date Fri, 28 Jan 2011 14:57:19 GMT
Author: pamarcelot
Date: Fri Jan 28 14:57:19 2011
New Revision: 1064712

URL: http://svn.apache.org/viewvc?rev=1064712&view=rev
Log:
Added a template for a dedicated SchemaLoader.
Added a utility class for converting schema elements to entries for the SchemaLoader (AttributeType
is implemented, other objects need to be added).

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

Modified: directory/studio/trunk/plugins/schemaeditor/pom.xml
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/schemaeditor/pom.xml?rev=1064712&r1=1064711&r2=1064712&view=diff
==============================================================================
--- directory/studio/trunk/plugins/schemaeditor/pom.xml (original)
+++ directory/studio/trunk/plugins/schemaeditor/pom.xml Fri Jan 28 14:57:19 2011
@@ -117,7 +117,9 @@
                org.apache.commons.io;bundle-version="${org.apache.commons.io.version}",
                org.apache.directory.shared.asn1.api;bundle-version="${org.apache.directory.shared.validversion}",
                org.apache.directory.shared.ldap;bundle-version="${org.apache.directory.shared.validversion}",
+               org.apache.directory.shared.ldap.schema;bundle-version="${org.apache.directory.shared.validversion}",
                org.apache.directory.shared.ldap.schema.converter;bundle-version="${org.apache.directory.shared.validversion}",
+               org.apache.directory.shared.util;bundle-version="${org.apache.directory.shared.validversion}",
                org.apache.directory.studio.common.core,
                org.apache.directory.studio.common.ui,
                org.apache.directory.studio.connection.core,
@@ -166,10 +168,20 @@
     </dependency>
     <dependency>
       <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-schema</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
       <artifactId>shared-ldap-schema-converter</artifactId>
       <scope>provided</scope>
     </dependency>
     <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-util</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
       <groupId>org.apache.directory.studio</groupId>
       <artifactId>org.apache.commons.io</artifactId>
       <scope>provided</scope>

Added: directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemamanager/SchemaEditorSchemaLoader.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemamanager/SchemaEditorSchemaLoader.java?rev=1064712&view=auto
==============================================================================
--- directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemamanager/SchemaEditorSchemaLoader.java
(added)
+++ directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemamanager/SchemaEditorSchemaLoader.java
Fri Jan 28 14:57:19 2011
@@ -0,0 +1,178 @@
+/*
+ *  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.studio.schemaeditor.model.schemamanager;
+
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+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.registries.AbstractSchemaLoader;
+import org.apache.directory.shared.ldap.model.schema.registries.Schema;
+
+
+/**
+ * Loads schema data from schema files (OpenLDAP and XML formats).
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SchemaEditorSchemaLoader extends AbstractSchemaLoader
+{
+    /**
+     * Creates a new instance of SchemaEditorSchemaLoader.
+     *
+     * @throws Exception
+     */
+    public SchemaEditorSchemaLoader()
+    {
+        initializeSchemas();
+    }
+
+
+    /**
+     * Initialize schemas.
+     */
+    private void initializeSchemas()
+    {
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public List<Entry> loadComparators( Schema... schemas ) throws LdapException, IOException
+    {
+        List<Entry> comparatorList = new ArrayList<Entry>();
+
+        return comparatorList;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public List<Entry> loadSyntaxCheckers( Schema... schemas ) throws LdapException,
IOException
+    {
+        List<Entry> syntaxCheckerList = new ArrayList<Entry>();
+
+        return syntaxCheckerList;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public List<Entry> loadNormalizers( Schema... schemas ) throws LdapException, IOException
+    {
+        List<Entry> normalizerList = new ArrayList<Entry>();
+
+        return normalizerList;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public List<Entry> loadMatchingRules( Schema... schemas ) throws LdapException,
IOException
+    {
+        List<Entry> matchingRuleList = new ArrayList<Entry>();
+
+        return matchingRuleList;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public List<Entry> loadSyntaxes( Schema... schemas ) throws LdapException, IOException
+    {
+        List<Entry> syntaxList = new ArrayList<Entry>();
+
+        return syntaxList;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public List<Entry> loadAttributeTypes( Schema... schemas ) throws LdapException,
IOException
+    {
+        List<Entry> attributeTypeList = new ArrayList<Entry>();
+
+        return attributeTypeList;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public List<Entry> loadMatchingRuleUses( Schema... schemas ) throws LdapException,
IOException
+    {
+        List<Entry> matchingRuleUseList = new ArrayList<Entry>();
+
+        return matchingRuleUseList;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public List<Entry> loadNameForms( Schema... schemas ) throws LdapException, IOException
+    {
+        List<Entry> nameFormList = new ArrayList<Entry>();
+
+        return nameFormList;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public List<Entry> loadDitContentRules( Schema... schemas ) throws LdapException,
IOException
+    {
+        List<Entry> ditContentRuleList = new ArrayList<Entry>();
+
+        return ditContentRuleList;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public List<Entry> loadDitStructureRules( Schema... schemas ) throws LdapException,
IOException
+    {
+        List<Entry> ditStructureRuleList = new ArrayList<Entry>();
+
+        return ditStructureRuleList;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public List<Entry> loadObjectClasses( Schema... schemas ) throws LdapException,
IOException
+    {
+        List<Entry> objectClassList = new ArrayList<Entry>();
+
+        return objectClassList;
+    }
+}

Added: 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=1064712&view=auto
==============================================================================
--- directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemamanager/SchemaEditorSchemaLoaderUtils.java
(added)
+++ directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemamanager/SchemaEditorSchemaLoaderUtils.java
Fri Jan 28 14:57:19 2011
@@ -0,0 +1,455 @@
+/*
+ *  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.studio.schemaeditor.model.schemamanager;
+
+
+import java.util.List;
+
+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.DefaultEntryAttribute;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+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.name.Rdn;
+import org.apache.directory.shared.ldap.model.schema.AttributeType;
+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;
+
+
+/**
+ * This class is a helper class for the {@link SchemaEditorSchemaLoader} class.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SchemaEditorSchemaLoaderUtils
+{
+    private static final String M_COLLECTIVE = "m-collective";
+    private static final String M_DESCRIPTION = "m-description";
+    private static final String M_EQUALITY = "m-equality";
+    private static final String M_LENGTH = "m-length";
+    private static final String M_NAME = "m-name";
+    private static final String M_NO_USER_MODIFICATION = "m-noUserModification";
+    private static final String M_OBSOLETE = "m-obsolete";
+    private static final String M_OID = "m-oid";
+    private static final String M_ORDERING = "m-ordering";
+    private static final String M_SINGLE_VALUE = "m-singleValue";
+    private static final String M_SUBSTR = "m-substr";
+    private static final String M_SUP_ATTRIBUTE_TYPE = "m-supAttributeType";
+    private static final String M_SYNTAX = "m-syntax";
+    private static final String M_USAGE = "m-usage";
+    private static final String TRUE = "TRUE";
+
+
+    /**
+     * Converts the given attribute type to an equivalent entry representation.
+     *
+     * @param attributeType
+     *      the attribute type
+     * @return
+     *      the attribute type converted to an equivalent entry representation
+     * @throws LdapException
+     */
+    public Entry toEntry( AttributeType attributeType ) throws LdapException
+    {
+        // Creating a blank entry
+        Entry entry = new DefaultEntry();
+
+        // Setting calculated DN
+        entry.setDn( getDn( attributeType, SchemaConstants.ATTRIBUTES_TYPE_PATH ) );
+
+        // Values common to all schema objects
+        addSchemaObjectValues( attributeType, SchemaConstants.META_ATTRIBUTE_TYPE_OC, entry
);
+
+        // Superior value
+        addSuperiorValue( attributeType, entry );
+
+        // Equality matching rule value
+        addEqualityValue( attributeType, entry );
+
+        // Ordering matching rule value
+        addOrderingValue( attributeType, entry );
+
+        // Substrings matching rule value
+        addSubstrValue( attributeType, entry );
+
+        // Syntax value
+        addSyntaxValue( attributeType, entry );
+
+        // Single value value
+        addSingleValueValue( attributeType, entry );
+
+        // Collective value
+        addCollectiveValue( attributeType, entry );
+
+        // No user modification value
+        addNoUserModificationValue( attributeType, entry );
+
+        // Usage value
+        addUsageValue( attributeType, entry );
+
+        return entry;
+    }
+
+
+    /**
+     * Returns the DN for the given schema object in the given object path.
+     *
+     * @param schemaObject
+     *      the schema object
+     * @param objectPath
+     *      the object path
+     * @return
+     *      the DN for the given schema object in the given object path
+     * @throws LdapInvalidDnException
+     */
+    private Dn getDn( SchemaObject schemaObject, String objectPath ) throws LdapInvalidDnException
+    {
+        return Dn.EMPTY_DN
+            .add( new Rdn( M_OID, schemaObject.getOid() ) )
+            .add( new Rdn( objectPath ) )
+            .add( new Rdn( SchemaConstants.CN_AT, schemaObject.getSchemaName() ) )
+            .add( new Rdn( SchemaConstants.OU_SCHEMA ) );
+    }
+
+
+    /**
+     * Adds the values common to all {@link SchemaObject}(s) to the entry.
+     *
+     * @param schemaObject
+     *      the schema object
+     * @param objectClassValue
+     *      the value for the objectClass attribute
+     * @param entry
+     *      the entry
+     * @throws LdapException
+     */
+    private void addSchemaObjectValues( SchemaObject schemaObject, String objectClassValue,
Entry entry )
+        throws LdapException
+    {
+        // ObjectClass
+        addObjectClassValue( schemaObject, objectClassValue, entry );
+
+        // OID
+        addOidValue( schemaObject, entry );
+
+        // Names
+        addNamesValue( schemaObject, entry );
+
+        // Description
+        addDescriptionValue( schemaObject, entry );
+
+        // Obsolete (only if true)
+        addObsoleteValue( schemaObject, entry );
+    }
+
+
+    /**
+     * Adds the objectClass value to the entry.
+     *
+     * @param schemaObject
+     *      the schema object
+     * @param objectClassValue
+     *      the value for the objectClass attribute
+     * @param entry
+     *      the entry
+     * @throws LdapException
+     */
+    private void addObjectClassValue( SchemaObject schemaObject, String objectClassValue,
Entry entry )
+        throws LdapException
+    {
+        EntryAttribute objectClassAttribute = new DefaultEntryAttribute( SchemaConstants.OBJECT_CLASS_AT
);
+        entry.add( objectClassAttribute );
+        objectClassAttribute.add( SchemaConstants.TOP_OC );
+        objectClassAttribute.add( SchemaConstants.META_TOP_OC );
+        objectClassAttribute.add( objectClassValue );
+    }
+
+
+    /**
+     * Adds the OID value to the entry.
+     *
+     * @param schemaObject
+     *      the schema object
+     * @param entry
+     *      the entry
+     * @throws LdapException
+     */
+    private void addOidValue( SchemaObject schemaObject, Entry entry ) throws LdapException
+    {
+        String oid = schemaObject.getOid();
+        if ( !Strings.isEmpty( oid ) )
+        {
+            EntryAttribute attribute = new DefaultEntryAttribute( M_OID, oid );
+            entry.add( attribute );
+        }
+    }
+
+
+    /**
+     * Adds the names value to the entry.
+     *
+     * @param schemaObject
+     *      the schema object
+     * @param entry
+     *      the entry
+     * @throws LdapException
+     */
+    private void addNamesValue( SchemaObject schemaObject, Entry entry ) throws LdapException
+    {
+        List<String> names = schemaObject.getNames();
+        if ( ( names != null ) && ( names.size() > 0 ) )
+        {
+            EntryAttribute attribute = new DefaultEntryAttribute( M_NAME );
+            entry.add( attribute );
+
+            for ( String name : names )
+            {
+                attribute.add( name );
+            }
+        }
+    }
+
+
+    /**
+     * Adds the description value to the entry.
+     *
+     * @param schemaObject
+     *      the schema object
+     * @param entry
+     *      the entry
+     * @throws LdapException
+     */
+    private void addDescriptionValue( SchemaObject schemaObject, Entry entry ) throws LdapException
+    {
+        String description = schemaObject.getDescription();
+        if ( !Strings.isEmpty( description ) )
+        {
+            EntryAttribute attribute = new DefaultEntryAttribute( M_DESCRIPTION, description
);
+            entry.add( attribute );
+        }
+    }
+
+
+    /**
+     * Adds the obsolete value to the entry.
+     *
+     * @param schemaObject
+     *      the schema object
+     * @param entry
+     *      the entry
+     * @throws LdapException
+     */
+    private void addObsoleteValue( SchemaObject schemaObject, Entry entry ) throws LdapException
+    {
+        if ( schemaObject.isObsolete() )
+        {
+            EntryAttribute attribute = new DefaultEntryAttribute( M_OBSOLETE, TRUE );
+            entry.add( attribute );
+        }
+    }
+
+
+    /**
+     * Adds the superior value.
+     *
+     * @param attributeType
+     *      the attribute type
+     * @param entry
+     *      the entry
+     * @throws LdapException
+     */
+    private void addSuperiorValue( AttributeType attributeType, Entry entry ) throws LdapException
+    {
+        String superior = attributeType.getSuperiorName();
+        if ( !Strings.isEmpty( superior ) )
+        {
+            EntryAttribute attribute = new DefaultEntryAttribute( M_SUP_ATTRIBUTE_TYPE, superior
);
+            entry.add( attribute );
+        }
+    }
+
+
+    /**
+     * Adds the equality matching rule value.
+     *
+     * @param attributeType
+     *      the attribute type
+     * @param entry
+     *      the entry
+     * @throws LdapException
+     */
+    private void addEqualityValue( AttributeType attributeType, Entry entry ) throws LdapException
+    {
+        String equality = attributeType.getEqualityName();
+        if ( !Strings.isEmpty( equality ) )
+        {
+            EntryAttribute attribute = new DefaultEntryAttribute( M_EQUALITY, equality );
+            entry.add( attribute );
+        }
+    }
+
+
+    /**
+     * Adds the ordering matching rule value.
+     *
+     * @param attributeType
+     *      the attribute type
+     * @param entry
+     *      the entry
+     * @throws LdapException
+     */
+    private void addOrderingValue( AttributeType attributeType, Entry entry ) throws LdapException
+    {
+        String ordering = attributeType.getOrderingName();
+        if ( !Strings.isEmpty( ordering ) )
+        {
+            EntryAttribute attribute = new DefaultEntryAttribute( M_ORDERING, ordering );
+            entry.add( attribute );
+        }
+    }
+
+
+    /**
+     * Adds the substring matching rule value.
+     *
+     * @param attributeType
+     *      the attribute type
+     * @param entry
+     *      the entry
+     * @throws LdapException
+     */
+    private void addSubstrValue( AttributeType attributeType, Entry entry ) throws LdapException
+    {
+        String substr = attributeType.getSubstringName();
+        if ( !Strings.isEmpty( substr ) )
+        {
+            EntryAttribute attribute = new DefaultEntryAttribute( M_SUBSTR, substr );
+            entry.add( attribute );
+        }
+    }
+
+
+    /**
+     * Adds the syntax value.
+     *
+     * @param attributeType
+     *      the attribute type
+     * @param entry
+     *      the entry
+     * @throws LdapException
+     */
+    private void addSyntaxValue( AttributeType attributeType, Entry entry ) throws LdapException
+    {
+        String syntax = attributeType.getSyntaxName();
+        if ( !Strings.isEmpty( syntax ) )
+        {
+            EntryAttribute attribute = new DefaultEntryAttribute( M_SYNTAX, syntax );
+            entry.add( attribute );
+
+            long syntaxLength = attributeType.getSyntaxLength();
+            if ( syntaxLength != -1 )
+            {
+                attribute = new DefaultEntryAttribute( M_LENGTH, "" + syntaxLength );
+                entry.add( attribute );
+            }
+        }
+    }
+
+
+    /**
+     * Adds the single value value.
+     *
+     * @param attributeType
+     *      the attribute type
+     * @param entry
+     *      the entry
+     * @throws LdapException
+     */
+    private void addSingleValueValue( AttributeType attributeType, Entry entry ) throws LdapException
+    {
+        if ( attributeType.isSingleValued() )
+        {
+            EntryAttribute attribute = new DefaultEntryAttribute( M_SINGLE_VALUE, TRUE );
+            entry.add( attribute );
+        }
+    }
+
+
+    /**
+     * Adds the collective value.
+     *
+     * @param attributeType
+     *      the attribute type
+     * @param entry
+     *      the entry
+     * @throws LdapException
+     */
+    private void addCollectiveValue( AttributeType attributeType, Entry entry ) throws LdapException
+    {
+        if ( attributeType.isCollective() )
+        {
+            EntryAttribute attribute = new DefaultEntryAttribute( M_COLLECTIVE, TRUE );
+            entry.add( attribute );
+        }
+    }
+
+
+    /**
+     * Adds the no user modification value.
+     *
+     * @param attributeType
+     *      the attribute type
+     * @param entry
+     *      the entry
+     * @throws LdapException
+     */
+    private void addNoUserModificationValue( AttributeType attributeType, Entry entry ) throws
LdapException
+    {
+        if ( !attributeType.isUserModifiable() )
+        {
+            EntryAttribute attribute = new DefaultEntryAttribute( M_NO_USER_MODIFICATION,
TRUE );
+            entry.add( attribute );
+        }
+    }
+
+
+    /**
+     * Adds the usage value.
+     *
+     * @param attributeType
+     *      the attribute type
+     * @param entry
+     *      the entry
+     * @throws LdapException
+     */
+    private void addUsageValue( AttributeType attributeType, Entry entry ) throws LdapException
+    {
+        UsageEnum usage = attributeType.getUsage();
+        if ( usage != UsageEnum.USER_APPLICATIONS )
+        {
+            EntryAttribute attribute = new DefaultEntryAttribute( M_USAGE, usage.render()
);
+            entry.add( attribute );
+        }
+    }
+}



Mime
View raw message