svn commit: r14800 - trunk/src/argouml-app/src/org/argouml: moduleloader profile profile/internal profile/profiles/uml14

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: maurelio1234
Date: 2008-05-26 00:56:08-0700
New Revision: 14800

Added:
   trunk/src/argouml-app/src/org/argouml/profile/internal/ProfileMeta.java
   trunk/src/argouml-app/src/org/argouml/profile/profiles/uml14/metaprofile.xmi
Modified:
   trunk/src/argouml-app/src/org/argouml/moduleloader/ModuleLoader2.java
   trunk/src/argouml-app/src/org/argouml/profile/URLModelLoader.java
   trunk/src/argouml-app/src/org/argouml/profile/UserDefinedProfile.java
   trunk/src/argouml-app/src/org/argouml/profile/internal/ProfileManagerImpl.java

Log:
trying euluis' approach for issue #5029

Modified: trunk/src/argouml-app/src/org/argouml/moduleloader/ModuleLoader2.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/moduleloader/ModuleLoader2.java?view=diff&rev=14800&p1=trunk/src/argouml-app/src/org/argouml/moduleloader/ModuleLoader2.java&p2=trunk/src/argouml-app/src/org/argouml/moduleloader/ModuleLoader2.java&r1=14799&r2=14800
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/moduleloader/ModuleLoader2.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/moduleloader/ModuleLoader2.java	2008-05-26 00:56:08-0700
@@ -27,6 +27,7 @@
 import java.io.File;
 import java.io.FileFilter;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.io.UnsupportedEncodingException;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
@@ -51,6 +52,11 @@
 import org.argouml.application.api.AbstractArgoJPanel;
 import org.argouml.application.api.Argo;
 import org.argouml.i18n.Translator;
+import org.argouml.profile.ProfileException;
+import org.argouml.profile.ProfileFacade;
+import org.argouml.profile.UserDefinedProfile;
+import org.argouml.profile.internal.ProfileManagerImpl;
+import org.argouml.ui.ProjectBrowser;
 
 /**
  * This is the module loader that loads modules implementing the
@@ -568,6 +574,9 @@
             return;
 	}
 
+        LOG.info("Reading profiles...");
+        loadProfilesFromJarFile(jarfile, file);
+        
         Manifest manifest;
         try {
             manifest = jarfile.getManifest();
@@ -600,7 +609,7 @@
         
         if (loadedClass) {
             // Add this to search list for I18N properties
-            Translator.addClassLoader(classloader);
+            Translator.addClassLoader(classloader);           
         } else {
             LOG.error("Failed to find any loadable ArgoUML modules in jar "
                     + file);
@@ -608,6 +617,30 @@
     }
 
     /**
+     * Searches for Profiles models (*.xmi) files in the directory "
+     * 
+     * @param jarfile the jarfile
+     * @param file 
+     */
+    private void loadProfilesFromJarFile(JarFile jarfile, File file) {       
+        Enumeration<JarEntry> entries = jarfile.entries();
+        for(JarEntry entry = entries.nextElement(); entries.hasMoreElements(); entry = entries.nextElement()) {
+            if (entry.getName().toLowerCase().endsWith(".xmi")) {
+                try {
+                    UserDefinedProfile udp = new UserDefinedProfile(new URL("jar:file:"+file.getCanonicalPath()+"!/"+entry.getName()));
+                    ProfileFacade.getManager().registerProfile(udp);
+                    
+                    LOG.debug("Registered Profile: " + udp.getDisplayName()+"...");
+                } catch (ProfileException e) {
+                    LOG.error("Exception", e);
+                } catch (IOException e) {
+                    LOG.error("Exception", e);
+                }
+            }
+        }
+    }
+
+    /**
      * Process a JAR file entry, attempting to load anything that looks like a
      * Java class.
      * 

Modified: trunk/src/argouml-app/src/org/argouml/profile/URLModelLoader.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/profile/URLModelLoader.java?view=diff&rev=14800&p1=trunk/src/argouml-app/src/org/argouml/profile/URLModelLoader.java&p2=trunk/src/argouml-app/src/org/argouml/profile/URLModelLoader.java&r1=14799&r2=14800
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/profile/URLModelLoader.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/profile/URLModelLoader.java	2008-05-26 00:56:08-0700
@@ -38,7 +38,7 @@
  *
  * @author Tom Morris
  */
-public abstract class URLModelLoader implements ProfileModelLoader {
+public class URLModelLoader implements ProfileModelLoader {
 
     private static final Logger LOG = Logger.getLogger(URLModelLoader.class);
 
@@ -64,4 +64,8 @@
             throw new ProfileException("Invalid XMI data!", e);
         }
     }
+
+    public Collection loadModel(ProfileReference reference) throws ProfileException {
+        return loadModel(reference.getPublicReference(), reference.getPublicReference());
+    }
 }

