svn commit: r14864 - branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml: moduleloader profile uml/cognitive/critics

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: maurelio1234
Date: 2008-06-03 04:22:32-0700
New Revision: 14864

Modified:
   branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/moduleloader/ModuleLoader2.java
   branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/UserDefinedProfile.java
   branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/uml/cognitive/critics/CrProfile.java

Log:
declaring profiles in the jar manifest

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=14864&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=14863&r2=14864
==============================================================================
--- 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-03 04:22:32-0700
@@ -50,10 +50,12 @@
 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;
 import org.argouml.profile.UserDefinedProfile;
+import org.argouml.uml.cognitive.critics.CrProfile;
 
 /**
  * This is the module loader that loads modules implementing the
@@ -554,8 +556,6 @@
      *
      * If there isn't a manifest or it isn't readable, we fail silently.
      *
-     * @param classloader The classloader to use.
-     * @param file The file to process.
      * @throws ClassNotFoundException if the manifest file contains a class
      *         that doesn't exist.
      */
@@ -570,9 +570,6 @@
 	    LOG.error("Unable to open " + file, e);
             return;
 	}
-
-        LOG.info("Reading profiles...");
-        loadProfilesFromJarFile(jarfile, file);
         
         Manifest manifest;
         try {
@@ -584,7 +581,23 @@
             LOG.error("Unable to read manifest of " + file, e);
             return;
         }
-	
+
+        LOG.info("Reading profiles...");
+        try {
+            loadProfilesFromJarFile(jarfile, file);
+        } 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);
+        }
+        
         boolean loadedClass = false;
         if (manifest == null) {
             Enumeration<JarEntry> jarEntries = jarfile.entries();
@@ -613,22 +626,53 @@
         }
     }
 
+    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 
+     * @throws IOException 
      */
-    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")) {
+    private void loadProfilesFromJarFile(JarFile jarfile, File file) 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.getName()));
+                    UserDefinedProfile udp = new UserDefinedProfile(
+                            new URL("jar:file:" + file.getCanonicalPath() + "!"
+                                    + entry));
                     ProfileFacade.getManager().registerProfile(udp);
 
                     LOG.debug("Registered Profile: " + udp.getDisplayName()

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=14864&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=14863&r2=14864
==============================================================================
--- 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-03 04:22:32-0700
@@ -39,8 +39,10 @@
 
 import javax.swing.ImageIcon;
 
+import org.apache.log4j.Logger;
 import org.argouml.i18n.Translator;
 import org.argouml.model.Model;
+import org.argouml.moduleloader.ModuleLoader2;
 
 /**
  * Represents a profile defined by the user
@@ -49,6 +51,11 @@
  */
 public class UserDefinedProfile extends Profile {
 
+    /**
+     * Logger.
+     */
+    private static final Logger LOG = Logger.getLogger(UserDefinedProfile.class);
+
     private String displayName;
 
     private File modelFile;
@@ -102,6 +109,7 @@
      * @throws ProfileException if the profile could not be loaded
      */
     public UserDefinedProfile(File file) throws ProfileException {
+        LOG.info("load " + file);
         displayName = file.getName();
         modelFile = file;
         ProfileReference reference = null;
@@ -128,6 +136,7 @@
      */
     public UserDefinedProfile(String fileName, Reader reader)
         throws ProfileException {
+        LOG.info("load " + fileName);
         displayName = fileName;
         ProfileReference reference = null;
         try {
@@ -148,6 +157,8 @@
      * @throws ProfileException
      */
     public UserDefinedProfile(URL url) throws ProfileException {
+        LOG.info("load " + url);
+        
         ProfileReference reference = null;
         reference = new UserProfileReference(url.getPath(), url);
         model = new URLModelLoader().loadModel(reference);
@@ -161,10 +172,11 @@
      */
     private void finishLoading() {
 
-        for (Object obj : model) {
+        for (Object obj : model) {            
             if (Model.getExtensionMechanismsHelper().hasStereotype(obj,
                     "profile")) {
 
+
                 // load profile name
                 String name = Model.getFacade().getName(obj);
                 if (name != null) {
@@ -172,6 +184,7 @@
                 } else {
                     displayName = Translator.localize("misc.profile.unnamed");
                 }
+                LOG.info("profile " + displayName);
 
                 // load profile dependencies
                 String dependencyListStr = Model.getFacade().getTaggedValueValue(obj,
@@ -183,6 +196,7 @@
                 do {
                     profile = st.nextToken();
                     if (profile != null) {
+                      LOG.debug("AddingDependency " + profile);
                       this.
                         addProfileDependency(lookForRegisteredProfile(profile));
                     }
@@ -200,6 +214,8 @@
             for (Object tag : tags) {
                 if (Model.getFacade().getTag(tag).toLowerCase()
                         .equals("figure")) {
+                    LOG.debug("AddFigNode " + Model.getFacade().getName(stereotype));
+                    
                     String value = Model.getFacade().getValueOfTag(tag);
                     File f = new File(value);
                     FigNodeDescriptor fnd = null;
@@ -208,6 +224,7 @@
                                 .toString(), f);
                         figNodeStrategy.addDesrciptor(fnd);
                     } catch (IOException e) {
+                        LOG.error("Error loading FigNode", e);
                     }
                 }
             }

Modified: branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/uml/cognitive/critics/CrProfile.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/uml/cognitive/critics/CrProfile.java?view=diff&rev=14864&p1=branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/uml/cognitive/critics/CrProfile.java&p2=branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/uml/cognitive/critics/CrProfile.java&r1=14863&r2=14864
==============================================================================
--- branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/uml/cognitive/critics/CrProfile.java	(original)
+++ branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/uml/cognitive/critics/CrProfile.java	2008-06-03 04:22:32-0700
@@ -25,6 +25,7 @@
 package org.argouml.uml.cognitive.critics;

 

 import org.argouml.cognitive.Translator;

+import org.argouml.model.Model;

 

 /**

  * "Abstract" Critic subclass that captures commonalities among all

@@ -72,4 +73,12 @@
      * The UID.

      */

     private static final long serialVersionUID = 1785043010468681602L;

+

+    /**

+     * @return the metatype to be criticized by this critic, the Class

+     * metatype is assumed by default.

+     */

+    public Object getCriticizedMetatype() {

+        return Model.getMetaTypes().getUMLClass();

+    }

 }
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.