directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r798617 [2/2] - in /directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor: ./ controller/ controller/actions/ model/ model/io/ view/dialogs/ view/wizards/
Date Tue, 28 Jul 2009 17:46:13 GMT
Added: directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/MergeSchemasWizard.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/MergeSchemasWizard.java?rev=798617&view=auto
==============================================================================
--- directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/MergeSchemasWizard.java (added)
+++ directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/MergeSchemasWizard.java Tue Jul 28 17:46:12 2009
@@ -0,0 +1,570 @@
+/*
+ *  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.view.wizards;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.directory.shared.ldap.schema.AbstractSchemaObject;
+import org.apache.directory.studio.schemaeditor.Activator;
+import org.apache.directory.studio.schemaeditor.model.AttributeTypeImpl;
+import org.apache.directory.studio.schemaeditor.model.ObjectClassImpl;
+import org.apache.directory.studio.schemaeditor.model.Project;
+import org.apache.directory.studio.schemaeditor.model.Schema;
+import org.apache.directory.studio.schemaeditor.model.SchemaImpl;
+import org.apache.directory.studio.schemaeditor.view.dialogs.MessageDialogWithTextarea;
+import org.apache.directory.studio.schemaeditor.view.wizards.MergeSchemasSelectionWizardPage.AttributeTypeFolder;
+import org.apache.directory.studio.schemaeditor.view.wizards.MergeSchemasSelectionWizardPage.ObjectClassFolder;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.ui.IImportWizard;
+import org.eclipse.ui.IWorkbench;
+
+
+/**
+ * This class represents the wizard to merge schema projects.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class MergeSchemasWizard extends Wizard implements IImportWizard
+{
+    // The pages of the wizard
+    private MergeSchemasSelectionWizardPage selectionPage;
+    private MergeSchemasOptionsWizardPage optionsPage;
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.wizard.Wizard#addPages()
+     */
+    public void addPages()
+    {
+        // Creating pages
+        selectionPage = new MergeSchemasSelectionWizardPage();
+        optionsPage = new MergeSchemasOptionsWizardPage();
+
+        // Adding pages
+        addPage( selectionPage );
+        addPage( optionsPage );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.wizard.Wizard#performFinish()
+     */
+    public boolean performFinish()
+    {
+        Object[] sourceObjects = selectionPage.getSelectedObjects();
+
+        boolean replaceUnknownSyntax = optionsPage.isReplaceUnknownSyntax();
+        boolean mergeDependencies = optionsPage.isMergeDependencies();
+        boolean pullUpAttributes = optionsPage.isPullUpAttributes();
+
+        List<String> errorMessages = new ArrayList<String>();
+        mergeObjects( sourceObjects, errorMessages, replaceUnknownSyntax, mergeDependencies, pullUpAttributes );
+        if ( !errorMessages.isEmpty() )
+        {
+            StringBuilder sb = new StringBuilder();
+            for ( String errorMessage : errorMessages )
+            {
+                sb.append( errorMessage );
+                sb.append( '\n' );
+            }
+            new MessageDialogWithTextarea( getShell(), Messages.getString( "MergeSchemasWizard.MergeResultTitle" ),
+                Messages.getString( "MergeSchemasWizard.MergeResultMessage" ), sb.toString() ).open();
+        }
+
+        return true;
+    }
+
+
+    private void mergeObjects( Object[] sourceObjects, List<String> errorMessages, boolean replaceUnknownSyntax,
+        boolean mergeDependencies, boolean pullUpAttributes )
+    {
+        /* 
+         * List of already processed schema objects. Used to avoid that schema objects are process multiple time.
+         */
+        Set<Object> processedObjects = new HashSet<Object>();
+
+        /*
+         * List of created target schemas. 
+         */
+        Map<String, Schema> targetSchemas = new HashMap<String, Schema>();
+
+        Project targetProject = Activator.getDefault().getProjectsHandler().getOpenProject();
+
+        // merge all source objects to the target project
+        for ( Object sourceObject : sourceObjects )
+        {
+            if ( sourceObject instanceof Project )
+            {
+                Project sourceProject = ( Project ) sourceObject;
+                for ( Schema sourceSchema : sourceProject.getSchemaHandler().getSchemas() )
+                {
+                    Schema targetSchema = getTargetSchema( sourceSchema.getProject(), targetProject, targetSchemas );
+                    mergeSchema( sourceSchema, targetProject, targetSchema, processedObjects, errorMessages,
+                        replaceUnknownSyntax, mergeDependencies, pullUpAttributes );
+                }
+            }
+            if ( sourceObject instanceof Schema )
+            {
+                Schema sourceSchema = ( Schema ) sourceObject;
+                Schema targetSchema = getTargetSchema( sourceSchema.getProject(), targetProject, targetSchemas );
+                mergeSchema( sourceSchema, targetProject, targetSchema, processedObjects, errorMessages,
+                    replaceUnknownSyntax, mergeDependencies, pullUpAttributes );
+            }
+            if ( sourceObject instanceof AttributeTypeFolder )
+            {
+                AttributeTypeFolder atf = ( AttributeTypeFolder ) sourceObject;
+                Schema targetSchema = getTargetSchema( atf.schema.getProject(), targetProject, targetSchemas );
+                List<AttributeTypeImpl> sourceAttributeTypes = atf.schema.getAttributeTypes();
+                for ( AttributeTypeImpl sourceAttributeType : sourceAttributeTypes )
+                {
+                    mergeAttributeType( sourceAttributeType, targetProject, targetSchema, processedObjects,
+                        errorMessages, replaceUnknownSyntax, mergeDependencies, pullUpAttributes );
+                }
+            }
+            if ( sourceObject instanceof ObjectClassFolder )
+            {
+                ObjectClassFolder ocf = ( ObjectClassFolder ) sourceObject;
+                Schema targetSchema = getTargetSchema( ocf.schema.getProject(), targetProject, targetSchemas );
+                List<ObjectClassImpl> sourceObjectClasses = ocf.schema.getObjectClasses();
+                for ( ObjectClassImpl sourceObjectClass : sourceObjectClasses )
+                {
+                    mergeObjectClass( sourceObjectClass, targetProject, targetSchema, processedObjects, errorMessages,
+                        replaceUnknownSyntax, mergeDependencies, pullUpAttributes );
+                }
+            }
+            if ( sourceObject instanceof AttributeTypeImpl )
+            {
+                AttributeTypeImpl at = ( AttributeTypeImpl ) sourceObject;
+                Schema targetSchema = getTargetSchema( at.getSchemaObject().getProject(), targetProject, targetSchemas );
+                mergeAttributeType( at, targetProject, targetSchema, processedObjects, errorMessages,
+                    replaceUnknownSyntax, mergeDependencies, pullUpAttributes );
+            }
+            if ( sourceObject instanceof ObjectClassImpl )
+            {
+                ObjectClassImpl oc = ( ObjectClassImpl ) sourceObject;
+                Schema targetSchema = getTargetSchema( oc.getSchemaObject().getProject(), targetProject, targetSchemas );
+                mergeObjectClass( oc, targetProject, targetSchema, processedObjects, errorMessages,
+                    replaceUnknownSyntax, mergeDependencies, pullUpAttributes );
+            }
+        }
+
+        //add created target schemas to project
+        for ( Schema targetSchema : targetSchemas.values() )
+        {
+            if ( !targetProject.getSchemaHandler().getSchemas().contains( targetSchema ) )
+            {
+                targetProject.getSchemaHandler().addSchema( targetSchema );
+            }
+        }
+    }
+
+
+    private Schema getTargetSchema( Project sourceProject, Project targetProject, Map<String, Schema> targetSchemas )
+    {
+        String targetSchemaName = "merge-from-" + sourceProject.getName();
+        Schema targetSchema = targetProject.getSchemaHandler().getSchema( targetSchemaName );
+        if ( targetSchema != null )
+        {
+            targetProject.getSchemaHandler().removeSchema( targetSchema );
+        }
+        else if ( targetSchemas.containsKey( targetSchemaName ) )
+        {
+            targetSchema = targetSchemas.get( targetSchemaName );
+        }
+        else
+        {
+            targetSchema = new SchemaImpl( targetSchemaName );
+            targetSchema.setProject( targetProject );
+        }
+        targetSchemas.put( targetSchemaName, targetSchema );
+        return targetSchema;
+    }
+
+
+    /**
+     * Merges all attribute types and object classes and form the given sourceSchema to the targetSchema. 
+     */
+    private void mergeSchema( Schema sourceSchema, Project targetProject, Schema targetSchema,
+        Set<Object> processedObjects, List<String> errorMessages, boolean replaceUnknownSyntax,
+        boolean mergeDependencies, boolean pullUpAttributes )
+    {
+        List<AttributeTypeImpl> sourceAttributeTypes = sourceSchema.getAttributeTypes();
+        for ( AttributeTypeImpl sourceAttributeType : sourceAttributeTypes )
+        {
+            mergeAttributeType( sourceAttributeType, targetProject, targetSchema, processedObjects, errorMessages,
+                replaceUnknownSyntax, mergeDependencies, pullUpAttributes );
+        }
+
+        List<ObjectClassImpl> sourceObjectClasses = sourceSchema.getObjectClasses();
+        for ( ObjectClassImpl sourceObjectClass : sourceObjectClasses )
+        {
+            mergeObjectClass( sourceObjectClass, targetProject, targetSchema, processedObjects, errorMessages,
+                replaceUnknownSyntax, mergeDependencies, pullUpAttributes );
+        }
+    }
+
+
+    /**
+     * Merges the given attribute type to the targetSchema. 
+     */
+    private void mergeAttributeType( AttributeTypeImpl sourceAttributeType, Project targetProject, Schema targetSchema,
+        Set<Object> processedObjects, List<String> errorMessages, boolean replaceUnknownSyntax,
+        boolean mergeDependencies, boolean pullUpAttributes )
+    {
+        if ( processedObjects.contains( sourceAttributeType ) )
+        {
+            return;
+        }
+        processedObjects.add( sourceAttributeType );
+
+        // check if attribute (identified by OID or name) already exists in the project
+        AttributeTypeImpl targetAttributeType = targetProject.getSchemaHandler().getAttributeType(
+            sourceAttributeType.getOid() );
+        if ( targetAttributeType == null )
+        {
+            for ( String name : sourceAttributeType.getNamesRef() )
+            {
+                targetAttributeType = targetProject.getSchemaHandler().getAttributeType( name );
+                if ( targetAttributeType != null )
+                {
+                    break;
+                }
+            }
+        }
+
+        // check if OID or alias name already exist in target project
+        boolean oidOrAliasAlreadyTaken = targetProject.getSchemaHandler().isAliasOrOidAlreadyTaken(
+            sourceAttributeType.getOid() );
+        if ( !oidOrAliasAlreadyTaken )
+        {
+            for ( String name : sourceAttributeType.getNamesRef() )
+            {
+                oidOrAliasAlreadyTaken = targetProject.getSchemaHandler().isAliasOrOidAlreadyTaken( name );
+                if ( oidOrAliasAlreadyTaken )
+                {
+                    break;
+                }
+            }
+        }
+
+        if ( targetAttributeType != null )
+        {
+            errorMessages.add( NLS.bind( Messages.getString( "MergeSchemasWizard.AttributeTypeExistsInTargetProject" ),
+                getIdString( sourceAttributeType ) ) );
+        }
+        else
+        {
+            if ( oidOrAliasAlreadyTaken )
+            {
+                errorMessages.add( NLS.bind( Messages.getString( "MergeSchemasWizard.OidOrAliasAlreadyTaken" ),
+                    getIdString( sourceAttributeType ) ) );
+            }
+            else
+            {
+                // remove attribute type if already there from previous merge
+                AttributeTypeImpl at = targetSchema.getAttributeType( sourceAttributeType.getOid() );
+                if ( at != null )
+                {
+                    targetSchema.removeAttributeType( at );
+                }
+
+                // clone attribute type
+                AttributeTypeImpl clonedAttributeType = new AttributeTypeImpl( sourceAttributeType.getOid() );
+                clonedAttributeType.setOid( sourceAttributeType.getOid() );
+                clonedAttributeType.setNames( sourceAttributeType.getNamesRef() );
+                clonedAttributeType.setDescription( sourceAttributeType.getDescription() );
+                clonedAttributeType.setSuperiorName( sourceAttributeType.getSuperiorName() );
+                clonedAttributeType.setUsage( sourceAttributeType.getUsage() );
+                clonedAttributeType.setSyntaxOid( sourceAttributeType.getSyntaxOid() );
+                clonedAttributeType.setLength( sourceAttributeType.getLength() );
+                clonedAttributeType.setObsolete( sourceAttributeType.isObsolete() );
+                clonedAttributeType.setCollective( sourceAttributeType.isCollective() );
+                clonedAttributeType.setSingleValue( sourceAttributeType.isSingleValue() );
+                clonedAttributeType.setCanUserModify( sourceAttributeType.isCanUserModify() );
+                clonedAttributeType.setEqualityName( sourceAttributeType.getEqualityName() );
+                clonedAttributeType.setOrderingName( sourceAttributeType.getOrderingName() );
+                clonedAttributeType.setSubstrName( sourceAttributeType.getSubstrName() );
+                clonedAttributeType.setSchema( targetSchema.getName() );
+                clonedAttributeType.setSchemaObject( targetSchema );
+
+                // if no/unknown syntax: set "Directory String" syntax and appropriate matching rules
+                if ( replaceUnknownSyntax )
+                {
+                    if ( clonedAttributeType.getSyntaxOid() == null
+                        || targetProject.getSchemaHandler().getSyntax( clonedAttributeType.getSyntaxOid() ) == null )
+                    {
+                        errorMessages.add( NLS.bind( Messages.getString( "MergeSchemasWizard.ReplacedSyntax" ),
+                            new String[]
+                                { getIdString( sourceAttributeType ), clonedAttributeType.getSyntaxOid(),
+                                    "1.3.6.1.4.1.1466.115.121.1.15 (Directory String)" } ) );
+                        clonedAttributeType.setSyntaxOid( "1.3.6.1.4.1.1466.115.121.1.15" );
+                        clonedAttributeType.setEqualityName( "caseIgnoreMatch" );
+                        clonedAttributeType.setOrderingName( null );
+                        clonedAttributeType.setSubstrName( "caseIgnoreSubstringsMatch" );
+                    }
+                }
+                // TODO: if unknown (single) matching rule: set appropriate matching rule according to syntax
+                // TODO: if no (all) matching rules: set appropriate matching rules according to syntax
+
+                // merge dependencies: super attribute type
+                if ( mergeDependencies )
+                {
+                    String superiorName = clonedAttributeType.getSuperiorName();
+                    if ( superiorName != null )
+                    {
+                        AttributeTypeImpl superiorAttributeType = sourceAttributeType.getSchemaObject().getProject()
+                            .getSchemaHandler().getAttributeType( superiorName );
+                        if ( superiorAttributeType != null )
+                        {
+                            mergeAttributeType( superiorAttributeType, targetProject, targetSchema, processedObjects,
+                                errorMessages, replaceUnknownSyntax, mergeDependencies, pullUpAttributes );
+                        }
+                    }
+                }
+
+                targetSchema.addAttributeType( clonedAttributeType );
+            }
+        }
+    }
+
+
+    /**
+     * Merges the given object class to the targetSchema. 
+     */
+    private void mergeObjectClass( ObjectClassImpl sourceObjectClass, Project targetProject, Schema targetSchema,
+        Set<Object> processedObjects, List<String> errorMessages, boolean replaceUnknownSyntax,
+        boolean mergeDependencies, boolean pullUpAttributes )
+    {
+        if ( processedObjects.contains( sourceObjectClass ) )
+        {
+            return;
+        }
+        processedObjects.add( sourceObjectClass );
+
+        // check if object class (identified by OID or alias name) already exists in the target project
+        ObjectClassImpl targetObjectClass = targetProject.getSchemaHandler()
+            .getObjectClass( sourceObjectClass.getOid() );
+        if ( targetObjectClass == null )
+        {
+            for ( String name : sourceObjectClass.getNamesRef() )
+            {
+                targetObjectClass = targetProject.getSchemaHandler().getObjectClass( name );
+                if ( targetObjectClass != null )
+                {
+                    break;
+                }
+            }
+        }
+
+        // check if OID or alias name already exist in target project
+        boolean oidOrAliasAlreadyTaken = targetProject.getSchemaHandler().isAliasOrOidAlreadyTaken(
+            sourceObjectClass.getOid() );
+        if ( !oidOrAliasAlreadyTaken )
+        {
+            for ( String name : sourceObjectClass.getNamesRef() )
+            {
+                oidOrAliasAlreadyTaken = targetProject.getSchemaHandler().isAliasOrOidAlreadyTaken( name );
+                if ( oidOrAliasAlreadyTaken )
+                {
+                    break;
+                }
+            }
+        }
+
+        if ( targetObjectClass != null )
+        {
+            errorMessages.add( NLS.bind( Messages.getString( "MergeSchemasWizard.ObjectClassExistsInTargetProject" ),
+                getIdString( sourceObjectClass ) ) );
+        }
+        else
+        {
+            if ( oidOrAliasAlreadyTaken )
+            {
+                errorMessages.add( NLS.bind( Messages.getString( "MergeSchemasWizard.OidOrAliasAlreadyTaken" ),
+                    getIdString( sourceObjectClass ) ) );
+            }
+            else
+            {
+                // remove object class if already there from previous merge
+                ObjectClassImpl oc = targetSchema.getObjectClass( sourceObjectClass.getOid() );
+                if ( oc != null )
+                {
+                    targetSchema.removeObjectClass( oc );
+                }
+
+                // create object class
+                ObjectClassImpl clonedObjectClass = new ObjectClassImpl( sourceObjectClass.getOid() );
+                clonedObjectClass.setOid( sourceObjectClass.getOid() );
+                clonedObjectClass.setNames( sourceObjectClass.getNamesRef() );
+                clonedObjectClass.setDescription( sourceObjectClass.getDescription() );
+                clonedObjectClass.setSuperClassesNames( sourceObjectClass.getSuperClassesNames() );
+                clonedObjectClass.setType( sourceObjectClass.getType() );
+                clonedObjectClass.setObsolete( sourceObjectClass.isObsolete() );
+                clonedObjectClass.setMustNamesList( sourceObjectClass.getMustNamesList() );
+                clonedObjectClass.setMayNamesList( sourceObjectClass.getMayNamesList() );
+                clonedObjectClass.setSchema( targetSchema.getName() );
+                clonedObjectClass.setSchemaObject( targetSchema );
+
+                // merge dependencies: super object classes and must/may attributes
+                if ( mergeDependencies )
+                {
+                    String[] superClassesNames = clonedObjectClass.getSuperClassesNames();
+                    if ( superClassesNames != null )
+                    {
+                        for ( String superClassName : superClassesNames )
+                        {
+                            if ( superClassName != null )
+                            {
+                                ObjectClassImpl superSourceObjectClass = sourceObjectClass.getSchemaObject()
+                                    .getProject().getSchemaHandler().getObjectClass( superClassName );
+                                ObjectClassImpl superTargetObjectClass = targetProject.getSchemaHandler()
+                                    .getObjectClass( superClassName );
+                                if ( superSourceObjectClass != null )
+                                {
+                                    if ( superTargetObjectClass == null )
+                                    {
+                                        mergeObjectClass( superSourceObjectClass, targetProject, targetSchema,
+                                            processedObjects, errorMessages, replaceUnknownSyntax, mergeDependencies,
+                                            pullUpAttributes );
+                                    }
+                                    else
+                                    {
+                                        // pull-up may and must attributes to this OC if super already exists in target
+                                        if ( pullUpAttributes )
+                                        {
+                                            pullUpAttributes( clonedObjectClass, superSourceObjectClass,
+                                                superTargetObjectClass );
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+
+                    String[] mustNamesList = clonedObjectClass.getMustNamesList();
+                    String[] mayNamesList = clonedObjectClass.getMayNamesList();
+                    List<String> attributeNames = new ArrayList<String>();
+                    if ( mustNamesList != null )
+                    {
+                        attributeNames.addAll( Arrays.asList( mustNamesList ) );
+                    }
+                    if ( mayNamesList != null )
+                    {
+                        attributeNames.addAll( Arrays.asList( mayNamesList ) );
+                    }
+                    for ( String attributeName : attributeNames )
+                    {
+                        if ( attributeName != null )
+                        {
+                            AttributeTypeImpl attributeType = sourceObjectClass.getSchemaObject().getProject()
+                                .getSchemaHandler().getAttributeType( attributeName );
+                            if ( attributeType != null )
+                            {
+                                mergeAttributeType( attributeType, targetProject, targetSchema, processedObjects,
+                                    errorMessages, replaceUnknownSyntax, mergeDependencies, pullUpAttributes );
+                            }
+                        }
+                    }
+                }
+
+                targetSchema.addObjectClass( clonedObjectClass );
+            }
+        }
+    }
+
+
+    private void pullUpAttributes( ObjectClassImpl targetObjectClass, ObjectClassImpl sourceSuperObjectClass,
+        ObjectClassImpl targetSuperObjectClass )
+    {
+        // must
+        Set<String> sourceMustAttributeNames = new HashSet<String>();
+        fetchAttributes( sourceMustAttributeNames, sourceSuperObjectClass, true );
+        Set<String> targetMustAttributeNames = new HashSet<String>();
+        fetchAttributes( targetMustAttributeNames, targetSuperObjectClass, true );
+        sourceMustAttributeNames.removeAll( targetMustAttributeNames );
+        if ( !sourceMustAttributeNames.isEmpty() )
+        {
+            sourceMustAttributeNames.addAll( Arrays.asList( targetObjectClass.getMustNamesList() ) );
+            targetObjectClass.setMustNamesList( sourceMustAttributeNames.toArray( new String[0] ) );
+        }
+
+        // may
+        Set<String> sourceMayAttributeNames = new HashSet<String>();
+        fetchAttributes( sourceMayAttributeNames, sourceSuperObjectClass, false );
+        Set<String> targetMayAttributeNames = new HashSet<String>();
+        fetchAttributes( targetMayAttributeNames, targetSuperObjectClass, false );
+        sourceMayAttributeNames.removeAll( targetMayAttributeNames );
+        if ( !sourceMayAttributeNames.isEmpty() )
+        {
+            sourceMayAttributeNames.addAll( Arrays.asList( targetObjectClass.getMayNamesList() ) );
+            targetObjectClass.setMayNamesList( sourceMayAttributeNames.toArray( new String[0] ) );
+        }
+    }
+
+
+    private void fetchAttributes( Set<String> attributeNameList, ObjectClassImpl oc, boolean must )
+    {
+        String[] attributeNames = must ? oc.getMustNamesList() : oc.getMayNamesList();
+        attributeNameList.addAll( Arrays.asList( attributeNames ) );
+
+        for ( String superClassName : oc.getSuperClassesNames() )
+        {
+            ObjectClassImpl superObjectClass = oc.getSchemaObject().getProject().getSchemaHandler().getObjectClass(
+                superClassName );
+            fetchAttributes( attributeNameList, superObjectClass, must );
+        }
+    }
+
+
+    private String getIdString( AbstractSchemaObject schemaObject )
+    {
+        StringBuilder sb = new StringBuilder();
+        sb.append( '[' );
+        if ( schemaObject.getNamesRef() != null )
+        {
+            for ( String name : schemaObject.getNamesRef() )
+            {
+                sb.append( name );
+                sb.append( ',' );
+            }
+        }
+        sb.append( schemaObject.getOid() );
+        sb.append( ']' );
+        return sb.toString();
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
+     */
+    public void init( IWorkbench workbench, IStructuredSelection selection )
+    {
+    }
+}

Modified: directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewAttributeTypeWizard.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewAttributeTypeWizard.java?rev=798617&r1=798616&r2=798617&view=diff
==============================================================================
--- directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewAttributeTypeWizard.java (original)
+++ directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewAttributeTypeWizard.java Tue Jul 28 17:46:12 2009
@@ -76,6 +76,7 @@
         // Creating the new attribute type
         AttributeTypeImpl newAT = new AttributeTypeImpl( generalPage.getOidValue() );
         newAT.setSchema( generalPage.getSchemaValue() );
+        newAT.setSchemaObject( Activator.getDefault().getSchemaHandler().getSchema( generalPage.getSchemaValue() ) );
         newAT.setNames( generalPage.getAliasesValue() );
         newAT.setDescription( generalPage.getDescriptionValue() );
         newAT.setSuperiorName( contentPage.getSuperiorValue() );

Modified: directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewObjectClassWizard.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewObjectClassWizard.java?rev=798617&r1=798616&r2=798617&view=diff
==============================================================================
--- directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewObjectClassWizard.java (original)
+++ directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewObjectClassWizard.java Tue Jul 28 17:46:12 2009
@@ -79,6 +79,7 @@
         // Creating the new object class
         ObjectClassImpl newOC = new ObjectClassImpl( generalPage.getOidValue() );
         newOC.setSchema( generalPage.getSchemaValue() );
+        newOC.setSchemaObject( Activator.getDefault().getSchemaHandler().getSchema( generalPage.getSchemaValue() ) );
         newOC.setNames( generalPage.getAliasesValue() );
         newOC.setDescription( generalPage.getDescriptionValue() );
         newOC.setSuperClassesNames( contentPage.getSuperiorsNameValue() );

Modified: directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewProjectWizard.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewProjectWizard.java?rev=798617&r1=798616&r2=798617&view=diff
==============================================================================
--- directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewProjectWizard.java (original)
+++ directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewProjectWizard.java Tue Jul 28 17:46:12 2009
@@ -20,12 +20,13 @@
 package org.apache.directory.studio.schemaeditor.view.wizards;
 
 
-import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.directory.studio.connection.core.Connection;
 import org.apache.directory.studio.connection.core.jobs.StudioProgressMonitor;
+import org.apache.directory.studio.connection.core.jobs.StudioRunnableWithProgress;
+import org.apache.directory.studio.connection.ui.RunnableContextRunner;
 import org.apache.directory.studio.schemaeditor.Activator;
 import org.apache.directory.studio.schemaeditor.PluginConstants;
 import org.apache.directory.studio.schemaeditor.PluginUtils;
@@ -36,10 +37,7 @@
 import org.apache.directory.studio.schemaeditor.model.Schema;
 import org.apache.directory.studio.schemaeditor.model.io.GenericSchemaConnector;
 import org.apache.directory.studio.schemaeditor.model.io.SchemaConnector;
-import org.apache.directory.studio.schemaeditor.view.ViewUtils;
 import org.apache.directory.studio.schemaeditor.view.widget.CoreSchemasSelectionWidget.ServerTypeEnum;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.wizard.IWizardPage;
 import org.eclipse.jface.wizard.Wizard;
@@ -63,8 +61,6 @@
     private NewProjectWizardSchemasSelectionPage schemasSelectionPage;
 
 
-    private Throwable exceptionThrown = null;
-
     /* (non-Javadoc)
      * @see org.eclipse.jface.wizard.Wizard#addPages()
      */
@@ -94,103 +90,87 @@
         final Project project = new Project( projectType, projectName );
 
         if ( projectType.equals( ProjectType.ONLINE ) )
-            // Project is an "Online Project"
+        // Project is an "Online Project"
         {
             // Setting the connection to use
             project.setConnection( connectionSelectionPage.getSelectedConnection() );
 
-            // Reseting the Exception Thrown
-            exceptionThrown = null;
-
-            try
+            RunnableContextRunner.execute( new StudioRunnableWithProgress()
             {
-                getContainer().run( false, false, new IRunnableWithProgress()
+
+                public void run( StudioProgressMonitor monitor )
                 {
-                    public void run( IProgressMonitor monitor )
+                    // Getting the correct SchemaConnector for this connection
+                    List<SchemaConnector> correctSchemaConnectors = getCorrectSchemaConnectors(
+                        project.getConnection(), monitor );
+
+                    // If no suitable SchemaConnector has been found, we display an
+                    // error message and return false;
+                    if ( correctSchemaConnectors.size() == 0 )
                     {
-                        StudioProgressMonitor studioProgressMonitor = new StudioProgressMonitor( monitor );
-
-                        // Getting the correct SchemaConnector for this connection
-                        List<SchemaConnector> correctSchemaConnectors = getCorrectSchemaConnectors( project
-                            .getConnection(), studioProgressMonitor );
-
-                        // If no suitable SchemaConnector has been found, we display an
-                        // error message and return false;
-                        if ( correctSchemaConnectors.size() == 0 )
-                        {
-                            studioProgressMonitor.reportError(
-                                "No suitable SchemaConnector has been found for the choosen Directory Server.",
-                                new NoSuitableSchemaConnectorException() );
-                        }
+                        monitor.reportError(
+                            "No suitable SchemaConnector has been found for the choosen Directory Server.",
+                            new NoSuitableSchemaConnectorException() );
+                    }
 
-                        // Check if generic schema connector is included, then remove it to use a specific one
-                        if ( correctSchemaConnectors.size() > 1 )
+                    // Check if generic schema connector is included, then remove it to use a specific one
+                    if ( correctSchemaConnectors.size() > 1 )
+                    {
+                        for ( SchemaConnector schemaConnector : correctSchemaConnectors )
                         {
-                            for ( SchemaConnector schemaConnector : correctSchemaConnectors )
+                            if ( schemaConnector instanceof GenericSchemaConnector )
                             {
-                                if ( schemaConnector instanceof GenericSchemaConnector )
-                                {
-                                    correctSchemaConnectors.remove( schemaConnector );
-                                    break;
-                                }
+                                correctSchemaConnectors.remove( schemaConnector );
+                                break;
                             }
                         }
+                    }
 
-                        // Getting the correct SchemaConnector
-                        SchemaConnector correctSchemaConnector = null;
-                        if ( correctSchemaConnectors.size() == 1 )
-                        {
-                            correctSchemaConnector = correctSchemaConnectors.get( 0 );
-                        }
-                        else
-                        {
-                            // TODO display a dialog in which the user can select the correct schema connector
-                        }
+                    // Getting the correct SchemaConnector
+                    SchemaConnector correctSchemaConnector = null;
+                    if ( correctSchemaConnectors.size() == 1 )
+                    {
+                        correctSchemaConnector = correctSchemaConnectors.get( 0 );
+                    }
+                    else
+                    {
+                        // TODO display a dialog in which the user can select the correct schema connector
+                    }
 
-                        project.setSchemaConnector( correctSchemaConnector );
+                    project.setSchemaConnector( correctSchemaConnector );
 
-                        // Fetching the Online Schema
-                        project.fetchOnlineSchema( new StudioProgressMonitor( monitor ) );
+                    // Fetching the Online Schema
+                    project.fetchOnlineSchema( monitor );
+                }
 
-                        // Checking if an error has occured
-                        if ( studioProgressMonitor.errorsReported() )
-                        {
-                            exceptionThrown = studioProgressMonitor.getException();
-                            return;
-                        }
-                    }
-                } );
-            }
-            catch ( InvocationTargetException e )
-            {
-                // Nothing to do (it will never occur)
-            }
-            catch ( InterruptedException e )
-            {
-                // Nothing to do.
-            }
 
-            if ( exceptionThrown != null )
-            {
-                if ( exceptionThrown instanceof NoSuitableSchemaConnectorException )
-                    // Special case for the 'NoSuitableSchemaConnectorException'
+                public String getName()
                 {
-                    PluginUtils.logError( "No suitable SchemaConnector has been found for the selected connection.",
-                        exceptionThrown );
-                    ViewUtils.displayErrorMessageBox( "Error", "An error occured when creating the project.\n"
-                        + "No suitable SchemaConnector has been found for the selected connection." );
+                    return null;
                 }
-                else
-                    // Standard case
+
+
+                public Object[] getLockedObjects()
                 {
-                    PluginUtils.logError( "An error occured when creating the project.", exceptionThrown );
-                    ViewUtils.displayErrorMessageBox( "Error", "An error occured when creating the project." );
+                    return null;
                 }
-                return false;
-            }
+
+
+                public String getErrorMessage()
+                {
+                    return null;
+                }
+
+
+                public Connection[] getConnections()
+                {
+                    return null;
+                }
+
+            }, getContainer(), true );
         }
         else if ( projectType.equals( ProjectType.OFFLINE ) )
-            // Project is an "Offline Project"
+        // Project is an "Offline Project"
         {
             // Getting the selected 'core' schemas
             String[] selectedSchemas = schemasSelectionPage.getSelectedSchemas();
@@ -203,6 +183,7 @@
                     Schema schema = PluginUtils.loadCoreSchema( serverType, selectedSchema );
                     if ( schema != null )
                     {
+                        schema.setProject( project );
                         schemaHandler.addSchema( schema );
                     }
                 }
@@ -243,6 +224,7 @@
         return suitableSchemaConnectors;
     }
 
+
     /* (non-Javadoc)
      * @see org.eclipse.jface.wizard.Wizard#getNextPage(org.eclipse.jface.wizard.IWizardPage)
      */
@@ -264,6 +246,7 @@
         return null;
     }
 
+
     /* (non-Javadoc)
      * @see org.eclipse.jface.wizard.Wizard#getPreviousPage(org.eclipse.jface.wizard.IWizardPage)
      */
@@ -278,6 +261,7 @@
         return null;
     }
 
+
     /* (non-Javadoc)
      * @see org.eclipse.jface.wizard.Wizard#canFinish()
      */

Modified: directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewSchemaWizard.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewSchemaWizard.java?rev=798617&r1=798616&r2=798617&view=diff
==============================================================================
--- directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewSchemaWizard.java (original)
+++ directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewSchemaWizard.java Tue Jul 28 17:46:12 2009
@@ -62,6 +62,7 @@
     public boolean performFinish()
     {
         SchemaImpl schema = new SchemaImpl( page.getSchemaName() );
+        schema.setProject( Activator.getDefault().getProjectsHandler().getOpenProject() );
         Activator.getDefault().getSchemaHandler().addSchema( schema );
 
         return true;

Modified: directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/messages.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/messages.properties?rev=798617&r1=798616&r2=798617&view=diff
==============================================================================
--- directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/messages.properties (original)
+++ directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/messages.properties Tue Jul 28 17:46:12 2009
@@ -287,3 +287,24 @@
 NewSchemaWizardPage.ErrorSchemaNameExists=A schema with this name already exists.
 NewSchemaWizardPage.PleaseSpecifiyName=Please specify a name to create a new schema.
 NewSchemaWizardPage.SchemaName=Schema name:
+
+MergeSchemasSelectionWizardPage.ImportSchemasFromProjects=Merge Schemas from other Projects
+MergeSchemasSelectionWizardPage.PleaseSelectElements=Please select schema elements to merge.
+MergeSchemasSelectionWizardPage.SelectElements=Select the schema elements to merge:
+MergeSchemasSelectionWizardPage.ErrorNoElementsSelected=No schema elements selected
+MergeSchemasSelectionWizardPage.ImportSchemasFromProjects=Merge Schemas from other Projects
+MergeSchemasSelectionWizardPage.SelectOptions=Please select merge options
+MergeSchemasSelectionWizardPage.AttributeTypes=Attribute Types
+MergeSchemasSelectionWizardPage.ObjectClasses=Object Classes
+MergeSchemasOptionsWizardPage.MergeDependencies=Merge dependencies
+MergeSchemasOptionsWizardPage.MergeDependenciesTooltip=If enabled, dependent schema elements (super classes, super attribute types, may and must attriutes) are also merged. 
+MergeSchemasOptionsWizardPage.PullUpAttributes=Pull up attributes
+MergeSchemasOptionsWizardPage.PullUpAttributesTooltip=If enabled, must and may attributes that are not defined in the class hierarchy in the target schema are added to the merged object class.
+MergeSchemasOptionsWizardPage.ReplaceUnknownSyntax=Replace unknown syntax
+MergeSchemasOptionsWizardPage.ReplaceUnknownSyntaxTooltip=If enabled, unknown syntaxes are replaced by Directory String syntax, and appropriate matching rules (caseIgnoreMatch, caseIgnoreSubstringsMatch) are set.
+MergeSchemasWizard.AttributeTypeExistsInTargetProject=Attribute type {0} already exists in target project.
+MergeSchemasWizard.ObjectClassExistsInTargetProject=Object class {0} already exists in target project.
+MergeSchemasWizard.OidOrAliasAlreadyTaken=OID or alias {0} already exists in target project.
+MergeSchemasWizard.ReplacedSyntax=Replaced unknown syntax of {0}: {1} -> {2}
+MergeSchemasWizard.MergeResultTitle=Merge Result
+MergeSchemasWizard.MergeResultMessage=Merge finished successful, please note the following warnings:

Modified: directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/messages_de.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/messages_de.properties?rev=798617&r1=798616&r2=798617&view=diff
==============================================================================
--- directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/messages_de.properties (original)
+++ directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/messages_de.properties Tue Jul 28 17:46:12 2009
@@ -296,3 +296,24 @@
 NewSchemaWizardPage.ErrorSchemaNameExists=Ein Schema mit diesem Namen existiert bereits
 NewSchemaWizardPage.PleaseSpecifiyName=Bitte einen Namen f\u00FCr das neue Schema eingeben.
 NewSchemaWizardPage.SchemaName=Schemaname:
+
+MergeSchemasSelectionWizardPage.ImportSchemasFromProjects=Schemas von anderen Projekten kopieren
+MergeSchemasSelectionWizardPage.PleaseSelectElements=Bitte Schemaelemente ausw\u00E4hlen, die kopiert werden sollen.
+MergeSchemasSelectionWizardPage.SelectElements=Schemaelemente ausw\u00E4hlen, die kopiert werden sollen:
+MergeSchemasSelectionWizardPage.ErrorNoElementsSelected=Keine Schemaelemente ausgew\u00E4hlt
+MergeSchemasSelectionWizardPage.ImportSchemasFromProjects=Schemas von anderen Projekten kopieren
+MergeSchemasSelectionWizardPage.SelectOptions=Bitte Kopieroptionen ausw\u00E4hlen
+MergeSchemasSelectionWizardPage.AttributeTypes=Attribut-Typen
+MergeSchemasSelectionWizardPage.ObjectClasses=Objektklassen
+MergeSchemasOptionsWizardPage.MergeDependencies=Abh\u00E4nigkeiten kopieren
+MergeSchemasOptionsWizardPage.MergeDependenciesTooltip=Wenn aktiviert, werden abh\u00E4ngige Schemaelemente (\u00FCbergeordnete Klassen und Attribute) ebenfalls kopiert. 
+MergeSchemasOptionsWizardPage.PullUpAttributes=Attribute hochziehen
+MergeSchemasOptionsWizardPage.PullUpAttributesTooltip=Wenn aktiviert, werden Attribute, die nicht in \u00FCbergeordneten Klassen im Zielprojekt vorhanden sind, zur kopierten Objektklasse hinzugef\u00FCgt.
+MergeSchemasOptionsWizardPage.ReplaceUnknownSyntax=Unbekannte Syntax ersetzen
+MergeSchemasOptionsWizardPage.ReplaceUnknownSyntaxTooltip=Wenn aktiviert, werden unbekannte Syntax durch Directory String ersetzt und passende Vergleichsregeln (caseIgnoreMatch, caseIgnoreSubstringsMatch) gesetzt.
+MergeSchemasWizard.AttributeTypeExistsInTargetProject=Attribut-Typ {0} existiert bereits im Zielprojekt.
+MergeSchemasWizard.ObjectClassExistsInTargetProject=Objektklasse {0} existiert bereits im Zielprojekt.
+MergeSchemasWizard.OidOrAliasAlreadyTaken=OID oder Alias {0} existiert bereits im Zielprojekt.
+MergeSchemasWizard.ReplacedSyntax=Unbekannte Syntax in {0} wurde ersetzt: {1} -> {2}
+MergeSchemasWizard.MergeResultTitle=Ergebnis
+MergeSchemasWizard.MergeResultMessage=Schema wurde erfolgreich kopiert, bitte die folgenden Warnungen beachten:

Modified: directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/messages_fr.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/messages_fr.properties?rev=798617&r1=798616&r2=798617&view=diff
==============================================================================
--- directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/messages_fr.properties (original)
+++ directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/messages_fr.properties Tue Jul 28 17:46:12 2009
@@ -305,3 +305,24 @@
 NewSchemaWizardPage.ErrorSchemaNameExists=Un sch\u00E9ma avec ce nom existe d\u00E9j\u00E0.
 NewSchemaWizardPage.PleaseSpecifiyName=Veuillez sp\u00E9cifier un nom pour cr\u00E9er un nouveau sch\u00E9ma.
 NewSchemaWizardPage.SchemaName=Nom du sch\u00E9ma:
+
+MergeSchemasSelectionWizardPage.ImportSchemasFromProjects=TODO:Merge Schemas from other Projects
+MergeSchemasSelectionWizardPage.PleaseSelectElements=TODO:Please select schema elements to merge.
+MergeSchemasSelectionWizardPage.SelectElements=TODO:Select the schema elements to merge:
+MergeSchemasSelectionWizardPage.ErrorNoElementsSelected=TODO:No schema elements selected
+MergeSchemasSelectionWizardPage.ImportSchemasFromProjects=TODO:Merge Schemas from other Projects
+MergeSchemasSelectionWizardPage.SelectOptions=TODO:Please select merge options
+MergeSchemasSelectionWizardPage.AttributeTypes=TODO:Attribute Types
+MergeSchemasSelectionWizardPage.ObjectClasses=TODO:Object Classes
+MergeSchemasOptionsWizardPage.MergeDependencies=TODO:Merge dependencies
+MergeSchemasOptionsWizardPage.MergeDependenciesTooltip=TODO:If enabled, dependent schema elements (super classes, super attribute types, may and must attriutes) are also merged. 
+MergeSchemasOptionsWizardPage.PullUpAttributes=TODO:Pull up attributes
+MergeSchemasOptionsWizardPage.PullUpAttributesTooltip=TODO:If enabled, must and may attributes that are not defined in the class hierarchy in the target schema are added to the merged object class.
+MergeSchemasOptionsWizardPage.ReplaceUnknownSyntax=TODO:Replace unknown syntax
+MergeSchemasOptionsWizardPage.ReplaceUnknownSyntaxTooltip=TODO:If enabled, unknown syntaxes are replaced by Directory String syntax, and appropriate matching rules (caseIgnoreMatch, caseIgnoreSubstringsMatch) are set.
+MergeSchemasWizard.AttributeTypeExistsInTargetProject=TODO:Attribute type {0} already exists in target project.
+MergeSchemasWizard.ObjectClassExistsInTargetProject=TODO:Object class {0} already exists in target project.
+MergeSchemasWizard.OidOrAliasAlreadyTaken=TODO:OID or alias {0} already exists in target project.
+MergeSchemasWizard.ReplacedSyntax=TODO:Replaced unknown syntax of {0}: {1} -> {2}
+MergeSchemasWizard.MergeResultTitle=TODO:Merge Result
+MergeSchemasWizard.MergeResultMessage=TODO:Merge finished successful, please note the following warnings:



Mime
View raw message