Modified: trunk/src/argouml-app/src/org/argouml/profile/UserDefinedProfile.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/profile/UserDefinedProfile.java?view=diff&rev=14800&p1=trunk/src/argouml-app/src/org/argouml/profile/UserDefinedProfile.java&p2=trunk/src/argouml-app/src/org/argouml/profile/UserDefinedProfile.java&r1=14799&r2=14800
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/profile/UserDefinedProfile.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/profile/UserDefinedProfile.java	2008-05-26 00:56:08-0700
@@ -27,12 +27,18 @@
 import java.io.File;
 import java.io.Reader;
 import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.Collection;
+import java.util.List;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+import org.argouml.model.Model;
 
 /**
  * Represents a profile defined by the user
  *
- * @author Marcos Aurélio
+ * @author Marcos Aur�lio
  */
 public class UserDefinedProfile extends Profile {
 
@@ -59,6 +65,8 @@
         }
         model = new FileModelLoader().loadModel(reference);
         fromZargo = false;
+
+        completeLoading();
     }
 
     
@@ -84,8 +92,68 @@
         }
         model = new ReaderModelLoader(reader).loadModel(reference);
         fromZargo = true;
+        
+        completeLoading();
+    }
+
+
+    public UserDefinedProfile(URL url) throws ProfileException {
+        ProfileReference reference = null;
+        reference = new UserProfileReference(url.getPath(), url);
+        model = new URLModelLoader().loadModel(reference);
+        fromZargo = false;
+
+        completeLoading();
+     }
+
+
+    /**
+     * Reads the informations defined as TaggedValues
+     */
+    private void completeLoading() {
+        
+        for (Object obj : model) {
+            if (Model.getExtensionMechanismsHelper().hasStereotype(obj,
+                    "profile")) {
+
+                // load profile name
+                String name = Model.getFacade().getName(obj);
+                if (name != null) {
+                    displayName = name;
+                } else {
+                    displayName = "Untitled";
+                }
+                                
+                // load profile dependencies
+                String dep = Model.getFacade().getTaggedValueValue(obj, "Dependency");
+                StringTokenizer st = new StringTokenizer(dep, " ,;:");
+                
+                String prof = null;
+                
+                do {
+                    prof = st.nextToken();
+                    if (prof != null) {
+                        this.addProfileDependency(lookForRegisteredProfile(prof));
+                    }
+                } while(st.hasMoreTokens());
+                
+            }
+        }
+                
     }
 
+    private Profile lookForRegisteredProfile(String value) {
+        ProfileManager man = ProfileFacade.getManager();
+        List<Profile> regs = man.getRegisteredProfiles();
+
+        for (Profile profile : regs) {
+            if (profile.getDisplayName().equalsIgnoreCase(value)) {
+                return profile;
+            }
+        }
+        return null;
+    }
+    
 
     /**
      * @return the string that should represent this profile in the GUI. An

Modified: trunk/src/argouml-app/src/org/argouml/profile/internal/ProfileManagerImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/profile/internal/ProfileManagerImpl.java?view=diff&rev=14800&p1=trunk/src/argouml-app/src/org/argouml/profile/internal/ProfileManagerImpl.java&p2=trunk/src/argouml-app/src/org/argouml/profile/internal/ProfileManagerImpl.java&r1=14799&r2=14800
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/profile/internal/ProfileManagerImpl.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/profile/internal/ProfileManagerImpl.java	2008-05-26 00:56:08-0700
@@ -43,7 +43,7 @@
 /**
  * Default <code>ProfileManager</code> implementation
  *
- * @author Marcos Aurélio
+ * @author Marcos Aur�lio
  */
 public class ProfileManagerImpl implements ProfileManager {
     
@@ -84,6 +84,7 @@
             defaultProfiles.add(uml);
             registerProfile(uml);
             registerProfile(new ProfileJava(uml));
+            registerProfile(new ProfileMeta());
         } catch (ProfileException e) {
             throw new RuntimeException(e);
         }

