svn commit: r17277 - trunk/src/argouml-app: src/org/argouml/i18n src/org/argouml/profile/internal tests/org/argouml/profile/internal

Luis Sergio Oliveira <[email protected]>
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: euluis
Date: 2009-08-16 10:06:52-0700
New Revision: 17277

Added:
   trunk/src/argouml-app/src/org/argouml/i18n/profile.properties   (contents, props changed)
   trunk/src/argouml-app/src/org/argouml/profile/internal/FormatingStrategyUML.java
      - copied, changed from r17148, /trunk/src/argouml-app/src/org/argouml/profile/internal/JavaFormatingStrategy.java
   trunk/src/argouml-app/tests/org/argouml/profile/internal/TestFormatingStrategyUML.java   (contents, props changed)
Removed:
   trunk/src/argouml-app/src/org/argouml/profile/internal/JavaFormatingStrategy.java
Modified:
   trunk/src/argouml-app/src/org/argouml/profile/internal/ProfileUML.java

Log:
Issue 4885: TODOs 1, 2 and 3 as documented in my comment in the issue on 25th of June 2009 implemented. Bonus - added beginings of i18n support specific for the profile subsystem.

Added: trunk/src/argouml-app/src/org/argouml/i18n/profile.properties
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/i18n/profile.properties?view=markup&pathrev277
=============================================================================--- (empty file)
+++ trunk/src/argouml-app/src/org/argouml/i18n/profile.properties	2009-08-16 10:06:52-0700
@@ -0,0 +1,31 @@
+# $Id$
+# Copyright (c) 2009 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.
+#
+# Keys for the profile subsystem (org.argouml.profile) in alphabetical order.
+#
+profile.anonymous = anon
+# Expression place-holders are "<Child> specializes <Parent>".
+profile.default.specializes.expression = {0} specializes {1}
+profile.empty.collection = [empty]
+profile.unknown-type = unknown type

Copied: trunk/src/argouml-app/src/org/argouml/profile/internal/FormatingStrategyUML.java (from r17148, /trunk/src/argouml-app/src/org/argouml/profile/internal/JavaFormatingStrategy.java)
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/profile/internal/FormatingStrategyUML.java?view=diff&pathrev277&r1148&r2277
=============================================================================--- /trunk/src/argouml-app/src/org/argouml/profile/internal/JavaFormatingStrategy.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/profile/internal/FormatingStrategyUML.java	2009-08-16 10:06:52-0700
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 2007 The Regents of the University of California. All
+// Copyright (c) 2007-2009 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
@@ -26,15 +26,16 @@

 import java.util.Iterator;

+import org.argouml.i18n.Translator;
 import org.argouml.model.Model;
 import org.argouml.profile.FormatingStrategy;

 /**
- * The Formating Strategy based on Java naming conventions.
+ * The Formating Strategy based on UML naming conventions.
  *
- * @author Marcos Aurélio
+ * @author Marcos Aur�lio
  */
