svn commit: r19260 - 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

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: thn
Date: 2011-04-19 00:28:41-0700
New Revision: 19260

Modified:
   trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/DataTypesHelperEUMLImpl.java
   trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/DataTypesHelperMDRImpl.java
   trunk/src/argouml-core-model/src/org/argouml/model/AbstractDataTypesHelperDecorator.java
   trunk/src/argouml-core-model/src/org/argouml/model/DataTypesHelper.java

Log:
UML2: adding methods for handling of ValueSpecification objects
Patch obtained from Laurent Braud

Modified: trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/DataTypesHelperEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/DataTypesHelperEUMLImpl.java?view=diff&pathrev=19260&r1=19259&r2=19260
==============================================================================
--- trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/DataTypesHelperEUMLImpl.java	(original)
+++ trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/DataTypesHelperEUMLImpl.java	2011-04-19 00:28:41-0700
@@ -9,17 +9,28 @@
  * Contributors:
  *    Tom Morris - initial implementation
  *    Thomas Neustupny
+ *    Laurent Braud 
  *******************************************************************************/
 package org.argouml.model.euml;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import org.argouml.model.DataTypesHelper;
 import org.eclipse.emf.common.util.EList;
+import org.eclipse.uml2.uml.LiteralBoolean;
+import org.eclipse.uml2.uml.LiteralInteger;
+import org.eclipse.uml2.uml.LiteralNull;
+import org.eclipse.uml2.uml.LiteralString;
+import org.eclipse.uml2.uml.LiteralUnlimitedNatural;
 import org.eclipse.uml2.uml.MultiplicityElement;
 import org.eclipse.uml2.uml.OpaqueBehavior;
 import org.eclipse.uml2.uml.OpaqueExpression;
+import org.eclipse.uml2.uml.Property;
 import org.eclipse.uml2.uml.PseudostateKind;
