Author: maurelio1234
Date: 2008-07-04 07:23:38-0700
New Revision: 15160
Added:
branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/CollectionsModelInterpreter.java
branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/ModelAccessModelInterpreter.java
branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/OCLAPIModelInterpreter.java
Modified:
branches/gsoc2008/work_criticsprofiles_maurelio1234/ext/argouml-critics.jar
branches/gsoc2008/work_criticsprofiles_maurelio1234/ext/jbeans.jar
branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/Uml14ModelInterpreter.java
branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/uml/cognitive/critics/CrAttrNameConflict.java
Log:
working on ocl interpreter
Modified: branches/gsoc2008/work_criticsprofiles_maurelio1234/ext/argouml-critics.jar
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_criticsprofiles_maurelio1234/ext/argouml-critics.jar?view=diff&rev=15160&p1=branches/gsoc2008/work_criticsprofiles_maurelio1234/ext/argouml-critics.jar&p2=branches/gsoc2008/work_criticsprofiles_maurelio1234/ext/argouml-critics.jar&r1=15159&r2=15160
==============================================================================
Binary files. No diff available.
Modified: branches/gsoc2008/work_criticsprofiles_maurelio1234/ext/jbeans.jar
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_criticsprofiles_maurelio1234/ext/jbeans.jar?view=diff&rev=15160&p1=branches/gsoc2008/work_criticsprofiles_maurelio1234/ext/jbeans.jar&p2=branches/gsoc2008/work_criticsprofiles_maurelio1234/ext/jbeans.jar&r1=15159&r2=15160
==============================================================================
Binary files. No diff available.
Added: branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/CollectionsModelInterpreter.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/CollectionsModelInterpreter.java?view=auto&rev=15160
==============================================================================
--- (empty file)
+++ branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/CollectionsModelInterpreter.java 2008-07-04 07:23:38-0700
@@ -0,0 +1,141 @@
+// $Id: eclipse-argo-codetemplates.xml 11347 2006-10-26 22:37:44Z linus $
+// Copyright (c) 2008 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.profile.internal.ocl.uml14;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.Vector;
+
+import org.argouml.profile.internal.ocl.LambdaEvaluator;
+import org.argouml.profile.internal.ocl.ModelInterpreter;
+
+/**
+ * Interprets invocations to OCL collections API
+ *
+ * @author maurelio1234
+ */
+public class CollectionsModelInterpreter implements ModelInterpreter {
+
+ /**
+ * @see org.argouml.profile.internal.ocl.ModelInterpreter#invokeFeature(java.util.HashMap,
+ * java.lang.Object, java.lang.String, java.lang.String,
+ * java.lang.Object[])
+ */
+ @SuppressWarnings("unchecked")
+ public Object invokeFeature(HashMap<String, Object> vt, Object subject,
+ String feature, String type, Object[] parameters) {
+ if (subject instanceof Collection) {
+ if (type.equals("->")) {
+ if (feature.toString().trim().equals("select")) {
+ Vector<String> vars = (Vector<String>) parameters[0];
+ Object exp = parameters[1];
+ LambdaEvaluator eval = (LambdaEvaluator) parameters[2];
+
+ Collection col = cloneCollection((Collection) subject);
+ Vector<Object> remove = new Vector<Object>();
+
+ // TODO is it possible to use more than one variable?
+ String varName = vars.elementAt(0);
+ Object oldVal = vt.get(varName);
+
+ for (Object object : col) {
+ vt.put(varName, object);
+ Object res = eval.evaluate(vt, exp);
+ if (res instanceof Boolean && (Boolean) res) {
+ // do nothing
+ } else {
+ // if test fails this element should not
+ // be in the result set
+ remove.add(object);
+ }
+ }
+
+ col.removeAll(remove);
+ vt.put(varName, oldVal);
+
+ return col;
+ } else if (feature.toString().trim().equals("forAll")) {
+ Vector<String> vars = (Vector<String>) parameters[0];
+ Object exp = parameters[1];
+ LambdaEvaluator eval = (LambdaEvaluator) parameters[2];
+
+ return doForAll(vt, (Collection)subject, vars, exp, eval);
+ }
+ }
+ }
+
+ if (subject instanceof Set) {
+ if (type.equals("->")) {
+ if (feature.equals("size")) {
+ return ((Set) subject).size();
+ }
+ }
+ }
+
+ return null;
+ }
+
+ private boolean doForAll(HashMap<String,Object> vt, Collection collection, Vector<String> vars, Object exp, LambdaEvaluator eval) {
+ if (vars.isEmpty()) {
+ return (Boolean) eval.evaluate(vt, exp);
+ } else {
+ String var = vars.firstElement();
+ vars.removeElement(var);
+ Object oldval = vt.get(var);
+
+ for (Object element : collection) {
+ vt.put(var, element);
+
+ boolean ret = doForAll(vt, collection, vars, exp, eval);
+
+ if (!ret) {
+ return false;
+ }
+ }
+
+ vt.put(var, oldval);
+ }
+ return true;
+ }
+
+ @SuppressWarnings("unchecked")
+ private Collection cloneCollection(Collection col) {
+ if (col instanceof Set) {
+ return new HashSet(col);
+ } else if (col instanceof List) {
+ return new ArrayList(col);
+ } else if (col instanceof Bag) {
+ return new HashBag(col);
+ } else {
+ throw new IllegalArgumentException();
+ }
+ }
+
+
+}
Added: branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/ModelAccessModelInterpreter.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/ModelAccessModelInterpreter.java?view=auto&rev=15160
==============================================================================
--- (empty file)
+++ branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/ModelAccessModelInterpreter.java 2008-07-04 07:23:38-0700
@@ -0,0 +1,74 @@
+// $Id: eclipse-argo-codetemplates.xml 11347 2006-10-26 22:37:44Z linus $
+// Copyright (c) 2008 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.profile.internal.ocl.uml14;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.argouml.model.Model;
+import org.argouml.profile.internal.ocl.ModelInterpreter;
+
+/**
+ * Model Access
+ *
+ * @author maurelio1234
+ */
+public class ModelAccessModelInterpreter implements ModelInterpreter {
+
+ /**
+ * @see org.argouml.profile.internal.ocl.ModelInterpreter#invokeFeature(java.util.HashMap, java.lang.Object, java.lang.String, java.lang.String, java.lang.Object[])
+ */
+ @SuppressWarnings("unchecked")
+ public Object invokeFeature(HashMap<String, Object> vt, Object subject,
+ String feature, String type, Object[] parameters) {
+
+ if (subject == null) {
+ subject = vt.get("self");
+ }
+
+ if (Model.getFacade().isAModelElement(subject)) {
+ if (type.equals(".")) {
+ if (feature.equals("name")) {
+ return Model.getFacade().getName(subject);
+ }
+ }
+ }
+
+ if (Model.getFacade().isAClass(subject)) {
+ if (type.equals(".")) {
+ if (feature.equals("feature")) {
+ Set<Object> ret = new HashSet<Object>();
+ ret.addAll(Model.getCoreHelper().getAllAttributes(subject));
+ ret.addAll(Model.getCoreHelper().getOperationsInh(subject));
+ return ret;
+ }
+ }
+ }
+
+ return null;
+ }
+
+}
Added: branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/OCLAPIModelInterpreter.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/OCLAPIModelInterpreter.java?view=auto&rev=15160
==============================================================================
--- (empty file)
+++ branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/OCLAPIModelInterpreter.java 2008-07-04 07:23:38-0700
@@ -0,0 +1,53 @@
+// $Id: eclipse-argo-codetemplates.xml 11347 2006-10-26 22:37:44Z linus $
+// Copyright (c) 2008 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.profile.internal.ocl.uml14;
+
+import java.util.HashMap;
+
+import org.argouml.profile.internal.ocl.ModelInterpreter;
+
+/**
+ * OCL API
+ *
+ * @author maurelio1234
+ */
+public class OCLAPIModelInterpreter implements ModelInterpreter {
+
+ /**
+ * @see org.argouml.profile.internal.ocl.ModelInterpreter#invokeFeature(java.util.HashMap,
+ * java.lang.Object, java.lang.String, java.lang.String,
+ * java.lang.Object[])
+ */
+ public Object invokeFeature(HashMap<String, Object> vt, Object subject,
+ String feature, String type, Object[] parameters) {
+ if (type.equals(".")) {
+ if (feature.toString().trim().equals("oclIsKindOf")) {
+ return true;
+ }
+ }
+ return null;
+ }
+
+}
Modified: branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/Uml14ModelInterpreter.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/Uml14ModelInterpreter.java?view=diff&rev=15160&p1=branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/Uml14ModelInterpreter.java&p2=branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/Uml14ModelInterpreter.java&r1=15159&r2=15160
==============================================================================
--- branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/Uml14ModelInterpreter.java (original)
+++ branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/Uml14ModelInterpreter.java 2008-07-04 07:23:38-0700
@@ -24,124 +24,22 @@
package org.argouml.profile.internal.ocl.uml14;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.Vector;
-
-import org.argouml.model.Model;
-import org.argouml.profile.internal.ocl.LambdaEvaluator;
-import org.argouml.profile.internal.ocl.ModelInterpreter;
+import org.argouml.profile.internal.ocl.CompositeModelInterpreter;
/**
* Interpreter for UML 1.4 / OCL 1.4
*
* @author maurelio1234
*/
-public class Uml14ModelInterpreter implements ModelInterpreter {
+public class Uml14ModelInterpreter extends CompositeModelInterpreter {
/**
- * @see org.argouml.profile.internal.ocl.ModelInterpreter#invokeFeature(java.util.HashMap, java.lang.Object, java.lang.String, java.lang.String, java.lang.Object[])
+ * Default Constructor
*/
- @SuppressWarnings("unchecked")
- public Object invokeFeature(HashMap<String, Object> vt, Object subject, String feature, String type, Object[] parameters) {
-
- if (subject == null) {
- subject = vt.get("self");
- }
-
- if (type.equals(".")) {
- if (feature.toString().trim().equals("oclIsKindOf")) {
- return true;
- }
- }
-
- if (subject instanceof Collection) {
- if (type.equals("->")) {
- if (feature.toString().trim().equals("select")) {
- Vector<String> vars = (Vector<String>) parameters[0];
- Object exp = parameters[1];
- LambdaEvaluator eval = (LambdaEvaluator) parameters[2];
-
- Collection col = cloneCollection((Collection)subject);
- Vector<Object> remove = new Vector<Object>();
-
- // TODO is it possible to use more than one variable?
- String varName = vars.elementAt(0);
- Object oldVal = vt.get(varName);
-
- for (Object object : col) {
- vt.put(varName, object);
- Object res = eval.evaluate(vt, exp);
- if (res instanceof Boolean && (Boolean)res) {
- // do nothing
- } else {
- // if test fails this element should not
- // be in the result set
- remove.add(object);
- }
- }
-
- col.removeAll(remove);
- vt.put(varName, oldVal);
-
- return col;
- }
- }
- }
-
- if (subject instanceof Collection) {
- if (type.equals("->")) {
- if (feature.toString().trim().equals("forAll")) {
-
- }
- }
- }
-
-
- if (Model.getFacade().isAModelElement(subject)) {
- if (type.equals(".")) {
- if (feature.equals("name")) {
- return Model.getFacade().getName(subject);
- }
- }
- }
-
- if (Model.getFacade().isAClass(subject)) {
- if (type.equals(".")) {
- if (feature.equals("feature")) {
- Set<Object> ret = new HashSet<Object>();
- ret.addAll(Model.getCoreHelper().getAllAttributes(subject));
- ret.addAll(Model.getCoreHelper().getOperationsInh(subject));
- return ret;
- }
- }
- }
-
- if (subject instanceof Set) {
- if (type.equals("->")) {
- if (feature.equals("size")) {
- return ((Set)subject).size();
- }
- }
- }
- return null;
- }
-
- @SuppressWarnings("unchecked")
- private Collection cloneCollection(Collection col) {
- if (col instanceof Set) {
- return new HashSet(col);
- } else if (col instanceof List) {
- return new ArrayList(col);
- } else if (col instanceof Bag) {
- return new HashBag(col);
- } else {
- throw new IllegalArgumentException();
- }
+ public Uml14ModelInterpreter() {
+ addModelInterpreter(new ModelAccessModelInterpreter());
+ addModelInterpreter(new OCLAPIModelInterpreter());
+ addModelInterpreter(new CollectionsModelInterpreter());
}
}
Modified: branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/uml/cognitive/critics/CrAttrNameConflict.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/uml/cognitive/critics/CrAttrNameConflict.java?view=diff&rev=15160&p1=branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/uml/cognitive/critics/CrAttrNameConflict.java&p2=branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/uml/cognitive/critics/CrAttrNameConflict.java&r1=15159&r2=15160
==============================================================================
--- branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/uml/cognitive/critics/CrAttrNameConflict.java (original)
+++ branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/uml/cognitive/critics/CrAttrNameConflict.java 2008-07-04 07:23:38-0700
@@ -26,7 +26,9 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashSet;
import java.util.Iterator;
+import java.util.Set;
import javax.swing.Icon;
@@ -104,5 +106,14 @@
return ClAttributeCompartment.getTheInstance();
}
+ /**
+ * @see org.argouml.uml.cognitive.critics.CrUML#getCriticizedMetatypes()
+ */
+ public Set<Object> getCriticizedMetatypes() {
+ Set<Object> ret = new HashSet<Object>();
+ ret.add(Model.getMetaTypes().getClassifier());
+ return ret;
+ }
+
}
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.