Author: b00__1
Date: 2007-08-15 03:09:56-0700
New Revision: 13362
Modified:
branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/CoreHelperEUMLImpl.java
branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java
Log:
Refactor getAllModelElementsOfKind to be reused.
Implemented a few methods.
Tweeked a little the style (empty lines, etc).
Modified: branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/CoreHelperEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/CoreHelperEUMLImpl.java?view=diff&rev=13362&p1=branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/CoreHelperEUMLImpl.java&p2=branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/CoreHelperEUMLImpl.java&r1=13361&r2=13362
==============================================================================
--- branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/CoreHelperEUMLImpl.java (original)
+++ branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/CoreHelperEUMLImpl.java 2007-08-15 03:09:56-0700
@@ -499,34 +499,20 @@
return result;
}
- private Collection getAllOwnedElementsOfKind(Object owner, Class kind) {
- if (!(owner instanceof Element)) {
- throw new IllegalArgumentException(
- "owner must be instance of Element"); //$NON-NLS-1$
- }
- Collection<Element> result = new ArrayList<Element>();
- for (Element e : ((Element) owner).allOwnedElements()) {
- if (kind.isInstance(e)) {
- result.add(e);
- }
- }
- return result;
- }
-
public Collection getAllBehavioralFeatures(Object element) {
- return getAllOwnedElementsOfKind(element, BehavioralFeature.class);
+ return modelImpl.getModelManagementHelper().getAllModelElementsOfKind(element, BehavioralFeature.class);
}
public Collection getAllClasses(Object ns) {
- return getAllOwnedElementsOfKind(ns, org.eclipse.uml2.uml.Class.class);
+ return modelImpl.getModelManagementHelper().getAllModelElementsOfKind(ns, org.eclipse.uml2.uml.Class.class);
}
public Collection getAllClassifiers(Object namespace) {
- return getAllOwnedElementsOfKind(namespace, Classifier.class);
+ return modelImpl.getModelManagementHelper().getAllModelElementsOfKind(namespace, Classifier.class);
}
public Collection getAllComponents(Object ns) {
- return getAllOwnedElementsOfKind(ns, Component.class);
+ return modelImpl.getModelManagementHelper().getAllModelElementsOfKind(ns, org.eclipse.uml2.uml.Component.class);
}
public Collection getAllContents(Object namespace) {
@@ -534,11 +520,11 @@
}
public Collection getAllDataTypes(Object ns) {
- return getAllOwnedElementsOfKind(ns, DataType.class);
+ return modelImpl.getModelManagementHelper().getAllModelElementsOfKind(ns, DataType.class);
}
public Collection getAllInterfaces(Object ns) {
- return getAllOwnedElementsOfKind(ns, Interface.class);
+ return modelImpl.getModelManagementHelper().getAllModelElementsOfKind(ns, Interface.class);
}
public Collection getAllMetatypeNames() {
@@ -560,7 +546,7 @@
}
public Collection getAllNodes(Object ns) {
- return getAllOwnedElementsOfKind(ns, Node.class);
+ return modelImpl.getModelManagementHelper().getAllModelElementsOfKind(ns, Node.class);
}
public Collection getAllPossibleNamespaces(Object modelElement, Object model) {
@@ -572,7 +558,8 @@
if (isValidNamespace(modelElement, model)) {
result.add((Namespace) model);
}
- for (Object o : getAllOwnedElementsOfKind(model, Namespace.class)) {
+ for (Object o : modelImpl.getModelManagementHelper().getAllModelElementsOfKind(
+ model, Namespace.class)) {
if (isValidNamespace(modelElement, o)) {
result.add((Namespace) o);
}
Modified: branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java?view=diff&rev=13362&p1=branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java&p2=branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java&r1=13361&r2=13362
==============================================================================
--- branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java (original)
+++ branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/ModelManagementHelperEUMLImpl.java 2007-08-15 03:09:56-0700
@@ -29,15 +29,17 @@
import java.util.ArrayList;
import java.util.Collection;
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.PackageableElement;
+import org.eclipse.uml2.uml.VisibilityKind;
/**
* The implementation of the ModelManagementHelper for EUML2.
@@ -59,16 +61,17 @@
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);
}
+ @SuppressWarnings("unchecked")
public Collection getAllContents(Object element) {
if (!(element instanceof Element)) {
throw new IllegalArgumentException(
@@ -82,7 +85,19 @@
result.addAll(((Classifier) element).allFeatures());
}
if (element instanceof Namespace) {
- result.addAll(((Namespace) element).getOwnedMembers());
+ 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;
}
@@ -93,9 +108,9 @@
}
public Collection getAllModelElementsOfKind(Object nsa, Object type) {
- if (!(nsa instanceof Namespace)) {
+ if (!(nsa instanceof Element)) {
throw new IllegalArgumentException(
- "nsa must be instance of Namespace"); //$NON-NLS-1$
+ "nsa must be instance of Element"); //$NON-NLS-1$
}
Class theType = null;
if (type instanceof String) {
@@ -121,33 +136,23 @@
result.add(element);
}
}
-
+
return result;
}
- /*
- * 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);
- }
- return false;
- }
-
public Collection getAllModelElementsOfKind(Object nsa, String 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);
@@ -161,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) {
@@ -180,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) {
@@ -219,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
-
}
}
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.