+import org.eclipse.uml2.uml.UMLFactory;
+import org.eclipse.uml2.uml.UMLPackage;
+import org.eclipse.uml2.uml.ValueSpecification;
 
 /**
  * The implementation of the DataTypesHelper for EUML2.
@@ -149,4 +160,162 @@
         return handle;
     }
 
+    /**
+     * @see org.argouml.model.DataTypesHelper#getValueSpecifications()
+     */
+    public ArrayList<String> getValueSpecifications() {
+        ArrayList<String> list = new ArrayList<String>(); 
+        //
+        list.add("OpaqueExpression");
+        //list.add("OpaqueExpression");
+        
+        //LiteralSpecification
+        //list.add("LiteralNull");//When other ok
+        list.add("LiteralString");
+        //list.add("LiteralInteger");//When other ok
+        list.add("LiteralBoolean");
+        //list.add("LiteralUnlimitedNatural");//When other ok
+        
+        //list.add("LiteralReal");//UML 2.4
+        //End LiteralSpecification     
+        
+        //list.add("InstanceValue");
+        
+        return list;
+    }
+    
+    /**
+     * @see org.argouml.model.DataTypesHelper#createValueValueSpecification(java.lang.String, java.lang.Object)
+     */
+    public Object createValueSpecification(Object handle,
+            String type) {
+        
+        ValueSpecification newValueSpecification = null;
+        if (handle instanceof Property) {
+            Property property = (Property) handle;
+            
+            Object[] tabValues = null;
+            if (type.equals("LiteralBoolean")) {
+                newValueSpecification = (ValueSpecification)UMLFactory.eINSTANCE.create(UMLPackage.eINSTANCE.getLiteralBoolean());
+            } else if (type.equals("LiteralNull")) {
+        	newValueSpecification = (ValueSpecification)UMLFactory.eINSTANCE.create(UMLPackage.eINSTANCE.getLiteralNull());
+            } else if (type.equals("LiteralString")) {
+                newValueSpecification = (ValueSpecification)UMLFactory.eINSTANCE.create(UMLPackage.eINSTANCE.getLiteralString());
+                tabValues = new String[]{""};
+            } else if (type.equals("LiteralUnlimitedNatural")) {
+                newValueSpecification = (ValueSpecification)UMLFactory.eINSTANCE.create(UMLPackage.eINSTANCE.getLiteralUnlimitedNatural());
+                tabValues = new String[]{"0"};
+            } else if (type.equals("LiteralInteger")) {
+                newValueSpecification = (ValueSpecification)UMLFactory.eINSTANCE.create(UMLPackage.eINSTANCE.getLiteralInteger());
+                tabValues = new String[]{"0"};
+            } else if (type.equals("OpaqueExpression")) {
+                newValueSpecification = (ValueSpecification)UMLFactory.eINSTANCE.create(UMLPackage.eINSTANCE.getOpaqueExpression());
+                setLanguage(newValueSpecification, "");
+                setBody(newValueSpecification, "");
+            }
+            if(tabValues != null){
+                modifyValueSpecification(newValueSpecification,tabValues);
+            }
+            
+            if(newValueSpecification!=null){
+                property.setDefaultValue(newValueSpecification);
+            }
+        }// TODO else => Exception !
+
+        return newValueSpecification;
+        
+    }
+    
+    /**
+     * @see org.argouml.model.DataTypesHelper#modifyValueSpecification(java.lang.Object, java.lang.Object[])
+     */
+    public void modifyValueSpecification(Object handle, Object[] tabValues) {
+        // LiteralSpecification  
+        if (handle instanceof LiteralBoolean) {
+            LiteralBoolean lb = (LiteralBoolean) handle;
+            if (tabValues != null && tabValues.length == 1) {
+                Boolean value = (Boolean) tabValues[0];
+                lb.setValue(value);
+            }
+        } else if (handle instanceof LiteralNull) {
+            // Can't be changed
+        } else if (handle instanceof LiteralString) {
+            LiteralString ls = (LiteralString) handle;
+            if (tabValues != null && tabValues.length == 1) {
+                String value = (String) tabValues[0];
+                ls.setValue(value);
+            }
+        } else if (handle instanceof LiteralUnlimitedNatural) {
+            LiteralUnlimitedNatural ls = (LiteralUnlimitedNatural) handle;
+            if (tabValues != null && tabValues.length == 1) {
+                Integer value = (Integer) tabValues[0];
+                ls.setValue(value);
+            }
+        } else if (handle instanceof LiteralInteger) {
+            LiteralInteger ls = (LiteralInteger) handle;
+            if (tabValues != null && tabValues.length == 1) {
+                Integer value = (Integer) tabValues[0];
+                ls.setValue(value);
+            }
+        } else if (handle instanceof OpaqueExpression) {
+            //rewrite it after change setExpression ?
+            OpaqueExpression oe=(OpaqueExpression) handle;
+            List<String> bodies = oe.getBodies();
+            List<String> langs = oe.getLanguages();
+            // as write in UML specification, we have size(bodies)==size(langs)
+            // we must have tabValues.length%2==0 
+            bodies.clear();
+            langs.clear();
+            for (int i = 0; i < tabValues.length; i += 2) {
+                bodies.add((String)tabValues[i]);
+                langs.add((String)tabValues[i+1]);
+            }
+        }
+        // TODO Expression and InstanceValue (how)
+        // If anyone have an example.
+        
+    }
+    
+    /**
+     * @see org.argouml.model.DataTypesHelper#getValueSpecificationValues(java.lang.Object)
+     */
+    public Object[] getValueSpecificationValues(Object handle) {
+        Object[] tabValues = null;
+        // LiteralSpecification  
+        if (handle instanceof LiteralBoolean) {
+            LiteralBoolean lb = (LiteralBoolean) handle;
+            tabValues = new Boolean[]{lb.isValue()};
+            
+        } else if (handle instanceof LiteralNull) {
+            // Can't be set
+        } else if (handle instanceof LiteralString) {
+            LiteralString ls = (LiteralString) handle;
+            tabValues = new String[]{ls.getValue()};
+        } else if (handle instanceof LiteralUnlimitedNatural) {
+            LiteralUnlimitedNatural lun = (LiteralUnlimitedNatural) handle;
+            tabValues = new String[]{""+lun.getValue()};
+        } else if (handle instanceof LiteralInteger) {
+            LiteralInteger li = (LiteralInteger) handle;
+            tabValues = new Integer[]{li.getValue()};
+        }
+        else if (handle instanceof OpaqueExpression) {
+            //rewrite it after change setExpression ?
+            OpaqueExpression oe = (OpaqueExpression) handle;
+            List<String> bodies = oe.getBodies();
+            List<String> langs = oe.getLanguages();
+            // as write in UML specification, we have size(bodies)==size(langs)
+            // we must have tabValues.length%2==0
+            if (bodies.size() > 0) {
+                tabValues= new String[bodies.size()*2];
+                for (int i = 0; i < bodies.size(); i++) {
+                    tabValues[i*2] = bodies.get(i);
+                    tabValues[i*2+1] = langs.get(i);
+                }
+            }
+        }
+        // TODO Expression and InstanceValue (how)
+        // If anyone have an example.
+        
+        return tabValues;
+    }
 }

Modified: trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/DataTypesHelperMDRImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/DataTypesHelperMDRImpl.java?view=diff&pathrev=19260&r1=19259&r2=19260
==============================================================================
--- trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/DataTypesHelperMDRImpl.java	(original)
+++ trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/DataTypesHelperMDRImpl.java	2011-04-19 00:28:41-0700
@@ -7,7 +7,9 @@
  * http://www.eclipse.org/legal/epl-v10.html
  *
  * Contributors:
- *    tfmorris
+ *    Tom Morris
+ *    Thomas Neustupny
+ *    Laurent Braud
  *****************************************************************************
  *
  * Some portions of this file was previously release using the BSD License:
@@ -38,6 +40,7 @@
 
 package org.argouml.model.mdr;
 
