svn commit: r16419 - trunk/src: argouml-core-model-euml/src/org/argouml/model/euml argouml-core-model-mdr/src/org/argouml/model/mdr argouml-core-model/src/org/argouml/model

Tom Morris <[email protected]>
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: tfmorris
Date: 2008-12-22 14:24:34-0800
New Revision: 16419

Modified:
   trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/FacadeEUMLImpl.java
   trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/FacadeMDRImpl.java
   trunk/src/argouml-core-model/src/org/argouml/model/Facade.java

Log:
Issue 5568: Add methods to get all UML metatype names and check an element's metatype using a text string
http://argouml.tigris.org/issues/show_bug.cgi?id=5568

Modified: trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/FacadeEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/FacadeEUMLImpl.java?view=diff&pathrev=16419&r1=16418&r2=16419
==============================================================================
--- trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/FacadeEUMLImpl.java	(original)
+++ trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/FacadeEUMLImpl.java	2008-12-22 14:24:34-0800
@@ -2109,4 +2109,16 @@
         return c;
     }
 
+    public String[] getMetatypeNames() {
+        // TODO: Auto-generated method stub
+        throw new NotYetImplementedException();
+        
+    }
+
+    public boolean isA(String metatypeName, Object element) {
+        // TODO: Auto-generated method stub
+        throw new NotYetImplementedException();
+        
+    }
+
 }

Modified: trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/FacadeMDRImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/FacadeMDRImpl.java?view=diff&pathrev=16419&r1=16418&r2=16419
==============================================================================
--- trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/FacadeMDRImpl.java	(original)
+++ trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/FacadeMDRImpl.java	2008-12-22 14:24:34-0800
@@ -36,8 +36,10 @@
 import javax.jmi.model.Reference;
 import javax.jmi.reflect.InvalidObjectException;
 import javax.jmi.reflect.RefBaseObject;
+import javax.jmi.reflect.RefClass;
 import javax.jmi.reflect.RefFeatured;
 import javax.jmi.reflect.RefObject;
+import javax.jmi.reflect.RefPackage;
 
 import org.apache.log4j.Logger;
 import org.argouml.model.CoreFactory;
@@ -4462,4 +4464,51 @@
     }
 
 
+    public String[] getMetatypeNames() {
+        // Get all (UML) metaclasses
+        Collection<MofClass> metaTypes = getMetaClasses();
+        String[] names = new String[metaTypes.size()];
+        int i = 0;
+        for (MofClass mofClass : metaTypes) {
+            // TODO: Do we need to worry about UmlClass, UmlPackage, etc?
+            names[i++] = mofClass.getName();
+        }
+        return names;
+    }
+
+    Collection<MofClass> getMetaClasses() {
+        Collection<MofClass> metaTypes = modelImpl.getModelPackage()
+                .getMofClass().refAllOfClass();
+        return metaTypes;
+    }
+
+    public boolean isA(String metatypeName, Object element) {
+        MofClass metaObject = (MofClass) ((RefObject) element).refMetaObject();
+        return metatypeName != null
+                && metatypeName.equals(metaObject.getName());
+    }
+    
+    MofClass getMofClass(String metatypeName) {
+        Collection<MofClass> metaTypes = getMetaClasses();
+        for (MofClass mofClass : metaTypes) {
+            // TODO: Generalize - assumes UML type names are unique
+            // without the qualifying package names - true for UML 1.4
+            if (metatypeName.equals(mofClass.getName())) {
+                return mofClass;
+            }
+        }
+        return null;
+    }
+    
+    RefClass getProxy(String metatypeName, RefPackage extent) {
+        Collection<MofClass> metaTypes = getMetaClasses();
+        MofClass mofClass = getMofClass(metatypeName);
+        List<String> names = mofClass.getQualifiedName();
+        // Although this only handles one level of package, it is
+        // OK for UML 1.4 because of clustering
+        // Get the right UML package in the extent
+        RefPackage pkg = extent.refPackage(names.get(0));
+        // Return the metatype proxy 
+        return pkg.refClass(names.get(1));
+    }
 }

Modified: trunk/src/argouml-core-model/src/org/argouml/model/Facade.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model/src/org/argouml/model/Facade.java?view=diff&pathrev=16419&r1=16418&r2=16419
==============================================================================
--- trunk/src/argouml-core-model/src/org/argouml/model/Facade.java	(original)
+++ trunk/src/argouml-core-model/src/org/argouml/model/Facade.java	2008-12-22 14:24:34-0800
@@ -3183,4 +3183,25 @@
      * @since 0.25.4
      */
     boolean isReadOnly(Object handle);
+    
+    
+    /**
+     * Get the names of all valid metatypes.
+     * 
+     * @return the list of valid metatype names.
+     * @since 0.28
+     */
+    String[] getMetatypeNames();
+    
+    /**
+     * Test whether the provided element is an instance of the given metatype.
+     * 
+     * @param metatypeName the name of the metatype given as a string. Use the
+     *            name as given in the UML spec, not any specific
+     *            implementation's renaming (ie Class, not UmlClass which has
+     *            been renamed to avoid a Java conflict)
+     * @param element the UML element to test
+     * @return true if the element is an instance of the given metatype
+     */
+    boolean isA(String metatypeName, Object element);
 }

------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=990120

To unsubscribe from this discussion, e-mail: [[email protected]].
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.