svn commit: r14894 - branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml: kernel moduleloader profile profile/internal profile/profiles/uml14

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: maurelio1234
Date: 2008-06-10 10:53:47-0700
New Revision: 14894

Modified:
   branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/kernel/ProfileConfiguration.java
   branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/moduleloader/ModuleLoader2.java
   branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/Profile.java
   branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/UserDefinedProfile.java
   branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/internal/ProfileManagerImpl.java
   branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/profiles/uml14/metaprofile.xmi

Log:
adding support for critics defined by profiles

Modified: branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/kernel/ProfileConfiguration.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/kernel/ProfileConfiguration.java?view=diff&rev=14894&p1=branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/kernel/ProfileConfiguration.java&p2=branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/kernel/ProfileConfiguration.java&r1=14893&r2=14894
==============================================================================
--- branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/kernel/ProfileConfiguration.java	(original)
+++ branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/kernel/ProfileConfiguration.java	2008-06-10 10:53:47-0700
@@ -46,6 +46,7 @@
 import org.argouml.profile.Profile;

 import org.argouml.profile.ProfileException;

 import org.argouml.profile.ProfileFacade;

+import org.argouml.uml.cognitive.critics.CrProfile;

 

 /**

  *   This class captures represents the unique access point for the 

@@ -192,7 +193,12 @@
                 addProfile(dependency);

             }

 

+            for (CrProfile critic : p.getCritics()) {

+                critic.setEnabled(true);

+            }

+            

             updateStrategies();

+            

             ArgoEventPump.fireEvent(new ArgoProfileEvent(

                     ArgoEventTypes.PROFILE_ADDED, new PropertyChangeEvent(this,

                             "profile", null, p)));

@@ -213,6 +219,11 @@
      */

     public void removeProfile(Profile p) {

         profiles.remove(p);

+

+        for (CrProfile critic : p.getCritics()) {

+            critic.setEnabled(false);

+        }

+

         try {

             profileModels.removeAll(p.getProfilePackages());

         } catch (ProfileException e) {


Modified: branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/moduleloader/ModuleLoader2.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/moduleloader/ModuleLoader2.java?view=diff&rev=14894&p1=branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/moduleloader/ModuleLoader2.java&p2=branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/moduleloader/ModuleLoader2.java&r1=14893&r2=14894
==============================================================================
--- branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/moduleloader/ModuleLoader2.java	(original)
+++ branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/moduleloader/ModuleLoader2.java	2008-06-10 10:53:47-0700
@@ -41,6 +41,7 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.StringTokenizer;
 import java.util.jar.Attributes;
 import java.util.jar.JarEntry;
@@ -50,7 +51,6 @@
 import org.apache.log4j.Logger;
 import org.argouml.application.api.AbstractArgoJPanel;
 import org.argouml.application.api.Argo;
-import org.argouml.cognitive.Agency;
 import org.argouml.i18n.Translator;
 import org.argouml.profile.ProfileException;
 import org.argouml.profile.ProfileFacade;
@@ -584,18 +584,9 @@
 
         LOG.info("Reading profiles...");
         try {
-            loadProfilesFromJarFile(jarfile, file);
+            loadProfilesFromJarFile(jarfile, file, classloader);
         } catch (IOException e) {
-            // TODO: Auto-generated catch block
-            LOG.error("Exception", e);
-        }
-
-        LOG.info("Reading critics...");
-        try {
-            loadCriticsFromJarFile(jarfile, classloader);
-        } catch (IOException e) {
-            // TODO: Auto-generated catch block
-            LOG.error("Exception", e);
+            LOG.error("Unable to read profiles of " + file, e);
         }
         
         boolean loadedClass = false;
@@ -626,55 +617,36 @@
         }
     }
 
-    private void loadCriticsFromJarFile(JarFile jarfile, ClassLoader classloader) throws IOException {
-        Manifest manifest = jarfile.getManifest();
-        Attributes att = manifest.getMainAttributes();
-
-        String value = att.getValue("Java-Critics");
-        if (value != null) {
-            StringTokenizer st = new StringTokenizer(value, ",");
-
-            while(st.hasMoreElements()) {
-                String entry = st.nextToken().trim();
-                
-                try {
-                    Class cl = classloader.loadClass(entry);
-                    CrProfile critic = (CrProfile) cl.newInstance();
-                    Agency.register(critic, critic.getCriticizedMetatype());                    
-                } catch (ClassNotFoundException e) {
-                    LOG.error("Error loading class: " + entry, e);
-                } catch (InstantiationException e) {
-                    LOG.error("Error instantianting class: " + entry, e);
-                } catch (IllegalAccessException e) {
-                    LOG.error("Exception", e);
-                }                
-            }            
-        }        
-    }
 
     /**
      * Searches for Profiles models (*.xmi) files in the directory "
      * 
      * @param jarfile the jarfile
      * @param file 
+     * @param classloader 
      * @throws IOException 
      */