Added: trunk/src/argouml-app/src/org/argouml/profile/internal/ProfileMeta.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/profile/internal/ProfileMeta.java?view=auto&rev=14800
==============================================================================
--- (empty file)
+++ trunk/src/argouml-app/src/org/argouml/profile/internal/ProfileMeta.java	2008-05-26 00:56:08-0700
@@ -0,0 +1,83 @@
+// $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;
+
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.argouml.model.Model;
+import org.argouml.profile.CoreProfileReference;
+import org.argouml.profile.Profile;
+import org.argouml.profile.ProfileException;
+import org.argouml.profile.ProfileModelLoader;
+import org.argouml.profile.ProfileReference;
+import org.argouml.profile.ResourceModelLoader;
+
+/**
+ * Meta Profile which defines the TaggedValues to be used in User defined Profiles
+ *
+ * @author maas
+ */
+public class ProfileMeta extends Profile {
+
+    private static final String PROFILE_FILE = "metaprofile.xmi";
+    private Collection model;
+
+    /**
+     * Creates a new instance of this profile
+     * 
+     * @throws ProfileException
+     */
+    @SuppressWarnings("unchecked")
+    public ProfileMeta() throws ProfileException {
+        ProfileModelLoader profileModelLoader = new ResourceModelLoader();
+        ProfileReference profileReference = null;
+        try {
+            profileReference = new CoreProfileReference(PROFILE_FILE);
+        } catch (MalformedURLException e) {
+            throw new ProfileException(
+                "Exception while creating profile reference.", e);
+        }
+        model = profileModelLoader.loadModel(profileReference);
+
+        if (model == null) {
+            model = new ArrayList();
+            model.add(Model.getModelManagementFactory().createModel());
+        }
+
+    }
+    
+    @Override
+    public String getDisplayName() {
+        return "MetaProfile";
+    }
+
+    @Override
+    public Collection getProfilePackages() throws ProfileException {
+        return model;
+    }
+
+}

Added: trunk/src/argouml-app/src/org/argouml/profile/profiles/uml14/metaprofile.xmi
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/profile/profiles/uml14/metaprofile.xmi?view=auto&rev=14800
==============================================================================
--- (empty file)
+++ trunk/src/argouml-app/src/org/argouml/profile/profiles/uml14/metaprofile.xmi	2008-05-26 00:56:08-0700
@@ -0,0 +1,45 @@
+<?xml version = '1.0' encoding = 'UTF-8' ?>
+<XMI xmi.version = '1.2' xmlns:UML = 'org.omg.xmi.namespace.UML' timestamp = 'Sun May 25 10:34:59 CEST 2008'>
+  <XMI.header>    <XMI.documentation>
+      <XMI.exporter>ArgoUML (using Netbeans XMI Writer version 1.0)</XMI.exporter>
+      <XMI.exporterVersion>PRE-0.25.5(6) revised on $Date: 2007-05-12 08:08:08 +0200 (sam., 12 mai 2007) $ </XMI.exporterVersion>
+    </XMI.documentation>
+    <XMI.metamodel xmi.name="UML" xmi.version="1.4"/></XMI.header>
+  <XMI.content>
+    <UML:Model xmi.id = '127-0-1-1--3790810c:11a1f2b16a5:-8000:00000000000007BD'
+      name = 'ArgoUMLProfile' isSpecification = 'false' isRoot = 'false' isLeaf = 'false'
+      isAbstract = 'false'>
+      <UML:ModelElement.stereotype>
+        <UML:Stereotype href = 'http://argouml.org/profiles/uml14/default-uml14.xmi#.:0000000000000877'/>
+      </UML:ModelElement.stereotype>
+      <UML:ModelElement.taggedValue>
+        <UML:TaggedValue xmi.id = '127-0-1-1--3790810c:11a1f2b16a5:-8000:00000000000007C2'
+          isSpecification = 'false'/>
+      </UML:ModelElement.taggedValue>
+      <UML:Namespace.ownedElement>
+        <UML:TagDefinition xmi.id = '127-0-1-1--3790810c:11a1f2b16a5:-8000:00000000000007C8'
+          name = 'Dependency' visibility = 'public' isSpecification = 'false'>
+          <UML:TagDefinition.multiplicity>
+            <UML:Multiplicity xmi.id = '127-0-1-1--3790810c:11a1f2b16a5:-8000:00000000000007D7'>
+              <UML:Multiplicity.range>
+                <UML:MultiplicityRange xmi.id = '127-0-1-1--3790810c:11a1f2b16a5:-8000:00000000000007D6'
+                  lower = '0' upper = '-1'/>
+              </UML:Multiplicity.range>
+            </UML:Multiplicity>
+          </UML:TagDefinition.multiplicity>
+        </UML:TagDefinition>
+        <UML:TagDefinition xmi.id = '127-0-1-1--3790810c:11a1f2b16a5:-8000:00000000000007D1'
+          name = 'Figure' isSpecification = 'false'>
+          <UML:TagDefinition.multiplicity>
+            <UML:Multiplicity xmi.id = '127-0-1-1--3790810c:11a1f2b16a5:-8000:00000000000007D2'>
+              <UML:Multiplicity.range>
+                <UML:MultiplicityRange xmi.id = '127-0-1-1--3790810c:11a1f2b16a5:-8000:00000000000007D3'
+                  lower = '0' upper = '1'/>
+              </UML:Multiplicity.range>
+            </UML:Multiplicity>
+          </UML:TagDefinition.multiplicity>
+        </UML:TagDefinition>
+      </UML:Namespace.ownedElement>
+    </UML:Model>
+  </XMI.content>
+</XMI>
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.