svn commit: r13880 - trunk/src/model-mdr/src/org/argouml/model/mdr/ModelManagementHelperMDRImpl.java
| Newsgroups | gmane.comp.lang.uml.argouml.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: tfmorris
Date: 2007-12-08 02:08:27-0800
New Revision: 13880
Modified:
trunk/src/model-mdr/src/org/argouml/model/mdr/ModelManagementHelperMDRImpl.java
Log:
Add getElement() variant which starts at the repository root.
Modified: trunk/src/model-mdr/src/org/argouml/model/mdr/ModelManagementHelperMDRImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-mdr/src/org/argouml/model/mdr/ModelManagementHelperMDRImpl.java?view=diff&rev=13880&p1=trunk/src/model-mdr/src/org/argouml/model/mdr/ModelManagementHelperMDRImpl.java&p2=trunk/src/model-mdr/src/org/argouml/model/mdr/ModelManagementHelperMDRImpl.java&r1=13879&r2=13880
==============================================================================
--- trunk/src/model-mdr/src/org/argouml/model/mdr/ModelManagementHelperMDRImpl.java (original)
+++ trunk/src/model-mdr/src/org/argouml/model/mdr/ModelManagementHelperMDRImpl.java 2007-12-08 02:08:27-0800
@@ -342,30 +342,71 @@
public Object getElement(List<String> path, Object theRootNamespace) {
ModelElement root = (ModelElement) theRootNamespace;
- for (int i = 0; i < path.size(); i++) {
- if (root == null || !(root instanceof Namespace)) {
- return null;
- }
+ if (root == null) {
+ return getElement(path);
+ } else {
+
+ for (int i = 0; i < path.size(); i++) {
+ if (root == null || !(root instanceof Namespace)) {
+ return null;
+ }
- String name = path.get(i);
- boolean found = false;
- for (ModelElement me : ((Namespace) root).getOwnedElement()) {
- if (i < path.size() - 1 && !(me instanceof Namespace)) {
- continue;
+ String name = path.get(i);
+ boolean found = false;
+ for (ModelElement me : ((Namespace) root).getOwnedElement()) {
+ if (i < path.size() - 1 && !(me instanceof Namespace)) {
+ continue;
+ }
+ if (name.equals(me.getName())) {
+ root = me;
+ found = true;
+ break;
+ }
}
- if (name.equals(me.getName())) {
- root = me;
- found = true;
- break;
+ if (!found) {
+ return null;
}
}
- if (!found) {
- return null;
+ return root;
+ }
+ }
+
+
+ public Object getElement (List<String> fullPath) {
+ if (fullPath == null || fullPath.isEmpty()) {
+ return null;
+ }
+ Object element = null;
+ for (Object root : modelImpl.getFacade().getRootElements()) {
+ /*
+ * modelImpl.getFacade().getRootElements() gets all root elements
+ * in the UML repository, including available profiles that are not
+ * part of the current project (degrades performance).
+ *
+ * ProjectManager.getManager().getCurrentProject().getRoots() only
+ * returns user model roots, and no profiles.
+ *
+ * ProjectManager.getManager().getCurrentProject().getModels() gets
+ * all root models, but no root namespaces.
+ *
+ * TODO: Which is best? Is there any other way?
+ */
+ if (((ModelElement) root).getName().equals(fullPath.get(0))) {
+ element = root;
+ if (root instanceof Namespace && fullPath.size() > 1) {
+ element = modelImpl.getModelManagementHelper().
+ getElement(fullPath.subList(1, fullPath.size()),
+ root);
+ }
+ if (element != null) {
+ break;
+ }
}
}
- return root;
+ return element;
}
+
@Deprecated
public Vector<String> getPath(Object element) {
Vector<String> path;