Author: tfmorris
Date: 2007-08-30 11:48:34-0700
New Revision: 13462
Added:
trunk/src/model-euml/src/org/argouml/model/euml/ChangeCommand.java
trunk/src/model-euml/src/org/argouml/model/euml/CommandStackImpl.java
trunk/src/model-euml/src/org/argouml/model/euml/UMLUtil.java
Modified:
trunk/src/model-euml/META-INF/MANIFEST.MF
trunk/src/model-euml/src/org/argouml/model/euml/ChangeableKindEUMLImpl.java
trunk/src/model-euml/src/org/argouml/model/euml/CopyHelperEUMLImpl.java
trunk/src/model-euml/src/org/argouml/model/euml/CoreFactoryEUMLImpl.java
trunk/src/model-euml/src/org/argouml/model/euml/CoreHelperEUMLImpl.java
trunk/src/model-euml/src/org/argouml/model/euml/DataTypesFactoryEUMLImpl.java
trunk/src/model-euml/src/org/argouml/model/euml/DataTypesHelperEUMLImpl.java
trunk/src/model-euml/src/org/argouml/model/euml/EUMLModelImplementation.java
trunk/src/model-euml/src/org/argouml/model/euml/ExtensionMechanismsHelperEUMLImpl.java
trunk/src/model-euml/src/org/argouml/model/euml/FacadeEUMLImpl.java
trunk/src/model-euml/src/org/argouml/model/euml/MetaTypesEUMLImpl.java
trunk/src/model-euml/src/org/argouml/model/euml/ModelEventPumpEUMLImpl.java
trunk/src/model-euml/src/org/argouml/model/euml/ModelManagementFactoryEUMLImpl.java
trunk/src/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java
trunk/src/model-euml/src/org/argouml/model/euml/RootContainerAdapter.java
trunk/src/model-euml/src/org/argouml/model/euml/RunnableClass.java
trunk/src/model-euml/src/org/argouml/model/euml/UmlFactoryEUMLImpl.java
trunk/src/model-euml/src/org/argouml/model/euml/UseCasesFactoryEUMLImpl.java
trunk/src/model-euml/src/org/argouml/model/euml/UseCasesHelperEUMLImpl.java
trunk/src/model-euml/src/org/argouml/model/euml/XmiReaderEUMLImpl.java
trunk/src/model-euml/src/org/argouml/model/euml/XmiWriterEUMLImpl.java
Log:
Merge Bogdan's end of term GSoC work for eUML
Modified: trunk/src/model-euml/META-INF/MANIFEST.MF
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-euml/META-INF/MANIFEST.MF?view=diff&rev=13462&p1=trunk/src/model-euml/META-INF/MANIFEST.MF&p2=trunk/src/model-euml/META-INF/MANIFEST.MF&r1=13461&r2=13462
==============================================================================
--- trunk/src/model-euml/META-INF/MANIFEST.MF (original)
+++ trunk/src/model-euml/META-INF/MANIFEST.MF 2007-08-30 11:48:34-0700
@@ -9,3 +9,17 @@
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Export-Package: org.argouml.model.euml
Eclipse-RegisterBuddy: org.argouml.core.lib
+Bundle-ClassPath: lib/emf/org.eclipse.emf.common_2.3.0.v200708072030.jar,
+ lib/emf/org.eclipse.emf.ecore_2.3.1.v200708072030.jar,
+ lib/emf/org.eclipse.emf.ecore.change_2.3.0.v200708072030.jar,
+ lib/emf/org.eclipse.emf.ecore.change.edit_2.3.0.v200708072030.jar,
+ lib/emf/org.eclipse.emf.ecore.edit_2.3.0.v200708072030.jar,
+ lib/emf/org.eclipse.emf.ecore.xmi_2.3.1.v200708072030.jar,
+ lib/emf/org.eclipse.emf.edit_2.3.1.v200708072030.jar,
+ lib/emf/org.eclipse.emf.mapping_2.3.0.v200708072030.jar,
+ lib/emf/org.eclipse.emf.mapping.ecore2xml_2.3.0.v200708072030.jar,
+ lib/uml2/org.eclipse.uml2.common_1.3.1.v200707311200.jar,
+ lib/uml2/org.eclipse.uml2.common.edit_1.3.0.v200706251652.jar,
+ lib/uml2/org.eclipse.uml2.uml_2.1.1.v200707311200.jar,
+ lib/uml2/org.eclipse.uml2.uml.edit_2.1.0.v200706251652.jar,
+ lib/uml2/org.eclipse.uml2.uml.resources_2.1.0.v200706251652.jar
Added: trunk/src/model-euml/src/org/argouml/model/euml/ChangeCommand.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-euml/src/org/argouml/model/euml/ChangeCommand.java?view=auto&rev=13462
==============================================================================
--- (empty file)
+++ trunk/src/model-euml/src/org/argouml/model/euml/ChangeCommand.java 2007-08-30 11:48:34-0700
@@ -0,0 +1,106 @@
+// $Id: ChangeCommand.java 13359 2007-08-15 08:23:10Z b00__1 $
+// Copyright (c) 2007, ArgoUML Project
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// * Neither the name of the ArgoUML Project nor the
+// names of its contributors may be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE ArgoUML PROJECT ``AS IS'' AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE ArgoUML PROJECT BE LIABLE FOR ANY
+// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+package org.argouml.model.euml;
+
+import org.eclipse.emf.common.notify.impl.NotificationImpl;
+
+/**
+ * A ChangeCommand that updates its label.
+ * <p>
+ * The label of this command can contain the character '#' that will be replaced
+ * with information about an object when the label is returned.
+ *
+ * @author Bogdan Pistol
+ */
+public class ChangeCommand extends
+ org.eclipse.uml2.common.edit.command.ChangeCommand {
+
+ private Object objects[];
+
+ private EUMLModelImplementation modelImpl;
+
+ public ChangeCommand(EUMLModelImplementation modelImplementation,
+ Runnable runnable, String label) {
+ super(modelImplementation.getEditingDomain(), runnable, label);
+ modelImpl = modelImplementation;
+ }
+
+ public ChangeCommand(EUMLModelImplementation modelImplementation,
+ Runnable runnable, String label, Object... objects) {
+ super(modelImplementation.getEditingDomain(), runnable, label);
+ if (!isValid(label, objects)) {
+ throw new IllegalArgumentException(
+ "The label is not compatible with the objects"); //$NON-NLS-1$
+ }
+ this.objects = objects;
+ modelImpl = modelImplementation;
+ }
+
+ public void setObjects(Object... objects) {
+ if (!isValid(label, objects)) {
+ throw new IllegalArgumentException(
+ "The label is not compatible with the objects"); //$NON-NLS-1$
+ }
+ this.objects = objects;
+ modelImpl.getModelEventPump().notifyChanged(
+ new NotificationImpl(
+ ModelEventPumpEUMLImpl.COMMAND_STACK_UPDATE, false,
+ false));
+ }
+
+ @Override
+ public String getLabel() {
+ if (objects == null) {
+ return label;
+ }
+ StringBuilder sb = new StringBuilder();
+ int j = 0;
+ for (int i = 0; i < label.length(); i++) {
+ if (label.charAt(i) == '#') {
+ sb.append(UMLUtil.toString(objects[j]));
+ j++;
+ } else {
+ sb.append(label.charAt(i));
+ }
+ }
+ return sb.toString();
+ }
+
+ private boolean isValid(String label, Object objects[]) {
+ if (objects == null) {
+ return true;
+ }
+ int i = 0;
+ for (int j = 0; j < label.length(); j++) {
+ if (label.charAt(j) == '#') {
+ i++;
+ }
+ }
+ return i == objects.length;
+ }
+
+}
Modified: trunk/src/model-euml/src/org/argouml/model/euml/ChangeableKindEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-euml/src/org/argouml/model/euml/ChangeableKindEUMLImpl.java?view=diff&rev=13462&p1=trunk/src/model-euml/src/org/argouml/model/euml/ChangeableKindEUMLImpl.java&p2=trunk/src/model-euml/src/org/argouml/model/euml/ChangeableKindEUMLImpl.java&r1=13461&r2=13462
==============================================================================
--- trunk/src/model-euml/src/org/argouml/model/euml/ChangeableKindEUMLImpl.java (original)
+++ trunk/src/model-euml/src/org/argouml/model/euml/ChangeableKindEUMLImpl.java 2007-08-30 11:48:34-0700
@@ -40,7 +40,9 @@
public Object getAddOnly() {
- throw new NotImplementedException();
+ // TODO: Change to throw exception when uses are fixed
+// throw new NotImplementedException();
+ return "";
}
public Object getChangeable() {
Added: trunk/src/model-euml/src/org/argouml/model/euml/CommandStackImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-euml/src/org/argouml/model/euml/CommandStackImpl.java?view=auto&rev=13462
==============================================================================
--- (empty file)
+++ trunk/src/model-euml/src/org/argouml/model/euml/CommandStackImpl.java 2007-08-30 11:48:34-0700
@@ -0,0 +1,78 @@
+// $Id: CommandStackImpl.java 13421 2007-08-20 17:04:35Z b00__1 $
+// Copyright (c) 2007, The ArgoUML Project
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// * Neither the name of the ArgoUML Project nor the
+// names of its contributors may be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE ArgoUML PROJECT ``AS IS'' AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE ArgoUML PROJECT BE LIABLE FOR ANY
+// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+package org.argouml.model.euml;
+
+import org.argouml.model.CommandStack;
+
+/**
+ * CommandStack implementation to support Undo/Redo.
+ *
+ */
+public class CommandStackImpl implements CommandStack {
+
+ private EUMLModelImplementation modelImplementation;
+
+ public CommandStackImpl(EUMLModelImplementation implementation) {
+ modelImplementation = implementation;
+ implementation.getEditingDomain().getCommandStack().flush();
+ }
+
+ public boolean canRedo() {
+ return modelImplementation.getEditingDomain().getCommandStack()
+ .canRedo();
+ }
+
+ public boolean canUndo() {
+ return modelImplementation.getEditingDomain().getCommandStack()
+ .canUndo();
+ }
+
+ public String getRedoLabel() {
+ return canRedo() ? modelImplementation.getEditingDomain()
+ .getCommandStack().getRedoCommand().getLabel()
+ : null;
+ }
+
+ public String getUndoLabel() {
+ return canUndo() ? modelImplementation.getEditingDomain()
+ .getCommandStack().getUndoCommand().getLabel()
+ : null;
+ }
+
+ public boolean isCommandStackCapabilityAvailable() {
+ return true;
+ }
+
+ public void redo() {
+ modelImplementation.getEditingDomain().getCommandStack().redo();
+ }
+
+ public void undo() {
+ modelImplementation.getEditingDomain().getCommandStack().undo();
+ }
+
+}
Modified: trunk/src/model-euml/src/org/argouml/model/euml/CopyHelperEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-euml/src/org/argouml/model/euml/CopyHelperEUMLImpl.java?view=diff&rev=13462&p1=trunk/src/model-euml/src/org/argouml/model/euml/CopyHelperEUMLImpl.java&p2=trunk/src/model-euml/src/org/argouml/model/euml/CopyHelperEUMLImpl.java&r1=13461&r2=13462
==============================================================================
--- trunk/src/model-euml/src/org/argouml/model/euml/CopyHelperEUMLImpl.java (original)
+++ trunk/src/model-euml/src/org/argouml/model/euml/CopyHelperEUMLImpl.java 2007-08-30 11:48:34-0700
@@ -27,6 +27,7 @@
package org.argouml.model.euml;
import org.argouml.model.CopyHelper;
+import org.eclipse.uml2.uml.Element;
/**
* The implementation of the CopyHelper for EUML2.
@@ -40,17 +41,27 @@
/**
* Constructor.
- *
- * @param implementation The ModelImplementation.
+ *
+ * @param implementation
+ * The ModelImplementation.
*/
public CopyHelperEUMLImpl(EUMLModelImplementation implementation) {
modelImpl = implementation;
}
-
- public Object copy(Object source, Object destination) {
- // TODO Auto-generated method stub
- return null;
+
+ public Element copy(Object source, Object destination) {
+ if (!(source instanceof Element) || !(destination instanceof Element)) {
+ throw new IllegalArgumentException(
+ "The source and destination must be instances of Element"); //$NON-NLS-1$
+ }
+ Element copiedElement = UMLUtil.copy(
+ modelImpl, (Element) source, (Element) destination);
+ if (copiedElement == null) {
+ throw new UnsupportedOperationException(
+ "Could not copy " + source + " to destination " + destination); //$NON-NLS-1$//$NON-NLS-2$
+ }
+ return copiedElement;
}
-
+
}
Modified: trunk/src/model-euml/src/org/argouml/model/euml/CoreFactoryEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-euml/src/org/argouml/model/euml/CoreFactoryEUMLImpl.java?view=diff&rev=13462&p1=trunk/src/model-euml/src/org/argouml/model/euml/CoreFactoryEUMLImpl.java&p2=trunk/src/model-euml/src/org/argouml/model/euml/CoreFactoryEUMLImpl.java&r1=13461&r2=13462
==============================================================================
--- trunk/src/model-euml/src/org/argouml/model/euml/CoreFactoryEUMLImpl.java (original)
+++ trunk/src/model-euml/src/org/argouml/model/euml/CoreFactoryEUMLImpl.java 2007-08-30 11:48:34-0700
@@ -32,15 +32,16 @@
import org.argouml.model.CoreFactory;
import org.argouml.model.NotImplementedException;
import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.uml2.common.edit.command.ChangeCommand;
import org.eclipse.uml2.uml.Abstraction;
import org.eclipse.uml2.uml.AggregationKind;
import org.eclipse.uml2.uml.Artifact;
import org.eclipse.uml2.uml.Association;
import org.eclipse.uml2.uml.AssociationClass;
+import org.eclipse.uml2.uml.BehavioralFeature;
import org.eclipse.uml2.uml.BehavioredClassifier;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Comment;
+import org.eclipse.uml2.uml.Component;
import org.eclipse.uml2.uml.Constraint;
import org.eclipse.uml2.uml.DataType;
import org.eclipse.uml2.uml.Dependency;
@@ -50,6 +51,7 @@
import org.eclipse.uml2.uml.Generalization;
import org.eclipse.uml2.uml.Interface;
import org.eclipse.uml2.uml.InterfaceRealization;
+import org.eclipse.uml2.uml.MultiplicityElement;
import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.Namespace;
import org.eclipse.uml2.uml.Node;
@@ -58,14 +60,18 @@
import org.eclipse.uml2.uml.Parameter;
import org.eclipse.uml2.uml.PrimitiveType;
import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
import org.eclipse.uml2.uml.TemplateBinding;
import org.eclipse.uml2.uml.TemplateParameter;
+import org.eclipse.uml2.uml.TemplateParameterSubstitution;
+import org.eclipse.uml2.uml.TemplateSignature;
+import org.eclipse.uml2.uml.TemplateableElement;
import org.eclipse.uml2.uml.Type;
import org.eclipse.uml2.uml.UMLFactory;
import org.eclipse.uml2.uml.Usage;
+import org.eclipse.uml2.uml.ValueSpecification;
import org.eclipse.uml2.uml.VisibilityKind;
-
/**
* The implementation of the CoreFactory for EUML2.
*/
@@ -78,55 +84,119 @@
private EditingDomain editingDomain;
- private UMLFactory uml = UMLFactory.eINSTANCE;
-
/**
* Constructor.
- *
- * @param implementation The ModelImplementation.
+ *
+ * @param implementation
+ * The ModelImplementation.
*/
public CoreFactoryEUMLImpl(EUMLModelImplementation implementation) {
modelImpl = implementation;
editingDomain = implementation.getEditingDomain();
}
- public Abstraction buildAbstraction(String name, Object supplier,
- Object client) {
- Abstraction abstraction = uml.createAbstraction();
- abstraction.setName(name);
- abstraction.getSuppliers().add((NamedElement) supplier);
- abstraction.getClients().add((NamedElement) client);
- return abstraction;
+ public Abstraction buildAbstraction(final String name,
+ final Object supplier, final Object client) {
+ if (!(client instanceof NamedElement)
+ || !(supplier instanceof NamedElement)) {
+ throw new IllegalArgumentException(
+ "The client and the supplier " + //$NON-NLS-1$
+ "must be NamedElements."); //$NON-NLS-1$
+ }
+ if (((NamedElement) client).getNearestPackage() == null) {
+ throw new NullPointerException(
+ "The containing package of the client " + //$NON-NLS-1$
+ "must be non-null."); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ Abstraction abstraction = createAbstraction();
+ if (name != null) {
+ abstraction.setName(name);
+ }
+ abstraction.getSuppliers().add((NamedElement) supplier);
+ abstraction.getClients().add((NamedElement) client);
+ ((NamedElement) client).getNearestPackage()
+ .getPackagedElements().add(abstraction);
+ getParams().add(abstraction);
+ }
+ };
+ ChangeCommand cmd = new ChangeCommand(
+ modelImpl, run,
+ "Create the abstraction # between " + //$NON-NLS-1$
+ "the client # and the supplier #"); //$NON-NLS-1$
+ editingDomain.getCommandStack().execute(cmd);
+ cmd.setObjects(run.getParams().get(0), client, supplier);
+
+ return (Abstraction) run.getParams().get(0);
}
- Association buildAssociation(final Object type1,
+ private Association buildAssociation(final Object type1,
final Boolean navigability1, final Object aggregationKind1,
- final String name1, final Object type2,
- final Boolean navigability2, final Object aggregationKind2,
- final String name2, final String associationName) {
-
+ final Object type2, final Boolean navigability2,
+ final Object aggregationKind2, final String associationName) {
+ if (!(type1 instanceof Type) || !(type2 instanceof Type)) {
+ throw new IllegalArgumentException(
+ "The types must be instances of Type."); //$NON-NLS-1$
+ }
+ if ((aggregationKind1 != null
+ && !(aggregationKind1 instanceof AggregationKind))
+ || (aggregationKind2 != null
+ && !(aggregationKind2 instanceof AggregationKind))) {
+ throw new IllegalArgumentException(
+ "The aggregations of the association ends" + //$NON-NLS-1$
+ " must be instances of AggregationKind."); //$NON-NLS-1$
+ }
+ if (((Type) type1).getNearestPackage() == null) {
+ throw new NullPointerException(
+ "The containing package of the type1" + //$NON-NLS-1$
+ " must be non-null."); //$NON-NLS-1$
+ }
RunnableClass run = new RunnableClass() {
public void run() {
- Association assoc = ((Type) type1).createAssociation(
- navigability1,
- aggregationKind1 == null ? AggregationKind.NONE_LITERAL
- : (AggregationKind) aggregationKind1, name1, 0,
- 1, (Type) type2, navigability2,
- aggregationKind2 == null ? AggregationKind.NONE_LITERAL
- : (AggregationKind) aggregationKind2, name2, 0,
- 1);
- for (Property p : assoc.getMemberEnds()) {
- p.setLowerValue(null);
- p.setUpperValue(null);
+ Association association = createAssociation();
+ Property property1 = createAssociationEnd();
+ Property property2 = createAssociationEnd();
+ property1.setType((Type) type2);
+ property2.setType((Type) type1);
+ property1.setAssociation(association);
+ property2.setAssociation(association);
+ if (aggregationKind1 != null) {
+ property1.setAggregation(
+ (AggregationKind) aggregationKind1);
+ }
+ if (aggregationKind2 != null) {
+ property2.setAggregation(
+ (AggregationKind) aggregationKind2);
}
if (associationName != null) {
- assoc.setName(associationName);
+ association.setName(associationName);
+ }
+ if (UMLUtil.getOwnedAttributes((Type) type1) == null) {
+ association.getOwnedEnds().add(property1);
+ } else {
+ UMLUtil.getOwnedAttributes((Type) type1).add(property1);
+ }
+ if (UMLUtil.getOwnedAttributes((Type) type2) == null) {
+ association.getOwnedEnds().add(property2);
+ } else {
+ UMLUtil.getOwnedAttributes((Type) type2).add(property2);
+ }
+ if (navigability1 != null) {
+ property1.setIsNavigable(navigability1);
+ }
+ if (navigability2 != null) {
+ property2.setIsNavigable(navigability2);
}
- getParams().add(assoc);
+ ((Type) type1).getNearestPackage().getPackagedElements().add(
+ association);
+ getParams().add(association);
}
};
- editingDomain.getCommandStack().execute(
- new ChangeCommand(editingDomain, run));
+ ChangeCommand cmd = new ChangeCommand(
+ modelImpl, run, "Create the association # between # and #");
+ editingDomain.getCommandStack().execute(cmd);
+ cmd.setObjects(run.getParams().get(0), type1, type2);
return (Association) run.getParams().get(0);
}
@@ -134,82 +204,299 @@
public Association buildAssociation(Object fromClassifier,
Object aggregationKind1, Object toClassifier,
Object aggregationKind2, Boolean unidirectional) {
-
- return buildAssociation(fromClassifier, true, aggregationKind1, null,
- toClassifier, !unidirectional, aggregationKind2, null, null);
+ if (unidirectional != null) {
+ return buildAssociation(
+ fromClassifier, true, aggregationKind1, toClassifier,
+ !unidirectional, aggregationKind2, null);
+ } else {
+ return buildAssociation(
+ fromClassifier, null, aggregationKind1, toClassifier, null,
+ aggregationKind2, null);
+ }
}
public Association buildAssociation(Object classifier1,
Object classifier2) {
- return buildAssociation(classifier1, true,
- AggregationKind.NONE_LITERAL, null, classifier2, true,
- AggregationKind.NONE_LITERAL, null, null);
+ return buildAssociation(
+ classifier1, null, null, classifier2, null, null, null);
}
public Association buildAssociation(Object c1, boolean nav1, Object c2,
boolean nav2, String name) {
- return buildAssociation(c1, nav1, AggregationKind.NONE_LITERAL, null,
- c2, nav2, AggregationKind.NONE_LITERAL, null, name);
+ return buildAssociation(c1, nav1, null, c2, nav2, null, name);
}
- public Association buildAssociationClass(Object end1, Object end2) {
- // TODO Auto-generated method stub
- return null;
+ public AssociationClass buildAssociationClass(final Object end1,
+ final Object end2) {
+ if (!(end1 instanceof Type) || !(end2 instanceof Type)) {
+ throw new IllegalArgumentException(
+ "end1 and end2 must be instances of Type"); //$NON-NLS-1$
+ }
+ if (((Type) end1).getNearestPackage() == null) {
+ throw new NullPointerException(
+ "The containing package of " + //$NON-NLS-1$
+ "the end1 must be non-null."); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ AssociationClass associationClass = createAssociationClass();
+ Property property1 = createAssociationEnd();
+ Property property2 = createAssociationEnd();
+ property1.setType((Type) end2);
+ property2.setType((Type) end1);
+ property1.setAssociation(associationClass);
+ property2.setAssociation(associationClass);
+ ((Type) end1).getNearestPackage().getPackagedElements().add(
+ associationClass);
+ if (UMLUtil.getOwnedAttributes((Type) end1) == null) {
+ associationClass.getOwnedAttributes().add(property1);
+ } else {
+ UMLUtil.getOwnedAttributes((Type) end1).add(property1);
+ }
+ if (UMLUtil.getOwnedAttributes((Type) end2) == null) {
+ associationClass.getOwnedAttributes().add(property2);
+ } else {
+ UMLUtil.getOwnedAttributes((Type) end2).add(property2);
+ }
+ getParams().add(associationClass);
+ }
+ };
+ ChangeCommand cmd = new ChangeCommand(
+ modelImpl, run,
+ "Create the association class # between # and #");
+ editingDomain.getCommandStack().execute(cmd);
+ cmd.setObjects(run.getParams().get(0), end1, end2);
+
+ return (AssociationClass) run.getParams().get(0);
+ }
+
+ private Property buildAssociationEnd(final Object assoc, final String name,
+ final Object type, final Object multi, final Object stereo,
+ final Boolean navigable, final Object order,
+ final Object aggregation, final Object scope,
+ final Object changeable, final Object visibility) {
+ // The attribute 'targetScope' of an AssociationEnd in UML1.x is no
+ // longer supported in UML2.x
+ if (!(assoc instanceof Association)) {
+ throw new IllegalArgumentException(
+ "The assoc must be instance of Association."); //$NON-NLS-1$
+ }
+ if (!(type instanceof Type)) {
+ throw new IllegalArgumentException(
+ "The type of the property " + //$NON-NLS-1$
+ "must be instance of Type."); //$NON-NLS-1$
+ }
+ if (aggregation != null && !(aggregation instanceof AggregationKind)) {
+ throw new IllegalArgumentException(
+ "The aggregation of the property " + //$NON-NLS-1$
+ "must be instance of AggregationKind."); //$NON-NLS-1$
+ }
+ if (visibility != null && !(visibility instanceof VisibilityKind)) {
+ throw new IllegalArgumentException(
+ "The visibility of the property must" + //$NON-NLS-1$
+ " be instance of VisibilityKind."); //$NON-NLS-1$
+ }
+ if (multi != null && !(multi instanceof MultiplicityElement)) {
+ throw new IllegalArgumentException(
+ "The multilicity of the property must" + //$NON-NLS-1$
+ " be instance of MultiplicityElement."); //$NON-NLS-1$
+ }
+ if ((order != null && !(order instanceof Boolean))
+ || (changeable != null && !(changeable instanceof Boolean))) {
+ throw new IllegalArgumentException(
+ "The isOrdered, isReadOnly attributes of " + //$NON-NLS-1$
+ "the property must be instances of Boolean."); //$NON-NLS-1$
+ }
+ if (stereo != null && !(stereo instanceof Stereotype)) {
+ throw new IllegalArgumentException(
+ "stereo must be instance of Stereotype."); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ Property property = createAssociationEnd();
+ property.setType((Type) type);
+ property.setAssociation((Association) assoc);
+ if (name != null) {
+ property.setName(name);
+ }
+ if (navigable != null) {
+ property.setIsNavigable(navigable);
+ if (!(Boolean) navigable) {
+ ((Association) assoc).getOwnedEnds().add(property);
+ }
+ }
+ if (aggregation != null) {
+ property.setAggregation((AggregationKind) aggregation);
+ }
+ if (visibility != null) {
+ property.setVisibility((VisibilityKind) visibility);
+ }
+ if (multi != null) {
+ if (((MultiplicityElement) multi).getLowerValue() != null) {
+ property.setLowerValue(
+ ((MultiplicityElement) multi).getLowerValue());
+ }
+ if (((MultiplicityElement) multi).getUpperValue() != null) {
+ property.setLowerValue(
+ ((MultiplicityElement) multi).getUpperValue());
+ }
+ }
+ if (order != null) {
+ property.setIsOrdered((Boolean) order);
+ }
+ if (changeable != null) {
+ property.setIsReadOnly((Boolean) changeable);
+ }
+ if (stereo != null) {
+ if (property.isStereotypeApplicable((Stereotype) stereo)) {
+ property.applyStereotype((Stereotype) stereo);
+ } else {
+ return;
+ }
+ }
+ getParams().add(property);
+ }
+ };
+ modelImpl.getModelEventPump().getRootContainer().setHoldEvents(true);
+ ChangeCommand cmd = new ChangeCommand(
+ modelImpl, run,
+ "Create the association end # of the association #");
+ editingDomain.getCommandStack().execute(cmd);
+ if (run.getParams().isEmpty()) {
+ editingDomain.getCommandStack().undo();
+ editingDomain.getCommandStack().flush();
+ modelImpl.getModelEventPump().getRootContainer().clearHeldEvents();
+ modelImpl.getModelEventPump().getRootContainer().setHoldEvents(
+ false);
+ throw new UnsupportedOperationException(
+ "This stereotype cannot be applied " + //$NON-NLS-1$
+ "to the association end."); //$NON-NLS-1$
+ }
+ cmd.setObjects(run.getParams().get(0), assoc);
+ modelImpl.getModelEventPump().getRootContainer().setHoldEvents(false);
+
+ return (Property) run.getParams().get(0);
}
- public Object buildAssociationEnd(Object assoc, String name, Object type,
+ public Property buildAssociationEnd(Object assoc, String name, Object type,
Object multi, Object stereo, boolean navigable, Object order,
Object aggregation, Object scope, Object changeable,
Object visibility) {
- // TODO Auto-generated method stub
- return null;
+ return buildAssociationEnd(
+ assoc, name, type, multi, stereo, navigable, order,
+ aggregation, scope, changeable, visibility);
}
- public Object buildAssociationEnd(Object type, Object assoc) {
- // TODO Auto-generated method stub
- return null;
- }
-
- Property buildAttribute() {
- Property attr = createAttribute();
- attr.setName("newAttr");
- attr.setLower(1);
- attr.setUpper(1);
- attr.setVisibility(VisibilityKind.PUBLIC_LITERAL);
- attr.setIsStatic(false);
- attr.setIsReadOnly(false);
- return attr;
+ public Property buildAssociationEnd(Object type, Object assoc) {
+ return buildAssociationEnd(
+ assoc, null, type, null, null, null, null, null, null, null,
+ null);
}
public Property buildAttribute(Object model, Object type) {
- Property attr = buildAttribute();
- attr.setType((Type) type);
- return attr;
+ return buildAttribute2(type);
+ }
+
+ public Property buildAttribute2(Object type) {
+ if (!(type instanceof Type)) {
+ throw new IllegalArgumentException(
+ "The type of the attribute must" + //$NON-NLS-1$
+ " be instance of Type."); //$NON-NLS-1$
+ }
+ Property property = createAttribute();
+ property.setType((Type) type);
+ return property;
}
@SuppressWarnings("deprecation")
public Property buildAttribute(Object handle, Object model, Object type) {
- // TODO Auto-generated method stub
- return null;
+ return buildAttribute2(handle, type);
}
- public Object buildAttribute2(Object type) {
- // TODO Auto-generated method stub
- return null;
- }
+ public Property buildAttribute2(final Object handle, final Object type) {
+ if (!(handle instanceof Type) || !(type instanceof Type)) {
+ throw new IllegalArgumentException(
+ "handle and type must be instances of Type."); //$NON-NLS-1$
+ }
+ if (UMLUtil.getOwnedAttributes((Type) handle) == null) {
+ throw new UnsupportedOperationException(
+ "The type " + handle.getClass() //$NON-NLS-1$
+ + " does not support owning attributes."); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ Property property = createAttribute();
+ UMLUtil.getOwnedAttributes((Type) handle).add(property);
+ property.setType((Type) type);
+ property.setName("newAttr");
+ getParams().add(property);
+ }
+ };
+ ChangeCommand cmd = new ChangeCommand(
+ modelImpl, run, "Create the attribute # of the type #");
+ editingDomain.getCommandStack().execute(cmd);
+ cmd.setObjects(run.getParams().get(0), handle);
- public Object buildAttribute2(Object handle, Object type) {
- // TODO Auto-generated method stub
- return null;
+ return (Property) run.getParams().get(0);
}
+ /**
+ * Removed from UML2.x, use buildTemplateBinding instead.
+ */
+ @Deprecated
public Object buildBinding(Object client, Object supplier, List arguments) {
- // TODO Auto-generated method stub
- return null;
+ return buildTemplateBinding(client, supplier, arguments);
+ }
+
+ public TemplateBinding buildTemplateBinding(final Object client,
+ final Object supplier, final List arguments) {
+ // TODO: Is it appropriate the TemplateableElement as the client and a
+ // list of TemplateParameterSubstitution as the list of parameters?
+ if (!(client instanceof TemplateableElement)) {
+ throw new IllegalArgumentException(
+ "The supplier must be instance of " + //$NON-NLS-1$
+ "TemplateableElement."); //$NON-NLS-1$
+ }
+ if (!(supplier instanceof TemplateSignature)) {
+ throw new IllegalArgumentException(
+ "The supplier must be instance of " + //$NON-NLS-1$
+ "TemplateSignature."); //$NON-NLS-1$
+ }
+ if (arguments != null) {
+ for (Object o : arguments) {
+ if (!(o instanceof TemplateParameterSubstitution)) {
+ throw new IllegalArgumentException(
+ "The list of arguments must be instances" + //$NON-NLS-1$
+ " of TemplateParameterSubstitutions."); //$NON-NLS-1$
+ }
+ }
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ TemplateBinding templateBinding = createTemplateBinding();
+ templateBinding.setBoundElement((TemplateableElement) client);
+ templateBinding.setSignature((TemplateSignature) supplier);
+ if (arguments != null) {
+ for (Object o : arguments) {
+ templateBinding.getParameterSubstitutions().add(
+ (TemplateParameterSubstitution) o);
+ }
+ }
+ getParams().add(templateBinding);
+ }
+ };
+ ChangeCommand cmd = new ChangeCommand(
+ modelImpl, run,
+ "Create the template binding # between "
+ + "the client # and the supplier #");
+ editingDomain.getCommandStack().execute(cmd);
+ cmd.setObjects(run.getParams().get(0), client, supplier);
+
+ return (TemplateBinding) run.getParams().get(0);
}
public org.eclipse.uml2.uml.Class buildClass() {
- return uml.createClass();
+ return createClass();
}
public org.eclipse.uml2.uml.Class buildClass(Object owner) {
@@ -217,77 +504,252 @@
}
public org.eclipse.uml2.uml.Class buildClass(String name) {
- return buildClass(name, null);
+ org.eclipse.uml2.uml.Class clazz = createClass();
+ if (name != null) {
+ clazz.setName(name);
+ }
+ return clazz;
}
public org.eclipse.uml2.uml.Class buildClass(final String name,
final Object owner) {
- org.eclipse.uml2.uml.Class cls = uml.createClass();
- if (name != null) {
- cls.setName(name);
+ if (!(owner instanceof org.eclipse.uml2.uml.Package)
+ && !(owner instanceof org.eclipse.uml2.uml.Class)
+ && !(owner instanceof Interface)) {
+ throw new IllegalArgumentException(
+ "The owner must be instance of Package" + //$NON-NLS-1$
+ " or UML2 Class or Interface."); //$NON-NLS-1$
}
- if (owner != null)
- modelImpl.getCoreHelper().addOwnedElement(owner, cls);
- return cls;
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ org.eclipse.uml2.uml.Class clazz = createClass();
+ if (name != null) {
+ clazz.setName(name);
+ }
+ if (owner instanceof org.eclipse.uml2.uml.Package) {
+ clazz.setPackage((org.eclipse.uml2.uml.Package) owner);
+ } else if (owner instanceof org.eclipse.uml2.uml.Class) {
+ ((org.eclipse.uml2.uml.Class) owner).getNestedClassifiers()
+ .add(clazz);
+ } else if (owner instanceof Interface) {
+ ((Interface) owner).getNestedClassifiers().add(clazz);
+ }
+ getParams().add(clazz);
+ }
+ };
+ ChangeCommand cmd = new ChangeCommand(
+ modelImpl, run, "Create the class # of the owner #");
+ editingDomain.getCommandStack().execute(cmd);
+ cmd.setObjects(run.getParams().get(0), owner);
+
+ return (org.eclipse.uml2.uml.Class) run.getParams().get(0);
}
- public Comment buildComment(Object element, Object model) {
- if (model == null) {
+ public Comment buildComment(final Object element, final Object model) {
+ if (!(model instanceof Namespace)) {
throw new IllegalArgumentException(
"A namespace must be supplied."); //$NON-NLS-1$
}
- Element elementToAnnotate = (Element) element;
- // TODO: This actually creates the Comment as owned by
- // the Element itself, rather than the Element's namespace which
- // seems to make more sense, but is different than the specified
- // Model API semantics - tfm
- if (elementToAnnotate != null) {
- return elementToAnnotate.createOwnedComment();
+ if (element != null && !(element instanceof Element)) {
+ throw new IllegalArgumentException(
+ "The annotated element must be instance of Element."); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ Comment comment = createComment();
+ if (element != null) {
+ comment.getAnnotatedElements().add((Element) element);
+ }
+ ((Namespace) model).getOwnedComments().add(comment);
+ getParams().add(comment);
+ }
+ };
+ ChangeCommand cmd;
+ if (element == null) {
+ cmd = new ChangeCommand(modelImpl, run, "Create the comment #");
+ } else {
+ cmd = new ChangeCommand(
+ modelImpl, run,
+ "Create the comment # attached to the element #");
+ }
+ editingDomain.getCommandStack().execute(cmd);
+ if (element == null) {
+ cmd.setObjects(run.getParams().get(0));
} else {
- return ((Namespace) model).createOwnedComment();
+ cmd.setObjects(run.getParams().get(0), element);
}
+ return (Comment) run.getParams().get(0);
}
- public Object buildConstraint(Object constrElement) {
- // TODO Auto-generated method stub
- return null;
+ public Constraint buildConstraint(final Object constrElement) {
+ if (!(constrElement instanceof Element)) {
+ throw new IllegalArgumentException(
+ "The constrained element must be instance of Element."); //$NON-NLS-1$
+ }
+ if (((Element) constrElement).getNearestPackage() == null) {
+ throw new NullPointerException(
+ "The containing package of the constrained" //$NON-NLS-1$
+ + " element must be non-null."); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ Constraint constraint = createConstraint();
+ constraint.getConstrainedElements()
+ .add((Element) constrElement);
+ getParams().add(constraint);
+ }
+ };
+ ChangeCommand cmd = new ChangeCommand(
+ modelImpl, run,
+ "Create the constraint # that constrains the element #");
+ editingDomain.getCommandStack().execute(cmd);
+ cmd.setObjects(run.getParams().get(0), constrElement);
+
+ return (Constraint) run.getParams().get(0);
}
- public Object buildConstraint(String name, Object bexpr) {
- // TODO Auto-generated method stub
- return null;
+ public Constraint buildConstraint(String name, Object bexpr) {
+ // TODO: BooleanExpresion is removed from UML2.x, is it OK to use
+ // ValueSpecification?
+ if (!(bexpr instanceof ValueSpecification)) {
+ throw new IllegalArgumentException(
+ "The 'bexpr' value specification must be " //$NON-NLS-1$
+ + "instance of ValueSpecification"); //$NON-NLS-1$
+ }
+ Constraint constraint = createConstraint();
+ if (name != null) {
+ constraint.setName(name);
+ }
+ constraint.setSpecification((ValueSpecification) bexpr);
+ return constraint;
}
- public DataType buildDataType(String name, Object owner) {
- DataType dt = (DataType) createDataType();
- dt.setName(name);
- modelImpl.getCoreHelper().addOwnedElement(owner, dt);
- return dt;
+ public DataType buildDataType(final String name, final Object owner) {
+ if (!(owner instanceof org.eclipse.uml2.uml.Package)
+ && !(owner instanceof org.eclipse.uml2.uml.Class)
+ && !(owner instanceof Interface)) {
+ throw new IllegalArgumentException(
+ "The owner must be instance of Package" //$NON-NLS-1$
+ + " or UML2 Class or Interface."); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ DataType dataType = createDataType();
+ if (name != null) {
+ dataType.setName(name);
+ }
+ if (owner instanceof org.eclipse.uml2.uml.Package) {
+ dataType.setPackage((org.eclipse.uml2.uml.Package) owner);
+ } else if (owner instanceof org.eclipse.uml2.uml.Class) {
+ ((org.eclipse.uml2.uml.Class) owner).getNestedClassifiers()
+ .add(dataType);
+ } else if (owner instanceof Interface) {
+ ((Interface) owner).getNestedClassifiers().add(dataType);
+ }
+ getParams().add(dataType);
+ }
+ };
+ ChangeCommand cmd = new ChangeCommand(
+ modelImpl, run, "Create the data type # owned by #");
+ editingDomain.getCommandStack().execute(cmd);
+ cmd.setObjects(run.getParams().get(0), owner);
+
+ return (DataType) run.getParams().get(0);
}
- public Object buildDependency(Object clientObj, Object supplierObj) {
- // TODO Auto-generated method stub
- return null;
+ public Dependency buildDependency(final Object clientObj,
+ final Object supplierObj) {
+ if (!(clientObj instanceof NamedElement)
+ || !(supplierObj instanceof NamedElement)) {
+ throw new IllegalArgumentException(
+ "The client and the supplier must be" //$NON-NLS-1$
+ + " instances of NamedElement."); //$NON-NLS-1$
+ }
+ if (((NamedElement) clientObj).getNearestPackage() == null) {
+ throw new NullPointerException(
+ "The containing package of the client must be non-null."); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ Dependency dependency = createDependency();
+ dependency.getClients().add((NamedElement) clientObj);
+ dependency.getSuppliers().add((NamedElement) supplierObj);
+ ((NamedElement) clientObj).getNearestPackage()
+ .getPackagedElements().add(dependency);
+ getParams().add(dependency);
+ }
+ };
+ ChangeCommand cmd = new ChangeCommand(
+ modelImpl, run, "Create the dependency # between the"
+ + " client # and the supplier #");
+ editingDomain.getCommandStack().execute(cmd);
+ cmd.setObjects(run.getParams().get(0), clientObj, supplierObj);
+
+ return (Dependency) run.getParams().get(0);
}
public Object buildElementResidence(Object me, Object component) {
- // TODO Auto-generated method stub
- return null;
+ // TODO: Is this removed from UML2 ?
+ throw new NotImplementedException();
}
- public Enumeration buildEnumeration(String name, Object owner) {
- Enumeration enumer = (Enumeration) createEnumeration();
- enumer.setName(name);
- if (owner != null) {
- modelImpl.getCoreHelper().addOwnedElement(owner, enumer);
+ public Enumeration buildEnumeration(final String name, final Object owner) {
+ if (!(owner instanceof org.eclipse.uml2.uml.Package)
+ && !(owner instanceof org.eclipse.uml2.uml.Class)
+ && !(owner instanceof Interface)) {
+ throw new IllegalArgumentException(
+ "The owner must be instance of Package or UML2 Class or Interface."); //$NON-NLS-1$
}
- return enumer;
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ Enumeration enumeration = createEnumeration();
+ if (name != null) {
+ enumeration.setName(name);
+ }
+ if (owner instanceof org.eclipse.uml2.uml.Package) {
+ enumeration.setPackage(
+ (org.eclipse.uml2.uml.Package) owner);
+ } else if (owner instanceof org.eclipse.uml2.uml.Class) {
+ ((org.eclipse.uml2.uml.Class) owner).getNestedClassifiers()
+ .add(enumeration);
+ } else if (owner instanceof Interface) {
+ ((Interface) owner).getNestedClassifiers().add(enumeration);
+ }
+ getParams().add(enumeration);
+ }
+ };
+ ChangeCommand cmd = new ChangeCommand(
+ modelImpl, run, "Create the enumeration # owned by #");
+ editingDomain.getCommandStack().execute(cmd);
+ cmd.setObjects(run.getParams().get(0), owner);
+
+ return (Enumeration) run.getParams().get(0);
}
- public EnumerationLiteral buildEnumerationLiteral(String name,
- Object enumeration) {
- return ((Enumeration) enumeration).createOwnedLiteral(name);
+ public EnumerationLiteral buildEnumerationLiteral(final String name,
+ final Object enumeration) {
+ if (!(enumeration instanceof Enumeration)) {
+ throw new IllegalArgumentException(
+ "The enumeration must be instance of Enumeration."); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ EnumerationLiteral enumerationLiteral =
+ createEnumerationLiteral();
+ if (name != null) {
+ enumerationLiteral.setName(name);
+ }
+ enumerationLiteral.setEnumeration((Enumeration) enumeration);
+ getParams().add(enumerationLiteral);
+ }
+ };
+ ChangeCommand cmd = new ChangeCommand(
+ modelImpl, run, "Create the enumeration literal # owned by #");
+ editingDomain.getCommandStack().execute(cmd);
+ cmd.setObjects(run.getParams().get(0), enumeration);
+
+ return (EnumerationLiteral) run.getParams().get(0);
}
@SuppressWarnings("deprecation")
@@ -297,11 +759,27 @@
return buildGeneralization(parent, child);
}
- public Generalization buildGeneralization(Object child, Object parent) {
- Generalization generalization =
- ((BehavioredClassifier) child)
- .createGeneralization((Classifier) parent);
- return generalization;
+ public Generalization buildGeneralization(final Object child,
+ final Object parent) {
+ if (!(child instanceof Classifier) || !(parent instanceof Classifier)) {
+ throw new IllegalArgumentException(
+ "The general (the parent) and the specific (the child) must be instances of Classifier."); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ Generalization generalization = createGeneralization();
+ generalization.setGeneral((Classifier) parent);
+ generalization.setSpecific((Classifier) child);
+ getParams().add(generalization);
+ }
+ };
+ ChangeCommand cmd = new ChangeCommand(
+ modelImpl, run,
+ "Create the generalization # between # (general) and # (specific)");
+ editingDomain.getCommandStack().execute(cmd);
+ cmd.setObjects(run.getParams().get(0), parent, child);
+
+ return (Generalization) run.getParams().get(0);
}
public Interface buildInterface() {
@@ -309,61 +787,135 @@
}
public Interface buildInterface(Object owner) {
- // TODO Auto-generated method stub
- return null;
+ return buildInterface(null, owner);
}
public Interface buildInterface(String name) {
- Interface i = buildInterface();
- i.setName(name);
- return i;
+ Interface interfaze = createInterface();
+ if (name != null) {
+ interfaze.setName(name);
+ }
+ return interfaze;
}
- public Interface buildInterface(String name, Object owner) {
- // TODO Auto-generated method stub
- return null;
+ public Interface buildInterface(final String name, final Object owner) {
+ if (!(owner instanceof org.eclipse.uml2.uml.Package)
+ && !(owner instanceof org.eclipse.uml2.uml.Class)
+ && !(owner instanceof Interface)) {
+ throw new IllegalArgumentException(
+ "The owner must be instance of Package" + //$NON-NLS-1$
+ " or UML2 Class or Interface."); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ Interface interfaze = createInterface();
+ if (owner instanceof org.eclipse.uml2.uml.Package) {
+ interfaze.setPackage((org.eclipse.uml2.uml.Package) owner);
+ } else if (owner instanceof org.eclipse.uml2.uml.Class) {
+ ((org.eclipse.uml2.uml.Class) owner).getNestedClassifiers()
+ .add(interfaze);
+ } else if (owner instanceof Interface) {
+ ((Interface) owner).getNestedClassifiers().add(interfaze);
+ }
+ if (name != null) {
+ interfaze.setName(name);
+ }
+ getParams().add(interfaze);
+ }
+ };
+ ChangeCommand cmd = new ChangeCommand(
+ modelImpl, run, "Create the interface # owned by #");
+ editingDomain.getCommandStack().execute(cmd);
+ cmd.setObjects(run.getParams().get(0), owner);
+
+ return (Interface) run.getParams().get(0);
}
public Object buildMethod(String name) {
- // TODO Auto-generated method stub
- return null;
+ // TODO: Is this removed from UML2 ?
+ throw new NotImplementedException();
}
@SuppressWarnings("deprecation")
public Operation buildOperation(Object classifier, Object model,
Object returnType) {
- // TODO Auto-generated method stub
- return null;
+ return buildOperation2(classifier, returnType, null);
}
public Operation buildOperation(Object classifier, Object returnType) {
- // TODO Auto-generated method stub
- return null;
+ return buildOperation2(classifier, returnType, null);
}
@SuppressWarnings("deprecation")
public Operation buildOperation(Object cls, Object model,
Object returnType, String name) {
- // TODO Auto-generated method stub
- return null;
+ return buildOperation2(cls, returnType, name);
}
- public Operation buildOperation2(Object cls, Object returnType,
- String name) {
- // TODO Auto-generated method stub
- return null;
+ public Operation buildOperation2(final Object cls, final Object returnType,
+ final String name) {
+ if ((returnType != null && !(returnType instanceof Type))
+ || !(cls instanceof Type)) {
+ throw new IllegalArgumentException(
+ "cls and returnType must be instances of Type."); //$NON-NLS-1$
+ }
+ if (UMLUtil.getOwnedOperations((Type) cls) == null) {
+ throw new UnsupportedOperationException(
+ "The type " + cls.getClass() //$NON-NLS-1$
+ + " does not support owning operations."); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ Operation operation = createOperation();
+ UMLUtil.getOwnedOperations((Type) cls).add(operation);
+ operation.createReturnResult(null, (Type) returnType);
+ if (name != null) {
+ operation.setName(name);
+ }
+ getParams().add(operation);
+ }
+ };
+ ChangeCommand cmd = new ChangeCommand(
+ modelImpl, run, "Create the operation # owned by #");
+ editingDomain.getCommandStack().execute(cmd);
+ cmd.setObjects(run.getParams().get(0), cls);
+
+ return (Operation) run.getParams().get(0);
}
@SuppressWarnings("deprecation")
public Parameter buildParameter(Object o, Object model, Object type) {
- // TODO Auto-generated method stub
- return null;
+ return buildParameter(o, type);
}
- public Parameter buildParameter(Object o, Object type) {
- // TODO Auto-generated method stub
- return null;
+ public Parameter buildParameter(final Object o, final Object type) {
+ // TODO: In UML2.x Event has no parameters. The Event metaclass in
+ // UML1.x corresponds to the Trigger metaclass in UML2.x (see UML
+ // Superstructure page 456).
+ if (!(o instanceof BehavioralFeature)) {
+ throw new IllegalArgumentException(
+ "The parameter must be attached to a BehavioralFeature."); //$NON-NLS-1$
+ }
+ if (!(type instanceof Type)) {
+ throw new IllegalArgumentException(
+ "The type of the parameter must be instance of Type."); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ Parameter param = createParameter();
+ param.setType((Type) type);
+ ((BehavioralFeature) o).getOwnedParameters().add(param);
+ getParams().add(param);
+ }
+ };
+ ChangeCommand cmd = new ChangeCommand(
+ modelImpl, run, "Create the parameter # owned by #");
+ editingDomain.getCommandStack().execute(cmd);
+ cmd.setObjects(run.getParams().get(0), o);
+
+ return (Parameter) run.getParams().get(0);
}
+
/**
* Removed from UML2.x, use buildPackageImport instead.
*/
@@ -372,16 +924,17 @@
return buildPackageImport(client, supplier);
}
- public PackageImport buildPackageAccess(final Object client,
- final Object supplier) {
- PackageImport packageImport = buildPackageImport(client, supplier);
- // TODO: Do we care if this is undoable?
- packageImport.setVisibility(VisibilityKind.PACKAGE_LITERAL);
- return packageImport;
- }
-
- public PackageImport buildPackageImport(final Object client,
- final Object supplier) {
+ public PackageImport buildPackageAccess(Object client, Object supplier) {
+ return buildPackageImport(
+ client, supplier, VisibilityKind.PRIVATE_LITERAL);
+ }
+
+ public PackageImport buildPackageImport(Object client, Object supplier) {
+ return buildPackageImport(client, supplier, null);
+ }
+
+ private PackageImport buildPackageImport(final Object client,
+ final Object supplier, final VisibilityKind visibility) {
if (!(client instanceof Namespace)) {
throw new IllegalArgumentException(
"The client must be instance of Namespace."); //$NON-NLS-1$
@@ -395,149 +948,206 @@
PackageImport packageImport = createPackageImport();
packageImport.setImportedPackage((org.eclipse.uml2.uml.Package) supplier);
packageImport.setImportingNamespace((Namespace) client);
+ if (visibility != null) {
+ packageImport.setVisibility(visibility);
+ }
getParams().add(packageImport);
}
};
- editingDomain.getCommandStack().execute(
- new ChangeCommand(editingDomain, run, "Create a PackageImport"));
+ ChangeCommand cmd = new ChangeCommand(
+ modelImpl, run,
+ "Create the package import # between the client # and the supplier #");
+ editingDomain.getCommandStack().execute(cmd);
+ cmd.setObjects(run.getParams().get(0), client, supplier);
return (PackageImport) run.getParams().get(0);
}
- public InterfaceRealization buildRealization(Object client,
- Object supplier, Object namespace) {
- // TODO: namespace is ignored
- InterfaceRealization realization =
- ((BehavioredClassifier) client).createInterfaceRealization(
- null, (Interface) supplier);
- return realization;
+
+ public InterfaceRealization buildRealization(final Object client,
+ final Object supplier, Object namespace) {
+ // The interface realization will be created in the client namespace
+ // (client is a namespace)
+ if (!(client instanceof BehavioredClassifier)) {
+ throw new IllegalArgumentException(
+ "The client must be instance of BehavioredClassifier"); //$NON-NLS-1$
+ }
+ if (!(supplier instanceof Interface)) {
+ throw new IllegalArgumentException(
+ "The supplier must be an Interface"); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ InterfaceRealization realization =
+ UMLFactory.eINSTANCE.createInterfaceRealization();
+ realization.setImplementingClassifier(
+ (BehavioredClassifier) client);
+ realization.setContract((Interface) supplier);
+ ((BehavioredClassifier) client).getInterfaceRealizations()
+ .add(realization);
+ getParams().add(realization);
+ }
+ };
+ ChangeCommand cmd = new ChangeCommand(
+ modelImpl, run,
+ "Create the interface realization # between" //$NON-NLS-1$
+ + " the client # and the supplier #"); //$NON-NLS-1$
+ editingDomain.getCommandStack().execute(cmd);
+ cmd.setObjects(run.getParams().get(0), client, supplier);
+
+ return (InterfaceRealization) run.getParams().get(0);
}
public Object buildTemplateArgument(Object element) {
- // TODO Auto-generated method stub
- return null;
+ // TODO: Is this removed from UML2 ?
+ throw new NotImplementedException();
}
- public Usage buildUsage(Object client, Object supplier) {
- // TODO Auto-generated method stub
- return null;
+ public Usage buildUsage(final Object client, final Object supplier) {
+ if (!(client instanceof NamedElement)
+ || !(supplier instanceof NamedElement)) {
+ throw new IllegalArgumentException(
+ "The client and the supplier must be NamedElements."); //$NON-NLS-1$
+ }
+ if (((NamedElement) client).getNearestPackage() == null) {
+ throw new NullPointerException(
+ "The client is not contained in a package."); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ Usage usage = createUsage();
+ usage.getClients().add((NamedElement) client);
+ usage.getSuppliers().add((NamedElement) supplier);
+ ((NamedElement) client).getNearestPackage()
+ .getPackagedElements().add(usage);
+ getParams().add(usage);
+ }
+ };
+ ChangeCommand cmd = new ChangeCommand(
+ modelImpl, run,
+ "Create the usage # between the client # and the supplier #");
+ editingDomain.getCommandStack().execute(cmd);
+ cmd.setObjects(run.getParams().get(0), client, supplier);
+
+ return (Usage) run.getParams().get(0);
}
public Object copyClass(Object source, Object ns) {
- // TODO Auto-generated method stub
- return null;
+ return modelImpl.getCopyHelper().copy(source, ns);
}
public Object copyDataType(Object source, Object ns) {
- // TODO Auto-generated method stub
- return null;
+ return modelImpl.getCopyHelper().copy(source, ns);
}
public Object copyFeature(Object source, Object classifier) {
- // TODO Auto-generated method stub
- return null;
+ return modelImpl.getCopyHelper().copy(source, classifier);
}
public Object copyInterface(Object source, Object ns) {
- // TODO Auto-generated method stub
- return null;
+ return modelImpl.getCopyHelper().copy(source, ns);
}
public Abstraction createAbstraction() {
- return uml.createAbstraction();
+ return UMLFactory.eINSTANCE.createAbstraction();
}
public Artifact createArtifact() {
- return uml.createArtifact();
+ return UMLFactory.eINSTANCE.createArtifact();
}
public Association createAssociation() {
- return uml.createAssociation();
+ return UMLFactory.eINSTANCE.createAssociation();
}
public AssociationClass createAssociationClass() {
- return uml.createAssociationClass();
+ return UMLFactory.eINSTANCE.createAssociationClass();
}
public Property createAssociationEnd() {
- // TODO: Double check - tfm
- return uml.createProperty();
+ return UMLFactory.eINSTANCE.createProperty();
}
public Property createAttribute() {
- // TODO: Double check - tfm
- return uml.createProperty();
+ return UMLFactory.eINSTANCE.createProperty();
}
+ /**
+ * Removed from UML2.x, use createTemplateBinding instead.
+ */
+ @Deprecated
public TemplateBinding createBinding() {
- return uml.createTemplateBinding();
+ return createTemplateBinding();
+ }
+
+ public TemplateBinding createTemplateBinding() {
+ return UMLFactory.eINSTANCE.createTemplateBinding();
}
public org.eclipse.uml2.uml.Class createClass() {
- return uml.createClass();
+ return UMLFactory.eINSTANCE.createClass();
}
public Comment createComment() {
- return uml.createComment();
+ return UMLFactory.eINSTANCE.createComment();
}
- public Object createComponent() {
- // TODO Auto-generated method stub
- return null;
+ public Component createComponent() {
+ return UMLFactory.eINSTANCE.createComponent();
}
public Constraint createConstraint() {
- return uml.createConstraint();
+ return UMLFactory.eINSTANCE.createConstraint();
}
public DataType createDataType() {
- return uml.createDataType();
+ return UMLFactory.eINSTANCE.createDataType();
}
public Dependency createDependency() {
- return uml.createDependency();
+ return UMLFactory.eINSTANCE.createDependency();
}
public Object createElementResidence() {
- // TODO Auto-generated method stub
- return null;
+ // TODO: Is this removed from UML2 ?
+ throw new NotImplementedException();
}
public Enumeration createEnumeration() {
- return uml.createEnumeration();
+ return UMLFactory.eINSTANCE.createEnumeration();
}
public EnumerationLiteral createEnumerationLiteral() {
- return uml.createEnumerationLiteral();
+ return UMLFactory.eINSTANCE.createEnumerationLiteral();
}
public Object createFlow() {
- // TODO Auto-generated method stub
- return null;
+ // TODO: Is this removed from UML2 ?
+ throw new NotImplementedException();
}
public Generalization createGeneralization() {
- return uml.createGeneralization();
+ return UMLFactory.eINSTANCE.createGeneralization();
}
public Interface createInterface() {
- return uml.createInterface();
+ return UMLFactory.eINSTANCE.createInterface();
}
public Object createMethod() {
- // TODO Auto-generated method stub
- return null;
+ // TODO: Is this removed from UML2 ?
+ throw new NotImplementedException();
}
public Node createNode() {
- return uml.createNode();
+ return UMLFactory.eINSTANCE.createNode();
}
public Operation createOperation() {
- return uml.createOperation();
+ return UMLFactory.eINSTANCE.createOperation();
}
public Parameter createParameter() {
- return uml.createParameter();
+ return UMLFactory.eINSTANCE.createParameter();
}
/**
@@ -551,14 +1161,14 @@
public PackageImport createPackageImport() {
return UMLFactory.eINSTANCE.createPackageImport();
}
-
+
@SuppressWarnings("deprecation")
public Object createPrimitive() {
return createPrimitiveType();
}
public PrimitiveType createPrimitiveType() {
- return uml.createPrimitiveType();
+ return UMLFactory.eINSTANCE.createPrimitiveType();
}
@SuppressWarnings("deprecation")
@@ -568,17 +1178,16 @@
}
public Object createTemplateArgument() {
- // TODO Auto-generated method stub
- return null;
+ // TODO: Is this removed from UML2 ?
+ throw new NotImplementedException();
}
public TemplateParameter createTemplateParameter() {
- return uml.createTemplateParameter();
+ return UMLFactory.eINSTANCE.createTemplateParameter();
}
public Usage createUsage() {
- return uml.createUsage();
+ return UMLFactory.eINSTANCE.createUsage();
}
-
}
Modified: trunk/src/model-euml/src/org/argouml/model/euml/CoreHelperEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-euml/src/org/argouml/model/euml/CoreHelperEUMLImpl.java?view=diff&rev=13462&p1=trunk/src/model-euml/src/org/argouml/model/euml/CoreHelperEUMLImpl.java&p2=trunk/src/model-euml/src/org/argouml/model/euml/CoreHelperEUMLImpl.java&r1=13461&r2=13462
==============================================================================
--- trunk/src/model-euml/src/org/argouml/model/euml/CoreHelperEUMLImpl.java (original)
+++ trunk/src/model-euml/src/org/argouml/model/euml/CoreHelperEUMLImpl.java 2007-08-30 11:48:34-0700
@@ -26,34 +26,55 @@
package org.argouml.model.euml;
+import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashSet;
+import java.util.LinkedList;
import java.util.List;
import org.argouml.model.CoreHelper;
import org.argouml.model.NotImplementedException;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.edit.command.AddCommand;
+import org.eclipse.emf.edit.command.CommandParameter;
+import org.eclipse.emf.edit.command.RemoveCommand;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.uml2.uml.AggregationKind;
import org.eclipse.uml2.uml.Association;
+import org.eclipse.uml2.uml.Behavior;
import org.eclipse.uml2.uml.BehavioralFeature;
import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.Comment;
+import org.eclipse.uml2.uml.Constraint;
+import org.eclipse.uml2.uml.DataType;
import org.eclipse.uml2.uml.Dependency;
+import org.eclipse.uml2.uml.DirectedRelationship;
import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.Extend;
+import org.eclipse.uml2.uml.Enumeration;
+import org.eclipse.uml2.uml.EnumerationLiteral;
import org.eclipse.uml2.uml.Feature;
import org.eclipse.uml2.uml.Generalization;
-import org.eclipse.uml2.uml.Include;
+import org.eclipse.uml2.uml.Interface;
+import org.eclipse.uml2.uml.MultiplicityElement;
import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.Namespace;
+import org.eclipse.uml2.uml.Node;
import org.eclipse.uml2.uml.Operation;
-import org.eclipse.uml2.uml.PackageableElement;
+import org.eclipse.uml2.uml.Parameter;
+import org.eclipse.uml2.uml.ParameterDirectionKind;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.RedefinableElement;
+import org.eclipse.uml2.uml.Relationship;
+import org.eclipse.uml2.uml.Stereotype;
import org.eclipse.uml2.uml.StructuralFeature;
import org.eclipse.uml2.uml.Type;
import org.eclipse.uml2.uml.TypedElement;
+import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.VisibilityKind;
-
/**
* Eclipse UML2 implementation of CoreHelper.
*/
@@ -64,283 +85,610 @@
*/
private EUMLModelImplementation modelImpl;
+ private EditingDomain editingDomain;
+
/**
* Constructor.
- *
- * @param implementation The ModelImplementation.
+ *
+ * @param implementation
+ * The ModelImplementation.
*/
public CoreHelperEUMLImpl(EUMLModelImplementation implementation) {
modelImpl = implementation;
+ editingDomain = implementation.getEditingDomain();
}
- public void addAllStereotypes(Object modelElement, Collection stereos) {
- throw new NotYetImplementedException();
-
+ public void addAllStereotypes(final Object modelElement,
+ final Collection stereos) {
+ if (!(modelElement instanceof Element)) {
+ throw new IllegalArgumentException(
+ "modelElement must be instance of Element"); //$NON-NLS-1$
+ }
+ if (stereos == null) {
+ throw new NullPointerException(
+ "stereos must be non-null"); //$NON-NLS-1$
+ }
+ for (Object o : stereos) {
+ if (!(o instanceof Stereotype)) {
+ throw new IllegalArgumentException(
+ "The stereotypes from stereo collection" //$NON-NLS-1$
+ + " must be instances of Stereotype"); //$NON-NLS-1$
+ }
+ if (!((Element) modelElement).isStereotypeApplicable((Stereotype) o)) {
+ throw new UnsupportedOperationException(
+ "The stereotype " + o //$NON-NLS-1$
+ + " cannot be applied to " + modelElement); //$NON-NLS-1$
+ }
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ for (Object o : stereos) {
+ ((Element) modelElement).applyStereotype((Stereotype) o);
+ }
+ }
+ };
+ ChangeCommand cmd;
+ if (stereos.size() == 1) {
+ cmd = new ChangeCommand(
+ modelImpl, run, "Apply the stereotype # to the element #",
+ stereos.iterator().next(), modelElement);
+ } else {
+ cmd = new ChangeCommand(
+ modelImpl, run, "Apply # stereotypes to the element #",
+ stereos.size(), modelElement);
+ }
+ editingDomain.getCommandStack().execute(cmd);
}
- public void addAnnotatedElement(Object comment, Object annotatedElement) {
- throw new NotYetImplementedException();
-
+ public void addAnnotatedElement(final Object comment,
+ final Object annotatedElement) {
+ if (!(annotatedElement instanceof Element)) {
+ throw new IllegalArgumentException(
+ "annotatedElement must be instance of Element"); //$NON-NLS-1$
+ }
+ if (!(comment instanceof Comment)) {
+ throw new IllegalArgumentException(
+ "comment must be instance of Comment"); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ ((Comment) comment).getAnnotatedElements().add(
+ (Element) annotatedElement);
+ }
+ };
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, run, "Add the comment # to the element #",
+ comment, annotatedElement));
}
- public void addClient(Object dependency, Object element) {
- throw new NotYetImplementedException();
+ public void addClient(final Object dependency, final Object element) {
+ if (!(dependency instanceof Dependency)) {
+ throw new IllegalArgumentException(
+ "The dependency must be instance of Dependency"); //$NON-NLS-1$
+ }
+ if (!(element instanceof NamedElement)) {
+ throw new IllegalArgumentException(
+ "The element must be instance of NamedElement"); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ ((Dependency) dependency).getClients().add(
+ (NamedElement) element);
+ }
+ };
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, run, "Add the client # to the dependency #",
+ element, dependency));
}
public void addClientDependency(Object handle, Object dependency) {
- throw new NotYetImplementedException();
-
+ addClient(dependency, handle);
}
public void addComment(Object element, Object comment) {
- throw new NotYetImplementedException();
-
+ addAnnotatedElement(comment, element);
}
public void addConnection(Object handle, Object connection) {
- throw new NotYetImplementedException();
-
+ addConnection(handle, CommandParameter.NO_INDEX, connection);
}
public void addConnection(Object handle, int position, Object connection) {
- throw new NotYetImplementedException();
-
+ if (!(handle instanceof Association)) {
+ throw new IllegalArgumentException(
+ "The handle must be instance of Association"); //$NON-NLS-1$
+ }
+ if (!(connection instanceof Property)) {
+ throw new IllegalArgumentException(
+ "The connection must be instance of Property"); //$NON-NLS-1$
+ }
+ RunnableClass run = getRunnableClassForAddCommand(
+ (Association) handle, position, (Property) connection);
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl,
+ run,
+ "Add the AssociationEnd (Property) # to the Association #",
+ connection, handle));
}
- public void addConstraint(Object handle, Object mc) {
- throw new NotYetImplementedException();
-
+ public void addConstraint(final Object handle, final Object mc) {
+ if (!(handle instanceof Element)) {
+ throw new IllegalArgumentException(
+ "The handle must be instance of Element"); //$NON-NLS-1$
+ }
+ if (!(mc instanceof Constraint)) {
+ throw new IllegalArgumentException(
+ "mc must be instance of Constraint"); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ ((Constraint) mc).getConstrainedElements().add((Element) handle);
+ }
+ };
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, run,
+ "Add the constraint # to the element #", mc, handle));
}
public void addDeploymentLocation(Object handle, Object node) {
+ // TODO: Implement
throw new NotYetImplementedException();
-
}
public void addElementResidence(Object handle, Object residence) {
+ // TODO Is it removed from UML2 ?
throw new NotYetImplementedException();
-
+ }
+
+ private RunnableClass getRunnableClassForAddCommand(Element owner,
+ Element element) {
+ return getRunnableClassForAddCommand(
+ owner, CommandParameter.NO_INDEX, element);
+ }
+
+ private RunnableClass getRunnableClassForAddCommand(Element owner,
+ int index, Element element) {
+ final Command cmd = AddCommand.create(
+ editingDomain, owner, null, element, index);
+ if (cmd == null || !cmd.canExecute()) {
+ throw new UnsupportedOperationException(
+ "The element " + element + " cannot be added to the element " + owner); //$NON-NLS-1$//$NON-NLS-2$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ cmd.execute();
+ }
+ };
+ return run;
+ }
+
+ private RunnableClass getRunnableClassForRemoveCommand(Element element) {
+ final Command cmd = RemoveCommand.create(editingDomain, element);
+ if (cmd == null || !cmd.canExecute()) {
+ String s = "The element " + element; //$NON-NLS-1$
+ if (element.getOwner() != null) {
+ s += ", owned by " + element.getOwner() + ", "; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ s += " cannot be removed"; //$NON-NLS-1$
+ throw new UnsupportedOperationException(s);
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ cmd.execute();
+ }
+ };
+ return run;
}
public void addFeature(Object handle, int index, Object f) {
- throw new NotYetImplementedException();
-
+ if (!(handle instanceof Classifier)) {
+ throw new IllegalArgumentException(
+ "The handle must be instance of Classifier"); //$NON-NLS-1$
+ }
+ if (!(f instanceof Feature)) {
+ throw new IllegalArgumentException("f must be instance of Feature"); //$NON-NLS-1$
+ }
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, getRunnableClassForAddCommand(
+ (Classifier) handle, index, (Feature) f),
+ "Add the feature # to the classifier #", f, handle));
}
public void addFeature(Object handle, Object f) {
- throw new NotYetImplementedException();
-
+ addFeature(handle, CommandParameter.NO_INDEX, f);
}
public void addLink(Object handle, Object link) {
+ // A Link is an Assocation in UML2.x
throw new NotYetImplementedException();
-
}
public void addLiteral(Object handle, int index, Object literal) {
- throw new NotYetImplementedException();
-
+ if (!(handle instanceof Enumeration)) {
+ throw new IllegalArgumentException(
+ "The handle must be instance of Enumeration"); //$NON-NLS-1$
+ }
+ if (!(literal instanceof EnumerationLiteral)) {
+ throw new IllegalArgumentException(
+ "literal must be instance of EnumerationLiteral"); //$NON-NLS-1$
+ }
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, getRunnableClassForAddCommand(
+ (Enumeration) handle, index,
+ (EnumerationLiteral) literal),
+ "Add the EnumerationLiteral # to the Enumeration #",
+ literal, handle));
+ }
+
+ public void addMethod(final Object handle, final Object method) {
+ // In UML2.x there is no metaclass named Method, but we could use the
+ // 'method' association of BehavioralFeature
+ // TODO: It's OK like this?
+ if (!(handle instanceof BehavioralFeature)) {
+ throw new IllegalArgumentException(
+ "The handle must be instance of BehavioralFeature"); //$NON-NLS-1$
+ }
+ if (!(method instanceof Behavior)) {
+ throw new IllegalArgumentException(
+ "method must be instance of Behavior"); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ ((BehavioralFeature) handle).getMethods().add((Behavior) method);
+ }
+ };
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl,
+ run,
+ "Add the Behavior (method) # to the BehavioralFeature (operation) #",
+ method, handle));
}
-
- public void addMethod(Object handle, Object method) {
- throw new NotYetImplementedException();
+
+ public void addOwnedElement(Object handle, Object me, String msg,
+ Object... objects) {
+ if (!(handle instanceof Namespace)) {
+ throw new IllegalArgumentException(
+ "The handle must be instance of Namespace"); //$NON-NLS-1$
+ }
+ if (!(me instanceof Element)) {
+ throw new IllegalArgumentException(
+ "'me' must be instance of Element"); //$NON-NLS-1$
+ }
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(modelImpl, getRunnableClassForAddCommand(
+ (Namespace) handle, (Element) me), msg, objects));
}
public void addOwnedElement(Object handle, Object me) {
- if (handle instanceof org.eclipse.uml2.uml.Package
- && me instanceof Type) {
- ((org.eclipse.uml2.uml.Package) handle).getOwnedTypes().add(
- (Type) me);
- } else if (handle instanceof org.eclipse.uml2.uml.Package
- && me instanceof PackageableElement) {
- ((org.eclipse.uml2.uml.Package) handle).getPackagedElements().add(
- (PackageableElement) me);
- } else {
- throw new NotYetImplementedException();
- }
+ addOwnedElement(handle, me, "Add the owned element # to the owner #", me, handle);
}
public void addParameter(Object handle, int index, Object parameter) {
- throw new NotYetImplementedException();
+ // TODO: In UML2.x Event has no parameters.
+ // TODO: Treat ObjectFlowState (this doesn't exist anymore in UML2) and Classifier
+ if (!(handle instanceof BehavioralFeature)) {
+ throw new IllegalArgumentException(
+ "handle must be instance of BehavioralFeature"); //$NON-NLS-1$
+ }
+ if (!(parameter instanceof Parameter)) {
+ throw new IllegalArgumentException(
+ "parameter must be instance of Parameter"); //$NON-NLS-1$
+ }
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, getRunnableClassForAddCommand(
+ (BehavioralFeature) handle, index,
+ (Parameter) parameter),
+ "Add the owned element # to the owner #", parameter,
+ handle));
}
public void addParameter(Object handle, Object parameter) {
- throw new NotYetImplementedException();
-
+ addParameter(handle, CommandParameter.NO_INDEX, parameter);
}
public void addQualifier(Object handle, int position, Object qualifier) {
- throw new NotYetImplementedException();
-
+ if (!(handle instanceof Property) || !(qualifier instanceof Property)) {
+ throw new IllegalArgumentException(
+ "handle and qualifier must be instances of Property"); //$NON-NLS-1$
+ }
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, getRunnableClassForAddCommand(
+ (Property) handle, position,
+ (Property) qualifier),
+ "Add the qualifier # to the property #", qualifier,
+ handle));
}
public void addRaisedSignal(Object handle, Object sig) {
+ // TODO: implement
throw new NotYetImplementedException();
-
}
public void addSourceFlow(Object handle, Object flow) {
+ // TODO: implement
throw new NotYetImplementedException();
-
}
public void addStereotype(Object modelElement, Object stereo) {
- throw new NotYetImplementedException();
-
+ addAllStereotypes(modelElement, Collections.singleton(stereo));
}
- public void addSupplier(Object handle, Object element) {
- throw new NotYetImplementedException();
-
+ public void addSupplier(final Object dependency, final Object element) {
+ if (!(dependency instanceof Dependency)) {
+ throw new IllegalArgumentException(
+ "The dependency must be instance of Dependency"); //$NON-NLS-1$
+ }
+ if (!(element instanceof NamedElement)) {
+ throw new IllegalArgumentException(
+ "The element must be instance of NamedElement"); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ ((Dependency) dependency).getSuppliers().add(
+ (NamedElement) element);
+ }
+ };
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, run,
+ "Add the supplier # to the dependency #", element,
+ dependency));
}
public void addSupplierDependency(Object supplier, Object dependency) {
- throw new NotYetImplementedException();
-
+ addSupplier(dependency, supplier);
}
public void addTaggedValue(Object handle, Object taggedValue) {
+ // TODO: implement
throw new NotYetImplementedException();
-
}
public void addTargetFlow(Object handle, Object flow) {
+ // TODO: implement
throw new NotYetImplementedException();
-
}
public void addTemplateArgument(Object handle, int index, Object argument) {
+ // TODO Is it removed from UML2 ?
throw new NotYetImplementedException();
-
}
public void addTemplateArgument(Object handle, Object argument) {
+ // TODO Is it removed from UML2 ?
throw new NotYetImplementedException();
-
}
public void addTemplateParameter(Object handle, int index, Object parameter) {
+ // TODO: implement
throw new NotYetImplementedException();
-
}
public void addTemplateParameter(Object handle, Object parameter) {
+ // TODO: implement
throw new NotYetImplementedException();
-
}
public void clearStereotypes(Object handle) {
+ // TODO: implement
throw new NotYetImplementedException();
-
}
public boolean equalsAggregationKind(Object associationEnd, String kindType) {
- throw new NotYetImplementedException();
-
+ if (!(associationEnd instanceof Property)) {
+ throw new IllegalArgumentException(
+ "associationEnd must be instance of Property"); //$NON-NLS-1$
+ }
+ return ((Property) associationEnd).getAggregation().getLiteral().equals(
+ kindType);
}
public Collection getAllAttributes(Object classifier) {
- throw new NotYetImplementedException();
-
+ if (!(classifier instanceof Classifier)) {
+ throw new IllegalArgumentException(
+ "classifier must be instance of Classifier"); //$NON-NLS-1$
+ }
+ Collection result = new HashSet();
+ result.addAll(((Classifier) classifier).getAttributes());
+ for (Classifier c : ((Classifier) classifier).allParents()) {
+ result.addAll(c.getAttributes());
+ }
+ return result;
}
public Collection getAllBehavioralFeatures(Object element) {
- throw new NotYetImplementedException();
-
+ return modelImpl.getModelManagementHelper().getAllModelElementsOfKind(element, BehavioralFeature.class);
}
public Collection getAllClasses(Object ns) {
- throw new NotYetImplementedException();
-
+ return modelImpl.getModelManagementHelper().getAllModelElementsOfKind(ns, org.eclipse.uml2.uml.Class.class);
}
public Collection getAllClassifiers(Object namespace) {
- throw new NotYetImplementedException();
-
+ return modelImpl.getModelManagementHelper().getAllModelElementsOfKind(namespace, Classifier.class);
}
public Collection getAllComponents(Object ns) {
- throw new NotYetImplementedException();
-
+ return modelImpl.getModelManagementHelper().getAllModelElementsOfKind(ns, org.eclipse.uml2.uml.Component.class);
}
public Collection getAllContents(Object namespace) {
- throw new NotYetImplementedException();
-
+ return modelImpl.getModelManagementHelper().getAllContents(namespace);
}
public Collection getAllDataTypes(Object ns) {
- throw new NotYetImplementedException();
-
+ return modelImpl.getModelManagementHelper().getAllModelElementsOfKind(ns, DataType.class);
}
public Collection getAllInterfaces(Object ns) {
- throw new NotYetImplementedException();
-
+ return modelImpl.getModelManagementHelper().getAllModelElementsOfKind(ns, Interface.class);
}
public Collection getAllMetatypeNames() {
- throw new NotYetImplementedException();
-
+ Collection result = new ArrayList();
+ for (Field f : UMLPackage.Literals.class.getDeclaredFields()) {
+ Object o;
+ try {
+ o = f.get(null);
+ } catch (IllegalArgumentException e) {
+ throw e;
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ if (o instanceof EClass) {
+ result.add(((EClass) o).getName());
+ }
+ }
+ return result;
}
public Collection getAllNodes(Object ns) {
- throw new NotYetImplementedException();
-
+ return modelImpl.getModelManagementHelper().getAllModelElementsOfKind(ns, Node.class);
}
public Collection getAllPossibleNamespaces(Object modelElement, Object model) {
- // TODO: Dummy implementation that just returns the current namespace hierarchy
- Collection<Namespace> result = new ArrayList<Namespace>();
- result.addAll(((NamedElement) modelElement).allNamespaces());
+ if (!(model instanceof Element) || !(modelElement instanceof Element)) {
+ throw new IllegalArgumentException(
+ "modelElement and model must be instances of Element"); //$NON-NLS-1$
+ }
+ Collection result = new ArrayList();
+ if (isValidNamespace(modelElement, model)) {
+ result.add((Namespace) model);
+ }
+ for (Object o : modelImpl.getModelManagementHelper().getAllModelElementsOfKind(
+ model, Namespace.class)) {
+ if (isValidNamespace(modelElement, o)) {
+ result.add((Namespace) o);
+ }
+ }
return result;
}
public Collection getAllRealizedInterfaces(Object element) {
- return ((Classifier) element).getAllUsedInterfaces();
+ if (!(element instanceof org.eclipse.uml2.uml.Class)) {
+ throw new IllegalArgumentException(
+ "element must be instance of UML2 Class"); //$NON-NLS-1$
+ }
+ return ((org.eclipse.uml2.uml.Class) element).getAllImplementedInterfaces();
}
public Collection getAllSupertypes(Object classifier) {
+ if (!(classifier instanceof Classifier)) {
+ throw new IllegalArgumentException(
+ "classifier must be instance of Classifier"); //$NON-NLS-1$
+ }
return ((Classifier) classifier).allParents();
}
public Collection getAllVisibleElements(Object ns) {
- throw new NotYetImplementedException();
+ if (!(ns instanceof Namespace)) {
+ throw new IllegalArgumentException(
+ "ns must be instance of Namespace"); //$NON-NLS-1$
+ }
+ Collection result = new ArrayList();
+ for (NamedElement e : ((Namespace) ns).getOwnedMembers()) {
+ if (e.getVisibility() == VisibilityKind.PUBLIC_LITERAL) {
+ result.add(e);
+ }
+ }
+ return result;
}
public Collection getAssociateEnds(Object classifier) {
- throw new NotYetImplementedException();
+ return modelImpl.getFacade().getAssociationEnds(classifier);
}
public Collection getAssociateEndsInh(Object classifier) {
- throw new NotYetImplementedException();
+ if (!(classifier instanceof Classifier)) {
+ throw new IllegalArgumentException(
+ "classifier must be instance of Classifier"); //$NON-NLS-1$
+ }
+ Collection result = new ArrayList();
+ result.addAll(getAssociateEnds(classifier));
+ for (Classifier o : ((Classifier) classifier).allParents()) {
+ result.addAll(getAssociateEnds(o));
+ }
+ return result;
}
public Collection getAssociatedClassifiers(Object aclassifier) {
- throw new NotYetImplementedException();
-
+ if (!(aclassifier instanceof Classifier)) {
+ throw new IllegalArgumentException(
+ "aclassifier must be instance of Classifier"); //$NON-NLS-1$
+ }
+ Collection result = new ArrayList();
+ for (Association a : ((Classifier) aclassifier).getAssociations()) {
+ for (Type t : a.getEndTypes()) {
+ if (t != aclassifier && t instanceof Classifier) {
+ result.add((Classifier) t);
+ }
+ }
+ }
+ return result;
}
public Object getAssociationEnd(Object type, Object assoc) {
- throw new NotYetImplementedException();
+ if (!(type instanceof Classifier)) {
+ throw new IllegalArgumentException(
+ "type must be instance of Classifier"); //$NON-NLS-1$
+ }
+ if (!(assoc instanceof Association)) {
+ throw new IllegalArgumentException(
+ "assoc must be instance of Association"); //$NON-NLS-1$
+ }
+ return ((Association) assoc).getMemberEnd(null, (Classifier) type);
}
public Collection getAssociations(Object from, Object to) {
- throw new NotYetImplementedException();
-
+ // TODO: The javadoc specifies that null should be returned if 'from' or
+ // 'to' are null or if there are no associations between them. We should
+ // return an empty collection instead and the javadoc should be changed.
+ if (from == null || to == null) {
+ return Collections.EMPTY_LIST;
+ }
+ if (!(from instanceof Classifier) || !(to instanceof Classifier)) {
+ throw new IllegalArgumentException(
+ "'from' and 'to' must be instances of Classifier"); //$NON-NLS-1$
+ }
+ Collection result = new ArrayList();
+ for (Association a : ((Classifier) from).getAssociations()) {
+ if (((Classifier) to).getAssociations().contains(a)) {
+ result.add(a);
+ }
+ }
+ return result;
}
- public Collection getAssociations(Object oclassifier) {
- throw new NotYetImplementedException();
-
+ public Collection getAssociations(Object classifier) {
+ if (!(classifier instanceof Classifier)) {
+ throw new IllegalArgumentException(
+ "'classifier' must be instance of Classifier"); //$NON-NLS-1$
+ }
+ return ((Classifier) classifier).getAssociations();
}
public Collection getAttributesInh(Object classifier) {
- throw new NotYetImplementedException();
-
+ if (!(classifier instanceof Classifier)) {
+ throw new IllegalArgumentException(
+ "'classifier' must be instance of Classifier"); //$NON-NLS-1$
+ }
+ return ((Classifier) classifier).getAllAttributes();
}
public List<BehavioralFeature> getBehavioralFeatures(Object classifier) {
+ if (!(classifier instanceof Classifier)) {
+ throw new IllegalArgumentException(
+ "'classifier' must be instance of Classifier"); //$NON-NLS-1$
+ }
List<BehavioralFeature> result = new ArrayList<BehavioralFeature>();
for (Feature feature : ((Classifier) classifier).getFeatures()) {
if (feature instanceof BehavioralFeature) {
@@ -351,361 +699,599 @@
}
public String getBody(Object comment) {
- throw new NotYetImplementedException();
-
+ if (!(comment instanceof Comment)) {
+ throw new IllegalArgumentException(
+ "'comment' must be instance of Comment"); //$NON-NLS-1$
+ }
+ return ((Comment) comment).getBody();
}
public Collection<Classifier> getChildren(Object element) {
+ if (!(element instanceof Classifier)) {
+ throw new IllegalArgumentException(
+ "'element' must be instance of Classifier"); //$NON-NLS-1$
+ }
Collection<Classifier> results = new HashSet<Classifier>();
- for (Generalization g : ((Classifier) element).getGeneralizations()) {
- results.addAll(getChildren(g.getSpecific()));
+ LinkedList<Classifier> classifiers = new LinkedList<Classifier>();
+ classifiers.add((Classifier) element);
+ while (!classifiers.isEmpty()) {
+ Classifier c = classifiers.removeFirst();
+ if (results.contains(c)) {
+ break;
+ }
+ results.add(c);
+ for (DirectedRelationship d : c.getTargetDirectedRelationships(UMLPackage.Literals.GENERALIZATION)) {
+ for (Element e : d.getSources()) {
+ if (e instanceof Classifier && !results.contains(e)) {
+ classifiers.add((Classifier) e);
+ }
+ }
+ }
}
results.remove(element);
return results;
}
public Collection getDependencies(Object supplierObj, Object clientObj) {
- throw new NotYetImplementedException();
-
+ if (!(supplierObj instanceof NamedElement) || !(clientObj instanceof NamedElement)) {
+ throw new IllegalArgumentException(
+ "supplierObj and clientObj must be instances of NamedElement"); //$NON-NLS-1$
+ }
+ Collection result = new ArrayList();
+ for (Dependency d : ((NamedElement) clientObj).getClientDependencies()) {
+ if (d.getSuppliers().contains(supplierObj)) {
+ result.add(d);
+ }
+ }
+ return result;
}
public Collection getExtendedClassifiers(Object element) {
- throw new NotYetImplementedException();
-
+ // TODO: Does CoreHelper#getExtendedClassifiers(Object element) means
+ // all parents (direct and indirect) or only the direct parents?
+ if (!(element instanceof Classifier)) {
+ throw new IllegalArgumentException(
+ "'element' must be instance of Classifier"); //$NON-NLS-1$
+ }
+ return ((Classifier) element).getGenerals();
}
- public Collection getExtendingClassifiers(Object classifier) {
- throw new NotYetImplementedException();
-
+ public Collection<Element> getExtendingClassifiers(Object classifier) {
+ // TODO: Does CoreHelper#getExtendingClassifiers(Object element) means
+ // all direct and indirect extending classifiers or only the direct
+ // extending classifiers?
+ if (!(classifier instanceof Classifier)) {
+ throw new IllegalArgumentException(
+ "'classifier' must be instance of Classifier"); //$NON-NLS-1$
+ }
+ Collection<Element> result = new HashSet<Element>();
+ for (Element e : getExtendingElements(classifier)) {
+ if (e instanceof Classifier) {
+ result.add(e);
+ }
+ }
+ return result;
}
- public Collection getExtendingElements(Object element) {
- throw new NotYetImplementedException();
-
+ public Collection<Element> getExtendingElements(Object element) {
+ if (!(element instanceof Classifier)) {
+ throw new IllegalArgumentException(
+ "'element' must be instance of Classifier"); //$NON-NLS-1$
+ }
+ Collection<Element> result = new HashSet<Element>();
+ for (DirectedRelationship d : ((Classifier) element)
+ .getTargetDirectedRelationships(UMLPackage.Literals.GENERALIZATION)) {
+ for (Element e : d.getSources()) {
+ result.add(e);
+ }
+ }
+ return result;
}
public Object getFirstSharedNamespace(Object ns1, Object ns2) {
- throw new NotYetImplementedException();
-
+ if (!(ns1 instanceof Namespace) || !(ns2 instanceof Namespace)) {
+ throw new IllegalArgumentException(
+ "ns1 and ns2 must be instances of Namespace"); //$NON-NLS-1$
+ }
+ Namespace result = null;
+ List<Namespace> l1 = new ArrayList<Namespace>();
+ l1.add((Namespace) ns1);
+ l1.addAll(((Namespace) ns1).allNamespaces());
+ List<Namespace> l2 = new ArrayList<Namespace>();
+ l2.add((Namespace) ns2);
+ l2.addAll(((Namespace) ns2).allNamespaces());
+ int i = l1.size() - 1;
+ int j = l2.size() - 1;
+ while (i >= 0 && j >= 0) {
+ if (l1.get(i) == l2.get(j)) {
+ result = l1.get(i);
+ i--;
+ j--;
+ } else {
+ break;
+ }
+ }
+ return result;
}
public Collection getFlows(Object source, Object target) {
+ // TODO: implement
throw new NotYetImplementedException();
-
}
public Object getGeneralization(Object achild, Object aparent) {
- throw new NotYetImplementedException();
-
+ if (!(achild instanceof Classifier)
+ || !(aparent instanceof Classifier)) {
+ throw new IllegalArgumentException(
+ "'achild' and 'aparent' must "
+ + "be instances of Classifier"); //$NON-NLS-1$
+ }
+ return ((Classifier) achild).getGeneralization((Classifier) aparent);
}
public Collection getOperationsInh(Object classifier) {
- throw new NotYetImplementedException();
-
- }
-
- public Collection getParents(Object generalizableElement) {
- throw new NotYetImplementedException();
-
+ if (!(classifier instanceof Classifier)) {
+ throw new IllegalArgumentException(
+ "'classifier' must be instance of Classifier"); //$NON-NLS-1$
+ }
+ return ((Classifier) classifier).getAllOperations();
}
public Collection getRealizedInterfaces(Object cls) {
- throw new NotYetImplementedException();
-
+ if (!(cls instanceof org.eclipse.uml2.uml.Class)) {
+ throw new IllegalArgumentException(
+ "'cls' must be instance of UML2 Class"); //$NON-NLS-1$
+ }
+ return ((org.eclipse.uml2.uml.Class) cls).getImplementedInterfaces();
}
- public Collection getRelationships(Object source, Object dest) {
- throw new NotYetImplementedException();
-
+ public Collection<DirectedRelationship> getRelationships(Object source, Object dest) {
+ if (!(source instanceof Element) || !(dest instanceof Element)) {
+ throw new IllegalArgumentException(
+ "'source' and 'dest' must be instances of Element"); //$NON-NLS-1$
+ }
+ Collection<DirectedRelationship> result = new ArrayList<DirectedRelationship>();
+ for (DirectedRelationship d : ((Element) source)
+ .getSourceDirectedRelationships()) {
+ if (d.getTargets().contains(dest)) {
+ result.add(d);
+ }
+ }
+ for (DirectedRelationship d : ((Element) source)
+ .getTargetDirectedRelationships()) {
+ if (d.getSources().contains(dest)) {
+ result.add(d);
+ }
+ }
+ return result;
}
- public List getReturnParameters(Object operation) {
- throw new NotYetImplementedException();
-
+ public List<Parameter> getReturnParameters(Object operation) {
+ if (!(operation instanceof Operation)) {
+ throw new IllegalArgumentException(
+ "'operation' must be instance of Operation"); //$NON-NLS-1$
+ }
+ List<Parameter> result = new ArrayList<Parameter>();
+ for (Parameter p : ((Operation) operation).getOwnedParameters()) {
+ if (p.getDirection() == ParameterDirectionKind.RETURN_LITERAL) {
+ result.add(p);
+ }
+ }
+ return result;
}
public Object getSource(Object relationship) {
+ // Link does not exist in UML2, a link is represented just as an
+ // association
+
+ // TODO: treat Message
// TODO: not implemented for UML 2 - tfm
-// if (relationship instanceof Link) {
-// Iterator it =
-// modelImpl.getFacade()
-// .getConnections(relationship).iterator();
-// if (it.hasNext()) {
-// return modelImpl.getFacade().getInstance(it.next());
-// } else {
-// return null;
-// }
-// }
+ // } else if (relationship instanceof Flow) {
+ // Flow flow = (Flow) relationship;
+ // Collection col = flow.getSource();
+ // if (col.isEmpty()) {
+ // return null;
+ // }
+ // return (col.toArray())[0];
+
+ if (!(relationship instanceof Relationship)
+ && !(relationship instanceof Property)) {
+ throw new IllegalArgumentException(
+ "'relationship' must be instance of Relationship or Property"); //$NON-NLS-1$
+ }
+
if (relationship instanceof Association) {
- Association assoc = (Association) relationship;
- List conns = assoc.getMemberEnds();
- if (conns == null || conns.isEmpty()) {
+ List<Property> conns = ((Association) relationship).getMemberEnds();
+ if (conns.size() < 2) {
return null;
}
- // TODO: double check this - tfm
- return ((Property) conns.get(0)).getType();
- } else if (relationship instanceof Generalization) {
- Generalization gen = (Generalization) relationship;
- return gen.getSpecific();
- } else if (relationship instanceof Dependency) {
- Dependency dep = (Dependency) relationship;
- List col = dep.getClients();
- if (col.isEmpty()) {
+ return conns.get(1).getType();
+ }
+ if (relationship instanceof DirectedRelationship) {
+ List<Element> sources = ((DirectedRelationship) relationship)
+ .getSources();
+ if (sources.isEmpty()) {
return null;
}
- return col.get(0);
- // TODO: not implemented for UML 2 - tfm
-// } else if (relationship instanceof Flow) {
-// Flow flow = (Flow) relationship;
-// Collection col = flow.getSource();
-// if (col.isEmpty()) {
-// return null;
-// }
-// return (col.toArray())[0];
- } else if (relationship instanceof Extend) {
- Extend extend = (Extend) relationship;
- return extend.getExtension(); // we have to follow the
- // arrows..
- } else if (relationship instanceof Include) {
- Include include = (Include) relationship;
- return modelImpl.getFacade().getBase(include);
- } else if (relationship instanceof Property) {
+ return sources.get(0);
+ }
+ if (relationship instanceof Property) {
return ((Property) relationship).getAssociation();
- } else {
- throw new IllegalArgumentException();
}
-
+ return null;
}
-
-
+
public Object getDestination(Object relationship) {
+ // Link does not exist in UML2, a link is represented just as an
+ // association
-// if (relationship instanceof Link) {
-// Iterator it = modelImpl.getFacade()
-// .getConnections(relationship).iterator();
-// if (it.hasNext()) {
-// it.next();
-// if (it.hasNext()) {
-// return modelImpl.getFacade().getInstance(it.next());
-// } else {
-// return null;
-// }
-// } else {
-// return null;
-// }
-// }
+ // TODO: treat Message
+
+ // TODO: not implemented for UML 2 - tfm
+ // } else if (relationship instanceof Flow) {
+ // Flow flow = (Flow) relationship;
+ // Collection col = flow.getTarget();
+ // if (col.isEmpty()) {
+ // return null;
+ // }
+ // return getFirstItemOrNull(col);
+
+ if (!(relationship instanceof Relationship)
+ && !(relationship instanceof Property)) {
+ throw new IllegalArgumentException(
+ "'relationship' must be instance of Relationship or Property"); //$NON-NLS-1$
+ }
if (relationship instanceof Association) {
- Association assoc = (Association) relationship;
- List conns = assoc.getMemberEnds();
- if (conns.size() <= 1) {
+ List<Property> conns = ((Association) relationship).getMemberEnds();
+ if (conns.isEmpty()) {
return null;
}
- return ((Property) conns.get(1)).getType();
- } else if (relationship instanceof Generalization) {
- Generalization gen = (Generalization) relationship;
- return gen.getGeneral();
- } else if (relationship instanceof Dependency) {
- Dependency dep = (Dependency) relationship;
- List col = dep.getSuppliers();
- if (col.isEmpty()) {
+ return conns.get(0).getType();
+ }
+ if (relationship instanceof DirectedRelationship) {
+ List<Element> targets = ((DirectedRelationship) relationship).getTargets();
+ if (targets.isEmpty()) {
return null;
}
- return col.get(0);
-// } else if (relationship instanceof Flow) {
-// Flow flow = (Flow) relationship;
-// Collection col = flow.getTarget();
-// if (col.isEmpty()) {
-// return null;
-// }
-// return getFirstItemOrNull(col);
- } else if (relationship instanceof Extend) {
- Extend extend = (Extend) relationship;
- return extend.getExtendedCase();
- } else if (relationship instanceof Include) {
- Include include = (Include) relationship;
- return modelImpl.getFacade().getAddition(include);
- } else if (relationship instanceof Property) {
- return ((Property) relationship).getType();
- } else {
- throw new IllegalArgumentException();
+ return targets.get(0);
}
-
+ if (relationship instanceof Property) {
+ return ((Property) relationship).getAssociation();
+ }
+ return null;
}
-
public Object getSpecification(Object object) {
+ // In UML2 the metaclass Method does not exists
throw new NotYetImplementedException();
-
}
public Collection getSpecifications(Object classifier) {
- throw new NotYetImplementedException();
-
+ return getRealizedInterfaces(classifier);
}
- public Collection getSubtypes(Object cls) {
- throw new NotYetImplementedException();
-
+ public Collection<Element> getSubtypes(Object cls) {
+ if (!(cls instanceof Classifier)) {
+ throw new IllegalArgumentException(
+ "'cls' must be instance of Classifier"); //$NON-NLS-1$
+ }
+ Collection<Element> results = new HashSet<Element>();
+ for (DirectedRelationship d : ((Classifier) cls)
+ .getTargetDirectedRelationships(UMLPackage.Literals.GENERALIZATION)) {
+ results.addAll(d.getSources());
+ }
+ return results;
}
public Collection getSupertypes(Object generalizableElement) {
- throw new NotYetImplementedException();
-
+ if (!(generalizableElement instanceof Classifier)) {
+ throw new IllegalArgumentException(
+ "'generalizableElement' must be instance of Classifier"); //$NON-NLS-1$
+ }
+ return ((Classifier) generalizableElement).getGenerals();
}
public boolean hasCompositeEnd(Object association) {
- throw new NotYetImplementedException();
-
+ if (!(association instanceof Association)) {
+ throw new IllegalArgumentException(
+ "'association' must be instance of Association"); //$NON-NLS-1$
+ }
+ for (Property p : ((Association) association).getMemberEnds()) {
+ if (p.getAggregation() == AggregationKind.COMPOSITE_LITERAL) {
+ return true;
+ }
+ }
+ return false;
}
public boolean isSubType(Object type, Object subType) {
- throw new NotYetImplementedException();
-
+ if (!(type instanceof Class) || !(subType instanceof Class)) {
+ throw new IllegalArgumentException(
+ "type and subType must be instances of java.lang.Class"); //$NON-NLS-1$
+ }
+ return ((Class) type).isAssignableFrom((Class) subType);
}
public boolean isValidNamespace(Object element, Object namespace) {
-
- if (!(element instanceof Element)
+ if (!(element instanceof NamedElement)
|| !(namespace instanceof Namespace)) {
return false;
}
-
- Element e = (Element) element;
- Namespace ns = (Namespace) namespace;
-
- // TODO: Needs implementation - for now anything is valid
-
+ if (((NamedElement) element).getNamespace() == namespace) {
+ return true;
+ }
+ try {
+ RunnableClass run = getRunnableClassForAddCommand(
+ (Namespace) namespace, (NamedElement) element);
+ } catch (UnsupportedOperationException e) {
+ return false;
+ }
return true;
}
- public void removeAnnotatedElement(Object handle, Object me) {
- throw new NotYetImplementedException();
-
+ public void removeAnnotatedElement(final Object comment,
+ final Object annotatedElement) {
+ if (!(annotatedElement instanceof Element)) {
+ throw new IllegalArgumentException(
+ "annotatedElement must be instance of Element"); //$NON-NLS-1$
+ }
+ if (!(comment instanceof Comment)) {
+ throw new IllegalArgumentException(
+ "comment must be instance of Comment"); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ ((Comment) comment).getAnnotatedElements().remove(
+ (Element) annotatedElement);
+ }
+ };
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl,
+ run,
+ "Remove the link between the comment # and the element #",
+ comment, annotatedElement));
}
- public void removeClientDependency(Object handle, Object dep) {
- throw new NotYetImplementedException();
-
+ public void removeClientDependency(final Object handle, final Object dep) {
+ if (!(handle instanceof NamedElement)) {
+ throw new IllegalArgumentException(
+ "handle must be instance of NamedElement"); //$NON-NLS-1$
+ }
+ if (!(dep instanceof Dependency)) {
+ throw new IllegalArgumentException(
+ "dep must be instance of Dependency"); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ ((NamedElement) handle).getClientDependencies().remove(dep);
+ }
+ };
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, run,
+ "Remove the client dependency # from the element #",
+ handle, dep));
}
- public void removeConnection(Object handle, Object connection) {
- throw new NotYetImplementedException();
-
+ public void removeConnection(final Object handle, final Object connection) {
+ if (!(handle instanceof Association)) {
+ throw new IllegalArgumentException(
+ "handle must be instance of Association"); //$NON-NLS-1$
+ }
+ if (!(connection instanceof Property)) {
+ throw new IllegalArgumentException(
+ "connection must be instance of Property"); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ if (((Association) handle).getOwnedEnds().contains(connection)) {
+ ((Association) handle).getOwnedEnds().remove(connection);
+ }
+ if (((Property) connection).getAssociation() == handle) {
+ ((Property) connection).setAssociation(null);
+ }
+ }
+ };
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, run,
+ "Remove the association end # from the association #",
+ connection, handle));
}
public void removeConstraint(Object handle, Object cons) {
throw new NotYetImplementedException();
-
}
public void removeDeploymentLocation(Object handle, Object node) {
throw new NotYetImplementedException();
-
}
public void removeElementResidence(Object handle, Object residence) {
throw new NotYetImplementedException();
-
}
public void removeFeature(Object cls, Object feature) {
- throw new NotYetImplementedException();
-
+ removeOwnedElement(cls, feature);
}
public void removeLiteral(Object enumeration, Object literal) {
- throw new NotYetImplementedException();
-
+ removeOwnedElement(enumeration, literal);
}
public void removeOwnedElement(Object handle, Object value) {
- throw new NotYetImplementedException();
-
+ if (!(handle instanceof Element)) {
+ throw new IllegalArgumentException(
+ "handle must be instance of Element"); //$NON-NLS-1$
+ }
+ if (!(value instanceof Element)) {
+ throw new IllegalArgumentException(
+ "value must be instance of Element"); //$NON-NLS-1$
+ }
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl,
+ getRunnableClassForRemoveCommand((Element) value),
+ "Remove the element # from the owner #", value, handle));
}
public void removeParameter(Object handle, Object parameter) {
- throw new NotYetImplementedException();
-
+ removeOwnedElement(handle, parameter);
}
public void removeQualifier(Object handle, Object qualifier) {
- throw new NotYetImplementedException();
-
+ removeOwnedElement(handle, qualifier);
}
public void removeSourceFlow(Object handle, Object flow) {
throw new NotYetImplementedException();
-
}
public void removeStereotype(Object handle, Object stereo) {
throw new NotYetImplementedException();
-
}
- public void removeSupplierDependency(Object supplier, Object dependency) {
- throw new NotYetImplementedException();
-
+ public void removeSupplierDependency(final Object supplier,
+ final Object dependency) {
+ if (!(supplier instanceof NamedElement)) {
+ throw new IllegalArgumentException(
+ "supplier must be instance of NamedElement"); //$NON-NLS-1$
+ }
+ if (!(dependency instanceof Dependency)) {
+ throw new IllegalArgumentException(
+ "dependency must be instance of Dependency"); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ ((Dependency) dependency).getSuppliers().remove(supplier);
+ }
+ };
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, run,
+ "Remove the supplier # from the dependency #",
+ supplier, dependency));
}
public void removeTargetFlow(Object handle, Object flow) {
throw new NotYetImplementedException();
-
}
public void removeTemplateArgument(Object binding, Object argument) {
throw new NotYetImplementedException();
-
}
public void removeTemplateParameter(Object handle, Object parameter) {
throw new NotYetImplementedException();
-
}
- public void setAbstract(Object handle, boolean isAbstract) {
- if (handle instanceof Classifier) {
- ((Classifier) handle).setIsAbstract(isAbstract);
- } else if (handle instanceof BehavioralFeature) {
- ((BehavioralFeature) handle).setIsAbstract(isAbstract);
- } else {
- throw new IllegalArgumentException();
+ public void setAbstract(final Object handle, final boolean isAbstract) {
+ if (!(handle instanceof Classifier)
+ && !(handle instanceof BehavioralFeature)) {
+ throw new IllegalArgumentException(
+ "handle must be instance of Classifier or BehavioralFeature"); //$NON-NLS-1$
}
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ if (handle instanceof Classifier) {
+ ((Classifier) handle).setIsAbstract(isAbstract);
+ } else if (handle instanceof BehavioralFeature) {
+ ((BehavioralFeature) handle).setIsAbstract(isAbstract);
+ }
+ }
+ };
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, run, "Set isAbstract to # for #",
+ isAbstract, handle));
}
- public void setActive(Object handle, boolean isActive) {
- ((org.eclipse.uml2.uml.Class) handle).setIsActive(isActive);
+ public void setActive(final Object handle, final boolean isActive) {
+ if (!(handle instanceof org.eclipse.uml2.uml.Class)) {
+ throw new IllegalArgumentException(
+ "handle must be instance of UML2 Class"); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ ((org.eclipse.uml2.uml.Class) handle).setIsActive(isActive);
+ }
+ };
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, run, "Set isActive to # for #", isActive,
+ handle));
}
- public void setAggregation(Object handle, Object aggregationKind) {
- throw new NotYetImplementedException();
+ public void setAggregation(final Object handle, final Object aggregationKind) {
+ if (!(handle instanceof Property)) {
+ throw new IllegalArgumentException(
+ "handle must be instance of Property"); //$NON-NLS-1$
+ }
+ if (!(aggregationKind instanceof AggregationKind)) {
+ throw new IllegalArgumentException(
+ "aggregationKind must be instance of AggregationKind"); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ ((Property) handle).setAggregation((AggregationKind) aggregationKind);
+ }
+ };
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, run,
+ "Set the aggregation # to the association end #",
+ aggregationKind, handle));
}
- public void setAnnotatedElements(Object handle, Collection elems) {
- throw new NotYetImplementedException();
-
+ public void setAnnotatedElements(final Object handle, final Collection elems) {
+ if (!(handle instanceof Comment)) {
+ throw new IllegalArgumentException(
+ "handle must be instance of Comment"); //$NON-NLS-1$
+ }
+ if (!(elems == null)) {
+ throw new NullPointerException("elems must be non-null"); //$NON-NLS-1$
+ }
+ for (Object o : elems) {
+ if (!(o instanceof Element)) {
+ throw new IllegalArgumentException(
+ "the collection must contain only instances of Element"); //$NON-NLS-1$
+ }
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ ((Comment) handle).getAnnotatedElements().clear();
+ for (Object o : elems) {
+ ((Comment) handle).getAnnotatedElements().add((Element) o);
+ }
+ }
+ };
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, run,
+ "Set # annotated alements for the comment #",
+ elems.size(), handle));
}
public void setAssociation(Object handle, Object association) {
throw new NotYetImplementedException();
-
}
public void setAttributes(Object classifier, List attributes) {
throw new NotYetImplementedException();
-
}
public void setBody(Object handle, Object expr) {
throw new NotYetImplementedException();
-
}
public void setBody(Object handle, String body) {
- throw new NotYetImplementedException();
-
+ if (!(handle instanceof Comment)) {
+ throw new IllegalArgumentException();
+ }
+ ((Comment) handle).setBody(body);
}
@SuppressWarnings("deprecation")
@@ -718,34 +1304,46 @@
setReadOnly(handle, !changeable);
}
- public void setChild(Object handle, Object child) {
- throw new NotYetImplementedException();
-
+ public void setChild(final Object handle, final Object child) {
+ if (!(handle instanceof Generalization)) {
+ throw new IllegalArgumentException(
+ "handle must be instance of Generalization"); //$NON-NLS-1$
+ }
+ if (!(child instanceof Classifier)) {
+ throw new IllegalArgumentException(
+ "child must be instance of Classifier"); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ ((Generalization) handle).setSpecific((Classifier) child);
+ }
+ };
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl,
+ run,
+ "Set the # as the specific classifier of the generalization #",
+ child, handle));
}
public void setConcurrency(Object handle, Object concurrencyKind) {
throw new NotYetImplementedException();
-
}
public void setConnections(Object handle, Collection ends) {
throw new NotYetImplementedException();
-
}
public void setContainer(Object handle, Object component) {
throw new NotYetImplementedException();
-
}
public void setDefaultElement(Object handle, Object element) {
throw new NotYetImplementedException();
-
}
public void setDefaultValue(Object handle, Object expression) {
throw new NotYetImplementedException();
-
}
public void setDiscriminator(Object handle, String discriminator) {
@@ -755,31 +1353,37 @@
public void setEnumerationLiterals(Object enumeration, List literals) {
throw new NotYetImplementedException();
-
}
public void setFeature(Object classifier, int index, Object feature) {
throw new NotYetImplementedException();
-
}
public void setFeatures(Object classifier, Collection features) {
throw new NotYetImplementedException();
-
}
public void setInitialValue(Object attribute, Object expression) {
throw new NotYetImplementedException();
-
}
public void setKind(Object handle, Object kind) {
throw new NotYetImplementedException();
-
}
- public void setLeaf(Object handle, boolean isLeaf) {
- ((RedefinableElement) handle).setIsLeaf(isLeaf);
+ public void setLeaf(final Object handle, final boolean isLeaf) {
+ if (!(handle instanceof RedefinableElement)) {
+ throw new IllegalArgumentException(
+ "handle must be instance of RedefinableElement"); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ ((RedefinableElement) handle).setIsLeaf(isLeaf);
+ }
+ };
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, run, "Set isLeaf to # for #", isLeaf, handle));
}
public void setModelElementContainer(Object handle, Object container) {
@@ -787,30 +1391,87 @@
addOwnedElement(container, handle);
}
- public void setMultiplicity(Object handle, Object arg) {
- throw new NotYetImplementedException();
-
+ public void setMultiplicity(final Object handle, Object arg) {
+ if (arg == null) {
+ return;
+ }
+ if (!(handle instanceof MultiplicityElement)) {
+ throw new IllegalArgumentException();
+ }
+ if (arg instanceof String) {
+ int lower = 1, upper = 1;
+ try {
+ int i = Integer.parseInt((String) arg);
+ lower = i;
+ upper = i;
+ } catch (NumberFormatException e) {
+ // TODO: lower..upper
+ throw new NotYetImplementedException();
+ }
+ final int lower_ = lower, upper_ = upper;
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ ((MultiplicityElement) handle).setLower(lower_);
+ ((MultiplicityElement) handle).setUpper(upper_);
+ }
+ };
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, run,
+ "Set the multiplicity # to the element #", arg,
+ handle));
+ } else {
+ throw new NotYetImplementedException();
+ }
}
- public void setName(Object handle, String name) {
- ((NamedElement) handle).setName(name);
+ public void setName(final Object handle, final String name) {
+ if (!(handle instanceof NamedElement)) {
+ throw new IllegalArgumentException(
+ "handle must be instance of NamedElement"); //$NON-NLS-1$
+ }
+ if (name == null) {
+ throw new NullPointerException("name must be non-null"); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ ((NamedElement) handle).setName(name);
+ }
+ };
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, run,
+ "Set the name \"#\" to the named element #",
+ name, handle));
}
public void setNamespace(Object handle, Object ns) {
addOwnedElement(ns, handle);
}
- public void setNavigable(Object handle, boolean flag) {
- ((Property) handle).setIsNavigable(flag);
+ public void setNavigable(final Object handle, final boolean flag) {
+ if (!(handle instanceof Property)) {
+ throw new IllegalArgumentException(
+ "handle must be instance of Property"); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ ((Property) handle).setIsNavigable(flag);
+ }
+ };
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, run,
+ "Set isNavigable to # for the association end #", flag,
+ handle));
}
public void setOperations(Object classifier, List operations) {
throw new NotYetImplementedException();
-
}
public void setOrdering(Object handle, Object ordering) {
-// ((Property) handle).setIsOrdered(ordering);
+ // ((Property) handle).setIsOrdered(ordering);
throw new NotYetImplementedException();
}
@@ -826,50 +1487,85 @@
public void setParameter(Object handle, Object parameter) {
throw new NotYetImplementedException();
-
}
public void setParameters(Object handle, Collection parameters) {
throw new NotYetImplementedException();
-
}
- public void setParent(Object handle, Object parent) {
- throw new NotYetImplementedException();
-
+ public void setParent(final Object handle, final Object parent) {
+ if (!(handle instanceof Generalization)) {
+ throw new IllegalArgumentException(
+ "handle must be instance of Generalization"); //$NON-NLS-1$
+ }
+ if (!(parent instanceof Classifier)) {
+ throw new IllegalArgumentException(
+ "parent must be instance of Classifier"); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ ((Generalization) handle).setGeneral((Classifier) parent);
+ }
+ };
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl,
+ run,
+ "Set the # as the general classifier of the generalization #",
+ parent, handle));
}
public void setPowertype(Object handle, Object powerType) {
throw new NotYetImplementedException();
-
}
public void setQualifiers(Object handle, List qualifiers) {
throw new NotYetImplementedException();
-
}
- public void setQuery(Object handle, boolean isQuery) {
- ((Operation) handle).setIsQuery(isQuery);
+ public void setQuery(final Object handle, final boolean isQuery) {
+ if (!(handle instanceof Operation)) {
+ throw new IllegalArgumentException(
+ "handle must be instance of Operation"); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ ((Operation) handle).setIsQuery(isQuery);
+ }
+ };
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, run, "Set isQuery to # for the operation #",
+ isQuery, handle));
}
public void setRaisedSignals(Object handle, Collection raisedSignals) {
throw new NotYetImplementedException();
-
}
-
- public void setReadOnly(Object handle, boolean isReadOnly) {
- ((StructuralFeature) handle).setIsReadOnly(isReadOnly);
+
+ public void setReadOnly(final Object handle, final boolean isReadOnly) {
+ if (!(handle instanceof StructuralFeature)) {
+ throw new IllegalArgumentException(
+ "handle must be instance of StructuralFeature"); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ ((StructuralFeature) handle).setIsReadOnly(isReadOnly);
+ }
+ };
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, run,
+ "Set isReadOnly to # for the structural feature #",
+ isReadOnly, handle));
}
public void setResident(Object handle, Object resident) {
throw new NotYetImplementedException();
-
}
public void setResidents(Object handle, Collection residents) {
throw new NotYetImplementedException();
-
}
public void setRoot(Object handle, boolean isRoot) {
@@ -879,12 +1575,10 @@
public void setSources(Object handle, Collection specifications) {
throw new NotYetImplementedException();
-
}
public void setSpecification(Object handle, boolean isSpecification) {
throw new NotYetImplementedException();
-
}
public void setSpecification(Object method, Object specification) {
@@ -897,21 +1591,30 @@
public void setSpecifications(Object handle, Collection specifications) {
throw new NotYetImplementedException();
-
}
-
- public void setStatic(Object feature, boolean isStatic) {
- ((Feature) feature).setIsStatic(isStatic);
+
+ public void setStatic(final Object feature, final boolean isStatic) {
+ if (!(feature instanceof Feature)) {
+ throw new IllegalArgumentException(
+ "feature must be instance of Feature"); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ ((Feature) feature).setIsStatic(isStatic);
+ }
+ };
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, run, "Set isStatic to # for the feature #",
+ isStatic, feature));
}
public void setTaggedValue(Object handle, String tag, String value) {
throw new NotYetImplementedException();
-
}
public void setTaggedValues(Object handle, Collection taggedValues) {
throw new NotYetImplementedException();
-
}
@SuppressWarnings("deprecation")
@@ -920,12 +1623,48 @@
throw new NotImplementedException();
}
- public void setType(Object handle, Object type) {
- ((TypedElement) handle).setType((Type) type);
+ public void setType(final Object handle, final Object type) {
+ if (!(handle instanceof TypedElement)) {
+ throw new IllegalArgumentException(
+ "handle must be instance of TypedElement"); //$NON-NLS-1$
+ }
+ if (!(type instanceof Type)) {
+ throw new IllegalArgumentException("type must be instance of Type"); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ ((TypedElement) handle).setType((Type) type);
+ }
+ };
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, run,
+ "Set the type # for the typed element #", type, handle));
+ }
+
+ public void setVisibility(final Object handle, final Object visibility) {
+ if (!(handle instanceof NamedElement)) {
+ throw new IllegalArgumentException(
+ "handle must be instance of NamedElement"); //$NON-NLS-1$
+ }
+ if (!(visibility instanceof VisibilityKind)) {
+ throw new IllegalArgumentException(
+ "visibility must be instance of VisibilityKind"); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ ((NamedElement) handle).setVisibility((VisibilityKind) visibility);
+ }
+ };
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, run,
+ "Set the visibility # to the named element #",
+ visibility, handle));
}
- public void setVisibility(Object handle, Object visibility) {
- ((NamedElement) handle).setVisibility((VisibilityKind) visibility);
+ public Collection getParents(Object generalizableElement) {
+ throw new NotYetImplementedException();
}
public Object getPackageImport(Object supplier, Object client) {
Modified: trunk/src/model-euml/src/org/argouml/model/euml/DataTypesFactoryEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-euml/src/org/argouml/model/euml/DataTypesFactoryEUMLImpl.java?view=diff&rev=13462&p1=trunk/src/model-euml/src/org/argouml/model/euml/DataTypesFactoryEUMLImpl.java&p2=trunk/src/model-euml/src/org/argouml/model/euml/DataTypesFactoryEUMLImpl.java&r1=13461&r2=13462
==============================================================================
--- trunk/src/model-euml/src/org/argouml/model/euml/DataTypesFactoryEUMLImpl.java (original)
+++ trunk/src/model-euml/src/org/argouml/model/euml/DataTypesFactoryEUMLImpl.java 2007-08-30 11:48:34-0700
@@ -31,7 +31,6 @@
import org.argouml.model.AbstractModelFactory;
import org.argouml.model.DataTypesFactory;
import org.argouml.model.NotImplementedException;
-import org.eclipse.uml2.uml.Expression;
import org.eclipse.uml2.uml.OpaqueExpression;
import org.eclipse.uml2.uml.UMLFactory;
@@ -92,23 +91,25 @@
// change in the way multiplicities work - tfm
public Object createMultiplicity(int lower, int upper) {
- return new NotImplementedException();
+ throw new NotImplementedException();
}
public Object createMultiplicity(List range) {
- return new NotImplementedException();
+ throw new NotImplementedException();
}
public Object createMultiplicity(String str) {
- return new NotImplementedException();
+ // TODO: This does not exist as a specific element in UML2
+ // As a workaround we return the string as the multiplicity
+ return str;
}
public Object createMultiplicityRange(String str) {
- return new NotImplementedException();
+ throw new NotImplementedException();
}
public Object createMultiplicityRange(int lower, int upper) {
- return new NotImplementedException();
+ throw new NotImplementedException();
}
public Object createObjectSetExpression(String language, String body) {
@@ -137,7 +138,7 @@
if (i == -1) {
return "*";
} else {
- return "" + i;
+ return Integer.toString(i);
}
}
@@ -155,8 +156,8 @@
return Integer.parseInt(b);
}
} catch (Exception ex) {
- throw new IllegalArgumentException("illegal range bound : "
- + (b == null ? "null" : b));
+ throw new IllegalArgumentException(
+ "illegal range bound : " + b); //$NON-NLS-1$
}
}
Modified: trunk/src/model-euml/src/org/argouml/model/euml/DataTypesHelperEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-euml/src/org/argouml/model/euml/DataTypesHelperEUMLImpl.java?view=diff&rev=13462&p1=trunk/src/model-euml/src/org/argouml/model/euml/DataTypesHelperEUMLImpl.java&p2=trunk/src/model-euml/src/org/argouml/model/euml/DataTypesHelperEUMLImpl.java&r1=13461&r2=13462
==============================================================================
--- trunk/src/model-euml/src/org/argouml/model/euml/DataTypesHelperEUMLImpl.java (original)
+++ trunk/src/model-euml/src/org/argouml/model/euml/DataTypesHelperEUMLImpl.java 2007-08-30 11:48:34-0700
@@ -50,8 +50,7 @@
}
public void copyTaggedValues(Object from, Object to) {
- // TODO Auto-generated method stub
-
+ throw new NotYetImplementedException();
}
public boolean equalsCHOICEKind(Object kind) {
@@ -100,6 +99,9 @@
}
public String multiplicityToString(Object multiplicity) {
+ if (!(multiplicity instanceof MultiplicityElement)) {
+ throw new IllegalArgumentException("multiplicity must be instance of MultiplicityElement"); //$NON-NLS-1$
+ }
MultiplicityElement mult = (MultiplicityElement) multiplicity;
if (mult.getLower() == mult.getUpper()) {
return DataTypesFactoryEUMLImpl.boundToString(mult.getLower());
@@ -110,7 +112,6 @@
+ DataTypesFactoryEUMLImpl.boundToString(mult.getUpper());
}
}
-
public Object setBody(Object handle, String body) {
// TODO Auto-generated method stub
@@ -122,5 +123,4 @@
return null;
}
-
}
Modified: trunk/src/model-euml/src/org/argouml/model/euml/EUMLModelImplementation.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-euml/src/org/argouml/model/euml/EUMLModelImplementation.java?view=diff&rev=13462&p1=trunk/src/model-euml/src/org/argouml/model/euml/EUMLModelImplementation.java&p2=trunk/src/model-euml/src/org/argouml/model/euml/EUMLModelImplementation.java&r1=13461&r2=13462
==============================================================================
--- trunk/src/model-euml/src/org/argouml/model/euml/EUMLModelImplementation.java (original)
+++ trunk/src/model-euml/src/org/argouml/model/euml/EUMLModelImplementation.java 2007-08-30 11:48:34-0700
@@ -42,58 +42,28 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
-import java.util.EventObject;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
-import org.argouml.model.ActivityGraphsFactory;
-import org.argouml.model.ActivityGraphsHelper;
-import org.argouml.model.AggregationKind;
-import org.argouml.model.ChangeableKind;
-import org.argouml.model.CollaborationsFactory;
-import org.argouml.model.CollaborationsHelper;
-import org.argouml.model.CommonBehaviorFactory;
-import org.argouml.model.CommonBehaviorHelper;
-import org.argouml.model.ConcurrencyKind;
-import org.argouml.model.CopyHelper;
-import org.argouml.model.CoreFactory;
-import org.argouml.model.CoreHelper;
-import org.argouml.model.DataTypesFactory;
-import org.argouml.model.DataTypesHelper;
import org.argouml.model.DiagramInterchangeModel;
-import org.argouml.model.DirectionKind;
-import org.argouml.model.ExtensionMechanismsFactory;
-import org.argouml.model.ExtensionMechanismsHelper;
-import org.argouml.model.Facade;
-import org.argouml.model.MetaTypes;
import org.argouml.model.ModelImplementation;
-import org.argouml.model.ModelManagementFactory;
-import org.argouml.model.ModelManagementHelper;
-import org.argouml.model.OrderingKind;
-import org.argouml.model.PseudostateKind;
-import org.argouml.model.ScopeKind;
-import org.argouml.model.StateMachinesFactory;
-import org.argouml.model.StateMachinesHelper;
import org.argouml.model.UmlException;
-import org.argouml.model.UmlFactory;
-import org.argouml.model.UmlHelper;
-import org.argouml.model.UseCasesFactory;
-import org.argouml.model.UseCasesHelper;
-import org.argouml.model.VisibilityKind;
-import org.argouml.model.XmiReader;
-import org.argouml.model.XmiWriter;
import org.eclipse.emf.common.command.BasicCommandStack;
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.common.command.CommandStack;
-import org.eclipse.emf.common.command.CommandStackListener;
+import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.ecore.provider.EcoreItemProviderAdapterFactory;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.uml2.common.edit.domain.UML2AdapterFactoryEditingDomain;
import org.eclipse.uml2.uml.UMLPackage;
+import org.eclipse.uml2.uml.edit.providers.UMLItemProviderAdapterFactory;
+import org.eclipse.uml2.uml.edit.providers.UMLReflectiveItemProviderAdapterFactory;
+import org.eclipse.uml2.uml.edit.providers.UMLResourceItemProviderAdapterFactory;
import org.eclipse.uml2.uml.resource.UML22UMLExtendedMetaData;
import org.eclipse.uml2.uml.resource.UML22UMLResource;
import org.eclipse.uml2.uml.resource.UMLResource;
@@ -121,71 +91,73 @@
private static final Logger LOG =
Logger.getLogger(EUMLModelImplementation.class);
- private ActivityGraphsFactory theActivityGraphsFactory;
+ private ActivityGraphsFactoryEUMLlImpl theActivityGraphsFactory;
- private ActivityGraphsHelper theActivityGraphsHelper;
+ private ActivityGraphsHelperEUMLImpl theActivityGraphsHelper;
- private AggregationKind theAggregationKind;
+ private AggregationKindEUMLImpl theAggregationKind;
@SuppressWarnings("deprecation")
- private ChangeableKind theChangeableKind;
+ private ChangeableKindEUMLImpl theChangeableKind;
- private CollaborationsFactory theCollaborationsFactory;
+ private CollaborationsFactoryEUMLImpl theCollaborationsFactory;
- private CollaborationsHelper theCollaborationsHelper;
+ private CollaborationsHelperEUMLImpl theCollaborationsHelper;
- private CommonBehaviorFactory theCommonBehaviorFactory;
+ private CommonBehaviorFactoryEUMLImpl theCommonBehaviorFactory;
- private CommonBehaviorHelper theCommonBehaviorHelper;
+ private CommonBehaviorHelperEUMLImpl theCommonBehaviorHelper;
- private ConcurrencyKind theConcurrencyKind;
+ private ConcurrencyKindEUMLImpl theConcurrencyKind;
- private CopyHelper theCopyHelper;
+ private CopyHelperEUMLImpl theCopyHelper;
- private CoreFactory theCoreFactory;
+ private CoreFactoryEUMLImpl theCoreFactory;
- private CoreHelper theCoreHelper;
+ private CoreHelperEUMLImpl theCoreHelper;
- private DataTypesFactory theDataTypesFactory;
+ private DataTypesFactoryEUMLImpl theDataTypesFactory;
- private DataTypesHelper theDataTypesHelper;
+ private DataTypesHelperEUMLImpl theDataTypesHelper;
- private DirectionKind theDirectionKind;
+ private DirectionKindEUMLImpl theDirectionKind;
- private ExtensionMechanismsFactory theExtensionMechanismsFactory;
+ private ExtensionMechanismsFactoryEUMLImpl theExtensionMechanismsFactory;
- private ExtensionMechanismsHelper theExtensionMechanismsHelper;
+ private ExtensionMechanismsHelperEUMLImpl theExtensionMechanismsHelper;
- private Facade theFacade;
+ private FacadeEUMLImpl theFacade;
- private MetaTypes theMetaTypes;
+ private MetaTypesEUMLImpl theMetaTypes;
private ModelEventPumpEUMLImpl theModelEventPump;
- private ModelManagementFactory theModelManagementFactory;
+ private ModelManagementFactoryEUMLImpl theModelManagementFactory;
- private ModelManagementHelper theModelManagementHelper;
+ private ModelManagementHelperEUMLImpl theModelManagementHelper;
- private OrderingKind theOrderingKind;
+ private OrderingKindEUMLImpl theOrderingKind;
- private PseudostateKind thePseudostateKind;
+ private PseudostateKindEUMLImpl thePseudostateKind;
@SuppressWarnings("deprecation")
- private ScopeKind theScopeKind;
+ private ScopeKindEUMLImpl theScopeKind;
- private StateMachinesFactory theStateMachinesFactory;
+ private StateMachinesFactoryEUMLImpl theStateMachinesFactory;
- private StateMachinesHelper theStateMachinesHelper;
+ private StateMachinesHelperEUMLImpl theStateMachinesHelper;
- private UmlFactory theUmlFactory;
+ private UmlFactoryEUMLImpl theUmlFactory;
- private UmlHelper theUmlHelper;
+ private UmlHelperEUMLImpl theUmlHelper;
- private UseCasesFactory theUseCasesFactory;
+ private UseCasesFactoryEUMLImpl theUseCasesFactory;
- private UseCasesHelper theUseCasesHelper;
+ private UseCasesHelperEUMLImpl theUseCasesHelper;
- private VisibilityKind theVisibilityKind;
+ private VisibilityKindEUMLImpl theVisibilityKind;
+
+ private CommandStackImpl theCommandStack;
/**
* This keeps track of the editing domain that is used to track all changes
@@ -202,42 +174,6 @@
}
/**
- * Verifies if the editing domain can undo the last changes in the UML
- * model.
- *
- * @return true if undo is possible, false otherwise
- */
- public boolean canUndo() {
- return editingDomain.getCommandStack().canUndo();
- }
-
- /**
- * Verifies if the editing domain can redo the last undone command.
- * @return true if redo is possible, false otherwise
- */
- public boolean canRedo() {
- return editingDomain.getCommandStack().canRedo();
- }
-
- /**
- * Undo the last command
- * <p>
- * If {@link #canUndo()} returns false, nothing will happen
- */
- public void undo() {
- editingDomain.getCommandStack().undo();
- }
-
- /**
- * Redo the last command
- * <p>
- * If {@link #canRedo()} returns false, nothing will happen
- */
- public void redo() {
- editingDomain.getCommandStack().redo();
- }
-
- /**
* This sets up the editing domain for the model editor.
*/
private void initializeEditingDomain() {
@@ -247,46 +183,26 @@
// org.eclipse.uml2.uml.resource jar plugin.
String path = System.getProperty("eUML.resources"); //$NON-NLS-1$
- ComposedAdapterFactory adapterFactory = null;
-
BasicCommandStack commandStack = new BasicCommandStack() {
@Override
protected void handleError(Exception exception) {
super.handleError(exception);
- exception.printStackTrace();
throw new RuntimeException(exception);
}
};
- commandStack.addCommandStackListener(new CommandStackListener() {
+ List<AdapterFactory> factories = new ArrayList<AdapterFactory>();
+ factories.add(new UMLResourceItemProviderAdapterFactory());
+ factories.add(new UMLItemProviderAdapterFactory());
+ factories.add(new EcoreItemProviderAdapterFactory());
+ factories.add(new UMLReflectiveItemProviderAdapterFactory());
+ ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(
+ factories);
- public void commandStackChanged(final EventObject event) {
- LOG.debug("Command stack changed"); //$NON-NLS-1$
- Command mostRecentCommand =
- ((CommandStack) event.getSource()).getMostRecentCommand();
- if (mostRecentCommand != null) {
- LOG.debug("Affected objects: " //$NON-NLS-1$
- + mostRecentCommand.getAffectedObjects());
- }
- }
-
- });
-
- if (path == null) {
- // TODO: figure out how to use the ItemProviders -
- // delayed until the ArgoEclipse version will be out
-// List<AdapterFactory> factories = new ArrayList<AdapterFactory>();
-// factories.add(new UMLResourceItemProviderAdapterFactory());
-// factories.add(new UMLItemProviderAdapterFactory());
-// factories.add(new EcoreItemProviderAdapterFactory());
-// factories.add(new UMLReflectiveItemProviderAdapterFactory());
-// adapterFactory = new ComposedAdapterFactory(factories);
- }
-
- editingDomain = new UML2AdapterFactoryEditingDomain(adapterFactory,
- commandStack);
+ editingDomain = new UML2AdapterFactoryEditingDomain(
+ adapterFactory, commandStack);
ResourceSet resourceSet = editingDomain.getResourceSet();
Map<String, Object> extensionToFactoryMap =
@@ -308,23 +224,28 @@
URI uri = URI.createURI("jar:file:" + path + "!/"); //$NON-NLS-1$ //$NON-NLS-2$
LOG.debug("eUML.resource URI --> " + uri); //$NON-NLS-1$
- resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI,
- UMLPackage.eINSTANCE);
- resourceSet.getPackageRegistry().put(EcorePackage.eNS_URI,
- EcorePackage.eINSTANCE);
- extensionToFactoryMap.put(UMLResource.FILE_EXTENSION,
- UMLResource.Factory.INSTANCE);
- uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP), uri
- .appendSegment("libraries").appendSegment("")); //$NON-NLS-1$ //$NON-NLS-2$
- uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), uri
- .appendSegment("metamodels").appendSegment("")); //$NON-NLS-1$//$NON-NLS-2$
- uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP), uri
- .appendSegment("profiles").appendSegment("")); //$NON-NLS-1$//$NON-NLS-2$
+ resourceSet.getPackageRegistry().put(
+ UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
+ resourceSet.getPackageRegistry().put(
+ EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
+ extensionToFactoryMap.put(
+ UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
+ uriMap.put(
+ URI.createURI(UMLResource.LIBRARIES_PATHMAP),
+ uri.appendSegment("libraries").appendSegment("")); //$NON-NLS-1$ //$NON-NLS-2$
+ uriMap.put(
+ URI.createURI(UMLResource.METAMODELS_PATHMAP),
+ uri.appendSegment("metamodels").appendSegment("")); //$NON-NLS-1$//$NON-NLS-2$
+ uriMap.put(
+ URI.createURI(UMLResource.PROFILES_PATHMAP),
+ uri.appendSegment("profiles").appendSegment("")); //$NON-NLS-1$//$NON-NLS-2$
}
- extensionToFactoryMap.put(UML22UMLResource.FILE_EXTENSION,
+ extensionToFactoryMap.put(
+ UML22UMLResource.FILE_EXTENSION,
UML22UMLResource.Factory.INSTANCE);
- extensionToFactoryMap.put(XMI2UMLResource.FILE_EXTENSION,
+ extensionToFactoryMap.put(
+ XMI2UMLResource.FILE_EXTENSION,
XMI2UMLResource.Factory.INSTANCE);
uriMap.putAll(UML22UMLExtendedMetaData.getURIMap());
uriMap.putAll(XMI2UMLExtendedMetaData.getURIMap());
@@ -340,7 +261,7 @@
return editingDomain;
}
- public ActivityGraphsFactory getActivityGraphsFactory() {
+ public ActivityGraphsFactoryEUMLlImpl getActivityGraphsFactory() {
if (theActivityGraphsFactory == null) {
theActivityGraphsFactory =
new ActivityGraphsFactoryEUMLlImpl(this);
@@ -348,14 +269,14 @@
return theActivityGraphsFactory;
}
- public ActivityGraphsHelper getActivityGraphsHelper() {
+ public ActivityGraphsHelperEUMLImpl getActivityGraphsHelper() {
if (theActivityGraphsHelper == null) {
theActivityGraphsHelper = new ActivityGraphsHelperEUMLImpl(this);
}
return theActivityGraphsHelper;
}
- public AggregationKind getAggregationKind() {
+ public AggregationKindEUMLImpl getAggregationKind() {
if (theAggregationKind == null) {
theAggregationKind = new AggregationKindEUMLImpl();
}
@@ -363,91 +284,91 @@
}
@SuppressWarnings("deprecation")
- public ChangeableKind getChangeableKind() {
+ public ChangeableKindEUMLImpl getChangeableKind() {
if (theChangeableKind == null) {
theChangeableKind = new ChangeableKindEUMLImpl();
}
return theChangeableKind;
}
- public CollaborationsFactory getCollaborationsFactory() {
+ public CollaborationsFactoryEUMLImpl getCollaborationsFactory() {
if (theCollaborationsFactory == null) {
theCollaborationsFactory = new CollaborationsFactoryEUMLImpl(this);
}
return theCollaborationsFactory;
}
- public CollaborationsHelper getCollaborationsHelper() {
+ public CollaborationsHelperEUMLImpl getCollaborationsHelper() {
if (theCollaborationsHelper == null) {
theCollaborationsHelper = new CollaborationsHelperEUMLImpl(this);
}
return theCollaborationsHelper;
}
- public CommonBehaviorFactory getCommonBehaviorFactory() {
+ public CommonBehaviorFactoryEUMLImpl getCommonBehaviorFactory() {
if (theCommonBehaviorFactory == null) {
theCommonBehaviorFactory = new CommonBehaviorFactoryEUMLImpl(this);
}
return theCommonBehaviorFactory;
}
- public CommonBehaviorHelper getCommonBehaviorHelper() {
+ public CommonBehaviorHelperEUMLImpl getCommonBehaviorHelper() {
if (theCommonBehaviorHelper == null) {
theCommonBehaviorHelper = new CommonBehaviorHelperEUMLImpl(this);
}
return theCommonBehaviorHelper;
}
- public ConcurrencyKind getConcurrencyKind() {
+ public ConcurrencyKindEUMLImpl getConcurrencyKind() {
if (theConcurrencyKind == null) {
theConcurrencyKind = new ConcurrencyKindEUMLImpl();
}
return theConcurrencyKind;
}
- public CopyHelper getCopyHelper() {
+ public CopyHelperEUMLImpl getCopyHelper() {
if (theCopyHelper == null) {
theCopyHelper = new CopyHelperEUMLImpl(this);
}
return theCopyHelper;
}
- public CoreFactory getCoreFactory() {
+ public CoreFactoryEUMLImpl getCoreFactory() {
if (theCoreFactory == null) {
theCoreFactory = new CoreFactoryEUMLImpl(this);
}
return theCoreFactory;
}
- public CoreHelper getCoreHelper() {
+ public CoreHelperEUMLImpl getCoreHelper() {
if (theCoreHelper == null) {
theCoreHelper = new CoreHelperEUMLImpl(this);
}
return theCoreHelper;
}
- public DataTypesFactory getDataTypesFactory() {
+ public DataTypesFactoryEUMLImpl getDataTypesFactory() {
if (theDataTypesFactory == null) {
theDataTypesFactory = new DataTypesFactoryEUMLImpl(this);
}
return theDataTypesFactory;
}
- public DataTypesHelper getDataTypesHelper() {
+ public DataTypesHelperEUMLImpl getDataTypesHelper() {
if (theDataTypesHelper == null) {
theDataTypesHelper = new DataTypesHelperEUMLImpl(this);
}
return theDataTypesHelper;
}
- public DirectionKind getDirectionKind() {
+ public DirectionKindEUMLImpl getDirectionKind() {
if (theDirectionKind == null) {
theDirectionKind = new DirectionKindEUMLImpl();
}
return theDirectionKind;
}
- public ExtensionMechanismsFactory getExtensionMechanismsFactory() {
+ public ExtensionMechanismsFactoryEUMLImpl getExtensionMechanismsFactory() {
if (theExtensionMechanismsFactory == null) {
theExtensionMechanismsFactory =
new ExtensionMechanismsFactoryEUMLImpl(this);
@@ -455,7 +376,7 @@
return theExtensionMechanismsFactory;
}
- public ExtensionMechanismsHelper getExtensionMechanismsHelper() {
+ public ExtensionMechanismsHelperEUMLImpl getExtensionMechanismsHelper() {
if (theExtensionMechanismsHelper == null) {
theExtensionMechanismsHelper =
new ExtensionMechanismsHelperEUMLImpl(this);
@@ -463,14 +384,14 @@
return theExtensionMechanismsHelper;
}
- public Facade getFacade() {
+ public FacadeEUMLImpl getFacade() {
if (theFacade == null) {
theFacade = new FacadeEUMLImpl(this);
}
return theFacade;
}
- public MetaTypes getMetaTypes() {
+ public MetaTypesEUMLImpl getMetaTypes() {
if (theMetaTypes == null) {
theMetaTypes = new MetaTypesEUMLImpl(this);
}
@@ -484,7 +405,7 @@
return theModelEventPump;
}
- public ModelManagementFactory getModelManagementFactory() {
+ public ModelManagementFactoryEUMLImpl getModelManagementFactory() {
if (theModelManagementFactory == null) {
theModelManagementFactory =
new ModelManagementFactoryEUMLImpl(this);
@@ -492,21 +413,21 @@
return theModelManagementFactory;
}
- public ModelManagementHelper getModelManagementHelper() {
+ public ModelManagementHelperEUMLImpl getModelManagementHelper() {
if (theModelManagementHelper == null) {
theModelManagementHelper = new ModelManagementHelperEUMLImpl(this);
}
return theModelManagementHelper;
}
- public OrderingKind getOrderingKind() {
+ public OrderingKindEUMLImpl getOrderingKind() {
if (theOrderingKind == null) {
theOrderingKind = new OrderingKindEUMLImpl();
}
return theOrderingKind;
}
- public PseudostateKind getPseudostateKind() {
+ public PseudostateKindEUMLImpl getPseudostateKind() {
if (thePseudostateKind == null) {
thePseudostateKind = new PseudostateKindEUMLImpl();
}
@@ -514,7 +435,7 @@
}
@SuppressWarnings("deprecation")
- public ScopeKind getScopeKind() {
+ public ScopeKindEUMLImpl getScopeKind() {
if (theScopeKind == null) {
theScopeKind = new ScopeKindEUMLImpl();
}
@@ -522,72 +443,78 @@
}
- public StateMachinesFactory getStateMachinesFactory() {
+ public StateMachinesFactoryEUMLImpl getStateMachinesFactory() {
if (theStateMachinesFactory == null) {
theStateMachinesFactory = new StateMachinesFactoryEUMLImpl(this);
}
return theStateMachinesFactory;
}
- public StateMachinesHelper getStateMachinesHelper() {
+ public StateMachinesHelperEUMLImpl getStateMachinesHelper() {
if (theStateMachinesHelper == null) {
theStateMachinesHelper = new StateMachinesHelperEUMLImpl(this);
}
return theStateMachinesHelper;
}
- public UmlFactory getUmlFactory() {
+ public UmlFactoryEUMLImpl getUmlFactory() {
if (theUmlFactory == null) {
theUmlFactory = new UmlFactoryEUMLImpl(this);
}
return theUmlFactory;
}
- public UmlHelper getUmlHelper() {
+ public UmlHelperEUMLImpl getUmlHelper() {
if (theUmlHelper == null) {
theUmlHelper = new UmlHelperEUMLImpl(this);
}
return theUmlHelper;
}
- public UseCasesFactory getUseCasesFactory() {
+ public UseCasesFactoryEUMLImpl getUseCasesFactory() {
if (theUseCasesFactory == null) {
theUseCasesFactory = new UseCasesFactoryEUMLImpl(this);
}
return theUseCasesFactory;
}
- public UseCasesHelper getUseCasesHelper() {
+ public UseCasesHelperEUMLImpl getUseCasesHelper() {
if (theUseCasesHelper == null) {
theUseCasesHelper = new UseCasesHelperEUMLImpl(this);
}
return theUseCasesHelper;
}
- public VisibilityKind getVisibilityKind() {
+ public VisibilityKindEUMLImpl getVisibilityKind() {
if (theVisibilityKind == null) {
theVisibilityKind = new VisibilityKindEUMLImpl();
}
return theVisibilityKind;
}
- public XmiReader getXmiReader() throws UmlException {
+ public XmiReaderEUMLImpl getXmiReader() throws UmlException {
return new XmiReaderEUMLImpl(this);
}
- public XmiWriter getXmiWriter(Object model, Writer writer, String version)
- throws UmlException {
+ public XmiWriterEUMLImpl getXmiWriter(Object model, Writer writer,
+ String version) throws UmlException {
return new XmiWriterEUMLImpl(this, model, writer, version);
}
- public XmiWriter getXmiWriter(Object model, OutputStream stream,
+ public XmiWriterEUMLImpl getXmiWriter(Object model, OutputStream stream,
String version) throws UmlException {
return new XmiWriterEUMLImpl(this, model, stream, version);
}
public DiagramInterchangeModel getDiagramInterchangeModel() {
- // TODO Auto-generated method stub
return null;
}
+ public CommandStackImpl getCommandStack() {
+ if (theCommandStack == null) {
+ theCommandStack = new CommandStackImpl(this);
+ }
+ return theCommandStack;
+ }
+
}
Modified: trunk/src/model-euml/src/org/argouml/model/euml/ExtensionMechanismsHelperEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-euml/src/org/argouml/model/euml/ExtensionMechanismsHelperEUMLImpl.java?view=diff&rev=13462&p1=trunk/src/model-euml/src/org/argouml/model/euml/ExtensionMechanismsHelperEUMLImpl.java&p2=trunk/src/model-euml/src/org/argouml/model/euml/ExtensionMechanismsHelperEUMLImpl.java&r1=13461&r2=13462
==============================================================================
--- trunk/src/model-euml/src/org/argouml/model/euml/ExtensionMechanismsHelperEUMLImpl.java (original)
+++ trunk/src/model-euml/src/org/argouml/model/euml/ExtensionMechanismsHelperEUMLImpl.java 2007-08-30 11:48:34-0700
@@ -27,6 +27,7 @@
package org.argouml.model.euml;
import java.util.Collection;
+import java.util.Collections;
import org.argouml.model.ExtensionMechanismsHelper;
import org.eclipse.uml2.uml.Element;
@@ -46,7 +47,8 @@
*
* @param implementation The ModelImplementation.
*/
- public ExtensionMechanismsHelperEUMLImpl(EUMLModelImplementation implementation) {
+ public ExtensionMechanismsHelperEUMLImpl(
+ EUMLModelImplementation implementation) {
modelImpl = implementation;
}
@@ -70,9 +72,10 @@
}
- public Collection getAllPossibleStereotypes(Collection models, Object modelElement) {
+ public Collection getAllPossibleStereotypes(Collection models,
+ Object modelElement) {
// TODO Auto-generated method stub
- return null;
+ return Collections.EMPTY_LIST;
}
public String getMetaModelName(Object m) {
@@ -80,7 +83,6 @@
return getMetaModelName(m.getClass());
}
throw new IllegalArgumentException("Not an Element");
-
}
/**
@@ -138,48 +140,44 @@
/**
* @deprecated Use {@link #isValidStereotype(Object,Object)} instead
*/
- public boolean isValidStereoType(Object theModelElement, Object theStereotype) {
+ @Deprecated
+ public boolean isValidStereoType(Object theModelElement,
+ Object theStereotype) {
return isValidStereotype(theModelElement, theStereotype);
}
- public boolean isValidStereotype(Object theModelElement, Object theStereotype) {
+ public boolean isValidStereotype(Object theModelElement,
+ Object theStereotype) {
// TODO Auto-generated method stub
return false;
}
public void removeBaseClass(Object handle, Object baseClass) {
// TODO Auto-generated method stub
-
}
public void removeTaggedValue(Object handle, Object taggedValue) {
// TODO Auto-generated method stub
-
}
public void setIcon(Object handle, Object icon) {
// TODO Auto-generated method stub
-
}
public void setTag(Object handle, Object tag) {
// TODO Auto-generated method stub
-
}
public void setTaggedValue(Object handle, Collection taggedValues) {
// TODO Auto-generated method stub
-
}
public void setType(Object handle, Object type) {
- // TODO Auto-generated method stub
-
+ // TODO Auto-generated method stub
}
public void setValueOfTag(Object handle, String value) {
// TODO Auto-generated method stub
-
}
Modified: trunk/src/model-euml/src/org/argouml/model/euml/FacadeEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-euml/src/org/argouml/model/euml/FacadeEUMLImpl.java?view=diff&rev=13462&p1=trunk/src/model-euml/src/org/argouml/model/euml/FacadeEUMLImpl.java&p2=trunk/src/model-euml/src/org/argouml/model/euml/FacadeEUMLImpl.java&r1=13461&r2=13462
==============================================================================
--- trunk/src/model-euml/src/org/argouml/model/euml/FacadeEUMLImpl.java (original)
+++ trunk/src/model-euml/src/org/argouml/model/euml/FacadeEUMLImpl.java 2007-08-30 11:48:34-0700
@@ -36,6 +36,9 @@
import org.argouml.model.Facade;
import org.argouml.model.NotImplementedException;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.uml2.uml.Abstraction;
import org.eclipse.uml2.uml.Action;
import org.eclipse.uml2.uml.ActivityPartition;
@@ -74,7 +77,6 @@
import org.eclipse.uml2.uml.InputPin;
import org.eclipse.uml2.uml.InstanceSpecification;
import org.eclipse.uml2.uml.Interface;
-import org.eclipse.uml2.uml.LinkEndData;
import org.eclipse.uml2.uml.Message;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.MultiplicityElement;
@@ -109,6 +111,7 @@
import org.eclipse.uml2.uml.Transition;
import org.eclipse.uml2.uml.Trigger;
import org.eclipse.uml2.uml.TypedElement;
+import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.Usage;
import org.eclipse.uml2.uml.UseCase;
import org.eclipse.uml2.uml.ValueSpecification;
@@ -138,7 +141,7 @@
public String getUmlVersion() {
// TODO: Can we get this from the metamodel?
- return "2.1.1";
+ return "2.1.1"; //$NON-NLS-1$
}
public boolean equalsPseudostateKind(Object ps1, Object ps2) {
@@ -187,6 +190,10 @@
}
public Object getAggregation(Object handle) {
+ if (!(handle instanceof Property)) {
+ throw new IllegalArgumentException(
+ "handle must be instance of Property"); //$NON-NLS-1$
+ }
return ((Property) handle).getAggregation();
}
@@ -196,6 +203,10 @@
}
public Collection getAnnotatedElements(Object handle) {
+ if (!(handle instanceof Comment)) {
+ throw new IllegalArgumentException(
+ "handle must be instance of Comment"); //$NON-NLS-1$
+ }
return ((Comment) handle).getAnnotatedElements();
}
@@ -210,25 +221,42 @@
}
public Object getAssociation(Object handle) {
- // TODO: Link not implemented
- return ((Property) handle).getOwningAssociation();
+ if (!(handle instanceof Property)) {
+ throw new IllegalArgumentException(
+ "handle must be instance of Property"); //$NON-NLS-1$
+ }
+ return ((Property) handle).getAssociation();
}
- public Object getAssociationEnd(Object classifier, Object association) {
- throw new NotYetImplementedException();
-
+ public Property getAssociationEnd(Object classifier, Object association) {
+ if (!(classifier instanceof Classifier)) {
+ throw new IllegalArgumentException(
+ "classifier must be instance of Classifier"); //$NON-NLS-1$
+ }
+ if (!(association instanceof Association)) {
+ throw new IllegalArgumentException(
+ "association must be Association"); //$NON-NLS-1$
+ }
+ for (Property p : UMLUtil.getOwnedAttributes((Classifier) classifier)) {
+ if (p.getAssociation() == association) {
+ return p;
+ }
+ }
+ return null;
}
public Collection getAssociationEnds(Object handle) {
- // TODO: Do we want near end, far end, or both here? - tfm
- // We'll just return them all for now
- Collection<Association> associations =
- ((Classifier) handle).getAssociations();
- Collection<Property> ends = new ArrayList<Property>();
- for (Association assoc : associations) {
- ends.addAll(assoc.getMemberEnds());
+ if (!(handle instanceof Classifier)) {
+ throw new IllegalArgumentException(
+ "handle must be instance of Classifier"); //$NON-NLS-1$
+ }
+ Collection result = new ArrayList();
+ for (Property p : ((Classifier) handle).getAttributes()) {
+ if (p.getAssociation() != null) {
+ result.add(p);
+ }
}
- return ends;
+ return result;
}
public Collection getAssociationRoles(Object handle) {
@@ -239,16 +267,20 @@
}
public List getAttributes(Object handle) {
- // TODO: Just a shortcut for now. Add real implementation - tfm
- return getStructuralFeatures(handle);
+ if (!(handle instanceof Classifier)) {
+ throw new IllegalArgumentException(
+ "handle must be instance of Classifier"); //$NON-NLS-1$
+ }
+ return UMLUtil.getOwnedAttributes((Classifier) handle);
}
public Object getBase(Object handle) {
if (handle instanceof Extend) {
return ((Extend) handle).getExtendedCase();
+ } else if (handle instanceof Include) {
+ return ((Include) handle).getAddition();
}
throw new NotYetImplementedException();
-
}
public Collection getBaseClasses(Object handle) {
@@ -262,14 +294,11 @@
}
public Object getBehavioralFeature(Object handle) {
- List<Feature> features = ((Classifier) handle).getFeatures();
- List<Feature> result = new ArrayList<Feature>();
- for (Feature f : features) {
- if (f instanceof BehavioralFeature) {
- result.add(f);
- }
+ if (!(handle instanceof Parameter)) {
+ throw new IllegalArgumentException(
+ "handle must be instance of Parameter"); //$NON-NLS-1$
}
- return result;
+ return ((Parameter) handle).getOperation();
}
public Collection getBehaviors(Object handle) {
@@ -283,6 +312,9 @@
}
public Object getBody(Object handle) {
+ if (handle instanceof Comment) {
+ return ((Comment) handle).getBody();
+ }
throw new NotYetImplementedException();
}
@@ -299,28 +331,30 @@
@SuppressWarnings("deprecation")
public Object getChangeability(Object handle) {
- if (handle instanceof Property) {
- if (((Property) handle).isReadOnly()) {
- return modelImpl.getChangeableKind().getFrozen();
- } else {
- return modelImpl.getChangeableKind().getChangeable();
- }
- }
- throw new NotYetImplementedException();
-
+ if (!(handle instanceof StructuralFeature)) {
+ throw new IllegalArgumentException(
+ "handle must be StructuralFeature"); //$NON-NLS-1$
+ }
+ return ((StructuralFeature) handle).isReadOnly() ? modelImpl
+ .getChangeableKind().getFrozen() : modelImpl
+ .getChangeableKind().getChangeable();
}
@SuppressWarnings("deprecation")
public Object getChild(Object handle) {
- return ((Generalization) handle).getSpecific();
+ return getSpecific(handle);
}
public Object getSpecific(Object handle) {
+ if (!(handle instanceof Generalization)) {
+ throw new IllegalArgumentException(
+ "handle must be instance of Generalization"); //$NON-NLS-1$
+ }
return ((Generalization) handle).getSpecific();
}
public Collection getChildren(Object handle) {
- throw new NotYetImplementedException();
+ return modelImpl.getCoreHelper().getSubtypes(handle);
}
public Object getClassifier(Object handle) {
@@ -343,18 +377,29 @@
}
public Collection<Dependency> getClientDependencies(Object handle) {
+ if (!(handle instanceof NamedElement)) {
+ throw new IllegalArgumentException(
+ "handle must be instance of NamedElement"); //$NON-NLS-1$
+ }
return ((NamedElement) handle).getClientDependencies();
}
public Collection<NamedElement> getClients(Object handle) {
+ if (!(handle instanceof Dependency)) {
+ throw new IllegalArgumentException(
+ "handle must be instance of Dependency"); //$NON-NLS-1$
+ }
return ((Dependency) handle).getClients();
}
public Collection<Collaboration> getCollaborations(Object handle) {
+ if (!(handle instanceof Classifier)) {
+ throw new IllegalArgumentException();
+ }
Set<Collaboration> result = new HashSet<Collaboration>();
if (handle instanceof Classifier) {
- for (CollaborationUse cu
- : ((Classifier) handle).getCollaborationUses()) {
+ for (CollaborationUse cu : ((Classifier) handle)
+ .getCollaborationUses()) {
result.add(cu.getType());
}
}
@@ -362,7 +407,18 @@
}
public Collection<Comment> getComments(Object handle) {
- return ((Element) handle).getOwnedComments();
+ if (!(handle instanceof Element)) {
+ throw new IllegalArgumentException(
+ "handle must be instance of Element"); //$NON-NLS-1$
+ }
+ Collection<Comment> result = new HashSet<Comment>();
+ for (EStructuralFeature.Setting reference : UMLUtil
+ .getInverseReferences((Element) handle)) {
+ if (reference.getEObject() instanceof Comment) {
+ result.add((Comment) reference.getEObject());
+ }
+ }
+ return result;
}
public Object getCommunicationConnection(Object handle) {
@@ -387,12 +443,17 @@
}
public Collection getConnections(Object handle) {
- // TODO: Link not implemented - tfm
- if (handle instanceof Association) {
- return ((Association) handle).getMemberEnds();
- } else {
- throw new IllegalArgumentException();
+ // Link does not exist in UML2
+ if (handle == null) {
+ // this is wrongly called with a null handle,
+ // as a workaround we return an empty collection
+ return Collections.EMPTY_LIST;
+ }
+ if (!(handle instanceof Association)) {
+ throw new IllegalArgumentException(
+ "handle must be instance of Association"); //$NON-NLS-1$
}
+ return ((Association) handle).getMemberEnds();
}
public List getConstrainedElements(Object handle) {
@@ -444,7 +505,7 @@
}
public Object getDefaultValue(Object handle) {
- throw new NotYetImplementedException();
+ return ((Parameter) handle).getDefault();
}
public Collection getDeferrableEvents(Object handle) {
@@ -479,11 +540,17 @@
}
public Collection getElementImports(Object handle) {
+ if (!(handle instanceof org.eclipse.uml2.uml.Package)) {
+ throw new IllegalArgumentException();
+ }
return Collections.EMPTY_LIST;
// throw new NotYetImplementedException();
}
public Collection getElementImports2(Object handle) {
+ if (!(handle instanceof Element)) {
+ throw new IllegalArgumentException();
+ }
throw new NotYetImplementedException();
}
@@ -524,15 +591,27 @@
}
public Collection<Extend> getExtends(Object handle) {
- return ((UseCase) handle).getExtends();
+ if (handle instanceof UseCase) {
+ return ((UseCase) handle).getExtends();
+ } else if (handle instanceof ExtensionPoint) {
+ // TODO:
+ throw new NotYetImplementedException();
+ }
+ throw new IllegalArgumentException();
}
public UseCase getExtension(Object handle) {
+ if (!(handle instanceof Extend)) {
+ throw new IllegalArgumentException();
+ }
return ((Extend) handle).getExtension();
}
public ExtensionPoint getExtensionPoint(Object handle, int index) {
- return ((UseCase) handle).getExtensionPoints().get(index);
+ if (!(handle instanceof Extend)) {
+ throw new IllegalArgumentException();
+ }
+ return ((Extend) handle).getExtensionLocations().get(index);
}
public List<ExtensionPoint> getExtensionPoints(Object handle) {
@@ -546,20 +625,20 @@
}
public List<Feature> getFeatures(Object handle) {
+ if (!(handle instanceof Classifier)) {
+ throw new IllegalArgumentException();
+ }
return ((Classifier) handle).getFeatures();
}
public Object getGeneralization(Object handle, Object parent) {
- throw new NotYetImplementedException();
-
+ return modelImpl.getCoreHelper().getGeneralization(handle, parent);
}
public Collection<Generalization> getGeneralizations(Object handle) {
Set<Generalization> result = new HashSet<Generalization>();
for (Generalization g : ((Classifier) handle).getGeneralizations()) {
- if (handle.equals(g.getSpecific())) {
- result.add(g);
- }
+ result.add(g);
}
return result;
}
@@ -575,11 +654,16 @@
}
public Object getImportedElement(Object elementImport) {
+ if (!(elementImport instanceof ElementImport)) {
+ throw new IllegalArgumentException();
+ }
return ((ElementImport) elementImport).getImportedElement();
}
public Collection<PackageableElement> getImportedElements(Object pack) {
- // TODO: double check - tfm
+ if (!(pack instanceof Namespace)) {
+ throw new IllegalArgumentException();
+ }
return ((Namespace) pack).getImportedElements();
}
@@ -594,6 +678,9 @@
}
public Collection<Include> getIncludes(Object handle) {
+ if (!(handle instanceof UseCase)) {
+ throw new IllegalArgumentException();
+ }
return ((UseCase) handle).getIncludes();
}
@@ -602,7 +689,10 @@
}
public Object getInitialValue(Object handle) {
- throw new NotYetImplementedException();
+ if (!(handle instanceof Property)) {
+ throw new IllegalArgumentException();
+ }
+ return ((Property) handle).getDefault();
}
public Object getInstance(Object handle) {
@@ -652,10 +742,14 @@
}
public String getLocation(Object handle) {
- throw new NotYetImplementedException();
+ // TODO: Removed from UML2
+ return "";
}
public int getLower(Object handle) {
+ if (!(handle instanceof MultiplicityElement)) {
+ throw new IllegalArgumentException();
+ }
return ((MultiplicityElement) handle).getLower();
}
@@ -668,7 +762,10 @@
}
public Object getModel(Object handle) {
- throw new NotYetImplementedException();
+ if (!(handle instanceof Element)) {
+ throw new IllegalArgumentException();
+ }
+ return ((Element) handle).getModel();
}
public Object getModelElement(Object handle) {
@@ -680,10 +777,16 @@
}
public Element getModelElementContainer(Object handle) {
+ if (!(handle instanceof Element)) {
+ throw new IllegalArgumentException();
+ }
return ((Element) handle).getOwner();
}
public List<Element> getModelElementContents(Object handle) {
+ if (!(handle instanceof Element)) {
+ throw new IllegalArgumentException();
+ }
return ((Element) handle).getOwnedElements();
}
@@ -698,10 +801,17 @@
}
public String getName(Object handle) {
+ if (!(handle instanceof Element) && !(handle instanceof String)) {
+ throw new IllegalArgumentException();
+ }
if (handle instanceof String) {
return (String) handle;
} else if (handle instanceof NamedElement) {
- return ((NamedElement) handle).getName();
+ if (((NamedElement) handle).getName() != null) {
+ return ((NamedElement) handle).getName();
+ } else {
+ return ""; //$NON-NLS-1$
+ }
} else {
// TODO: Some elements such as Generalization are
// no longer named. For a transitional period we'll
@@ -712,12 +822,25 @@
// throw new IllegalArgumentException();
}
- public Namespace getNamespace(Object handle) {
- return ((NamedElement) handle).getNamespace();
+ public Object getNamespace(Object handle) {
+ Object o = ((Element) handle).getOwner();
+ if (o instanceof Namespace) {
+ return o;
+ }
+ return null;
}
public Object getNextEnd(Object handle) {
- throw new NotYetImplementedException();
+ if (!isAAssociationEnd(handle)) {
+ throw new IllegalArgumentException();
+ }
+ List l = ((Property) handle).getAssociation().getMemberEnds();
+ int i = l.indexOf(handle);
+ if (i + 1 < l.size()) {
+ return l.get(i + 1);
+ } else {
+ return l.get(0);
+ }
}
public Object getNodeInstance(Object handle) {
@@ -737,6 +860,9 @@
}
public List<Operation> getOperations(Object handle) {
+ if (!(handle instanceof Classifier)) {
+ throw new IllegalArgumentException();
+ }
List<Feature> features = ((Classifier) handle).getFeatures();
List<Operation> result = new ArrayList<Operation>();
for (Feature f : features) {
@@ -748,6 +874,9 @@
}
public List<Feature> getOperationsAndReceptions(Object handle) {
+ if (!(handle instanceof Classifier)) {
+ throw new IllegalArgumentException();
+ }
List<Feature> features = ((Classifier) handle).getFeatures();
List<Feature> result = new ArrayList<Feature>();
for (Feature f : features) {
@@ -759,17 +888,11 @@
}
public Object getOppositeEnd(Object handle) {
- throw new NotYetImplementedException();
+ return getNextEnd(handle);
}
public Object getOrdering(Object handle) {
- if (handle instanceof Property) {
- if (((Property) handle).isOrdered()) {
- return modelImpl.getOrderingKind().getOrdered();
- } else {
- return modelImpl.getOrderingKind().getUnordered();
- }
- } else if (handle instanceof MultiplicityElement) {
+ if (handle instanceof MultiplicityElement) {
if (((MultiplicityElement) handle).isOrdered()) {
return modelImpl.getOrderingKind().getOrdered();
} else {
@@ -777,11 +900,16 @@
}
}
throw new NotYetImplementedException();
-
}
public Collection getOtherAssociationEnds(Object handle) {
- throw new NotYetImplementedException();
+ if (!isAAssociationEnd(handle)) {
+ throw new IllegalArgumentException();
+ }
+ List l = new ArrayList(
+ ((Property) handle).getAssociation().getMemberEnds());
+ l.remove(handle);
+ return l;
}
public Collection getOtherLinkEnds(Object handle) {
@@ -793,10 +921,16 @@
}
public Collection<Element> getOwnedElements(Object handle) {
+ if (!(handle instanceof Namespace)) {
+ throw new IllegalArgumentException();
+ }
return ((Namespace) handle).getOwnedElements();
}
public Element getOwner(Object handle) {
+ if (!(handle instanceof Element)) {
+ throw new IllegalArgumentException();
+ }
return ((Element) handle).getOwner();
}
@@ -804,10 +938,14 @@
public Object getOwnerScope(Object handle) {
// Removed from UML 2.x and deprecated in Model API
// so we won't implement it
- throw new NotImplementedException();
+// throw new NotImplementedException();
+ return null;
}
public Namespace getPackage(Object handle) {
+ if (!(handle instanceof ElementImport)) {
+ throw new IllegalArgumentException();
+ }
return ((ElementImport) handle).getImportingNamespace();
}
@@ -837,10 +975,16 @@
@SuppressWarnings("deprecation")
public Classifier getParent(Object handle) {
+ if (!(handle instanceof Generalization)) {
+ throw new IllegalArgumentException();
+ }
return ((Generalization) handle).getGeneral();
}
public Classifier getGeneral(Object handle) {
+ if (!(handle instanceof Generalization)) {
+ throw new IllegalArgumentException();
+ }
return ((Generalization) handle).getGeneral();
}
@@ -866,6 +1010,9 @@
}
public List<Property> getQualifiers(Object handle) {
+ if (!(handle instanceof Property)) {
+ throw new IllegalArgumentException();
+ }
return ((Property) handle).getQualifiers();
}
@@ -952,6 +1099,9 @@
}
public Vertex getSource(Object handle) {
+ if (!(handle instanceof Transition)) {
+ throw new IllegalArgumentException();
+ }
return ((Transition) handle).getSource();
}
@@ -966,13 +1116,10 @@
}
public Collection getSpecializations(Object handle) {
- Set<Generalization> result = new HashSet<Generalization>();
- for (Generalization g : ((Classifier) handle).getGeneralizations()) {
- if (handle.equals(g.getGeneral())) {
- result.add(g);
- }
+ if (!(handle instanceof Classifier)) {
+ throw new IllegalArgumentException();
}
- return result;
+ return ((Classifier) handle).getTargetDirectedRelationships(UMLPackage.Literals.GENERALIZATION);
}
public String getSpecification(Object handle) {
@@ -985,8 +1132,8 @@
// TODO: unimplemented
// return ((Property) handle).gets
return Collections.EMPTY_SET;
- } else if (handle instanceof Classifier) {
- ((Classifier) handle).getAllUsedInterfaces();
+ } else if (handle instanceof org.eclipse.uml2.uml.Class) {
+ ((org.eclipse.uml2.uml.Class) handle).getInterfaceRealizations();
}
throw new NotYetImplementedException();
@@ -1019,6 +1166,9 @@
}
public List<StructuralFeature> getStructuralFeatures(Object handle) {
+ if (!(handle instanceof Classifier)) {
+ throw new IllegalArgumentException();
+ }
List<Feature> features = ((Classifier) handle).getFeatures();
List<StructuralFeature> result = new ArrayList<StructuralFeature>();
for (Feature f : features) {
@@ -1055,6 +1205,9 @@
}
public Collection<NamedElement> getSuppliers(Object handle) {
+ if (!(handle instanceof Dependency)) {
+ throw new IllegalArgumentException();
+ }
return ((Dependency) handle).getSuppliers();
}
@@ -1096,6 +1249,9 @@
}
public Vertex getTarget(Object handle) {
+ if (!(handle instanceof Transition)) {
+ throw new IllegalArgumentException();
+ }
return ((Transition) handle).getTarget();
}
@@ -1107,7 +1263,9 @@
public Object getTargetScope(Object handle) {
// Removed from UML 2.x and deprecated in Model API
// so we won't implement it
- throw new NotImplementedException();
+// throw new NotImplementedException();
+ // we do not throw an exception because ArgoUML still uses this
+ return null;
}
public Object getTemplate(Object handle) {
@@ -1120,8 +1278,12 @@
public String getTipString(Object modelElement) {
// TODO: Not Model implementation dependent
- return getUMLClassName(modelElement) + ": " //$NON-NLS-1$
- + getName(modelElement);
+ String name = getName(modelElement);
+ if (name.equals("")) { //$NON-NLS-1$
+ return getUMLClassName(modelElement);
+ } else {
+ return getUMLClassName(modelElement) + ": " + name; //$NON-NLS-1$
+ }
}
public Object getTop(Object handle) {
@@ -1137,16 +1299,19 @@
}
public Trigger getTrigger(Object handle) {
+ if (!(handle instanceof Transition)) {
+ throw new IllegalArgumentException();
+ }
// TODO: Transitions can have multiple Triggers now?
// Need API change to handle - tfm
return ((Transition) handle).getTriggers().get(0);
}
public Object getType(Object handle) {
- if (handle instanceof TypedElement) {
- return ((TypedElement) handle).getType();
+ if (!(handle instanceof TypedElement)) {
+ throw new IllegalArgumentException();
}
- throw new NotYetImplementedException();
+ return ((TypedElement) handle).getType();
}
public Collection getTypedValues(Object handle) {
@@ -1158,17 +1323,27 @@
}
public String getUUID(Object element) {
- // TODO: Hack placeholder implementation
- // I think we need to use XMIResourceFactoryImpl to provide a way
- // to generate xmi.id's, but I don't know the details yet
- return element.toString();
+ if (!(element instanceof EObject)) {
+ throw new IllegalArgumentException();
+ }
+ Resource r = ((EObject) element).eResource();
+ if (r == null) {
+ throw new UnsupportedOperationException();
+ }
+ return r.getURIFragment((EObject) element);
}
public int getUpper(Object handle) {
+ if (!(handle instanceof MultiplicityElement)) {
+ throw new IllegalArgumentException();
+ }
return ((MultiplicityElement) handle).getUpper();
}
public UseCase getUseCase(Object handle) {
+ if (!(handle instanceof ExtensionPoint)) {
+ throw new IllegalArgumentException();
+ }
return ((ExtensionPoint) handle).getUseCase();
}
@@ -1181,10 +1356,16 @@
}
public VisibilityKind getVisibility(Object handle) {
+ if (!(handle instanceof NamedElement)) {
+ throw new IllegalArgumentException();
+ }
return ((NamedElement) handle).getVisibility();
}
public ValueSpecification getWhen(Object target) {
+ if (!(target instanceof TimeEvent)) {
+ throw new IllegalArgumentException();
+ }
return ((TimeEvent) target).getWhen();
}
@@ -1364,7 +1545,7 @@
}
public boolean isAConcurrentRegion(Object handle) {
- throw new NotYetImplementedException();
+ return false;
}
public boolean isAConstraint(Object handle) {
@@ -1381,7 +1562,7 @@
}
public boolean isADataValue(Object handle) {
- throw new NotYetImplementedException();
+ return false;
}
public boolean isADependency(Object handle) {
@@ -1469,8 +1650,7 @@
}
public boolean isAInstance(Object handle) {
- // TODO: Double check this - tfm
- return handle instanceof InstanceSpecification;
+ return handle instanceof InstanceSpecification;
}
public boolean isAInteraction(Object handle) {
@@ -1504,7 +1684,8 @@
public boolean isALinkEnd(Object handle) {
// TODO: just a guess, probably not right - tfm
- return handle instanceof LinkEndData;
+// return handle instanceof LinkEndData;
+ return false;
}
public boolean isALinkObject(Object handle) {
@@ -1532,7 +1713,7 @@
public boolean isAModelElement(Object handle) {
// TODO: What do we want to use as an equivalent here?
- return handle instanceof NamedElement;
+ return handle instanceof Element;
}
public boolean isAMultiplicity(Object handle) {
@@ -1872,7 +2053,7 @@
}
public boolean isNavigable(Object handle) {
- return ((Property) handle).isNavigable();
+ return !((Property) handle).isNavigable();
}
public boolean isPackage(Object handle) {
@@ -1950,9 +2131,45 @@
return false;
}
- public Object lookupIn(Object handle, String name) {
- throw new NotYetImplementedException();
+ private NamedElement getElementByName(Namespace ns, String name) {
+ if (name == null) {
+ return null;
+ }
+ for (NamedElement e : ns.getOwnedMembers()) {
+ if (e.getName() != null && e.getName().equals(name)) {
+ return e;
+ }
+ }
+ return null;
+ }
+
+ public Element lookupIn(Object handle, String name) {
+ if (!(handle instanceof Namespace)) {
+ throw new IllegalArgumentException();
+ }
+
+ StringBuffer sb = new StringBuffer(name);
+ Namespace ns = (Namespace) handle;
+ for (;;) {
+ int idx = sb.indexOf("::");
+
+ if (idx != -1) {
+ NamedElement subspace = getElementByName(ns, sb.substring(
+ 0, idx));
+ if (subspace instanceof Namespace) {
+ ns = (Namespace) subspace;
+ sb.delete(0, idx + 2);
+ continue;
+ } else {
+ break;
+ }
+ }
+
+ NamedElement e = getElementByName(ns, sb.toString());
+ return e;
+ }
+ return null;
}
public String toString(Object modelElement) {
@@ -1970,18 +2187,25 @@
}
public boolean isReadOnly(Object handle) {
+ if (!(handle instanceof StructuralFeature)) {
+ throw new IllegalArgumentException();
+ }
return ((StructuralFeature) handle).isReadOnly();
}
public boolean isStatic(Object handle) {
+ if (!(handle instanceof Feature)) {
+ throw new IllegalArgumentException();
+ }
return ((Feature) handle).isStatic();
}
public Collection getRootElements() {
- // TODO: Temporary hack to let ArgoUML start up
- Collection results = new ArrayList();
- results.add(modelImpl.getModelManagementFactory().getRootModel());
- return results;
+ Collection c = new ArrayList();
+ if (modelImpl.getModelManagementFactory().getRootModel() != null) {
+ c.add(modelImpl.getModelManagementFactory().getRootModel());
+ }
+ return c;
}
}
Modified: trunk/src/model-euml/src/org/argouml/model/euml/MetaTypesEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-euml/src/org/argouml/model/euml/MetaTypesEUMLImpl.java?view=diff&rev=13462&p1=trunk/src/model-euml/src/org/argouml/model/euml/MetaTypesEUMLImpl.java&p2=trunk/src/model-euml/src/org/argouml/model/euml/MetaTypesEUMLImpl.java&r1=13461&r2=13462
==============================================================================
--- trunk/src/model-euml/src/org/argouml/model/euml/MetaTypesEUMLImpl.java (original)
+++ trunk/src/model-euml/src/org/argouml/model/euml/MetaTypesEUMLImpl.java 2007-08-30 11:48:34-0700
@@ -44,6 +44,7 @@
import org.eclipse.uml2.uml.Component;
import org.eclipse.uml2.uml.DataType;
import org.eclipse.uml2.uml.Dependency;
+import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Enumeration;
import org.eclipse.uml2.uml.EnumerationLiteral;
import org.eclipse.uml2.uml.Extend;
@@ -55,7 +56,6 @@
import org.eclipse.uml2.uml.Interface;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.MultiplicityElement;
-import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.Namespace;
import org.eclipse.uml2.uml.Node;
import org.eclipse.uml2.uml.ObjectNode;
@@ -133,7 +133,6 @@
}
public Object getAssociationEnd() {
- // TODO: Needs checking -tfm
// an AssociationEnd is now a Property owned by an Association
return Property.class;
}
@@ -149,11 +148,10 @@
// TODO: In UML 2.0, ClassifierRole, AssociationRole, and
// AssociationEndRole have been replaced by the internal
// structure of the Collaboration
- return null;
+ return Classifier.class;
}
public Object getAttribute() {
- // TODO: changed in UML 2.x - needs review - tfm
return Property.class;
}
@@ -260,7 +258,7 @@
}
public Object getGeneralizableElement() {
- // TODO: Gone in UML 2.x - just Classifier now? - tfm
+ // Gone in UML 2.x - just Classifier now
return Classifier.class;
}
@@ -307,7 +305,7 @@
}
public Object getModelElement() {
- return NamedElement.class;
+ return Element.class;
}
public Object getMultiplicity() {
@@ -333,9 +331,6 @@
if (name.endsWith(suffix)) {
endName -= suffix.length();
}
- if (endName < 0) {
- endName = name.length();
- }
return name.substring(startName, endName);
}
@@ -355,8 +350,9 @@
}
public Object getObject() {
- // TODO: just a guess - double check
- return org.eclipse.uml2.uml.ObjectNode.class;
+ throw new NotImplementedException();
+ // TODO: what to use: InstanceSpecification, ObjectNode, etc?
+// return org.eclipse.uml2.uml.ObjectNode.class;
}
public Object getObjectFlowState() {
@@ -468,8 +464,9 @@
}
public Object getSubsystem() {
- // TODO: Changed in UML 2.1 - Package with <<subsystem>> stereotype?
- return org.eclipse.uml2.uml.Package.class;
+ // Changed in UML 2.1 - Component with <<subsystem>> stereotype
+ // TODO: We should deprecate this?
+ return Component.class;
}
public Object getSynchState() {
Modified: trunk/src/model-euml/src/org/argouml/model/euml/ModelEventPumpEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-euml/src/org/argouml/model/euml/ModelEventPumpEUMLImpl.java?view=diff&rev=13462&p1=trunk/src/model-euml/src/org/argouml/model/euml/ModelEventPumpEUMLImpl.java&p2=trunk/src/model-euml/src/org/argouml/model/euml/ModelEventPumpEUMLImpl.java&r1=13461&r2=13462
==============================================================================
--- trunk/src/model-euml/src/org/argouml/model/euml/ModelEventPumpEUMLImpl.java (original)
+++ trunk/src/model-euml/src/org/argouml/model/euml/ModelEventPumpEUMLImpl.java 2007-08-30 11:48:34-0700
@@ -29,6 +29,7 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
+import java.util.EventObject;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -42,20 +43,25 @@
import org.argouml.model.AddAssociationEvent;
import org.argouml.model.AttributeChangeEvent;
import org.argouml.model.DeleteInstanceEvent;
+import org.argouml.model.Model;
+import org.argouml.model.RemoveAssociationEvent;
+import org.eclipse.emf.common.command.CommandStackListener;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.common.notify.impl.NotificationImpl;
+import org.eclipse.emf.ecore.ENamedElement;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
/**
- * The implementation of the ModelEventPump for EUML2.
+ * The implementation of the ModelEventPump for eUML.
*/
class ModelEventPumpEUMLImpl extends AbstractModelEventPump {
/**
* A listener attached to a UML element
*/
- class Listener {
+ private class Listener {
private PropertyChangeListener listener;
@@ -64,24 +70,27 @@
Listener(PropertyChangeListener listener, String[] properties) {
this.listener = listener;
if (properties != null) {
- props = null;
- addProperties(properties);
+ setProperties(properties);
}
}
- void addProperties(String[] properties) {
+ void setProperties(String[] properties) {
if (properties == null) {
- return;
- }
- if (props == null) {
- props = new HashSet<String>();
- }
- for (String s : properties) {
- props.add(s);
+ props = null;
+ } else {
+ if (props == null) {
+ props = new HashSet<String>();
+ }
+ for (String s : properties) {
+ props.add(s);
+ }
}
}
void removeProperties(String[] properties) {
+ if (props == null) {
+ return;
+ }
for (String s : properties) {
props.remove(s);
}
@@ -102,45 +111,59 @@
*/
private EUMLModelImplementation modelImpl;
- private RootContainerAdapter rootContainerAdapter =
- new RootContainerAdapter(this);
+ private RootContainerAdapter rootContainerAdapter = new RootContainerAdapter(
+ this);
// Access should be fast
- private Map<Object, List<Listener>> registerForElements =
- new HashMap<Object, List<Listener>>();
+ private Map<Object, List<Listener>> registerForElements = new HashMap<Object, List<Listener>>();
// Iteration should be fast
- private Map<Object, List<Listener>> registerForClasses =
- new LinkedHashMap<Object, List<Listener>>();
+ private Map<Object, List<Listener>> registerForClasses = new LinkedHashMap<Object, List<Listener>>();
private Object mutex;
-
+
private Logger LOG = Logger.getLogger(ModelEventPumpEUMLImpl.class);
-
+
+ public static final int COMMAND_STACK_UPDATE = Notification.EVENT_TYPE_COUNT + 1;
+
/**
* Constructor.
*
* @param implementation
- * The ModelImplementation.
+ * The ModelImplementation.
*/
public ModelEventPumpEUMLImpl(EUMLModelImplementation implementation) {
modelImpl = implementation;
mutex = this;
+ implementation.getEditingDomain().getCommandStack().addCommandStackListener(
+ new CommandStackListener() {
+
+ public void commandStackChanged(EventObject event) {
+ notifyChanged(new NotificationImpl(
+ COMMAND_STACK_UPDATE, false, false));
+ }
+
+ });
}
/**
* Setter for the root container
+ *
* @param container
*/
public void setRootContainer(Notifier container) {
rootContainerAdapter.setRootContainer(container);
}
+ public RootContainerAdapter getRootContainer() {
+ return rootContainerAdapter;
+ }
+
public void addClassModelEventListener(PropertyChangeListener listener,
Object modelClass, String[] propertyNames) {
- if (!(modelClass instanceof Class && EObject.class
- .isAssignableFrom((Class) modelClass))) {
- throw new IllegalArgumentException();
+ if (!(modelClass instanceof Class && EObject.class.isAssignableFrom((Class) modelClass))) {
+ throw new IllegalArgumentException(
+ "The model class must be instance of java.lang.Class<EObject>"); //$NON-NLS-1$
}
registerListener(
modelClass, listener, propertyNames, registerForClasses);
@@ -148,24 +171,26 @@
public void addModelEventListener(PropertyChangeListener listener,
Object modelelement, String[] propertyNames) {
- if (!(modelelement instanceof EObject)) {
- throw new IllegalArgumentException();
+ if (!(modelelement instanceof EObject)
+ && !(modelelement instanceof String && modelelement.equals(CommandStackImpl.COMMAND_STACK_UPDATE_EVENT))) {
+ throw new IllegalArgumentException(
+ "The modelelement must be instance of EObject."); //$NON-NLS-1$
}
registerListener(
- (EObject) modelelement, listener, propertyNames,
- registerForElements);
+ modelelement, listener, propertyNames, registerForElements);
}
public void addModelEventListener(PropertyChangeListener listener,
Object modelelement) {
- addModelEventListener(listener, modelelement, (String []) null);
+ addModelEventListener(listener, modelelement, (String[]) null);
}
private void registerListener(Object notifier,
PropertyChangeListener listener, String[] propertyNames,
Map<Object, List<Listener>> register) {
if (notifier == null || listener == null) {
- throw new NullPointerException();
+ throw new NullPointerException(
+ "The model element/class and the listener must be non-null."); //$NON-NLS-1$
}
synchronized (mutex) {
List<Listener> list = register.get(notifier);
@@ -177,10 +202,7 @@
} else {
for (Listener l : list) {
if (l.getListener() == listener) {
- // TODO: Do we really want to add new properties to the
- // already registered listener or we want to replace the
- // old properties
- l.addProperties(propertyNames);
+ l.setProperties(propertyNames);
found = true;
break;
}
@@ -199,8 +221,7 @@
public void removeClassModelEventListener(PropertyChangeListener listener,
Object modelClass, String[] propertyNames) {
- if (!(modelClass instanceof Class && EObject.class
- .isAssignableFrom((Class) modelClass))) {
+ if (!(modelClass instanceof Class && EObject.class.isAssignableFrom((Class) modelClass))) {
throw new IllegalArgumentException();
}
unregisterListener(
@@ -209,7 +230,8 @@
public void removeModelEventListener(PropertyChangeListener listener,
Object modelelement, String[] propertyNames) {
- if (!(modelelement instanceof EObject)) {
+ if (!(modelelement instanceof EObject)
+ && !(modelelement instanceof String && modelelement.equals(CommandStackImpl.COMMAND_STACK_UPDATE_EVENT))) {
throw new IllegalArgumentException();
}
unregisterListener(
@@ -218,14 +240,15 @@
public void removeModelEventListener(PropertyChangeListener listener,
Object modelelement) {
- removeModelEventListener(listener, modelelement, (String []) null);
+ removeModelEventListener(listener, modelelement, (String[]) null);
}
private void unregisterListener(Object notifier,
PropertyChangeListener listener, String[] propertyNames,
Map<Object, List<Listener>> register) {
if (notifier == null || listener == null) {
- throw new NullPointerException();
+ throw new NullPointerException(
+ "The model element/class and the listener must be non-null."); //$NON-NLS-1$
}
synchronized (mutex) {
List<Listener> list = register.get(notifier);
@@ -249,83 +272,168 @@
/**
* @see org.eclipse.emf.common.notify.Adapter#notifyChanged(Notification)
- * @param notification The notification event
+ * @param notification
+ * The notification event
*/
- @SuppressWarnings("unchecked")
public void notifyChanged(Notification notification) {
if (notification.getEventType() == Notification.REMOVING_ADAPTER) {
return;
}
- Object source = null;
- switch (notification.getEventType()) {
- case Notification.REMOVE:
- source = notification.getOldValue();
- break;
- default:
- source = notification.getNotifier();
+
+ class EventAndListeners {
+ public EventAndListeners(PropertyChangeEvent e,
+ List<PropertyChangeListener> l) {
+ event = e;
+ listeners = l;
+ }
+
+ PropertyChangeEvent event;
+
+ List<PropertyChangeListener> listeners;
+ }
+
+ List<EventAndListeners> events = new ArrayList<EventAndListeners>();
+
+ if (notification.getEventType() == Notification.SET) {
+ if (notification.getFeature() instanceof ENamedElement) {
+ String propName = mapPropertyName(((ENamedElement) notification.getFeature()).getName());
+ events.add(new EventAndListeners(new AttributeChangeEvent(
+ notification.getNotifier(), propName,
+ notification.getOldValue(), notification.getNewValue(),
+ null), getListeners(
+ notification.getNotifier(), propName)));
+ }
+ } else if (notification.getEventType() == Notification.ADD
+ || notification.getEventType() == Notification.REMOVE) {
+ if (notification.getFeature() instanceof EReference) {
+ EReference ref = (EReference) notification.getFeature();
+ String propName = mapPropertyName(ref.getName());
+ if (notification.getEventType() == Notification.ADD) {
+ events.add(new EventAndListeners(new AddAssociationEvent(
+ notification.getNotifier(), propName, null,
+ notification.getNewValue(),
+ notification.getNewValue(), null), getListeners(
+ notification.getNotifier(), propName)));
+ events.add(new EventAndListeners(new AttributeChangeEvent(
+ notification.getNotifier(), propName, null,
+ notification.getNewValue(), null), getListeners(
+ notification.getNotifier(), propName)));
+ } else {
+ events.add(new EventAndListeners(
+ new DeleteInstanceEvent(
+ notification.getOldValue(),
+ "remove", null, null, null), getListeners(notification.getOldValue()))); //$NON-NLS-1$
+ events.add(new EventAndListeners(
+ new RemoveAssociationEvent(
+ notification.getNotifier(), propName,
+ notification.getOldValue(), null,
+ notification.getOldValue(), null),
+ getListeners(
+ notification.getNotifier(), propName)));
+ events.add(new EventAndListeners(
+ new AttributeChangeEvent(
+ notification.getNotifier(), propName,
+ notification.getOldValue(), null, null),
+ getListeners(
+ notification.getNotifier(), propName)));
+ }
+
+ EReference oppositeRef = ref.getEOpposite();
+ if (oppositeRef != null) {
+ propName = mapPropertyName(oppositeRef.getName());
+ if (notification.getEventType() == Notification.ADD) {
+ events.add(new EventAndListeners(
+ new AddAssociationEvent(
+ notification.getNewValue(),
+ propName, null,
+ notification.getNotifier(),
+ notification.getNotifier(), null),
+ getListeners(
+ notification.getNewValue(),
+ propName)));
+ events.add(new EventAndListeners(
+ new AttributeChangeEvent(
+ notification.getNewValue(),
+ propName, null,
+ notification.getNotifier(), null),
+ getListeners(
+ notification.getNewValue(),
+ propName)));
+ } else {
+ events.add(new EventAndListeners(
+ new AddAssociationEvent(
+ notification.getOldValue(),
+ propName,
+ notification.getNotifier(), null,
+ notification.getNotifier(), null),
+ getListeners(
+ notification.getOldValue(),
+ propName)));
+ events.add(new EventAndListeners(
+ new AttributeChangeEvent(
+ notification.getOldValue(),
+ propName,
+ notification.getNotifier(), null, null),
+ getListeners(
+ notification.getOldValue(),
+ propName)));
+ }
+ }
+ }
+ } else if (notification.getEventType() == COMMAND_STACK_UPDATE) {
+ events.add(new EventAndListeners(
+ new PropertyChangeEvent(
+ this, CommandStackImpl.COMMAND_STACK_UPDATE_EVENT,
+ false, false),
+ getListeners(CommandStackImpl.COMMAND_STACK_UPDATE_EVENT)));
+// TODO: Why is this commented out? - tfm
+// Model.notifyMementoCreationObserver(CommandStackImpl.getInstance(modelImpl));
}
- List<Listener> listeners = new ArrayList<Listener>();
- synchronized (mutex) {
- List<Listener> list = registerForElements.get(source);
- if (list != null) {
- for (Listener l : list) {
- listeners.add(l);
+ for (EventAndListeners e : events) {
+ if (e.listeners != null) {
+ for (PropertyChangeListener l : e.listeners) {
+ l.propertyChange(e.event);
}
}
+ }
+ }
- boolean logged = false;
+ private List<PropertyChangeListener> getListeners(Object element) {
+ return getListeners(element, null);
+ }
+
+ @SuppressWarnings("unchecked")
+ private List<PropertyChangeListener> getListeners(Object element,
+ String propName) {
+ List<PropertyChangeListener> returnedList = new ArrayList<PropertyChangeListener>();
+
+ synchronized (mutex) {
+ addListeners(returnedList, element, propName, registerForElements);
for (Object o : registerForClasses.keySet()) {
if (o instanceof Class) {
Class type = (Class) o;
- if (type.isAssignableFrom(source.getClass())) {
- if (!logged) {
- LOG.debug("eUML is firing " + notification); //$NON-NLS-1$
- logged = true;
- }
- for (Listener l : registerForClasses.get(o)) {
- listeners.add(l);
- }
+ if (type.isAssignableFrom(element.getClass())) {
+ addListeners(
+ returnedList, o, propName, registerForClasses);
}
}
}
}
-
- for (Listener l : listeners) {
- fireNotification(notification, l);
- }
+ return returnedList.isEmpty() ? null : returnedList;
}
- private void fireNotification(Notification n, Listener l) {
- PropertyChangeEvent event = null;
- switch (n.getEventType()) {
- case Notification.REMOVE:
- event = new DeleteInstanceEvent(
- n.getOldValue(), "remove", null, null, null); //$NON-NLS-1$
- l.getListener().propertyChange(event);
- removeModelEventListener(l.getListener(), n.getOldValue());
- break;
- case Notification.SET:
- if (n.getFeature() instanceof EAttribute) {
- event = new AttributeChangeEvent(
- n.getNotifier(),
- ((EAttribute) n.getFeature()).getName(),
- n.getOldValue(), n.getNewValue(), null);
- l.getListener().propertyChange(event);
- }
- break;
- case Notification.ADD:
-// event = new AddAssociationEvent(
-// n.getNewValue(), "end", null, n.getNotifier(),
-// n.getNotifier(), null);
-// l.getListener().propertyChange(event);
-// event = new AddAssociationEvent(
-// n.getNotifier(), "reverse-end", null, n.getNewValue(),
-// n.getNewValue(), null);
-// l.getListener().propertyChange(event);
- break;
- default:
- LOG.debug("Uncought notification: " + n); //$NON-NLS-1$
+ private void addListeners(List<PropertyChangeListener> listeners,
+ Object element, String propName,
+ Map<Object, List<Listener>> register) {
+ List<Listener> list = register.get(element);
+ if (list != null) {
+ for (Listener l : list) {
+ if (propName == null || l.getProperties() == null
+ || l.getProperties().contains(propName)) {
+ listeners.add(l.getListener());
+ }
+ }
}
}
@@ -336,5 +444,13 @@
public void stopPumpingEvents() {
rootContainerAdapter.setDeliverEvents(false);
}
+
+ private String mapPropertyName(String name) {
+ // TODO: map UML2 names to UML1.x names
+ if (name.equals("ownedAttribute")) {
+ return "feature";
+ }
+ return name;
+ }
}
Modified: trunk/src/model-euml/src/org/argouml/model/euml/ModelManagementFactoryEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-euml/src/org/argouml/model/euml/ModelManagementFactoryEUMLImpl.java?view=diff&rev=13462&p1=trunk/src/model-euml/src/org/argouml/model/euml/ModelManagementFactoryEUMLImpl.java&p2=trunk/src/model-euml/src/org/argouml/model/euml/ModelManagementFactoryEUMLImpl.java&r1=13461&r2=13462
==============================================================================
--- trunk/src/model-euml/src/org/argouml/model/euml/ModelManagementFactoryEUMLImpl.java (original)
+++ trunk/src/model-euml/src/org/argouml/model/euml/ModelManagementFactoryEUMLImpl.java 2007-08-30 11:48:34-0700
@@ -32,6 +32,7 @@
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.uml2.common.edit.command.ChangeCommand;
import org.eclipse.uml2.uml.ElementImport;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.Namespace;
@@ -53,8 +54,6 @@
private EditingDomain editingDomain;
private org.eclipse.uml2.uml.Package theRootModel;
-
- private UMLFactory uml = UMLFactory.eINSTANCE;
/**
* Constructor.
@@ -68,17 +67,35 @@
editingDomain = implementation.getEditingDomain();
}
- public ElementImport buildElementImport(Object pack, Object me) {
- ElementImport imp = (ElementImport) createElementImport();
- imp.setImportingNamespace((Namespace) pack);
- imp.setImportedElement((PackageableElement) me);
- return imp;
+ public ElementImport buildElementImport(final Object pack, final Object me) {
+ if (!(pack instanceof Namespace)) {
+ throw new IllegalArgumentException(
+ "pack must be instance of Namespace"); //$NON-NLS-1$
+ }
+ if (!(me instanceof PackageableElement)) {
+ throw new IllegalArgumentException(
+ "me must be instance of PackageableElement"); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ ElementImport elementImport = createElementImport();
+ elementImport.setImportingNamespace((Namespace) pack);
+ elementImport.setImportedElement((PackageableElement) me);
+ getParams().add(elementImport);
+ }
+ };
+ editingDomain.getCommandStack().execute(
+ new ChangeCommand(editingDomain, run));
+
+ return (ElementImport) run.getParams().get(0);
}
public org.eclipse.uml2.uml.Package buildPackage(String name, String uuid) {
org.eclipse.uml2.uml.Package pkg =
(org.eclipse.uml2.uml.Package) createPackage();
- pkg.setName(name);
+ if (name != null) {
+ pkg.setName(name);
+ }
// TODO: What about UUID? This has been gone since UML 1.4 transition - tfm
return pkg;
}
@@ -89,15 +106,15 @@
}
public ElementImport createElementImport() {
- return uml.createElementImport();
+ return UMLFactory.eINSTANCE.createElementImport();
}
public Model createModel() {
- return uml.createModel();
+ return UMLFactory.eINSTANCE.createModel();
}
public org.eclipse.uml2.uml.Package createPackage() {
- return uml.createPackage();
+ return UMLFactory.eINSTANCE.createPackage();
}
@Deprecated
@@ -112,7 +129,7 @@
if (rootModel != null
&& !(rootModel instanceof org.eclipse.uml2.uml.Package)) {
throw new IllegalArgumentException(
- "The rootModel supplied must be a Package. Got a "
+ "The rootModel supplied must be a Package. Got a " //$NON-NLS-1$
+ rootModel.getClass().getName());
}
if (theRootModel != null && theRootModel.eResource() != null) {
@@ -120,8 +137,7 @@
}
theRootModel = (org.eclipse.uml2.uml.Package) rootModel;
if (rootModel != null) {
- Resource r = editingDomain.createResource(
- "http://argouml.tigris.org/euml/resource/default_uri.xmi"); //$NON-NLS-1$
+ Resource r = UMLUtil.getResource(modelImpl, UMLUtil.DEFAULT_URI);
r.getContents().add(theRootModel);
}
modelImpl.getModelEventPump().setRootContainer(theRootModel);
Modified: trunk/src/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java?view=diff&rev=13462&p1=trunk/src/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java&p2=trunk/src/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java&r1=13461&r2=13462
==============================================================================
--- trunk/src/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java (original)
+++ trunk/src/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java 2007-08-30 11:48:34-0700
@@ -28,17 +28,18 @@
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashSet;
-import java.util.Set;
import java.util.Vector;
import org.argouml.model.ModelManagementHelper;
+import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.Collaboration;
import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.Namespace;
-import org.eclipse.uml2.uml.Type;
-
+import org.eclipse.uml2.uml.PackageableElement;
+import org.eclipse.uml2.uml.VisibilityKind;
/**
* The implementation of the ModelManagementHelper for EUML2.
@@ -54,25 +55,51 @@
* Constructor.
*
* @param implementation
- * The ModelImplementation.
+ * The ModelImplementation.
*/
- public ModelManagementHelperEUMLImpl(
- EUMLModelImplementation implementation) {
+ public ModelManagementHelperEUMLImpl(EUMLModelImplementation implementation) {
modelImpl = implementation;
}
+ @SuppressWarnings("deprecation")
public boolean corresponds(Object obj1, Object obj2) {
// TODO Auto-generated method stub
return false;
}
public Collection getAllBehavioralFeatures(Object ns) {
- // TODO Auto-generated method stub
- return null;
+ return modelImpl.getCoreHelper().getAllBehavioralFeatures(ns);
}
- public Collection getAllContents(Object namespace) {
- return ((Element) namespace).allOwnedElements();
+ @SuppressWarnings("unchecked")
+ public Collection getAllContents(Object element) {
+ if (!(element instanceof Element)) {
+ throw new IllegalArgumentException(
+ "The argument must be instance of Element"); //$NON-NLS-1$
+ }
+ Collection result = new HashSet();
+ if (element instanceof Collaboration) {
+ // TODO: implement
+ }
+ if (element instanceof Classifier) {
+ result.addAll(((Classifier) element).allFeatures());
+ }
+ if (element instanceof Namespace) {
+ result.addAll(((Namespace) element).getMembers());
+ }
+ if (element instanceof org.eclipse.uml2.uml.Package) {
+ result.addAll(((org.eclipse.uml2.uml.Package) element).getPackagedElements());
+ org.eclipse.uml2.uml.Package p = ((org.eclipse.uml2.uml.Package) element).getNestingPackage();
+ while (p != null) {
+ for (PackageableElement e : p.getPackagedElements()) {
+ if (e.getVisibility() == VisibilityKind.PUBLIC_LITERAL) {
+ result.add(e);
+ }
+ }
+ p = p.getNestingPackage();
+ }
+ }
+ return result;
}
public Collection getAllImportedElements(Object pack) {
@@ -81,65 +108,51 @@
}
public Collection getAllModelElementsOfKind(Object nsa, Object type) {
-
- if (nsa == null || type == null) {
- return Collections.EMPTY_LIST;
+ if (!(nsa instanceof Element)) {
+ throw new IllegalArgumentException(
+ "nsa must be instance of Element"); //$NON-NLS-1$
}
+ Class theType = null;
if (type instanceof String) {
- return getAllModelElementsOfKind(nsa, (String) type);
- }
- if (!(nsa instanceof org.eclipse.uml2.uml.Package) || !(type instanceof Class)) {
- throw new IllegalArgumentException("illegal argument - namespace: "
- + nsa + " type: " + type);
- }
-
- org.eclipse.uml2.uml.Package pkg = (org.eclipse.uml2.uml.Package) nsa;
- Class typeClass = (Class) type;
-
- Collection<Type> result = new HashSet<Type>();
- for (Type ownedType : pkg.getOwnedTypes()) {
- if (typeClass.isAssignableFrom(ownedType.getClass())) {
- result.add(ownedType);
+ try {
+ theType = Class.forName((String) type);
+ } catch (ClassNotFoundException e) {
+ throw new IllegalArgumentException(e);
}
+ } else if (type instanceof Class) {
+ theType = (Class) type;
+ } else {
+ throw new IllegalArgumentException(
+ "type must be instance of Class or String"); //$NON-NLS-1$
}
-
- for (org.eclipse.uml2.uml.Package nestedPackage : pkg
- .getNestedPackages()) {
- result.addAll(getAllModelElementsOfKind(nestedPackage, typeClass));
+ if (!Element.class.isAssignableFrom(theType)) {
+ throw new IllegalArgumentException("type must represent an Element"); //$NON-NLS-1$
}
- return result;
-
+ Collection<Element> result = new ArrayList<Element>();
- }
-
- /*
- * Check whether model element is contained in given namespace/container.
- * TODO: Investigate a faster way to do this
- */
- private boolean contained(Object container, Object candidate) {
- Object current = candidate;
- while (current != null) {
- if (container.equals(current))
- return true;
- current = modelImpl.getFacade().getModelElementContainer(current);
+ for (Element element : ((Namespace) nsa).allOwnedElements()) {
+ if (theType.isAssignableFrom(element.getClass())) {
+ result.add(element);
+ }
}
- return false;
+
+ return result;
}
-
+
public Collection getAllModelElementsOfKind(Object nsa, String kind) {
- try {
- return getAllModelElementsOfKind(nsa, Class.forName(kind));
- } catch (ClassNotFoundException cnfe) {
- throw new IllegalArgumentException(
- "Can't derive a class name from " + kind);
- }
+ return getAllModelElementsOfKind(nsa, kind);
}
public Collection getAllModelElementsOfKindWithModel(Object model,
Object type) {
- if (model == null) {
- throw new IllegalArgumentException("A model must be supplied");
+ if (!(model instanceof Model)) {
+ throw new IllegalArgumentException(
+ "model must be instance of Model"); //$NON-NLS-1$
+ }
+ if (!(type instanceof Class)) {
+ throw new IllegalArgumentException(
+ "type must be instance of java.lang.Class"); //$NON-NLS-1$
}
Class kind = (Class) type;
Collection ret = getAllModelElementsOfKind(model, kind);
@@ -153,13 +166,7 @@
}
public Collection getAllNamespaces(Object ns) {
- Set<Element> results = new HashSet<Element>();
- for (Element element : ((Namespace) ns).allOwnedElements()) {
- if (element instanceof Namespace) {
- results.add(element);
- }
- }
- return results;
+ return getAllModelElementsOfKind(ns, Namespace.class);
}
public Collection getAllPossibleImports(Object pack) {
@@ -172,13 +179,29 @@
return null;
}
- public Collection getAllSurroundingNamespaces(Object ns) {
- return ((NamedElement) ns).allNamespaces();
+ public Collection getAllSurroundingNamespaces(Object element) {
+ if (!(element instanceof NamedElement)) {
+ throw new IllegalArgumentException(
+ "element must be instance of NamedElement"); //$NON-NLS-1$
+ }
+ return ((NamedElement) element).allNamespaces();
}
- public Collection getContents(Object namespace) {
- // TODO Auto-generated method stub
- return null;
+ @SuppressWarnings("unchecked")
+ public Collection getContents(Object element) {
+ if (!(element instanceof Element)) {
+ throw new IllegalArgumentException(
+ "element must be instance of Element"); //$NON-NLS-1$
+ }
+ Collection result = new HashSet();
+ if (element instanceof Namespace) {
+ result.addAll(((Namespace) element).getOwnedMembers());
+ result.addAll(((Namespace) element).getImportedMembers());
+ }
+ if (element instanceof org.eclipse.uml2.uml.Package) {
+ result.addAll(((org.eclipse.uml2.uml.Package) element).getPackagedElements());
+ }
+ return result;
}
public Object getCorrespondingElement(Object elem, Object model) {
@@ -211,22 +234,18 @@
public void removeImportedElement(Object handle, Object me) {
// TODO Auto-generated method stub
-
}
public void setAlias(Object handle, String alias) {
// TODO Auto-generated method stub
-
}
public void setImportedElements(Object pack, Collection imports) {
// TODO Auto-generated method stub
-
}
public void setSpecification(Object handle, boolean isSpecification) {
// TODO Auto-generated method stub
-
}
}
Modified: trunk/src/model-euml/src/org/argouml/model/euml/RootContainerAdapter.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-euml/src/org/argouml/model/euml/RootContainerAdapter.java?view=diff&rev=13462&p1=trunk/src/model-euml/src/org/argouml/model/euml/RootContainerAdapter.java&p2=trunk/src/model-euml/src/org/argouml/model/euml/RootContainerAdapter.java&r1=13461&r2=13462
==============================================================================
--- trunk/src/model-euml/src/org/argouml/model/euml/RootContainerAdapter.java (original)
+++ trunk/src/model-euml/src/org/argouml/model/euml/RootContainerAdapter.java 2007-08-30 11:48:34-0700
@@ -43,12 +43,16 @@
private List<Notifier> notifiers = new ArrayList<Notifier>();
+ private List<Notification> events = new ArrayList<Notification>();
+
private Notifier rootContainer;
private ModelEventPumpEUMLImpl pump;
private boolean deliverEvents = true;
+ private boolean holdEvents = false;
+
/**
* Constructor
* @param pump The ModelEventPump instance
@@ -112,8 +116,35 @@
public void notifyChanged(Notification notification) {
super.notifyChanged(notification);
if (deliverEvents) {
- pump.notifyChanged(notification);
+ if (holdEvents) {
+ events.add(notification);
+ } else {
+ pump.notifyChanged(notification);
+ }
+ }
+ }
+
+ /**
+ * Clears all the events held until now
+ */
+ public void clearHeldEvents() {
+ events.clear();
+ }
+
+ /**
+ * Determine if the events should be delivered when they arrive or to wait until holdEvents is false
+ * @param value the holdEvents value
+ */
+ public void setHoldEvents(boolean value) {
+ if (value == false) {
+ if (deliverEvents) {
+ for (Notification n : events) {
+ pump.notifyChanged(n);
+ }
+ }
+ events.clear();
}
+ holdEvents = value;
}
}
Modified: trunk/src/model-euml/src/org/argouml/model/euml/RunnableClass.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-euml/src/org/argouml/model/euml/RunnableClass.java?view=diff&rev=13462&p1=trunk/src/model-euml/src/org/argouml/model/euml/RunnableClass.java&p2=trunk/src/model-euml/src/org/argouml/model/euml/RunnableClass.java&r1=13461&r2=13462
==============================================================================
--- trunk/src/model-euml/src/org/argouml/model/euml/RunnableClass.java (original)
+++ trunk/src/model-euml/src/org/argouml/model/euml/RunnableClass.java 2007-08-30 11:48:34-0700
@@ -27,6 +27,7 @@
package org.argouml.model.euml;
import java.util.ArrayList;
+import java.util.List;
/**
* This is a utility class useful in conjunction with
@@ -40,9 +41,10 @@
* A list of parameters useful for extraction/insertion of parameters
* into a Runnable instance.
*/
- private ArrayList<Object> params = new ArrayList<Object>();
+ private List<Object> params = new ArrayList<Object>();
- public ArrayList<Object> getParams() {
+ public List<Object> getParams() {
return params;
}
+
}
Added: trunk/src/model-euml/src/org/argouml/model/euml/UMLUtil.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-euml/src/org/argouml/model/euml/UMLUtil.java?view=auto&rev=13462
==============================================================================
--- (empty file)
+++ trunk/src/model-euml/src/org/argouml/model/euml/UMLUtil.java 2007-08-30 11:48:34-0700
@@ -0,0 +1,188 @@
+// $Id: UMLUtil.java 13394 2007-08-18 12:48:34Z b00__1 $
+// Copyright (c) 2007, The ArgoUML Project
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// * Neither the name of the ArgoUML Project nor the
+// names of its contributors may be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE ArgoUML PROJECT ``AS IS'' AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE ArgoUML PROJECT BE LIABLE FOR ANY
+// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+package org.argouml.model.euml;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.StrictCompoundCommand;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.edit.command.CopyToClipboardCommand;
+import org.eclipse.emf.edit.command.PasteFromClipboardCommand;
+import org.eclipse.uml2.uml.Association;
+import org.eclipse.uml2.uml.AssociationClass;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Operation;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Type;
+
+/**
+ * This class exposes protected methods from
+ * {@link org.eclipse.uml2.uml.UMLUtil} and adds additional util methods
+ *
+ * @author Bogdan Pistol
+ */
+public class UMLUtil extends org.eclipse.uml2.uml.util.UMLUtil {
+
+ /**
+ * The default URI used for eUML
+ */
+ public static final URI DEFAULT_URI = URI.createURI("http://argouml.tigris.org/euml/resource/default_uri.xmi"); //$NON-NLS-1$
+
+ /**
+ * Getter for the attributes of a Type
+ *
+ * @param type
+ * The Type that owns the attributes
+ * @return the attributes or null
+ */
+ public static EList<Property> getOwnedAttributes(Type type) {
+ if (type instanceof AssociationClass) {
+ return ((AssociationClass) type).getOwnedAttributes();
+ } else if (type instanceof Association) {
+ return ((Association) type).getOwnedEnds();
+ } else {
+ return org.eclipse.uml2.uml.util.UMLUtil.getOwnedAttributes(type);
+ }
+ }
+
+ /**
+ * Getter for the operations of a Type
+ *
+ * @param type
+ * The Type that owns the operations
+ * @return the operations or null
+ */
+ public static EList<Operation> getOwnedOperations(Type type) {
+ return org.eclipse.uml2.uml.util.UMLUtil.getOwnedOperations(type);
+ }
+
+ /**
+ * Copy a tree of UML elements into a destination location
+ *
+ * @param modelImplementation
+ * the eUML model implementation
+ * @param source
+ * the tree of UML elements to be copied
+ * @param destination
+ * the destination container
+ * @return the root of the newly copied tree of UML elements or null
+ */
+ public static Element copy(EUMLModelImplementation modelImplementation,
+ Element source, Element destination) {
+ Command copyToClipboard = CopyToClipboardCommand.create(
+ modelImplementation.getEditingDomain(), source);
+ Command pasteFromClipboard = PasteFromClipboardCommand.create(
+ modelImplementation.getEditingDomain(), destination, null);
+ StrictCompoundCommand copyCommand = new StrictCompoundCommand() {
+ {
+ isPessimistic = true;
+ }
+ };
+ copyCommand.append(copyToClipboard);
+ copyCommand.append(pasteFromClipboard);
+ copyCommand.setLabel("Copy a tree of UML elements to a destination");
+ if (copyCommand.canExecute()) {
+ modelImplementation.getModelEventPump().getRootContainer().setHoldEvents(
+ true);
+ modelImplementation.getEditingDomain().getCommandStack().execute(
+ copyCommand);
+ if (modelImplementation.getEditingDomain().getCommandStack().getMostRecentCommand().getAffectedObjects().size() == 1) {
+ modelImplementation.getModelEventPump().getRootContainer().setHoldEvents(
+ false);
+ return (Element) modelImplementation.getEditingDomain().getCommandStack().getMostRecentCommand().getAffectedObjects().iterator().next();
+ } else {
+ modelImplementation.getEditingDomain().getCommandStack().undo();
+ modelImplementation.getModelEventPump().getRootContainer().clearHeldEvents();
+ modelImplementation.getModelEventPump().getRootContainer().setHoldEvents(
+ false);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns information about an Object.
+ * <p>
+ * If it's an Element it returns its metaclass name, and if it's a
+ * NamedElement it appends its name.
+ *
+ * @param o
+ * The object
+ * @return the String description
+ */
+ public static String toString(Object o) {
+ if (o == null) {
+ return "null"; //$NON-NLS-1$
+ }
+ if (!(o instanceof Element)) {
+ return o.toString();
+ }
+
+ StringBuilder sb = new StringBuilder("'"); //$NON-NLS-1$
+ boolean named = false;
+
+ if (o instanceof NamedElement && ((NamedElement) o).getName() != null
+ && !((NamedElement) o).getName().equals("")) { //$NON-NLS-1$
+ named = true;
+ sb.append(((NamedElement) o).getName() + " ["); //$NON-NLS-1$
+ }
+
+ sb.append(((Element) o).eClass().getName());
+
+ if (named) {
+ sb.append("]"); //$NON-NLS-1$
+ }
+
+ sb.append("'"); //$NON-NLS-1$
+
+ return sb.toString();
+ }
+
+ /**
+ * Returns the Resource associated with an URI or creates the resource if it
+ * does not exist
+ *
+ * @param modelImplementation
+ * the eUML implementation
+ * @param uri
+ * the URI which identifies the resource
+ * @return the retrieved or created resource
+ */
+ public static Resource getResource(
+ EUMLModelImplementation modelImplementation, URI uri) {
+ Resource r = modelImplementation.getEditingDomain().getResourceSet().getResource(
+ uri, false);
+ if (r == null) {
+ r = modelImplementation.getEditingDomain().getResourceSet().createResource(
+ uri);
+ }
+ return r;
+ }
+
+}
Modified: trunk/src/model-euml/src/org/argouml/model/euml/UmlFactoryEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-euml/src/org/argouml/model/euml/UmlFactoryEUMLImpl.java?view=diff&rev=13462&p1=trunk/src/model-euml/src/org/argouml/model/euml/UmlFactoryEUMLImpl.java&p2=trunk/src/model-euml/src/org/argouml/model/euml/UmlFactoryEUMLImpl.java&r1=13461&r2=13462
==============================================================================
--- trunk/src/model-euml/src/org/argouml/model/euml/UmlFactoryEUMLImpl.java (original)
+++ trunk/src/model-euml/src/org/argouml/model/euml/UmlFactoryEUMLImpl.java 2007-08-30 11:48:34-0700
@@ -36,27 +36,24 @@
import org.argouml.model.IllegalModelElementConnectionException;
import org.argouml.model.MetaTypes;
import org.argouml.model.UmlFactory;
-import org.eclipse.emf.ecore.EAnnotation;
-import org.eclipse.emf.ecore.EModelElement;
-import org.eclipse.emf.ecore.impl.EcoreFactoryImpl;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.uml2.uml.Abstraction;
import org.eclipse.uml2.uml.AggregationKind;
import org.eclipse.uml2.uml.Association;
import org.eclipse.uml2.uml.AssociationClass;
import org.eclipse.uml2.uml.Classifier;
-import org.eclipse.uml2.uml.Component;
import org.eclipse.uml2.uml.Dependency;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Extend;
import org.eclipse.uml2.uml.Generalization;
import org.eclipse.uml2.uml.Include;
import org.eclipse.uml2.uml.Interface;
-import org.eclipse.uml2.uml.Message;
import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.PackageImport;
import org.eclipse.uml2.uml.State;
import org.eclipse.uml2.uml.Transition;
-import org.eclipse.uml2.uml.UMLFactory;
+import org.eclipse.uml2.uml.Type;
import org.eclipse.uml2.uml.Usage;
import org.eclipse.uml2.uml.UseCase;
@@ -66,11 +63,6 @@
*/
class UmlFactoryEUMLImpl implements UmlFactory, AbstractModelFactory {
- private static final String IS_REMOVED_NAME =
- "http://argouml.tigris.org/argouml-core-model-euml/isRemoved";
-
- private EAnnotation removedAnnotation;
-
/**
* The model implementation.
*/
@@ -121,20 +113,22 @@
{Usage.class, NamedElement.class, },
{PackageImport.class, NamedElement.class, },
// The following is specifically for Realizations
+ // TODO: correction in GEF, it should use InterfaceRealization, not Abstraction
{Abstraction.class, org.eclipse.uml2.uml.Class.class, Interface.class, null, },
// The next 3 restrictions for Abstraction seem to be Argo specific
// not something the UML spec requires - tfm - 20070215
- {Abstraction.class, org.eclipse.uml2.uml.Class.class, org.eclipse.uml2.uml.Class.class, null, },
- {Abstraction.class, org.eclipse.uml2.uml.Package.class,org.eclipse.uml2.uml.Package.class, null, },
- {Abstraction.class, Component.class, Interface.class, null, },
- {Association.class, Classifier.class, },
+ // There is no need for these because they arn't used by buildConnection() - b00__1
+// {Abstraction.class, org.eclipse.uml2.uml.Class.class, org.eclipse.uml2.uml.Class.class, null, },
+// {Abstraction.class, org.eclipse.uml2.uml.Package.class,org.eclipse.uml2.uml.Package.class, null, },
+// {Abstraction.class, Component.class, Interface.class, null, },
+ {Association.class, Type.class, },
// {AssociationRole.class, ClassifierRole.class, },
{Extend.class, UseCase.class, },
{Include.class, UseCase.class, },
// {Link.class, Instance.class, },
// {Transition.class, StateVertex.class, },
{Transition.class, State.class, },
- {AssociationClass.class, org.eclipse.uml2.uml.Class.class, },
+ {AssociationClass.class, Type.class, },
// {AssociationEnd.class, Classifier.class, Association.class, },
// {Message.class, ClassifierRole.class },
};
@@ -149,183 +143,199 @@
modelImpl = implementation;
metaTypes = modelImpl.getMetaTypes();
buildValidConnectionMap();
-
- removedAnnotation = EcoreFactoryImpl.eINSTANCE.createEAnnotation();
- removedAnnotation.setSource(IS_REMOVED_NAME);
}
- // TODO: This is unchanged from UML 1.4 - needs review - tfm
public Object buildConnection(Object elementType, Object fromElement,
Object fromStyle, Object toElement, Object toStyle,
Object unidirectional, Object namespace)
- throws IllegalModelElementConnectionException {
+ throws IllegalModelElementConnectionException {
+
+ IllegalModelElementConnectionException exception = new IllegalModelElementConnectionException(
+ "Cannot make a " + elementType.getClass().getName() //$NON-NLS-1$
+ + " between a " + fromElement.getClass().getName() //$NON-NLS-1$
+ + " and a " + toElement.getClass().getName()); //$NON-NLS-1$
+
if (!isConnectionValid(elementType, fromElement, toElement, true)) {
- throw new IllegalModelElementConnectionException("Cannot make a "
- + elementType.getClass().getName() + " between a "
- + fromElement.getClass().getName() + " and a "
- + toElement.getClass().getName());
+ throw exception;
}
Object connection = null;
if (elementType == metaTypes.getAssociation()) {
- connection =
- getCore().buildAssociation((Classifier) fromElement,
- (AggregationKind) fromStyle, (Classifier) toElement,
- (AggregationKind) toStyle, (Boolean) unidirectional);
+ connection = modelImpl.getCoreFactory().buildAssociation(
+ (Classifier) fromElement, (AggregationKind) fromStyle,
+ (Classifier) toElement, (AggregationKind) toStyle,
+ (Boolean) unidirectional);
} else if (elementType == metaTypes.getAssociationEnd()) {
if (fromElement instanceof Association) {
- connection =
- getCore().buildAssociationEnd(toElement, fromElement);
+ connection = modelImpl.getCoreFactory().buildAssociationEnd(
+ toElement, fromElement);
} else if (fromElement instanceof Classifier) {
- connection =
- getCore().buildAssociationEnd(fromElement, toElement);
+ connection = modelImpl.getCoreFactory().buildAssociationEnd(
+ fromElement, toElement);
}
- } else if (elementType
- == metaTypes.getAssociationClass()) {
- connection =
- getCore().buildAssociationClass(fromElement, toElement);
+ } else if (elementType == metaTypes.getAssociationClass()) {
+ connection = modelImpl.getCoreFactory().buildAssociationClass(
+ fromElement, toElement);
} else if (elementType == metaTypes.getAssociationRole()) {
- connection =
- getCollaborations().buildAssociationRole(fromElement,
- fromStyle, toElement, toStyle, (Boolean) unidirectional);
+ connection = modelImpl.getCollaborationsFactory().buildAssociationRole(
+ fromElement, fromStyle, toElement, toStyle,
+ (Boolean) unidirectional);
} else if (elementType == metaTypes.getGeneralization()) {
- connection = getCore().buildGeneralization(fromElement, toElement);
+ connection = modelImpl.getCoreFactory().buildGeneralization(
+ fromElement, toElement);
} else if (elementType == metaTypes.getPackageImport()) {
- connection = getCore().buildPackageImport(fromElement, toElement);
+ connection = modelImpl.getCoreFactory().buildPackageImport(
+ fromElement, toElement);
} else if (elementType == metaTypes.getUsage()) {
- connection = getCore().buildUsage(fromElement, toElement);
- } else if (elementType == metaTypes.getGeneralization()) {
- connection = getCore().buildGeneralization(fromElement, toElement);
+ connection = modelImpl.getCoreFactory().buildUsage(
+ fromElement, toElement);
} else if (elementType == metaTypes.getDependency()) {
- connection = getCore().buildDependency(fromElement, toElement);
+ connection = modelImpl.getCoreFactory().buildDependency(
+ fromElement, toElement);
} else if (elementType == metaTypes.getAbstraction()) {
- connection =
- getCore().buildRealization(fromElement, toElement, namespace);
+ connection = modelImpl.getCoreFactory().buildRealization(
+ fromElement, toElement, namespace);
} else if (elementType == metaTypes.getLink()) {
- connection = getCommonBehavior().buildLink(fromElement, toElement);
+ connection = modelImpl.getCommonBehaviorFactory().buildLink(
+ fromElement, toElement);
} else if (elementType == metaTypes.getExtend()) {
// Extend, but only between two use cases. Remember we draw from the
// extension port to the base port.
- connection = getUseCases().buildExtend(toElement, fromElement);
+ connection = modelImpl.getUseCasesFactory().buildExtend(
+ toElement, fromElement);
} else if (elementType == metaTypes.getInclude()) {
- connection = getUseCases().buildInclude(fromElement, toElement);
+ connection = modelImpl.getUseCasesFactory().buildInclude(
+ fromElement, toElement);
} else if (elementType == metaTypes.getTransition()) {
- connection =
- getStateMachines().buildTransition(fromElement, toElement);
+ connection = modelImpl.getStateMachinesFactory().buildTransition(
+ fromElement, toElement);
}
if (connection == null) {
- throw new IllegalModelElementConnectionException("Cannot make a "
- + elementType.getClass().getName() + " between a "
- + fromElement.getClass().getName() + " and a "
- + toElement.getClass().getName());
+ throw exception;
}
return connection;
}
public Object buildNode(Object elementType) {
+ Object o = null;
if (elementType == metaTypes.getActor()) {
- return getUseCases().createActor();
+ o = modelImpl.getUseCasesFactory().createActor();
} else if (elementType == metaTypes.getUseCase()) {
- return getUseCases().createUseCase();
+ o = modelImpl.getUseCasesFactory().createUseCase();
} else if (elementType == metaTypes.getUMLClass()) {
- return getCore().buildClass();
+ o = modelImpl.getCoreFactory().buildClass();
} else if (elementType == metaTypes.getInterface()) {
- return getCore().buildInterface();
+ o = modelImpl.getCoreFactory().buildInterface();
} else if (elementType == metaTypes.getDataType()) {
- return getCore().createDataType();
+ o = modelImpl.getCoreFactory().createDataType();
} else if (elementType == metaTypes.getPackage()) {
- return getModelManagement().createPackage();
+ o = modelImpl.getModelManagementFactory().createPackage();
} else if (elementType == metaTypes.getModel()) {
- return getModelManagement().createModel();
+ o = modelImpl.getModelManagementFactory().createModel();
} else if (elementType == metaTypes.getInstance()) {
throw new IllegalArgumentException(
- "Attempt to instantiate abstract type");
+ "Attempt to instantiate abstract type"); //$NON-NLS-1$
} else if (elementType == metaTypes.getSubsystem()) {
- return getModelManagement().createSubsystem();
+ o = modelImpl.getModelManagementFactory().createSubsystem();
} else if (elementType == metaTypes.getCallState()) {
- return getActivityGraphs().createCallState();
+ o = modelImpl.getActivityGraphsFactory().createCallState();
} else if (elementType == metaTypes.getSimpleState()) {
- return getStateMachines().createSimpleState();
+ o = modelImpl.getStateMachinesFactory().createSimpleState();
} else if (elementType == metaTypes.getFinalState()) {
- return getStateMachines().createFinalState();
+ o = modelImpl.getStateMachinesFactory().createFinalState();
} else if (elementType == metaTypes.getPseudostate()) {
- return getStateMachines().createPseudostate();
+ o = modelImpl.getStateMachinesFactory().createPseudostate();
} else if (elementType == metaTypes.getObjectFlowState()) {
- return getActivityGraphs().createObjectFlowState();
+ o = modelImpl.getActivityGraphsFactory().createObjectFlowState();
} else if (elementType == metaTypes.getActionState()) {
- return getActivityGraphs().createActionState();
+ o = modelImpl.getActivityGraphsFactory().createActionState();
} else if (elementType == metaTypes.getSubactivityState()) {
- return getActivityGraphs().createSubactivityState();
+ o = modelImpl.getActivityGraphsFactory().createSubactivityState();
} else if (elementType == metaTypes.getPartition()) {
- return getActivityGraphs().createPartition();
+ o = modelImpl.getActivityGraphsFactory().createPartition();
} else if (elementType == metaTypes.getStubState()) {
- return getStateMachines().createStubState();
+ o = modelImpl.getStateMachinesFactory().createStubState();
} else if (elementType == metaTypes.getSubmachineState()) {
- return getStateMachines().createSubmachineState();
+ o = modelImpl.getStateMachinesFactory().createSubmachineState();
} else if (elementType == metaTypes.getCompositeState()) {
- return getStateMachines().createCompositeState();
+ o = modelImpl.getStateMachinesFactory().createCompositeState();
} else if (elementType == metaTypes.getSynchState()) {
- return getStateMachines().createSynchState();
+ o = modelImpl.getStateMachinesFactory().createSynchState();
} else if (elementType == metaTypes.getState()) {
throw new IllegalArgumentException(
- "Attempt to instantiate abstract type");
+ "Attempt to instantiate abstract type"); //$NON-NLS-1$
} else if (elementType == modelImpl.getMetaTypes().getSimpleState()) {
- return getStateMachines().createSimpleState();
+ o = modelImpl.getStateMachinesFactory().createSimpleState();
} else if (elementType == metaTypes.getClassifierRole()) {
- return getCollaborations().createClassifierRole();
+ o = modelImpl.getCollaborationsFactory().createClassifierRole();
} else if (elementType == metaTypes.getComponent()) {
- return getCore().createComponent();
+ o = modelImpl.getCoreFactory().createComponent();
} else if (elementType == metaTypes.getComponentInstance()) {
- return getCommonBehavior().createComponentInstance();
+ o = modelImpl.getCommonBehaviorFactory().createComponentInstance();
} else if (elementType == metaTypes.getNode()) {
- return getCore().createNode();
+ o = modelImpl.getCoreFactory().createNode();
} else if (elementType == metaTypes.getNodeInstance()) {
- return getCommonBehavior().createNodeInstance();
+ o = modelImpl.getCommonBehaviorFactory().createNodeInstance();
} else if (elementType == metaTypes.getObject()) {
- return getCommonBehavior().createObject();
+ o = modelImpl.getCommonBehaviorFactory().createObject();
} else if (elementType == metaTypes.getComment()) {
- return getCore().createComment();
+ o = modelImpl.getCoreFactory().createComment();
} else if (elementType == metaTypes.getNamespace()) {
throw new IllegalArgumentException(
- "Attempt to instantiate abstract type");
+ "Attempt to instantiate abstract type"); //$NON-NLS-1$
} else if (elementType == metaTypes.getOperation()) {
- return getCore().createOperation();
+ o = modelImpl.getCoreFactory().createOperation();
} else if (elementType == metaTypes.getEnumeration()) {
- return getCore().createEnumeration();
+ o = modelImpl.getCoreFactory().createEnumeration();
} else if (elementType == metaTypes.getStereotype()) {
- return getExtensionMechanisms().createStereotype();
+ o = modelImpl.getExtensionMechanismsFactory().createStereotype();
} else if (elementType == metaTypes.getAttribute()) {
- return getCore().buildAttribute();
+ o = modelImpl.getCoreFactory().createAttribute();
} else if (elementType == metaTypes.getSignal()) {
- return getCommonBehavior().createSignal();
+ o = modelImpl.getCommonBehaviorFactory().createSignal();
} else if (elementType == metaTypes.getException()) {
- return getCommonBehavior().createException();
+ o = modelImpl.getCommonBehaviorFactory().createException();
} else if (elementType == metaTypes.getTransition()) {
- return getStateMachines().createTransition();
+ o = modelImpl.getStateMachinesFactory().createTransition();
}
-
- throw new IllegalArgumentException(
- "Attempted to create unsupported model element type: "
- + elementType);
+ if (!(o instanceof EObject)) {
+ throw new IllegalArgumentException(
+ "Attempted to create unsupported model element type: " //$NON-NLS-1$
+ + elementType);
+ }
+ return o;
}
- public void delete(Object elem) {
- // TODO: We probably need a better way of doing this - tfm
- // Add an annotation saying that we've deleted the element
- ((EModelElement) elem).getEAnnotations().add(removedAnnotation);
- ((Element) elem).destroy();
+ public void delete(final Object elem) {
+ if (!(elem instanceof EObject)) {
+ throw new IllegalArgumentException(
+ "elem must be instance of EObject"); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ EcoreUtil.delete((EObject) elem);
+ }
+ };
+ modelImpl.getEditingDomain().getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, run, "Remove from the model the element #",
+ elem));
}
public boolean isRemoved(Object o) {
- // TODO: We need a way to tell if #destroy() has
- // been called
+ // This triggers some warnings (in logs) because some elements are
+ // created without an owner (and eResource is null)
+ // TODO: fix this
+ // The warning log (if we would not add the EObject to a resource) would
+ // looks like this: "...WARN [AWT-EventQueue-0] Encountered deleted
+ // object during delete of..."
if (o instanceof Element) {
- return ((EModelElement) o).getEAnnotation(IS_REMOVED_NAME) != null;
+ return ((Element) o).eResource() == null;
}
- throw new IllegalArgumentException("Not an Element : " + o);
+ throw new IllegalArgumentException("Not an Element : " + o); //$NON-NLS-1$
}
public boolean isConnectionType(Object connectionType) {
@@ -338,7 +348,6 @@
return isConnectionValid(connectionType, fromElement, toElement, true);
}
- // TODO: This is unchanged from UML 1.4 - needs review - tfm
public boolean isConnectionValid(Object connectionType, Object fromElement,
Object toElement, boolean checkWFR) {
// Get the list of valid model item pairs for the given connection type
@@ -397,91 +406,6 @@
return true;
}
-
-
- /**
- * Returns the package factory for the UML package
- * Foundation::ExtensionMechanisms.
- *
- * @return the ExtensionMechanisms factory instance.
- */
- private ExtensionMechanismsFactoryEUMLImpl getExtensionMechanisms() {
- return (ExtensionMechanismsFactoryEUMLImpl) modelImpl.
- getExtensionMechanismsFactory();
- }
-
- /**
- * Returns the package factory for the UML package Foundation::Core.
- *
- * @return the Core factory instance.
- */
- private CoreFactoryEUMLImpl getCore() {
- return (CoreFactoryEUMLImpl) modelImpl.getCoreFactory();
- }
-
- /**
- * Returns the package factory for the UML package
- * BehavioralElements::CommonBehavior.
- *
- * @return the CommonBehavior factory instance.
- */
- private CommonBehaviorFactoryEUMLImpl getCommonBehavior() {
- return (CommonBehaviorFactoryEUMLImpl) modelImpl.
- getCommonBehaviorFactory();
- }
-
- /**
- * Returns the package factory for the UML package
- * BehavioralElements::UseCases.
- *
- * @return the UseCases factory instance.
- */
- private UseCasesFactoryEUMLImpl getUseCases() {
- return (UseCasesFactoryEUMLImpl) modelImpl.getUseCasesFactory();
- }
-
- /**
- * Returns the package factory for the UML package
- * BehavioralElements::StateMachines.
- *
- * @return the StateMachines factory instance.
- */
- private StateMachinesFactoryEUMLImpl getStateMachines() {
- return (StateMachinesFactoryEUMLImpl) modelImpl.getStateMachinesFactory();
- }
-
- /**
- * Returns the package factory for the UML package
- * BehavioralElements::Collaborations.
- *
- * @return the Collaborations factory instance.
- */
- private CollaborationsFactoryEUMLImpl getCollaborations() {
- return (CollaborationsFactoryEUMLImpl) modelImpl.
- getCollaborationsFactory();
- }
-
- /**
- * Returns the package factory for the UML package
- * BehavioralElements::ActivityGraphs.
- *
- * @return the ActivityGraphs factory instance.
- */
- private ActivityGraphsFactoryEUMLlImpl getActivityGraphs() {
- return (ActivityGraphsFactoryEUMLlImpl) modelImpl.
- getActivityGraphsFactory();
- }
-
- /**
- * Returns the package factory for the UML package ModelManagement.
- *
- * @return the ModelManagement factory instance.
- */
- private ModelManagementFactoryEUMLImpl getModelManagement() {
- return (ModelManagementFactoryEUMLImpl) modelImpl.
- getModelManagementFactory();
- }
-
private void buildValidConnectionMap() {
// A list of valid connections between elements, the
// connection type first and then the elements to be connected
@@ -510,7 +434,8 @@
validItems.add(modeElementPair);
// If the array hasn't been flagged to indicate otherwise
// swap elements the elemnts and add again.
- if (VALID_CONNECTIONS[i].length < 4) {
+ if (VALID_CONNECTIONS[i].length < 4
+ && VALID_CONNECTIONS[i][1] != VALID_CONNECTIONS[i][2]) {
Object[] reversedModeElementPair = new Class[2];
reversedModeElementPair[0] = VALID_CONNECTIONS[i][2];
reversedModeElementPair[1] = VALID_CONNECTIONS[i][1];
Modified: trunk/src/model-euml/src/org/argouml/model/euml/UseCasesFactoryEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-euml/src/org/argouml/model/euml/UseCasesFactoryEUMLImpl.java?view=diff&rev=13462&p1=trunk/src/model-euml/src/org/argouml/model/euml/UseCasesFactoryEUMLImpl.java&p2=trunk/src/model-euml/src/org/argouml/model/euml/UseCasesFactoryEUMLImpl.java&r1=13461&r2=13462
==============================================================================
--- trunk/src/model-euml/src/org/argouml/model/euml/UseCasesFactoryEUMLImpl.java (original)
+++ trunk/src/model-euml/src/org/argouml/model/euml/UseCasesFactoryEUMLImpl.java 2007-08-30 11:48:34-0700
@@ -60,45 +60,106 @@
}
public Actor buildActor(Object actor, Object model) {
+ if (!(actor instanceof Actor)) {
+ throw new IllegalArgumentException();
+ }
+ if (((Actor) actor).getNamespace() == null
+ && !(model instanceof Namespace)) {
+ throw new IllegalArgumentException();
+ }
Namespace ns = ((Actor) actor).getNamespace();
if (ns == null) {
ns = (Namespace) model;
}
- Actor actor2 = (Actor) createActor();
- modelImpl.getCoreHelper().addOwnedElement(ns, actor2);
- actor2.setIsLeaf(false);
-// actor2.setIsRoot(false);
- return actor2;
+ Actor ret = createActor();
+ modelImpl.getCoreHelper().addOwnedElement(
+ ns, ret, "Create the actor # in the namespace #", ret, ns);
+// ret.setIsLeaf(false);
+// ret.setIsRoot(false);
+ return ret;
}
public Extend buildExtend(Object abase, Object anextension) {
return buildExtend(abase, anextension, null);
}
- public Extend buildExtend(Object abase, Object anextension, Object apoint) {
- ExtensionPoint ep;
- if (apoint == null) {
- ep = buildExtensionPoint((UseCase) abase);
- } else {
- ep = (ExtensionPoint) apoint;
- if (!ep.getUseCase().equals(abase)) {
- throw new IllegalArgumentException(
- "extension point must belong to " + //$NON-NLS-1$
- "extended use case"); //$NON-NLS-1$
- }
+ public Extend buildExtend(final Object extendedCase,
+ final Object extension, final Object extensionLocation) {
+ if (!(extendedCase instanceof UseCase)
+ || !(extension instanceof UseCase)) {
+ throw new IllegalArgumentException();
}
- Extend extend =
- ((UseCase) anextension).createExtend(null, (UseCase) abase);
- extend.getExtensionLocations().add(ep);
- return extend;
+ if (extensionLocation != null
+ && !(extensionLocation instanceof ExtensionPoint)) {
+ throw new IllegalArgumentException();
+ }
+ if (extensionLocation != null
+ && !((ExtensionPoint) extensionLocation).getUseCase().equals(
+ extendedCase)) {
+ throw new IllegalArgumentException(
+ "extensionLocation must belong to " + extendedCase); //$NON-NLS-1$
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ ExtensionPoint ep;
+ if (extensionLocation == null) {
+ ep = createExtensionPoint();
+ ((UseCase) extendedCase).getExtensionPoints().add(ep);
+ } else {
+ ep = (ExtensionPoint) extensionLocation;
+ }
+ Extend extend = createExtend();
+ extend.setExtendedCase((UseCase) extendedCase);
+ extend.setExtension((UseCase) extension);
+ extend.getExtensionLocations().add(ep);
+ getParams().add(extend);
+ getParams().add(ep);
+ }
+ };
+ ChangeCommand cmd = new ChangeCommand(
+ modelImpl, run,
+ "Create the extend # for the case # that extends the case # through #");
+ modelImpl.getEditingDomain().getCommandStack().execute(cmd);
+ cmd.setObjects(
+ run.getParams().get(0), extension, extendedCase,
+ run.getParams().get(1));
+
+ return (Extend) run.getParams().get(0);
}
public ExtensionPoint buildExtensionPoint(Object modelElement) {
- return ((UseCase) modelElement).createExtensionPoint(null);
+ if (!(modelElement instanceof UseCase)) {
+ throw new IllegalArgumentException();
+ }
+ ExtensionPoint ep = createExtensionPoint();
+ modelImpl.getCoreHelper().addOwnedElement(
+ modelElement, ep,
+ "Create the extension point # for the case #", ep,
+ modelElement);
+ return ep;
}
- public Include buildInclude(Object abase, Object anaddition) {
- return ((UseCase) anaddition).createInclude(null, (UseCase) abase);
+ public Include buildInclude(final Object addition,
+ final Object includingCase) {
+ if (!(addition instanceof UseCase)
+ || !(includingCase instanceof UseCase)) {
+ throw new IllegalArgumentException();
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ Include include = createInclude();
+ include.setAddition((UseCase) addition);
+ include.setIncludingCase((UseCase) includingCase);
+ getParams().add(include);
+ }
+ };
+ ChangeCommand cmd = new ChangeCommand(
+ modelImpl, run,
+ "Create the include # of the including case # that include the case #");
+ modelImpl.getEditingDomain().getCommandStack().execute(cmd);
+ cmd.setObjects(run.getParams().get(0), includingCase, addition);
+
+ return (Include) run.getParams().get(0);
}
public Actor createActor() {
Modified: trunk/src/model-euml/src/org/argouml/model/euml/UseCasesHelperEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-euml/src/org/argouml/model/euml/UseCasesHelperEUMLImpl.java?view=diff&rev=13462&p1=trunk/src/model-euml/src/org/argouml/model/euml/UseCasesHelperEUMLImpl.java&p2=trunk/src/model-euml/src/org/argouml/model/euml/UseCasesHelperEUMLImpl.java&r1=13461&r2=13462
==============================================================================
--- trunk/src/model-euml/src/org/argouml/model/euml/UseCasesHelperEUMLImpl.java (original)
+++ trunk/src/model-euml/src/org/argouml/model/euml/UseCasesHelperEUMLImpl.java 2007-08-30 11:48:34-0700
@@ -31,11 +31,11 @@
import org.argouml.model.NotImplementedException;
import org.argouml.model.UseCasesHelper;
+import org.eclipse.emf.edit.command.CommandParameter;
import org.eclipse.uml2.uml.Actor;
import org.eclipse.uml2.uml.Extend;
import org.eclipse.uml2.uml.ExtensionPoint;
import org.eclipse.uml2.uml.Include;
-import org.eclipse.uml2.uml.Type;
import org.eclipse.uml2.uml.UseCase;
/**
@@ -58,54 +58,91 @@
modelImpl = implementation;
}
- public void addExtend(Object handle, Object extend) {
- if (handle instanceof UseCase) {
- ((UseCase) handle).getExtends().add(
- (Extend) extend);
- } else if (handle instanceof ExtensionPoint) {
- ((Extend) extend).getExtensionLocations().add(
- (ExtensionPoint) handle);
+ public void addExtend(final Object handle, final Object extend) {
+ if (!(handle instanceof UseCase) && !(handle instanceof ExtensionPoint)) {
+ throw new IllegalArgumentException();
}
- }
-
- public void addExtensionPoint(Object handle, Object extensionPoint) {
- if (handle instanceof UseCase) {
- ((UseCase) handle).getExtensionPoints().add(
- (ExtensionPoint) extensionPoint);
- } else if (handle instanceof Extend) {
- ((Extend) handle).getExtensionLocations().add(
- (ExtensionPoint) extensionPoint);
+ if (!(extend instanceof Extend)) {
+ throw new IllegalArgumentException();
}
- throw new IllegalArgumentException(
- "Must be UseCase or Extend : " //$NON-NLS-1$
- + handle);
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ if (handle instanceof UseCase) {
+ ((UseCase) handle).getExtends().add((Extend) extend);
+ } else if (handle instanceof ExtensionPoint) {
+ ((Extend) extend).getExtensionLocations().add(
+ (ExtensionPoint) handle);
+ }
+ }
+ };
+ modelImpl.getEditingDomain().getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, run, "Add the extend # to the #", extend,
+ handle));
}
-
- public void addExtensionPoint(Object handle, int position,
- Object extensionPoint) {
- ((Extend) handle).getExtensionLocations().add(position,
- (ExtensionPoint) extensionPoint);
+
+ public void addExtensionPoint(final Object handle,
+ final Object extensionPoint) {
+ addExtensionPoint(handle, CommandParameter.NO_INDEX, extensionPoint);
}
- public void addInclude(Object usecase, Object include) {
- ((UseCase) usecase).getIncludes().add((Include) include);
+ public void addExtensionPoint(final Object handle, final int position,
+ final Object extensionPoint) {
+ if (!(handle instanceof UseCase) && !(handle instanceof Extend)) {
+ throw new IllegalArgumentException();
+ }
+ if (!(extensionPoint instanceof ExtensionPoint)) {
+ throw new IllegalArgumentException();
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ if (handle instanceof UseCase) {
+ ((UseCase) handle).getExtensionPoints().add(
+ position, (ExtensionPoint) extensionPoint);
+ } else if (handle instanceof Extend) {
+ ((Extend) handle).getExtensionLocations().add(
+ position, (ExtensionPoint) extensionPoint);
+ }
+ }
+ };
+ modelImpl.getEditingDomain().getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, run, "Add the extension point # to the #",
+ extensionPoint, handle));
+ }
+
+ public void addInclude(final Object usecase, final Object include) {
+ if (!(usecase instanceof UseCase)) {
+ throw new IllegalArgumentException();
+ }
+ if (!(include instanceof Include)) {
+ throw new IllegalArgumentException();
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ ((UseCase) usecase).getIncludes().add((Include) include);
+ }
+ };
+ modelImpl.getEditingDomain().getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, run, "Add the include # to the case #",
+ include, usecase));
}
public Collection getAllActors(Object ns) {
- return getAllOfType((org.eclipse.uml2.uml.Package) ns, Actor.class);
+ return modelImpl.getModelManagementHelper().getAllModelElementsOfKind(
+ ns, Actor.class);
}
public Collection getAllUseCases(Object ns) {
- return getAllOfType((org.eclipse.uml2.uml.Package) ns, UseCase.class);
- }
-
- private Collection<Type> getAllOfType(org.eclipse.uml2.uml.Package pkg,
- Class type) {
return modelImpl.getModelManagementHelper().getAllModelElementsOfKind(
- pkg, type);
+ ns, UseCase.class);
}
public Collection getExtendedUseCases(Object ausecase) {
+ if (!(ausecase instanceof UseCase)) {
+ throw new IllegalArgumentException();
+ }
Collection<UseCase> result = new HashSet<UseCase>();
for (Extend extend : ((UseCase) ausecase).getExtends()) {
result.add(extend.getExtension());
@@ -120,10 +157,16 @@
}
public Extend getExtends(Object abase, Object anextension) {
+ if (!(abase instanceof UseCase) || !(anextension instanceof UseCase)) {
+ throw new IllegalArgumentException();
+ }
return ((UseCase) anextension).getExtend(null, (UseCase) abase);
}
public Collection<UseCase> getIncludedUseCases(Object ausecase) {
+ if (!(ausecase instanceof UseCase)) {
+ throw new IllegalArgumentException();
+ }
Collection<UseCase> result = new HashSet<UseCase>();
for (Include include : ((UseCase) ausecase).getIncludes() ) {
result.add(include.getAddition());
@@ -132,6 +175,9 @@
}
public Include getIncludes(Object abase, Object aninclusion) {
+ if (!(abase instanceof UseCase) || !(aninclusion instanceof UseCase)) {
+ throw new IllegalArgumentException();
+ }
return ((UseCase) abase).getInclude(null, (UseCase) aninclusion);
}
@@ -146,59 +192,103 @@
public void removeExtensionPoint(Object elem, Object ep) {
// TODO Auto-generated method stub
-
}
- public void removeInclude(Object usecase, Object include) {
- ((UseCase) usecase).getIncludes().remove((Include) include);
+ public void removeInclude(final Object usecase, final Object include) {
+ if (!(usecase instanceof UseCase)) {
+ throw new IllegalArgumentException();
+ }
+ if (!(include instanceof Include)) {
+ throw new IllegalArgumentException();
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ ((UseCase) usecase).getIncludes().remove((Include) include);
+ }
+ };
+ modelImpl.getEditingDomain().getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, run, "Remove the include # from the case #",
+ include, usecase));
}
- public void setAddition(Object handle, Object useCase) {
- ((Include) handle).setAddition((UseCase) useCase);
+ public void setAddition(final Object handle, final Object useCase) {
+ if (!(handle instanceof Include)) {
+ throw new IllegalArgumentException();
+ }
+ if (!(useCase instanceof UseCase)) {
+ throw new IllegalArgumentException();
+ }
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ ((Include) handle).setAddition((UseCase) useCase);
+ }
+ };
+ modelImpl.getEditingDomain().getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, run, "Set the addition # to the include #",
+ useCase, handle));
}
public void setBase(Object extend, Object base) {
// TODO Auto-generated method stub
-
}
public void setCondition(Object handle, Object booleanExpression) {
// TODO Auto-generated method stub
-
}
public void setExtension(Object handle, Object ext) {
}
- public void setExtensionPoints(Object handle, Collection extensionPoints) {
- if (handle instanceof Extend) {
- ((Extend) handle).getExtensionLocations().clear();
- ((Extend) handle).getExtensionLocations().addAll(
- (Collection<ExtensionPoint>) extensionPoints);
- } else if (handle instanceof UseCase) {
- ((UseCase) handle).getExtensionPoints().clear();
- ((UseCase) handle).getExtensionPoints().addAll(
- (Collection<ExtensionPoint>) extensionPoints);
- } else {
- throw new IllegalArgumentException(
- "Expected Extend or UseCase : " //$NON-NLS-1$
- + handle);
+ public void setExtensionPoints(final Object handle,
+ final Collection extensionPoints) {
+ if (!(handle instanceof UseCase) && !(handle instanceof Extend)) {
+ throw new IllegalArgumentException();
+ }
+ if (extensionPoints == null) {
+ throw new IllegalArgumentException();
+ }
+ for (Object o : extensionPoints) {
+ if (!(o instanceof ExtensionPoint)) {
+ throw new IllegalArgumentException(o.toString());
+ }
}
+ RunnableClass run = new RunnableClass() {
+ public void run() {
+ if (handle instanceof Extend) {
+ ((Extend) handle).getExtensionLocations().clear();
+ for (Object o : extensionPoints) {
+ ((Extend) handle).getExtensionLocations().add(
+ (ExtensionPoint) o);
+ }
+ } else if (handle instanceof UseCase) {
+ ((UseCase) handle).getExtensionPoints().clear();
+ for (Object o : extensionPoints) {
+ ((UseCase) handle).getExtensionPoints().add(
+ (ExtensionPoint) o);
+ }
+ }
+
+ }
+ };
+ modelImpl.getEditingDomain().getCommandStack().execute(
+ new ChangeCommand(
+ modelImpl, run,
+ "Set # extension points for the case #",
+ extensionPoints.size(), handle));
}
public void setIncludes(Object handle, Collection includes) {
// TODO Auto-generated method stub
-
}
public void setLocation(Object handle, String loc) {
// TODO Auto-generated method stub
-
}
public void setUseCase(Object elem, Object usecase) {
// TODO Auto-generated method stub
-
}
}
Modified: trunk/src/model-euml/src/org/argouml/model/euml/XmiReaderEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-euml/src/org/argouml/model/euml/XmiReaderEUMLImpl.java?view=diff&rev=13462&p1=trunk/src/model-euml/src/org/argouml/model/euml/XmiReaderEUMLImpl.java&p2=trunk/src/model-euml/src/org/argouml/model/euml/XmiReaderEUMLImpl.java&r1=13461&r2=13462
==============================================================================
--- trunk/src/model-euml/src/org/argouml/model/euml/XmiReaderEUMLImpl.java (original)
+++ trunk/src/model-euml/src/org/argouml/model/euml/XmiReaderEUMLImpl.java 2007-08-30 11:48:34-0700
@@ -26,16 +26,23 @@
package org.argouml.model.euml;
+import java.io.BufferedInputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
-import org.apache.log4j.Logger;
import org.argouml.model.UmlException;
import org.argouml.model.XmiReader;
-import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.xml.sax.InputSource;
@@ -45,13 +52,14 @@
*/
class XmiReaderEUMLImpl implements XmiReader {
- private static final Logger LOG =
- Logger.getLogger(XmiReaderEUMLImpl.class);
-
/**
* The model implementation.
*/
private EUMLModelImplementation modelImpl;
+
+ private static Set<String> searchDirs = new HashSet();
+
+ private Resource resource;
/**
* Constructor.
@@ -73,9 +81,18 @@
return new String[0];
}
+ @SuppressWarnings("unchecked")
public Map getXMIUUIDToObjectMap() {
- // TODO Auto-generated method stub
- return new HashMap();
+ if (resource == null) {
+ throw new IllegalStateException();
+ }
+ HashMap map = new HashMap();
+ Iterator<EObject> it = resource.getAllContents();
+ while (it.hasNext()) {
+ EObject o = it.next();
+ map.put(resource.getURIFragment(o), o);
+ }
+ return map;
}
public Collection parse(InputSource inputSource) throws UmlException {
@@ -84,20 +101,56 @@
public Collection parse(InputSource inputSource, boolean profile)
throws UmlException {
+ if (inputSource == null) {
+ throw new NullPointerException("The input source must be non-null."); //$NON-NLS-1$
+ }
+ InputStream is = null;
+ boolean needsClosing = false;
+ if (inputSource.getByteStream() != null) {
+ is = inputSource.getByteStream();
+ } else if (inputSource.getSystemId() != null) {
+ try {
+ URL url = new URL(inputSource.getSystemId());
+ if (url != null) {
+ is = url.openStream();
+ if (is != null) {
+ is = new BufferedInputStream(is);
+ needsClosing = true;
+ }
+ }
+ } catch (MalformedURLException e) {
+ // do nothing
+ } catch (IOException e) {
+ // do nothing
+ }
+
+ }
+ if (is == null) {
+ throw new UnsupportedOperationException();
+ }
+
EditingDomain editingDomain = modelImpl.getEditingDomain();
- for (Resource resource
- : (EList<Resource>) editingDomain.getResourceSet().getResources()) {
+ for (Resource resource : editingDomain.getResourceSet().getResources()) {
resource.unload();
}
-
- Resource r = editingDomain.createResource(
- "http://argouml.tigris.org/euml/resource/default_uri.xmi"); //$NON-NLS-1$
+
+ Resource r = UMLUtil.getResource(modelImpl, UMLUtil.DEFAULT_URI);
try {
- r.load(inputSource.getByteStream(), null);
+ modelImpl.getModelEventPump().stopPumpingEvents();
+ r.load(is, null);
} catch (IOException e) {
throw new UmlException(e);
+ } finally {
+ modelImpl.getModelEventPump().startPumpingEvents();
+ if (needsClosing) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
-
+ resource = r;
return r.getContents();
}
@@ -107,27 +160,27 @@
}
public String getTagName() {
- // This is not quite right
- // TODO: Solve this
- return "uml:Model"; //$NON-NLS-1$
+ if (resource == null) {
+ throw new IllegalStateException();
+ }
+ List l = resource.getContents();
+ if (!l.isEmpty()) {
+ return "uml:" + modelImpl.getMetaTypes().getName(l.get(0)); //$NON-NLS-1$
+ } else {
+ return null;
+ }
}
public void addSearchPath(String path) {
- // TODO: Auto-generated method stub
- throw new NotYetImplementedException();
-
+ searchDirs.add(path);
}
public List<String> getSearchPath() {
- // TODO: Auto-generated method stub
- throw new NotYetImplementedException();
-
+ return new ArrayList<String>(searchDirs);
}
public void removeSearchPath(String path) {
- // TODO: Auto-generated method stub
- throw new NotYetImplementedException();
-
+ searchDirs.remove(path);
}
}
Modified: trunk/src/model-euml/src/org/argouml/model/euml/XmiWriterEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-euml/src/org/argouml/model/euml/XmiWriterEUMLImpl.java?view=diff&rev=13462&p1=trunk/src/model-euml/src/org/argouml/model/euml/XmiWriterEUMLImpl.java&p2=trunk/src/model-euml/src/org/argouml/model/euml/XmiWriterEUMLImpl.java&r1=13461&r2=13462
==============================================================================
--- trunk/src/model-euml/src/org/argouml/model/euml/XmiWriterEUMLImpl.java (original)
+++ trunk/src/model-euml/src/org/argouml/model/euml/XmiWriterEUMLImpl.java 2007-08-30 11:48:34-0700
@@ -36,7 +36,6 @@
import org.argouml.model.UmlException;
import org.argouml.model.XmiExtensionWriter;
import org.argouml.model.XmiWriter;
-import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.xmi.XMLResource;
/**
@@ -81,14 +80,15 @@
public XmiWriterEUMLImpl(EUMLModelImplementation implementation,
Object theModel, OutputStream stream, String version) {
if (stream == null) {
- throw new IllegalArgumentException("An OutputStream must be provided");
+ throw new IllegalArgumentException(
+ "An OutputStream must be provided"); //$NON-NLS-1$
}
if (!(theModel instanceof org.eclipse.uml2.uml.Package)) {
- throw new IllegalArgumentException("A model must be provided"
- + " and it must be a UML 2 Package");
+ throw new IllegalArgumentException("A container must be provided" //$NON-NLS-1$
+ + " and it must be a UML 2 Package"); //$NON-NLS-1$
}
if (implementation == null) {
- throw new IllegalArgumentException("A parent must be provided");
+ throw new IllegalArgumentException("A parent must be provided"); //$NON-NLS-1$
}
modelImpl = implementation;
model = (org.eclipse.uml2.uml.Package) theModel;
@@ -96,9 +96,10 @@
}
public void write() throws UmlException {
- if (model.eResource() == null) {
- throw new UmlException("Root container is not affiliated with any resource!"); //$NON-NLS-1$
- }
+ if (model.eResource() == null) {
+ throw new UmlException(
+ "Root container is not affiliated with any resource!"); //$NON-NLS-1$
+ }
// Do we need to get stereotype applications for each element? - tfm
// for (Iterator allContents = UMLUtil.getAllContents(model, true,
@@ -108,15 +109,18 @@
// contents.addAll(((Element) eObject).getStereotypeApplications());
// }
// }
- Map options = new HashMap();
+ Map<String, Integer> options = new HashMap<String, Integer>();
options.put(XMLResource.OPTION_LINE_WIDTH, 100);
-
+
// TODO: Is there an option we can use to save our ArgoUML version?
-
+
try {
+ modelImpl.getModelEventPump().stopPumpingEvents();
model.eResource().save(oStream, options);
} catch (IOException ioe) {
throw new UmlException(ioe);
+ } finally {
+ modelImpl.getModelEventPump().startPumpingEvents();
}
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.