+import java.util.Collection;
 import java.util.Iterator;
 
 import javax.jmi.reflect.InvalidObjectException;
@@ -235,5 +238,34 @@
         }
         throw new IllegalArgumentException("handle: " + handle);
     }
-	
+    
+    /**
+     * @see org.argouml.model.DataTypesHelper#getValueSpecifications()
+     */
+    public Collection<String> getValueSpecifications() {
+        return null;
+    }
+
+    /**
+     * @see org.argouml.model.DataTypesHelper#createValueSpecification(java.lang.Object,java.lang.String)
+     */
+    public Object createValueSpecification(Object handle,
+            String type) {
+        return null;
+    }
+
+    /**
+     * @see org.argouml.model.DataTypesHelper#modifyValueSpecification(java.lang.Object, java.lang.Object[])
+     */
+    public void modifyValueSpecification(Object handle, Object[] tabValues) {
+        // Not implemented in MDR 
+    }
+    
+    /**
+     * @see org.argouml.model.DataTypesHelper#getValueSpecificationValues(java.lang.Object)
+     */
+    public Object[] getValueSpecificationValues(Object handle) {
+        return null;
+    }
+    
 }

Modified: trunk/src/argouml-core-model/src/org/argouml/model/AbstractDataTypesHelperDecorator.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model/src/org/argouml/model/AbstractDataTypesHelperDecorator.java?view=diff&pathrev=19260&r1=19259&r2=19260
==============================================================================
--- trunk/src/argouml-core-model/src/org/argouml/model/AbstractDataTypesHelperDecorator.java	(original)
+++ trunk/src/argouml-core-model/src/org/argouml/model/AbstractDataTypesHelperDecorator.java	2011-04-19 00:28:41-0700
@@ -7,7 +7,9 @@
  * http://www.eclipse.org/legal/epl-v10.html
  *
  * Contributors:
- *    tfmorris
+ *    Tom Morris
+ *    Thomas Neustupny
+ *    Laurent Braud
  *******************************************************************************
  *
  * Some portions of this file was previously release using the BSD License:
@@ -38,6 +40,8 @@
 
 package org.argouml.model;
 
+import java.util.Collection;
+
 /**
  * An abstract Decorator for the {@link DataTypesHelper}.
  *
@@ -115,4 +119,19 @@
         return impl.getLanguage(handle);
     }
 
+    public Collection<String> getValueSpecifications(){
+        return impl.getValueSpecifications();
+    }
+    
+    public Object createValueSpecification(Object handle, String type) {
+        return impl.createValueSpecification(handle, type);
+    }
+    
+    public void modifyValueSpecification(Object handle, Object[] tabValues) {
+        impl.modifyValueSpecification(handle, tabValues);
+    }
+
+    public Object[] getValueSpecificationValues(Object handle) {
+        return impl.getValueSpecificationValues(handle);
+    }    
 }

Modified: trunk/src/argouml-core-model/src/org/argouml/model/DataTypesHelper.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model/src/org/argouml/model/DataTypesHelper.java?view=diff&pathrev=19260&r1=19259&r2=19260
==============================================================================
--- trunk/src/argouml-core-model/src/org/argouml/model/DataTypesHelper.java	(original)
+++ trunk/src/argouml-core-model/src/org/argouml/model/DataTypesHelper.java	2011-04-19 00:28:41-0700
@@ -7,7 +7,9 @@
  * http://www.eclipse.org/legal/epl-v10.html
  *
  * Contributors:
- *    tfmorris
+ *    Tom Morris
+ *    Thomas Neustupny
+ *    Laurent Braud
  *******************************************************************************
  *
  * Some portions of this file was previously release using the BSD License:
@@ -38,6 +40,8 @@
 
 package org.argouml.model;
 
+import java.util.Collection;
+
 
 /**
  * The interface for the helper for DataTypes.<p>
@@ -145,4 +149,38 @@
      */
     String getLanguage(Object handle);
 
+    /**
+     * Return the list of implemented ValueSpecification
+     * @return All the type of ValueSpecification  
+     */
+    Collection<String> getValueSpecifications();
+    
+    /**
+     * Creates a value specification object of a given type.
+     * TODO move to DataTypesFactory?
+     * 
+     * @param handle The element that will own the value specification.
+     * @param type "OpaqueExpression", "LiteralBoolean",...
+     * @return The ValueSpecification created for handle.
+     * @since 20110407
+     */
+    Object createValueSpecification(Object handle, String type);
+
+    /**
+     * Modifies a value specification object.
+     * 
+     * @param handle The instance to modify.
+     * @param tabValues One ore more object in order to get the values.
+     * @since 20110407
+     */
+    void modifyValueSpecification(Object handle, Object[] tabValues);
+    
+    /**
+     * Gets the value specification values as an array.
+     * 
+     * @param handle
+     * @return The existing ValueSpecification for handle
+     * @since 20110412
+     */
+    Object[] getValueSpecificationValues(Object handle); 
 }

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

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.