-public class JavaFormatingStrategy implements FormatingStrategy {
+public class FormatingStrategyUML implements FormatingStrategy {

     public String formatElement(Object element, Object namespace) {
         String value = null;
@@ -68,6 +69,10 @@
     }

     /**
+     * Create a default association end name from the type of assocEnd.
+     * Follows the conventions in UML 2.2 Infrastructure,
+     * 6.2.1. "Diagram format".
+     *
      * @param assocEnd the given association end name
      * @param namespace the namespace
      * @return the default name for the given associationend
@@ -78,40 +83,55 @@
         Object type = Model.getFacade().getType(assocEnd);
         if (type != null) {
             name = formatElement(type, namespace);
+            name = ensureFirstCharLowerCase(name);
         } else {
-            name = "unknown type";
+            name = Translator.localize("profile.unknown-type");
         }
         Object mult = Model.getFacade().getMultiplicity(assocEnd);
         if (mult != null) {
-            StringBuffer buf = new StringBuffer(name);
-            buf.append("[");
-            buf.append(Integer.toString(Model.getFacade().getLower(mult)));
-            buf.append("..");
+            int lower = Model.getFacade().getLower(mult);
             int upper = Model.getFacade().getUpper(mult);
-            if (upper >= 0) {
-                buf.append(Integer.toString(upper));
-            } else {
-                buf.append("*");
+            if (lower == upper && lower == 1) {
+                // simply use name as it is
+            }
+            else {
+                StringBuffer buf = new StringBuffer(name);
+                buf.append("[");
+                buf.append(Integer.toString(lower));
+                buf.append("..");
+                if (upper >= 0) {
+                    buf.append(Integer.toString(upper));
+                } else {
+                    buf.append("*");
+                }
+                buf.append("]");
+                name = buf.toString();
             }
-            buf.append("]");
-            name = buf.toString();
         }
         return name;
     }

+    String ensureFirstCharLowerCase(String s) {
+        if (s.length() > 0) {
+            return s.substring(0, 1).toLowerCase() + s.substring(1);
+        }
+        return s;
+    }
+
     /**
-     * Create a default association name from its ends.
+     * Create a default association name from its ends. Follows the conventions
+     * in UML 2.2 Infrastructure, 6.2.1. "Diagram format".
      *
      * @param assoc the given association
      * @param ns the namespace
      * @return the default association name
      */
     protected String defaultAssocName(Object assoc, Object ns) {
-        StringBuffer buf = new StringBuffer();
+        StringBuffer buf = new StringBuffer("A_");
         Iterator iter = Model.getFacade().getConnections(assoc).iterator();
         for (int i = 0; iter.hasNext(); i++) {
             if (i != 0) {
-                buf.append("-");
+                buf.append("_");
             }
             buf.append(defaultAssocEndName(iter.next(), ns));
         }
@@ -119,6 +139,9 @@
     }

     /**
+     * Use the term specializes, which is referred some times in the
+     * UML 2.2 Infrastructure specification.
+     *
      * @param gen the given Generalization
      * @param namespace the namespace
      * @return the default generalization name
@@ -126,11 +149,10 @@
     protected String defaultGeneralizationName(Object gen, Object namespace) {
         Object child = Model.getFacade().getSpecific(gen);
         Object parent = Model.getFacade().getGeneral(gen);
-        StringBuffer buf = new StringBuffer();
-        buf.append(formatElement(child, namespace));
-        buf.append(" extends ");
-        buf.append(formatElement(parent, namespace));
-        return buf.toString();
+        return Translator.messageFormat(
+            "profile.default.specializes.expression",
+            new Object[] {formatElement(child, namespace),
+                formatElement(parent, namespace), });
     }

     /**
@@ -151,21 +173,21 @@
             }
         }
         if (name == null) {
-            name = "anon";
+            name = Translator.localize("profile.anonymous");
         }
         return name;
     }

     /**
-     * @return the path separator (currently ".")
+     * @return the path separator (currently "::")
      */
     protected String getPathSeparator() {
-        return ".";
+        return "::";
     }

     /**
      * @param buffer (out) the buffer that will contain the path build
-     * @param element the given modelelement
+     * @param element the given model element
      * @param pathSep the path separator character(s)
      */
     private void buildPath(StringBuffer buffer, Object element,
@@ -195,7 +217,7 @@
      * @return the string that represents an empty collection
      */
     protected String getEmptyCollection() {
-        return "[empty]";
+        return Translator.localize("profile.empty.collection");
     }



Removed: trunk/src/argouml-app/src/org/argouml/profile/internal/JavaFormatingStrategy.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/profile/internal/JavaFormatingStrategy.java?view=markup&pathrev276

Modified: trunk/src/argouml-app/src/org/argouml/profile/internal/ProfileUML.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/profile/internal/ProfileUML.java?view=diff&pathrev277&r1276&r2277
=============================================================================--- trunk/src/argouml-app/src/org/argouml/profile/internal/ProfileUML.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/profile/internal/ProfileUML.java	2009-08-16 10:06:52-0700
@@ -99,7 +99,7 @@
      */
     @SuppressWarnings("unchecked")
     ProfileUML() throws ProfileException {
-        formatingStrategy = new JavaFormatingStrategy();
+        formatingStrategy = new FormatingStrategyUML();
         profileModelLoader = new ResourceModelLoader();
         ProfileReference profileReference = null;
         try {

Added: trunk/src/argouml-app/tests/org/argouml/profile/internal/TestFormatingStrategyUML.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/tests/org/argouml/profile/internal/TestFormatingStrategyUML.java?view=markup&pathrev277
=============================================================================--- (empty file)
+++ trunk/src/argouml-app/tests/org/argouml/profile/internal/TestFormatingStrategyUML.java	2009-08-16 10:06:52-0700
@@ -0,0 +1,104 @@
+// $Id$
+// Copyright (c) 2009 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;
+
+import static org.argouml.model.Model.getCoreFactory;
+import static org.argouml.model.Model.getFacade;
+
+import org.argouml.model.InitializeModel;
+import org.argouml.model.Model;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for the FormatingStrategyUML class.
+ *
+ * @author Luis Sergio Oliveira (euluis)
+ * @since 0.29.1
+ */
+public class TestFormatingStrategyUML extends TestCase {
+
+    private Object model;
+    private Object classA;
+    private Object classB;
+    private Object association;
+    private Object classAAssociationEnd;
+    private Object classBAssociationEnd;
+    private FormatingStrategyUML formatingStrategyUML;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        InitializeModel.initializeDefault();
+        model = Model.getModelManagementFactory().createModel();
+        Model.getCoreHelper().setName(model, "Model");
+        classA = getCoreFactory().buildClass("ClassA", model);
+        classB = getCoreFactory().buildClass("ClassB", model);
+        association = getCoreFactory().buildAssociation(classA, true,
+            classB, true, null);
+        classAAssociationEnd = getFacade().getAssociationEnd(classA,
+            association);
+        classBAssociationEnd = getFacade().getAssociationEnd(classB,
+            association);
+        formatingStrategyUML = new FormatingStrategyUML();
+    }
+
+    /**
+     * Test formatting of an unnamed association.
+     *
+     * @see FormatingStrategyUML#defaultAssocName(Object, Object)
+     */
+    public void testFormatUnnamedAssociation() {
+        assertEquals("A_classA_classB",
+            formatingStrategyUML.formatElement(association, model));
+    }
+
+    /**
+     * Various tests for
+     * {@link FormatingStrategyUML#ensureFirstCharLowerCase(String)}.
+     */
+    public void testEnsureFirstCharLowercase() {
+        assertEquals("", formatingStrategyUML.ensureFirstCharLowerCase(""));
+        assertEquals("a", formatingStrategyUML.ensureFirstCharLowerCase("a"));
+        assertEquals("a", formatingStrategyUML.ensureFirstCharLowerCase("A"));
+        assertEquals("aA", formatingStrategyUML.ensureFirstCharLowerCase("AA"));
+        assertEquals("3a", formatingStrategyUML.ensureFirstCharLowerCase("3a"));
+        assertEquals("theClass",
+            formatingStrategyUML.ensureFirstCharLowerCase("TheClass"));
+    }
+
+    /**
+     * Test formatting of an unnamed generalization.
+     *
+     * @see FormatingStrategyUML#defaultGeneralizationName(Object, Object)
+     */
+    public void testFormatUnnamedGeneralization() {
+        Object generalization = getCoreFactory().buildGeneralization(classA,
+            classB);
+        assertEquals("ClassA specializes ClassB",
+            formatingStrategyUML.formatElement(generalization, model));
+    }
+
+}

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

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.