svn commit: r15143 - branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl: . uml14

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: maurelio1234
Date: 2008-07-02 04:29:44-0700
New Revision: 15143

Added:
   branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/LambdaEvaluator.java
   branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/ModelInterpreter.java
   branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/
   branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/Bag.java
   branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/HashBag.java
   branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/Uml14ModelInterpreter.java
Modified:
   branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/CrOCL.java
   branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateInvariant.java
   branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/OclInterpreter.java

Log:
working on ocl interpreter

Modified: branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/CrOCL.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/CrOCL.java?view=diff&rev=15143&p1=branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/CrOCL.java&p2=branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/CrOCL.java&r1=15142&r2=15143
==============================================================================
--- branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/CrOCL.java	(original)
+++ branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/CrOCL.java	2008-07-02 04:29:44-0700
@@ -28,6 +28,7 @@
 
 import org.argouml.cognitive.Designer;
 import org.argouml.cognitive.ToDoItem;
+import org.argouml.profile.internal.ocl.uml14.Uml14ModelInterpreter;
 import org.argouml.uml.cognitive.UMLDecision;
 import org.argouml.uml.cognitive.critics.CrUML;
 
@@ -59,7 +60,7 @@
      * @param ocl ocl expression
      */
     public CrOCL(String ocl) {
-        interpreter = new OclInterpreter(ocl);
+        interpreter = new OclInterpreter(ocl, new Uml14ModelInterpreter());
         
         addSupportedDecision(UMLDecision.PLANNED_EXTENSIONS);
         setPriority(ToDoItem.HIGH_PRIORITY);

Modified: branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateInvariant.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateInvariant.java?view=diff&rev=15143&p1=branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateInvariant.java&p2=branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateInvariant.java&r1=15142&r2=15143
==============================================================================
--- branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateInvariant.java	(original)
+++ branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateInvariant.java	2008-07-02 04:29:44-0700
@@ -25,24 +25,61 @@
 package org.argouml.profile.internal.ocl;
 
 import java.util.HashMap;
-import java.util.Stack;
+import java.util.Vector;
 
 import org.apache.log4j.Logger;
 
 import tudresden.ocl.parser.analysis.DepthFirstAdapter;
-import tudresden.ocl.parser.node.AAdditiveExpression;
-import tudresden.ocl.parser.node.AConstraintBody;
-import tudresden.ocl.parser.node.AExpression;
+import tudresden.ocl.parser.node.AActualParameterList;
+import tudresden.ocl.parser.node.AAdditiveExpressionTail;
+import tudresden.ocl.parser.node.AAndLogicalOperator;
+import tudresden.ocl.parser.node.ABooleanLiteral;
+import tudresden.ocl.parser.node.AConstraint;
+import tudresden.ocl.parser.node.ADeclaratorTail;
+import tudresden.ocl.parser.node.ADivMultiplyOperator;
+import tudresden.ocl.parser.node.AEmptyFeatureCallParameters;
+import tudresden.ocl.parser.node.AEnumLiteral;
+import tudresden.ocl.parser.node.AEqualRelationalOperator;
+import tudresden.ocl.parser.node.AFeatureCall;
+import tudresden.ocl.parser.node.AFeatureCallParameters;
+import tudresden.ocl.parser.node.AFeaturePrimaryExpression;
+import tudresden.ocl.parser.node.AGtRelationalOperator;
+import tudresden.ocl.parser.node.AGteqRelationalOperator;
 import tudresden.ocl.parser.node.AIfExpression;
-import tudresden.ocl.parser.node.ALogicalExpression;
-import tudresden.ocl.parser.node.ARelationalExpression;
+import tudresden.ocl.parser.node.AImpliesLogicalOperator;
+import tudresden.ocl.parser.node.AIntegerLiteral;
+import tudresden.ocl.parser.node.AIterateDeclarator;
+import tudresden.ocl.parser.node.ALetExpression;
+import tudresden.ocl.parser.node.ALiteralCollection;
+import tudresden.ocl.parser.node.ALogicalExpressionTail;
+import tudresden.ocl.parser.node.ALtRelationalOperator;
+import tudresden.ocl.parser.node.ALteqRelationalOperator;
+import tudresden.ocl.parser.node.AMinusAddOperator;
+import tudresden.ocl.parser.node.AMinusUnaryOperator;
+import tudresden.ocl.parser.node.AMultMultiplyOperator;
+import tudresden.ocl.parser.node.AMultiplicativeExpressionTail;
+import tudresden.ocl.parser.node.ANEqualRelationalOperator;
+import tudresden.ocl.parser.node.ANamePathNameBegin;
+import tudresden.ocl.parser.node.ANotUnaryOperator;
+import tudresden.ocl.parser.node.AOrLogicalOperator;
+import tudresden.ocl.parser.node.APlusAddOperator;
+import tudresden.ocl.parser.node.APostfixExpressionTail;
+import tudresden.ocl.parser.node.ARealLiteral;
+import tudresden.ocl.parser.node.ARelationalExpressionTail;
+import tudresden.ocl.parser.node.AStandardDeclarator;
+import tudresden.ocl.parser.node.AStringLiteral;
+import tudresden.ocl.parser.node.AUnaryUnaryExpression;
+import tudresden.ocl.parser.node.AXorLogicalOperator;
 import tudresden.ocl.parser.node.Node;
-import tudresden.ocl.parser.node.PAdditiveExpressionTail;
-import tudresden.ocl.parser.node.PLetExpression;
-import tudresden.ocl.parser.node.PLogicalExpressionTail;
+import tudresden.ocl.parser.node.PActualParameterListTail;
+import tudresden.ocl.parser.node.PConstraintBody;
+import tudresden.ocl.parser.node.PDeclaratorTail;
+import tudresden.ocl.parser.node.PExpression;
+import tudresden.ocl.parser.node.Start;
 
 /**
- * Evaluates the OCL invariant 
+ * Evaluates OCL invariants, this class should not depend on the model
+ * subsystem. 
  * 
  * @author maurelio1234
  */
@@ -53,17 +90,39 @@
      */
     private static final Logger LOG = Logger.getLogger(EvaluateInvariant.class);
     
+    /**
+     * The Variable Table
+     */
+    private HashMap<String, Object> vt = new HashMap<String, Object>();
+    
+    /**
+     * Is this invariant satified?
+     */
     private boolean ok = true;
-    private Stack<Object> st = new Stack<Object>();
-    private HashMap<String, Object> vt = new HashMap<String,Object>();
-    private Object currentValue = null;
+    
+    /**
+     * Keeps the return value of the visitor 
+     */
+    private Object val = null;
+    
+    /**
+     * Keeps a forward propagated value
+     */
+    private Object fwd = null;    
+    
+    /**
+     * The model interpreter
+     */
+    private ModelInterpreter interp = null;
     
     /**
      * Constructor 
      * 
      * @param modelElement self
+     * @param mi model interpreter
      */
-    public EvaluateInvariant(Object modelElement) {
+    public EvaluateInvariant(Object modelElement, ModelInterpreter mi) {
+        this.interp = mi;
         vt.put("self", modelElement);
     }
 
@@ -74,43 +133,54 @@
         return ok;
     }
   
+    /** Interpreter Code **/   
+    public void outStart(Start node)
+    {
+        ok = asBoolean(val, node);
+    }
+    
     /**
-     * @param node
-     * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAConstraintBody(tudresden.ocl.parser.node.AConstraintBody)
+     * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#defaultIn(tudresden.ocl.parser.node.Node)
      */
-    public void caseAConstraintBody(AConstraintBody node)
+    public void defaultIn(Node node)
     {
-        inAConstraintBody(node);
-        if(node.getStereotype() != null)
-        {
-            node.getStereotype().apply(this);
-        }
-        if(node.getName() != null)
+        LOG.debug("\nEntering: " + node.getClass() + "\n NODE: " + node + "\n VAL: " + val + " fwd: "+ fwd);
+    }
+
+    /**
+     * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAConstraint(tudresden.ocl.parser.node.AConstraint)
+     */
+    public void caseAConstraint(AConstraint node)
+    {
+        inAConstraint(node);
+        if(node.getContextDeclaration() != null)
         {
-            node.getName().apply(this);
+            node.getContextDeclaration().apply(this);
         }
-        if(node.getColon() != null)
         {
-            node.getColon().apply(this);
-        }
-        if(node.getExpression() != null)
-        {            
-            st.removeAllElements();
-            node.getExpression().apply(this);
-            Object top = st.pop();
-            if (top instanceof Boolean) {
-                ok = (Boolean)top;
-            } else {
-                LOG.debug("Invariant does not evaluate to a Boolean! st = "
-                        + st);                
-                ok = false;
+            boolean localOk = true;
+            
+            Object temp[] = node.getConstraintBody().toArray();
+            for(int i = 0; i < temp.length; i++)
+            {
+                ((PConstraintBody) temp[i]).apply(this);
+
+                localOk &= asBoolean(val, temp[i]);
             }
+            
+            val = localOk;
         }
-        outAConstraintBody(node);
-    }    
+        outAConstraint(node);
+    }
 
+    /**
+     * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAIfExpression(tudresden.ocl.parser.node.AIfExpression)
+     */
     public void caseAIfExpression(AIfExpression node)
-    {            
+    {
+        boolean test = false;
+        boolean ret = false;
+        
         inAIfExpression(node);
         if(node.getTIf() != null)
         {
@@ -118,11 +188,9 @@
         }
         if(node.getIfBranch() != null)
         {
-            node.getIfBranch().apply(this);
-        }        
-
-        boolean iftest = (Boolean)st.pop();
-        
+            node.getIfBranch().apply(this);            
+            test = asBoolean(val, node.getIfBranch());
+        }
         if(node.getTThen() != null)
         {
             node.getTThen().apply(this);
@@ -130,8 +198,9 @@
         if(node.getThenBranch() != null)
         {
             node.getThenBranch().apply(this);
-            if (!iftest) // if "if" wasn't ok, forget if
-                st.pop();
+            if (test) {
+                ret = asBoolean(val, node.getThenBranch());
+            }
         }
         if(node.getTElse() != null)
         {
@@ -140,83 +209,587 @@
         if(node.getElseBranch() != null)
         {
             node.getElseBranch().apply(this);
-            if (iftest) // if "if" was ok, forget else
-                st.pop();
+            if (!test) {
+                ret = asBoolean(val, node.getThenBranch());                
+            }
         }
         if(node.getEndif() != null)
         {
             node.getEndif().apply(this);
         }
+        
+        val = ret;
         outAIfExpression(node);
     }
+
+    /**
+     * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseALogicalExpressionTail(tudresden.ocl.parser.node.ALogicalExpressionTail)
+     */
+    public void caseALogicalExpressionTail(ALogicalExpressionTail node)
+    {
+        Object left = val;
+
+        inALogicalExpressionTail(node);
+        if(node.getLogicalOperator() != null)
+        {
+            node.getLogicalOperator().apply(this);
+        }
+        if(node.getRelationalExpression() != null)
+        {
+            node.getRelationalExpression().apply(this);
+        }
+
+        Object op = node.getLogicalOperator();
+        Object right = val;
+        
+        if (left != null && op!= null && right != null) {
+            if (op instanceof AAndLogicalOperator) {
+                val = asBoolean(left, node) && asBoolean(right, node);
+            } else if (op instanceof AImpliesLogicalOperator) {
+                val = !asBoolean(left, node) || asBoolean(right, node);
+            } else if (op instanceof AOrLogicalOperator) {
+                val = asBoolean(left, node) || asBoolean(right, node);
+            } else if (op instanceof AXorLogicalOperator) {
+                val = !asBoolean(left, node) ^ asBoolean(right, node);
+            } else {
+                error(node);
+            }           
+        } else {
+            error(node);
+        }
+        outALogicalExpressionTail(node);
+    }
     
-    public void caseAExpression(AExpression node)
+    /**
+     * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseARelationalExpressionTail(tudresden.ocl.parser.node.ARelationalExpressionTail)
+     */
+    public void caseARelationalExpressionTail(ARelationalExpressionTail node)
     {
-        inAExpression(node);
+        Object left = val;
+        
+        inARelationalExpressionTail(node);
+        if(node.getRelationalOperator() != null)
         {
-            Object temp[] = node.getLetExpression().toArray();
-            for(int i = 0; i < temp.length; i++)
-            {
-                ((PLetExpression) temp[i]).apply(this);
+            node.getRelationalOperator().apply(this);                       
+        }
+        if(node.getAdditiveExpression() != null)
+        {
+            node.getAdditiveExpression().apply(this);
+        }
+
+        Object op = node.getRelationalOperator();
+        Object right = val;
+        
+        if (left != null && op!= null && right != null) {
+            if (op instanceof AEqualRelationalOperator) {
+                val = left.equals(right);                
+            } else if (op instanceof AGteqRelationalOperator) {
+                val = asInteger(left, node) >= asInteger(right, node);
+            } else if (op instanceof AGtRelationalOperator) {
+                val = asInteger(left, node) > asInteger(right, node);
+            } else if (op instanceof ALteqRelationalOperator) {
+                val = asInteger(left, node) <= asInteger(right, node);
+            } else if (op instanceof ALtRelationalOperator) {
+                val = asInteger(left, node) < asInteger(right, node);
+            } else if (op instanceof ANEqualRelationalOperator) {
+                val = !left.equals(right);                
+            } else {
+                error(node);                
             }
+        } else {
+            error(node);
         }
-        if(node.getLogicalExpression() != null)
+        outARelationalExpressionTail(node);
+    }
+
+    /**
+     * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAAdditiveExpressionTail(tudresden.ocl.parser.node.AAdditiveExpressionTail)
+     */
+    public void caseAAdditiveExpressionTail(AAdditiveExpressionTail node)
+    {
+        Object left = val;
+
+        inAAdditiveExpressionTail(node);
+        if(node.getAddOperator() != null)
         {
-            node.getLogicalExpression().apply(this);
+            node.getAddOperator().apply(this);
         }
-        outAExpression(node);
+        if(node.getMultiplicativeExpression() != null)
+        {
+            node.getMultiplicativeExpression().apply(this);
+        }
+
+        Object op = node.getAddOperator();
+        Object right = val;
+        
+        if (left != null && op!= null && right != null) {
+            if (op instanceof AMinusAddOperator) {
+                val = asInteger(left, node) - asInteger(right, node);
+            } else if (op instanceof APlusAddOperator) {
+                val = asInteger(left, node) + asInteger(right, node);
+            } else {
+                error(node);
+            }           
+        } else {
+            error(node);
+        }
+        
+        outAAdditiveExpressionTail(node);
     }
     
-    public void caseALogicalExpression(ALogicalExpression node)
+    /**
+     * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAMultiplicativeExpressionTail(tudresden.ocl.parser.node.AMultiplicativeExpressionTail)
+     */
+    public void caseAMultiplicativeExpressionTail(AMultiplicativeExpressionTail node)
     {
-        inALogicalExpression(node);
-        if(node.getRelationalExpression() != null)
+        Object left = val;
+
+        inAMultiplicativeExpressionTail(node);
+        if(node.getMultiplyOperator() != null)
         {
-            node.getRelationalExpression().apply(this);
+            node.getMultiplyOperator().apply(this);
         }
+        if(node.getUnaryExpression() != null)
         {
-            Object temp[] = node.getLogicalExpressionTail().toArray();
-            for(int i = 0; i < temp.length; i++)
-            {
-                ((PLogicalExpressionTail) temp[i]).apply(this);
+            node.getUnaryExpression().apply(this);
+        }
+
+        Object op = node.getMultiplyOperator();
+        Object right = val;
+        
+        if (left != null && op!= null && right != null) {
+            if (op instanceof ADivMultiplyOperator) {
+                val = asInteger(left, node) / asInteger(right, node);
+            } else if (op instanceof AMultMultiplyOperator) {
+                val = asInteger(left, node) * asInteger(right, node);
+            } else {
+                error(node);
+            }           
+        } else {
+            error(node);
+        }
+        
+        outAMultiplicativeExpressionTail(node);
+    }
+        
+    /**
+     * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAUnaryUnaryExpression(tudresden.ocl.parser.node.AUnaryUnaryExpression)
+     */
+    public void caseAUnaryUnaryExpression(AUnaryUnaryExpression node)
+    {
+        inAUnaryUnaryExpression(node);
+        if(node.getUnaryOperator() != null)
+        {
+            node.getUnaryOperator().apply(this);
+        }
+        if(node.getPostfixExpression() != null)
+        {
+            node.getPostfixExpression().apply(this);
+        }
+        
+        Object op = node.getUnaryOperator();
+        if (op instanceof AMinusUnaryOperator) {
+            val = -asInteger(val, node);
+        } else if (op instanceof ANotUnaryOperator) {
+            val = !asBoolean(val, node);
+        }
+        
+        outAUnaryUnaryExpression(node);
+    }
+    
+    /**
+     * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAPostfixExpressionTail(tudresden.ocl.parser.node.APostfixExpressionTail)
+     */
+    public void caseAPostfixExpressionTail(APostfixExpressionTail node)
+    {
+        inAPostfixExpressionTail(node);
+        if(node.getPostfixExpressionTailBegin() != null)
+        {
+            node.getPostfixExpressionTailBegin().apply(this);
+        }
+        if(node.getFeatureCall() != null)
+        {
+            fwd = node.getPostfixExpressionTailBegin();
+            node.getFeatureCall().apply(this);
+            
+            // XXX: hypotheses for AFeatureCall: fwd = op, val = head
+        }
+        outAPostfixExpressionTail(node);
+    }
+    
+    /**
+     * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAFeaturePrimaryExpression(tudresden.ocl.parser.node.AFeaturePrimaryExpression)
+     */
+    @SuppressWarnings("unchecked")
+    public void caseAFeaturePrimaryExpression(AFeaturePrimaryExpression node)
+    {
+        Object subject = val;
+        Object feature = null;
+        Vector<Object> parameters = null;
+        
+        inAFeaturePrimaryExpression(node);
+        if(node.getPathName() != null)
+        {
+            node.getPathName().apply(this);
+            feature = val;
+        }
+        if(node.getTimeExpression() != null)
+        {
+            // hypotheses no time expression (only invariants)
+            node.getTimeExpression().apply(this);
+        }
+        if(node.getQualifiers() != null)
+        {
+            // XXX: hypotheses no qualifiers (I don't know)
+            node.getQualifiers().apply(this);
+        }
+        if(node.getFeatureCallParameters() != null)
+        {
+            node.getFeatureCallParameters().apply(this);
+            
+            parameters = (Vector<Object>) val;
+        }
+
+        if (subject == null) {
+            val = vt.get(feature);
+        } else {
+            val = runFeatureCall(subject, feature,fwd,parameters);            
+        }
+        outAFeaturePrimaryExpression(node);
+    }       
+
+    /**
+     * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#outAEmptyFeatureCallParameters(tudresden.ocl.parser.node.AEmptyFeatureCallParameters)
+     */
+    public void outAEmptyFeatureCallParameters(AEmptyFeatureCallParameters node)
+    {
+        val = new Vector<Object>();
+        defaultOut(node);
+    }
+    
+    /**
+     * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAFeatureCallParameters(tudresden.ocl.parser.node.AFeatureCallParameters)
+     */
+    @SuppressWarnings("unchecked")
+    public void caseAFeatureCallParameters(AFeatureCallParameters node)
+    {
+        inAFeatureCallParameters(node);
+        if(node.getLPar() != null)
+        {
+            node.getLPar().apply(this);
+        }
+        
+        boolean hasDeclarator = false;
+        if(node.getDeclarator() != null)
+        {
+            node.getDeclarator().apply(this);
+            hasDeclarator = true;
+        }
+        if (node.getActualParameterList() != null) {
+            Vector<String> vars = null;
+            if (hasDeclarator) {
+                Vector<Object> ret = new Vector<Object>();
+                vars = (Vector<String>) val;
+                final PExpression exp = ((AActualParameterList) node
+                        .getActualParameterList()).getExpression();
+                
+                /*
+                 * For a iterator call we should provide:
+                 *  (a) the variables
+                 *  (b) the expression to be evaluated on each step
+                 *  (c) the lambda-evaluator to evaluate it
+                 */
+                
+                ret.add(vars);
+                ret.add(exp);
+                ret.add(new LambdaEvaluator() {
+
+                    /**
+                     * @see org.argouml.profile.internal.ocl.LambdaEvaluator#evaluate(java.util.HashMap, java.lang.Object)
+                     */
+                    public Object evaluate(HashMap<String, Object> vti, Object expi) {
+                        Object old_val = EvaluateInvariant.this.val; 
+                        ((PExpression)expi).apply(EvaluateInvariant.this);
+                        
+                        Object reti = EvaluateInvariant.this.val;
+                        EvaluateInvariant.this.val = old_val;
+                        
+                        return reti;
+                    }
+                    
+                });                
+                
+                val = ret;
+            } else {
+                node.getActualParameterList().apply(this);
             }
+
+        }
+        if (node.getRPar() != null) {
+            node.getRPar().apply(this);
         }
-        outALogicalExpression(node);
+        outAFeatureCallParameters(node);
     }
     
-    public void caseARelationalExpression(ARelationalExpression node)
+    /**
+     * @param node
+     * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAStandardDeclarator(tudresden.ocl.parser.node.AStandardDeclarator)
+     */
+    public void caseAStandardDeclarator(AStandardDeclarator node)
+    {        
+        inAStandardDeclarator(node);
+        
+        Vector<String> vars = new Vector<String>();
+        
+        if(node.getName() != null)
+        {
+            node.getName().apply(this);
+            
+            vars.add(node.getName().toString().trim());
+        }
+        {
+            Object temp[] = node.getDeclaratorTail().toArray();
+            for (int i = 0; i < temp.length; i++) {
+                ((PDeclaratorTail) temp[i]).apply(this);
+
+                vars.add(((ADeclaratorTail) temp[i]).getName()
+
+                .toString().trim());                
+            }
+            
+            val = vars;
+        }
+        if(node.getDeclaratorTypeDeclaration() != null)
+        {
+            // TODO check types!
+            node.getDeclaratorTypeDeclaration().apply(this);
+        }
+        if(node.getBar() != null)
+        {
+            node.getBar().apply(this);
+        }
+        outAStandardDeclarator(node);
+    }
+
+    public void outAIterateDeclarator(AIterateDeclarator node)
     {
-        inARelationalExpression(node);
-        if(node.getAdditiveExpression() != null)
+        //TODO support iterate declarator
+        val = new Vector<String>();
+        defaultOut(node);
+    }
+
+    /**
+     * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseALetExpression(tudresden.ocl.parser.node.ALetExpression)
+     */
+    public void caseALetExpression(ALetExpression node)
+    {
+        // TODO support nested let expressions !
+
+        Object name = null;
+        Object value = null;
+        
+        inALetExpression(node);
+        if(node.getTLet() != null)
         {
-            node.getAdditiveExpression().apply(this);
+            node.getTLet().apply(this);
+        }
+        if(node.getName() != null)
+        {
+            node.getName().apply(this);
+            name = val;
+        }
+        if(node.getLetExpressionTypeDeclaration() != null)
+        {
+            // TODO: check type!
+            node.getLetExpressionTypeDeclaration().apply(this);
+        }
+        if(node.getEqual() != null)
+        {
+            node.getEqual().apply(this);
+        }
+        if(node.getExpression() != null)
+        {
+            node.getExpression().apply(this);
         }
-        if(node.getRelationalExpressionTail() != null)
+        if(node.getTIn() != null)
         {
-            node.getRelationalExpressionTail().apply(this);
+            node.getTIn().apply(this);
         }
-        outARelationalExpression(node);
+        
+        vt.put((""+name).trim(), value);
+        val = value;
+        outALetExpression(node);
     }
     
-    public void caseAAdditiveExpression(AAdditiveExpression node)
+    /**
+     * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#outAStringLiteral(tudresden.ocl.parser.node.AStringLiteral)
+     */
+    public void outAStringLiteral(AStringLiteral node)
     {
-        inAAdditiveExpression(node);
-        if(node.getMultiplicativeExpression() != null)
+        val = node.getStringLit().getText();
+        defaultOut(node);
+    }
+
+    /**
+     * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#outARealLiteral(tudresden.ocl.parser.node.ARealLiteral)
+     */
+    public void outARealLiteral(ARealLiteral node)
+    {
+        // TODO support real types
+        val = (int)Double.parseDouble(node.getReal().getText());
+        defaultOut(node);
+    }
+    
+    /**
+     * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#outAIntegerLiteral(tudresden.ocl.parser.node.AIntegerLiteral)
+     */
+    public void outAIntegerLiteral(AIntegerLiteral node)
+    {
+        val = Integer.parseInt(node.getInt().getText());
+        defaultOut(node);
+    }
+    
+    /**
+     * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#outABooleanLiteral(tudresden.ocl.parser.node.ABooleanLiteral)
+     */
+    public void outABooleanLiteral(ABooleanLiteral node)
+    {
+        val = Boolean.parseBoolean(node.getBool().getText());
+        defaultOut(node);
+    }
+
+    /**
+     * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#outAEnumLiteral(tudresden.ocl.parser.node.AEnumLiteral)
+     */
+    public void outAEnumLiteral(AEnumLiteral node)
+    {
+        // TODO support enums!
+        val = null;
+        defaultOut(node);
+    }
+    
+    /**
+     * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#outALiteralCollection(tudresden.ocl.parser.node.ALiteralCollection)
+     */
+    public void outALiteralCollection(ALiteralCollection node)
+    {
+        // support collections
+        val = new Vector<Object>();
+        defaultOut(node);
+    }
+
+    /**
+     * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAFeatureCall(tudresden.ocl.parser.node.AFeatureCall)
+     */
+    @SuppressWarnings("unchecked")
+    public void caseAFeatureCall(AFeatureCall node)
+    {
+        Object subject = val;
+        Object feature = null;
+        Vector<Object> parameters = null;
+        
+        inAFeatureCall(node);
+        if(node.getPathName() != null)
         {
-            node.getMultiplicativeExpression().apply(this);
+            node.getPathName().apply(this);
+            
+            feature = val;
+        }
+        if(node.getTimeExpression() != null)
+        {
+            // XXX hypothesis: no time expression (inv)
+            node.getTimeExpression().apply(this);
+        }
+        if(node.getQualifiers() != null)
+        {
+            // TODO understand qualifiers
+            node.getQualifiers().apply(this);
+        }
+        if(node.getFeatureCallParameters() != null)
+        {            
+            node.getFeatureCallParameters().apply(this);
+            
+            parameters = (Vector<Object>) val;
+        } else {
+            parameters = new Vector<Object>();
+        }
+        
+        val = runFeatureCall(subject, feature, fwd, parameters);
+        outAFeatureCall(node);
+    }
+    
+    public void caseAActualParameterList(AActualParameterList node)
+    {
+        Vector<Object> list = new Vector<Object>(); 
+        inAActualParameterList(node);
+        if(node.getExpression() != null)
+        {
+            node.getExpression().apply(this);
+            list.add(val);
         }
         {
-            Object temp[] = node.getAdditiveExpressionTail().toArray();
+            
+            Object temp[] = node.getActualParameterListTail().toArray();
             for(int i = 0; i < temp.length; i++)
             {
-                ((PAdditiveExpressionTail) temp[i]).apply(this);
+                ((PActualParameterListTail) temp[i]).apply(this);
+                
+                list.add(val);
             }
         }
-        outAAdditiveExpression(node);
+        
+        val = list;
+        outAActualParameterList(node);
     }
     
-    public void defaultIn(Node node)
+    /**
+     * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#outANamePathNameBegin(tudresden.ocl.parser.node.ANamePathNameBegin)
+     */
+    public void outANamePathNameBegin(ANamePathNameBegin node)
     {
-        LOG.debug("Entering: " + node.getClass() + "\n VALUE: " + node);
+        // TODO support other name kinds 
+        val = node.getName().getText();
+        defaultOut(node);
+    }
+
+    /** HELPER METHODS **/
+    private boolean asBoolean(Object value, Object node) {
+        if (value instanceof Boolean) {
+            return (Boolean) value;
+        } else {
+            errorNotType(node, "Boolean", false);
+            return false;
+        }                
+    }
+
+    private int asInteger(Object value, Object node) {
+        if (value instanceof Integer) {
+            return (Integer) value;
+        } else {
+            errorNotType(node, "integer", 0);
+            return 0;
+        }                
     }
+
+    @SuppressWarnings("unchecked")
+    private Object runFeatureCall(Object subject, Object feature, Object type, Vector<Object> parameters) {
+        LOG.debug("OCL FEATURE CALL: " + subject + ""+ type +""+ feature + "" + parameters);
+        
+        return interp.invokeFeature(vt, subject, feature.toString().trim(),
+                type.toString().trim(), parameters.toArray());
+    }
+    
+    /** Error Handling **/
+    private void errorNotType(Object node, String type, Object dft) {
+        LOG.error("OCL does not evaluate to a "+type+ " expression!! Exp: "
+                + node + " Val: " + val);
+        val = dft;
+    }
+
+    private void error(Object node) {
+        LOG.error("Unknown error processing OCL exp!! Exp: "
+                + node + " Val: " + val);
+        val = null;
+    }
+    
 }

Added: branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/LambdaEvaluator.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/LambdaEvaluator.java?view=auto&rev=15143
==============================================================================
--- (empty file)
+++ branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/LambdaEvaluator.java	2008-07-02 04:29:44-0700
@@ -0,0 +1,43 @@
+// $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;
+
+import java.util.HashMap;
+
+/**
+ * Evaluates an OCL expression given a variable table
+ *
+ * @author maurelio1234
+ */
+public interface LambdaEvaluator {
+    /**
+     * Evaluates the given OCL expression 
+     * 
+     * @param vt variable table
+     * @param exp expression
+     * @return the return value
+     */
+    Object evaluate(HashMap<String, Object> vt, Object exp);
+}

Added: branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/ModelInterpreter.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/ModelInterpreter.java?view=auto&rev=15143
==============================================================================
--- (empty file)
+++ branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/ModelInterpreter.java	2008-07-02 04:29:44-0700
@@ -0,0 +1,48 @@
+// $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;
+
+import java.util.HashMap;
+
+/**
+ * Actually interprets the feature and operations in the model
+ *
+ * @author maurelio1234
+ */
+public interface ModelInterpreter {
+
+    /**
+     * Actually interprets the feature and operations in the model
+     * 
+     * @param vt
+     * @param subject
+     * @param feature
+     * @param type
+     * @param parameters
+     * @return the return value
+     */
+    Object invokeFeature(HashMap<String, Object> vt, Object subject, String feature, String type, Object[] parameters);
+    
+}

Modified: branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/OclInterpreter.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/OclInterpreter.java?view=diff&rev=15143&p1=branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/OclInterpreter.java&p2=branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/OclInterpreter.java&r1=15142&r2=15143
==============================================================================
--- branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/OclInterpreter.java	(original)
+++ branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/OclInterpreter.java	2008-07-02 04:29:44-0700
@@ -51,13 +51,21 @@
      * Parser OCL tree
      */
     private Start     tree   = null;
+
+    /**
+     * The model interpreter
+     */
+    private ModelInterpreter modelInterpreter;
     
     /**
      * Creates a new OCL interpreter for a given OCL expression
      * 
      * @param ocl expression
+     * @param interpreter 
      */
-    public OclInterpreter(String ocl) {
+    public OclInterpreter(String ocl, ModelInterpreter interpreter) {
+        this.modelInterpreter = interpreter;
+        
         Lexer lexer = new Lexer(new PushbackReader(new StringReader(ocl), 2));
 
         OclParser parser = new OclParser(lexer);
@@ -90,7 +98,8 @@
      * @return if is satisfied
      */
     public boolean check(Object modelElement) {
-        EvaluateInvariant ei = new EvaluateInvariant(modelElement);
+        EvaluateInvariant ei = new EvaluateInvariant(modelElement,
+                modelInterpreter);
         tree.apply(ei);
         return ei.isOK();
     }

Added: branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/Bag.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/Bag.java?view=auto&rev=15143
==============================================================================
--- (empty file)
+++ branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/Bag.java	2008-07-02 04:29:44-0700
@@ -0,0 +1,46 @@
+// $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.Set;
+
+/**
+ * Represent OCL bags (sets which allow repeated elements
+ *
+ * @author maurelio1234
+ * @param <E> the type
+ */
+public interface Bag<E> extends Set<E> {
+
+    
+    /**
+     * Counts the number of repetitons of E in this Bag, 
+     * if E is not present return 0
+     * 
+     * @param element
+     * @return the number of occourrences of E in this bag
+     */
+    int count(E element);
+}

Added: branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/HashBag.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/HashBag.java?view=auto&rev=15143
==============================================================================
--- (empty file)
+++ branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/HashBag.java	2008-07-02 04:29:44-0700
@@ -0,0 +1,183 @@
+// $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.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+
+
+/**
+ * An implementation for the Bag interface
+ * 
+ * @param <E>
+ * @author maas
+ */
+public class HashBag<E> implements Bag<E> {
+
+    private HashMap<E,Integer> map = new HashMap<E,Integer>(); 
+    
+    /**
+     * Creates a new Bag from a Collection
+     * 
+     * @param col
+     */
+    @SuppressWarnings("unchecked")
+    public HashBag(Collection col) {
+        addAll(col);
+    }
+    
+    /**
+     * @see org.argouml.profile.internal.ocl.uml14.Bag#count(java.lang.Object)
+     */
+    public int count(Object element) {
+        Integer c = map.get(element);
+        return  c == null ? 0 : c;
+    }
+
+    /**
+     * @param e
+     * @see java.util.Set#add(java.lang.Object)
+     */
+    public boolean add(E e) {
+        if (map.get(e) == null) {
+            map.put(e, 0);
+        } else {
+            map.put(e, map.get(e) + 1);
+        }
+        
+        return true;
+    }
+
+    /**
+     * @see java.util.Set#addAll(java.util.Collection)
+     */
+    @SuppressWarnings("unchecked")
+    public boolean addAll(Collection c) {
+        for (Object object : c) {
+            add((E) object);
+        }        
+        return true;
+    }
+
+    /**
+     * @see java.util.Set#clear()
+     */
+    public void clear() {
+        map.clear();
+    }
+
+    /**
+     * @see java.util.Set#contains(java.lang.Object)
+     */
+    public boolean contains(Object o) {
+        return count(o) > 0;            
+    }
+
+    /**
+     * @see java.util.Set#containsAll(java.util.Collection)
+     */
+    public boolean containsAll(Collection c) {
+        for (Object object : c) {
+            if (!contains(object)) return false;
+        }
+        return true;
+    }
+
+    /**
+     * @see java.util.Set#isEmpty()
+     */
+    public boolean isEmpty() {
+        return size() == 0;
+    }
+
+    /**
+     * @see java.util.Set#iterator()
+     */
+    public Iterator<E> iterator() {
+        return map.keySet().iterator();
+    }
+
+    /**
+     * @see java.util.Set#remove(java.lang.Object)
+     */
+    @SuppressWarnings("unchecked")
+    public boolean remove(Object o) {
+        boolean c = contains(o);
+        map.put((E) o, null);
+        return c;
+    }
+
+    /**
+     * @param c
+     * @return if the bag changed
+     * @see java.util.Set#removeAll(java.util.Collection)
+     */
+    public boolean removeAll(Collection c) {
+        boolean changed = false;
+        for (Object object : c) {
+            changed |= remove(object);
+        }
+        return changed;
+    }
+
+    /**
+     * @param c
+     * @see java.util.Set#retainAll(java.util.Collection)
+     */
+    public boolean retainAll(Collection c) {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * @return the number of elements in this bag
+     * @see java.util.Set#size()
+     */
+    public int size() {
+        int sum = 0;
+        
+        Iterator<E> it = iterator();
+        while(it.hasNext()) {
+            E next = it.next();
+            sum += count(next);
+        }
+        return sum;
+    }
+
+    /**
+     * @see java.util.Set#toArray()
+     */
+    public Object[] toArray() {
+        return map.keySet().toArray();
+    }
+
+    /**
+     * @see java.util.Set#toArray(T[])
+     */
+    public <T> T[] toArray(T[] a) {
+        return map.keySet().toArray(a);
+    }
+
+}

Added: 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=auto&rev=15143
==============================================================================
--- (empty file)
+++ branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/Uml14ModelInterpreter.java	2008-07-02 04:29:44-0700
@@ -0,0 +1,147 @@
+// $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.model.Model;
+import org.argouml.profile.internal.ocl.LambdaEvaluator;
+import org.argouml.profile.internal.ocl.ModelInterpreter;
+
+/**
+ * Interpreter for UML 1.4 / OCL 1.4
+ * 
+ * @author maurelio1234
+ */
+public class Uml14ModelInterpreter 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 (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();
+        }        
+    }
+
+}
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.