-    private void loadProfilesFromJarFile(JarFile jarfile, File file) throws IOException {       
+    private void loadProfilesFromJarFile(JarFile jarfile, File file, ClassLoader classloader) throws IOException {       
         Manifest manifest = jarfile.getManifest();
-        Attributes att = manifest.getMainAttributes();
-
-        String value = att.getValue("Profile-Models");
-        if (value != null) {
-            StringTokenizer st = new StringTokenizer(value, ",");
-
-            while (st.hasMoreElements()) {
-                String entry = st.nextToken().trim();
-                try {
-                    UserDefinedProfile udp = new UserDefinedProfile(
-                            new URL("jar:file:" + file.getCanonicalPath() + "!"
-                                    + entry));
+        Map<String, Attributes> entries = manifest.getEntries();
+        boolean classLoaderAlreadyLoaded = false;
+        
+        for (String entryName : entries.keySet()) {
+            Attributes attr = entries.get(entryName);
+            if (new Boolean(attr.getValue("Profile")+"").booleanValue()) {
+                try {          
+                    if (!classLoaderAlreadyLoaded) {
+                        Translator.addClassLoader(classloader);
+                        classLoaderAlreadyLoaded = true;
+                    }
+                    Set<CrProfile> profiles = loadCritiquesForProfile(attr, classloader);
+                    String modelPath = attr.getValue("Model");
+                    
+                    UserDefinedProfile udp = new UserDefinedProfile(new URL(
+                            "jar:file:" + file.getCanonicalPath() + "!"
+                                    + modelPath), profiles);
+                    
                     ProfileFacade.getManager().registerProfile(udp);
-
                     LOG.debug("Registered Profile: " + udp.getDisplayName()
                             + "...");
                 } catch (ProfileException e) {
@@ -686,6 +658,31 @@
         }
     }
 
+    private Set<CrProfile> loadCritiquesForProfile(Attributes attr, ClassLoader classloader) {
+        Set<CrProfile> ret = new HashSet<CrProfile>();
+        
+        String value = attr.getValue("Java-Critics");        
+        StringTokenizer st = new StringTokenizer(value, ",");
+
+        while(st.hasMoreElements()) {
+            String entry = st.nextToken().trim();
+            
+            try {
+                Class cl = classloader.loadClass(entry);
+                CrProfile critic = (CrProfile) cl.newInstance();
+                ret.add(critic);                    
+            } catch (ClassNotFoundException e) {
+                LOG.error("Error loading class: " + entry, e);
+            } catch (InstantiationException e) {
+                LOG.error("Error instantianting class: " + entry, e);
+            } catch (IllegalAccessException e) {
+                LOG.error("Exception", e);
+            }                
+        }            
+
+        return ret;
+    }
+
     /**
      * Process a JAR file entry, attempting to load anything that looks like a
      * Java class.

Modified: branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/Profile.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/Profile.java?view=diff&rev=14894&p1=branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/Profile.java&p2=branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/Profile.java&r1=14893&r2=14894
==============================================================================
--- branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/Profile.java	(original)
+++ branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/Profile.java	2008-06-10 10:53:47-0700
@@ -28,18 +28,21 @@
 import java.util.HashSet;
 import java.util.Set;
 
+import org.argouml.uml.cognitive.critics.CrProfile;
+
 
 /**
  * Abstract class representing a Profile.  It contains default types and 
  * presentation characteristics that can be tailored to various modeling
  * environments.
  * 
- * @author Marcos Aurélio
+ * @author Marcos Aur�lio
  */
 public abstract class Profile {
     
     private Set<Profile> importedProfiles  = new HashSet<Profile>();
     private Set<Profile> importingProfiles = new HashSet<Profile>();
+    protected Set<CrProfile> critics = new HashSet<CrProfile>();
         
     /**
      * Add a dependency on the given profile from this profile.
@@ -116,4 +119,11 @@
     public String toString() {
         return getDisplayName();
     }
+
+    /**
+     * @return Returns the critics defined by this profile.
+     */
+    public Set<CrProfile> getCritics() {
+        return critics;
+    }
 }

Modified: branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/UserDefinedProfile.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/UserDefinedProfile.java?view=diff&rev=14894&p1=branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/UserDefinedProfile.java&p2=branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/UserDefinedProfile.java&r1=14893&r2=14894
==============================================================================
--- branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/UserDefinedProfile.java	(original)
+++ branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/UserDefinedProfile.java	2008-06-10 10:53:47-0700
@@ -35,14 +35,16 @@
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Set;
 import java.util.StringTokenizer;
+import java.util.Vector;
 
 import javax.swing.ImageIcon;
 
 import org.apache.log4j.Logger;
 import org.argouml.i18n.Translator;
 import org.argouml.model.Model;
-import org.argouml.moduleloader.ModuleLoader2;
+import org.argouml.uml.cognitive.critics.CrProfile;
 
 /**
  * Represents a profile defined by the user
@@ -67,6 +69,7 @@
     private UserDefinedFigNodeStrategy figNodeStrategy 
                                     = new UserDefinedFigNodeStrategy();
 
+    
     private class UserDefinedFigNodeStrategy implements FigNodeStrategy {
 
         private HashMap<String, Image> images = new HashMap<String, Image>();
@@ -166,6 +169,27 @@
 
         finishLoading();
     }
+    
+    /**
+     * A constructor that reads a file from an URL 
+     * associated with some profiles
+     * 
+     * @param url the URL
+     * @param critics the Critics defined by this profile
+     * @throws ProfileException
+     */
+    public UserDefinedProfile(URL url, Set<CrProfile> critics) throws ProfileException {
+        LOG.info("load " + url);
+        
+        ProfileReference reference = null;
+        reference = new UserProfileReference(url.getPath(), url);
+        model = new URLModelLoader().loadModel(reference);
+        fromZargo = false;
+        this.critics = critics;
+        
+        finishLoading();
+    }
+    
 
     /**
      * Reads the informations defined as TaggedValues
@@ -229,6 +253,42 @@
                 }
             }
         }
+        
+        // load critiques
+        Collection allCritiques = getAllCritiques();
+        
+        for (Object critique : allCritiques) {
+            CrProfile c = generateCriticFromModel(critique);
+            if (c!=null) {
+                this.critics.add(c);
+            }
+        }
+    }
+
+    private CrProfile generateCriticFromModel(Object critique) {
+//        String ocl = Model.getDataTypesHelper().getBody(critique);
+                
+        return null;
+    }
+
+    @SuppressWarnings("unchecked")
+    private Collection getAllCritiques() {
+        Collection ret = new Vector();
+
+        for (Object obj : model) {
+            Collection comments = Model.getModelManagementHelper()
+                    .getAllModelElementsOfKindWithModel(obj,
+                            Model.getMetaTypes().getComment());
+
+            for (Object comment : comments) {
+                if (Model.getExtensionMechanismsHelper().hasStereotype(comment,
+                        "Critic")) {
+                    ret.add(comment);
+                }
+            }
+            
+        }
+        return ret;
     }
 
     private Profile lookForRegisteredProfile(String value) {

Modified: branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/internal/ProfileManagerImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/internal/ProfileManagerImpl.java?view=diff&rev=14894&p1=branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/internal/ProfileManagerImpl.java&p2=branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/internal/ProfileManagerImpl.java&r1=14893&r2=14894
==============================================================================
--- branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/internal/ProfileManagerImpl.java	(original)
+++ branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/internal/ProfileManagerImpl.java	2008-06-10 10:53:47-0700
@@ -31,6 +31,7 @@
 import java.util.StringTokenizer;
 
 import org.apache.log4j.Logger;
+import org.argouml.cognitive.Agency;
 import org.argouml.configuration.Configuration;
 import org.argouml.configuration.ConfigurationKey;
 import org.argouml.model.Model;
@@ -39,6 +40,7 @@
 import org.argouml.profile.ProfileException;
 import org.argouml.profile.ProfileManager;
 import org.argouml.profile.UserDefinedProfile;
+import org.argouml.uml.cognitive.critics.CrProfile;
 
 /**
  * Default <code>ProfileManager</code> implementation
@@ -181,6 +183,11 @@
                     || getProfileForClass(p.getClass().getName()) == null) {
                 profiles.add(p);
                 
+                for (CrProfile critic : p.getCritics()) {
+                    Agency.register(critic, critic.getCriticizedMetatype());
+                    critic.setEnabled(false);
+                }
+                
                 // this profile could have not been loaded when 
                 // the default profile configuration 
                 // was loaded at first, so we need to do it again

Modified: branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/profiles/uml14/metaprofile.xmi
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/profiles/uml14/metaprofile.xmi?view=diff&rev=14894&p1=branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/profiles/uml14/metaprofile.xmi&p2=branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/profiles/uml14/metaprofile.xmi&r1=14893&r2=14894
==============================================================================
--- branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/profiles/uml14/metaprofile.xmi	(original)
+++ branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/profiles/uml14/metaprofile.xmi	2008-06-10 10:53:47-0700
@@ -1,8 +1,8 @@
 <?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 xmi.version = '1.2' xmlns:UML = 'org.omg.xmi.namespace.UML' timestamp = 'Fri Jun 06 14:30:08 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.exporterVersion>PRE-0.25.6(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>
@@ -39,6 +39,11 @@
             </UML:Multiplicity>
           </UML:TagDefinition.multiplicity>
         </UML:TagDefinition>
+        <UML:Stereotype xmi.id = '127-0-1-1--259518d7:11a5dd26371:-8000:00000000000008DF'
+          name = 'Critic' isSpecification = 'false' isRoot = 'false' isLeaf = 'false'
+          isAbstract = 'false'>
+          <UML:Stereotype.baseClass>Comment</UML:Stereotype.baseClass>
+        </UML:Stereotype>
       </UML:Namespace.ownedElement>
     </UML:Model>
   </XMI.content>
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.