directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r570782 - in /directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor: model/ model/io/ view/wizards/
Date Wed, 29 Aug 2007 12:32:45 GMT
Author: pamarcelot
Date: Wed Aug 29 05:32:43 2007
New Revision: 570782

URL: http://svn.apache.org/viewvc?rev=570782&view=rev
Log:
Renamed OnlineSchemaImporter class.
Added ApacheDSSchemaExporter class that commit the new schema to the server.
Updated the Commit Changes Wizard to use the ApacheDSSchemaExporter.

Added:
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ApacheDSSchemaExporter.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ApacheDSSchemaImporter.java
      - copied, changed from r570699, directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/OnlineSchemaImporter.java
Removed:
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/OnlineSchemaImporter.java
Modified:
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/DependenciesComputer.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/Project.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/CommitChangesWizard.java

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/DependenciesComputer.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/DependenciesComputer.java?rev=570782&r1=570781&r2=570782&view=diff
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/DependenciesComputer.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/DependenciesComputer.java
Wed Aug 29 05:32:43 2007
@@ -384,7 +384,7 @@
      *      the dependencies of the schema
      */
     @SuppressWarnings("unchecked")
-    private List<Schema> getDependencies( Schema schema )
+    public List<Schema> getDependencies( Schema schema )
     {
         List<Schema> dependencies = ( List<Schema> ) schemasDependencies.get(
schema );
 

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/Project.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/Project.java?rev=570782&r1=570781&r2=570782&view=diff
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/Project.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/Project.java
Wed Aug 29 05:32:43 2007
@@ -25,7 +25,7 @@
 import javax.naming.NamingException;
 
 import org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandler;
-import org.apache.directory.studio.apacheds.schemaeditor.model.io.OnlineSchemaImporter;
+import org.apache.directory.studio.apacheds.schemaeditor.model.io.ApacheDSSchemaImporter;
 import org.apache.directory.studio.apacheds.schemaeditor.model.schemachecker.SchemaChecker;
 import org.apache.directory.studio.connection.core.Connection;
 import org.apache.directory.studio.connection.core.StudioProgressMonitor;
@@ -256,7 +256,7 @@
         {
             try
             {
-                schemaBackup = OnlineSchemaImporter.getOnlineSchema( connection.getJNDIConnectionWrapper(),
monitor );
+                schemaBackup = ApacheDSSchemaImporter.importSchema( connection.getJNDIConnectionWrapper(),
monitor );
             }
             catch ( NamingException e )
             {

Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ApacheDSSchemaExporter.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ApacheDSSchemaExporter.java?rev=570782&view=auto
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ApacheDSSchemaExporter.java
(added)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ApacheDSSchemaExporter.java
Wed Aug 29 05:32:43 2007
@@ -0,0 +1,189 @@
+/*
+ *  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.apacheds.schemaeditor.model.io;
+
+
+import java.util.List;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.ldap.Control;
+
+import org.apache.directory.shared.ldap.message.AttributeImpl;
+import org.apache.directory.shared.ldap.message.AttributesImpl;
+import org.apache.directory.studio.apacheds.schemaeditor.model.DependenciesComputer;
+import org.apache.directory.studio.apacheds.schemaeditor.model.Schema;
+import org.apache.directory.studio.connection.core.StudioProgressMonitor;
+import org.apache.directory.studio.connection.core.io.jndi.JNDIConnectionWrapper;
+
+
+/**
+ * This class is used to import the schema from Apache Directory Server.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ApacheDSSchemaExporter
+{
+    private static final String SCHEMA_BASE_DN = "dc=example,dc=com";
+
+    /** The Dependencies Computer */
+    private DependenciesComputer dependenciesComputer;
+
+    /** The JNDI Connection wrapper */
+    private JNDIConnectionWrapper wrapper;
+
+    /** The Progress Monitor */
+    private StudioProgressMonitor monitor;
+
+    /** The controls used in the request */
+    private Control[] controls = new Control[0];
+
+
+    /**
+     * Export the Schema to the given Apache Directory Server JNDIConnectionWrapper.
+     * @param dependenciesComputer 
+     * 
+     * @param  wrapper
+     *      the JNDIConnectionWrapper
+     * @param monitor 
+     * @throws NamingException 
+     */
+    public void exportSchema( List<Schema> schemas, DependenciesComputer dependenciesComputer,
+        JNDIConnectionWrapper wrapper, StudioProgressMonitor monitor ) throws NamingException
+    {
+        this.dependenciesComputer = dependenciesComputer;
+        this.wrapper = wrapper;
+        this.monitor = monitor;
+
+        monitor.beginTask( "Committing changes:", schemas.size() );
+
+        for ( Schema schema : schemas )
+        {
+            monitor.subTask( "Committing schema '" + schema.getName() + "'" );
+
+            createSchemaEntries( schema );
+
+            monitor.worked( 1 );
+        }
+
+        monitor.done();
+    }
+
+
+    /**
+     * Creates the schema entry WITH all its child nodes (including
+     * attribute types, object classes, etc.).
+     *
+     * @param schema
+     *      the schema
+     */
+    private void createSchemaEntries( Schema schema )
+    {
+        // Creating the schema entry
+        createSchemaEntry( schema );
+
+        // Creating the schema sub-entries
+        String schemaEntryDN = "cn=" + schema.getName() + "," + SCHEMA_BASE_DN;
+        createOrganizationalUnitEntry( "ou=attributeTypes," + schemaEntryDN, "attributeTypes"
);
+        createOrganizationalUnitEntry( "ou=comparators," + schemaEntryDN, "comparators" );
+        createOrganizationalUnitEntry( "ou=ditContentRules," + schemaEntryDN, "ditContentRules"
);
+        createOrganizationalUnitEntry( "ou=ditStructureRules," + schemaEntryDN, "ditStructureRules"
);
+        createOrganizationalUnitEntry( "ou=matchingRules," + schemaEntryDN, "matchingRules"
);
+        createOrganizationalUnitEntry( "ou=matchingRuleUse," + schemaEntryDN, "matchingRuleUse"
);
+        createOrganizationalUnitEntry( "ou=nameForms," + schemaEntryDN, "nameForms" );
+        createOrganizationalUnitEntry( "ou=normalizers," + schemaEntryDN, "normalizers" );
+        createOrganizationalUnitEntry( "ou=objectClasses," + schemaEntryDN, "objectClasses"
);
+        createOrganizationalUnitEntry( "ou=syntaxCheckers," + schemaEntryDN, "syntaxCheckers"
);
+        createOrganizationalUnitEntry( "ou=syntaxes," + schemaEntryDN, "syntaxes" );
+    }
+
+
+    /**
+     * Creates the schema entry WITHOUT all its child nodes .
+     *
+     * @param schema
+     *      the schema
+     */
+    private void createSchemaEntry( Schema schema )
+    {
+        // Attribute 'objectClass'
+        Attribute objectClassAttribute = new AttributeImpl( "objectClass" );
+        objectClassAttribute.add( "top" );
+        objectClassAttribute.add( "metaSchema" );
+
+        // Attribute 'cn'
+        Attribute cnAttribute = new AttributeImpl( "cn" );
+        cnAttribute.add( schema.getName() );
+
+        // Attribute 'm-dependencies'
+        Attribute dependenciesAttribute = null;
+        List<Schema> dependencies = dependenciesComputer.getDependencies( schema );
+        if ( ( dependencies != null ) && ( dependencies.size() > 0 ) )
+        {
+            dependenciesAttribute = new AttributeImpl( "m-dependencies" );
+            for ( Schema dependency : dependencies )
+            {
+                dependenciesAttribute.add( dependency.getName() );
+            }
+        }
+
+        // Building attributes
+        Attributes attributes = new AttributesImpl();
+        attributes.put( objectClassAttribute );
+        attributes.put( cnAttribute );
+        if ( dependenciesAttribute != null )
+        {
+            attributes.put( dependenciesAttribute );
+        }
+
+        // Schema entry's DN
+        String dn = "cn=" + schema.getName() + "," + SCHEMA_BASE_DN;
+
+        // Creating the entry
+        wrapper.createEntry( dn, attributes, controls, monitor );
+    }
+
+
+    /**
+     * Creates an OrganizationalUnit entry with the given information.
+     *
+     * @param dn
+     *      the DN
+     * @param ouValue
+     *      the value of the 'ou' attribute
+     */
+    private void createOrganizationalUnitEntry( String dn, String ouValue )
+    {
+        Attribute objectClassAttribute = new AttributeImpl( "objectClass" );
+        objectClassAttribute.add( "top" );
+        objectClassAttribute.add( "organizationalUnit" );
+
+        Attribute ouAttribute = new AttributeImpl( "ou" );
+        ouAttribute.add( ouValue );
+
+        Attributes attributes = new AttributesImpl();
+        attributes.put( objectClassAttribute );
+        attributes.put( ouAttribute );
+
+        wrapper.createEntry( dn, attributes, controls, monitor );
+    }
+}

Copied: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ApacheDSSchemaImporter.java
(from r570699, directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/OnlineSchemaImporter.java)
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ApacheDSSchemaImporter.java?p2=directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ApacheDSSchemaImporter.java&p1=directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/OnlineSchemaImporter.java&r1=570699&r2=570782&rev=570782&view=diff
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/OnlineSchemaImporter.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ApacheDSSchemaImporter.java
Wed Aug 29 05:32:43 2007
@@ -47,7 +47,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class OnlineSchemaImporter
+public class ApacheDSSchemaImporter
 {
     /** The Schema DN */
     public static final String SCHEMA_DN = "ou=schema";
@@ -75,7 +75,7 @@
 
 
     /**
-     * Gets the Online Schema of the given Apache Directory Server JNDIConnectionWrapper.
+     * Imports the Schema of the given Apache Directory Server JNDIConnectionWrapper.
      * 
      * @param  wrapper
      * 		the JNDIConnectionWrapper
@@ -83,7 +83,7 @@
      * @throws NamingException 
      */
     @SuppressWarnings("unchecked")
-    public static List<Schema> getOnlineSchema( JNDIConnectionWrapper wrapper, StudioProgressMonitor
monitor )
+    public static List<Schema> importSchema( JNDIConnectionWrapper wrapper, StudioProgressMonitor
monitor )
         throws NamingException
     {
         List<Schema> schemas = new ArrayList<Schema>();

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/CommitChangesWizard.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/CommitChangesWizard.java?rev=570782&r1=570781&r2=570782&view=diff
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/CommitChangesWizard.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/CommitChangesWizard.java
Wed Aug 29 05:32:43 2007
@@ -23,11 +23,15 @@
 import java.lang.reflect.InvocationTargetException;
 import java.util.List;
 
+import javax.naming.NamingException;
+
 import org.apache.directory.studio.apacheds.schemaeditor.Activator;
 import org.apache.directory.studio.apacheds.schemaeditor.model.DependenciesComputer;
 import org.apache.directory.studio.apacheds.schemaeditor.model.Project;
 import org.apache.directory.studio.apacheds.schemaeditor.model.Schema;
 import org.apache.directory.studio.apacheds.schemaeditor.model.DependenciesComputer.DependencyComputerException;
+import org.apache.directory.studio.apacheds.schemaeditor.model.io.ApacheDSSchemaExporter;
+import org.apache.directory.studio.connection.core.StudioProgressMonitor;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.viewers.IStructuredSelection;
@@ -50,6 +54,9 @@
     /** The flag to know if the Schema contains errors */
     private boolean schemaContainsErrors = false;
 
+    /** The project */
+    private Project project;
+
     /** The DependenciesComputer */
     private DependenciesComputer dependenciesComputer;
 
@@ -86,23 +93,16 @@
             {
                 public void run( IProgressMonitor monitor )
                 {
-                    monitor.beginTask( "Committing changes:", orderedSchemas.size() );
-
-                    for ( Schema schema : orderedSchemas )
+                    ApacheDSSchemaExporter exporter = new ApacheDSSchemaExporter();
+                    try
                     {
-                        monitor.subTask( "Committing schema '" + schema.getName() + "'" );
-                        
-                        try
-                        {
-                            Thread.sleep( 500 );
-                        }
-                        catch ( InterruptedException e )
-                        {
-                            // TODO Auto-generated catch block
-                            e.printStackTrace();
-                        }
-                        
-                        // TODO implement
+                        exporter.exportSchema( orderedSchemas, dependenciesComputer, project.getConnection().getJNDIConnectionWrapper(),
+                            new StudioProgressMonitor( monitor ) );
+                    }
+                    catch ( NamingException e )
+                    {
+                        // TODO Auto-generated catch block
+                        e.printStackTrace();
                     }
                 }
             } );
@@ -145,7 +145,8 @@
     {
         setNeedsProgressMonitor( true );
 
-        Project project = Activator.getDefault().getProjectsHandler().getOpenProject();
+        project = Activator.getDefault().getProjectsHandler().getOpenProject();
+
         try
         {
             dependenciesComputer = new DependenciesComputer( project.getSchemaHandler().getSchemas()
);



Mime
View raw message