Author: euluis
Date: 2008-05-12 16:48:51-0700
New Revision: 14716

Modified:
   
trunk/src/argouml-app/src/org/argouml/persistence/ProfileConfigurationFilePersister.java
   (contents, props changed)
   
trunk/src/argouml-app/src/org/argouml/profile/internal/ProfileManagerImpl.java
   trunk/src/argouml-app/tests/org/argouml/kernel/TestProjectWithProfiles.java
   trunk/src/argouml-app/tests/org/argouml/profile/TestProfileManager.java

Log:
issue 5040: adding a check to raise an exception when a module profile of which 
a ArgoUML to be loaded depends, isn't found in the installed ArgoUML

Modified: 
trunk/src/argouml-app/src/org/argouml/persistence/ProfileConfigurationFilePersister.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/persistence/ProfileConfigurationFilePersister.java?view=diff&rev=14716&p1=trunk/src/argouml-app/src/org/argouml/persistence/ProfileConfigurationFilePersister.java&p2=trunk/src/argouml-app/src/org/argouml/persistence/ProfileConfigurationFilePersister.java&r1=14715&r2=14716
==============================================================================
--- 
trunk/src/argouml-app/src/org/argouml/persistence/ProfileConfigurationFilePersister.java
    (original)
+++ 
trunk/src/argouml-app/src/org/argouml/persistence/ProfileConfigurationFilePersister.java
    2008-05-12 16:48:51-0700
@@ -1,317 +1,337 @@
-// $Id: ProfileConfigurationFilePersister.java 13298 2007-08-12 19:40:57Z 
maurelio1234 $

-// Copyright (c) 2007 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.persistence;

-

-import java.io.BufferedReader;

-import java.io.File;

-import java.io.FileWriter;

-import java.io.IOException;

-import java.io.InputStream;

-import java.io.InputStreamReader;

-import java.io.OutputStream;

-import java.io.PrintWriter;

-import java.io.StringWriter;

-import java.io.Writer;

-import java.net.URL;

-import java.util.ArrayList;

-import java.util.Collection;

-import java.util.Iterator;

-import java.util.List;

-

-import org.apache.log4j.Logger;

-import org.argouml.application.helpers.ApplicationVersion;

-import org.argouml.configuration.Configuration;

-import org.argouml.kernel.ProfileConfiguration;

-import org.argouml.kernel.Project;

-import org.argouml.kernel.ProjectMember;

-import org.argouml.model.Model;

-import org.argouml.model.UmlException;

-import org.argouml.model.XmiWriter;

-import org.argouml.profile.Profile;

-import org.argouml.profile.ProfileFacade;

-import org.argouml.profile.ProfileManager;

-import org.argouml.profile.UserDefinedProfile;

-

-/**

- * Persister for Project's Profile Configuration

- *

- * @author maurelio1234

- */

-public class ProfileConfigurationFilePersister extends MemberFilePersister {

-    

-    private static final Logger LOG = 

-        Logger.getLogger(ProfileConfigurationFilePersister.class);

-

-    /*

-     * @see org.argouml.persistence.MemberFilePersister#getMainTag()

-     */

-    public String getMainTag() {

-        return "profile";

-    }

-

-    /*

-     * @see 
org.argouml.persistence.MemberFilePersister#load(org.argouml.kernel.Project, 
java.io.InputStream)

-     */

-    public void load(Project project, InputStream inputStream)

-        throws OpenException {

-        try {

-            BufferedReader br = new BufferedReader(new InputStreamReader(

-                    inputStream));

-

-            String line = null;

-            while (true) {

-                line = br.readLine();

-                if (line.trim().equals("<profile>")) {

-                    break;

-                }

-            }

-            Collection<Profile> profiles = new ArrayList<Profile>();

-            while (true) {

-                line = br.readLine().trim();

-                if (line.equals("</profile>")) {

-                    break;

-                }

-                

-                Profile profile = null;

-

-                if (line.equals("<userDefined>")) {

-                    line = br.readLine().trim();

-                    String fileName = line.substring(line.indexOf(">") + 1,

-                            line.indexOf("</")).trim();

-

-                    // consumes the <model> tag

-                    br.readLine();

-

-                    StringBuffer xmi = new StringBuffer();

-                    

-                    while (true) {

-                        line = br.readLine();

-                        if (line == null || line.contains("</model>")) {

-                            break;

-                        }

-                        xmi.append(line + "\n");

-                    }

-                    ProfileManager profileManager = ProfileFacade.getManager();

-                    profile = getMatchingUserDefinedProfile(fileName, 

-                        profileManager);

-                    if (profile == null) {

-                        throw new XmiReferenceException("Profile: " + fileName,

-                                null);

-                        // Use xmi as a fall back alternative when the

-                        // file for the user defined profile isn't found by the

-                        // profile manager.

-//                        profile = new UserDefinedProfile(fileName,

-//                                new StringReader(xmi.toString()));

-//                        profile = createUserProfileDefinition(fileName, xmi,

-//                                profileManager);

-

-                    }

-                    

-                    // consumes the </userDefined>

-                    line = br.readLine().trim();                   

-                } else if (line.equals("<plugin>")) {

-                    String className = br.readLine().trim();

-                    profile = ProfileFacade.getManager().getProfileForClass(

-                            className);

-                    line = br.readLine().trim();

-                }

-

-                if (profile != null) {

-                    profiles.add(profile);

-                }

-            }

-            ProfileConfiguration pc = new ProfileConfiguration(project, 

-                    profiles);

-            project.setProfileConfiguration(pc);

-        } catch (Exception e) {

-            if (e instanceof OpenException) {

-                throw (OpenException) e;

-            }

-            throw new OpenException(e);

-        }

-    }

-

-    /**

-     * Create a user defined profile from the current project using the backup

-     * XMI file from the current project.  Currently unused.

-     * <p>

-     * <em>NOTE:</em> This has the side effect of permanently registering the

-     * profile which may not be what the user wants.

-     * 

-     * @param fileName name of original XMI file that the author of the project

-     *                used when creating the UserDefinedProfile.

-     * @param contents the contents of the XMI file.

-     * @return the new profile

-     * @throws IOException on any i/o error

-     */

-    private Profile createUserProfileDefinition(String fileName,

-            StringBuffer contents, ProfileManager profileManager)

-        throws IOException {

-

-

-        Profile profile;

-        File profilesDirectory = getProfilesDirectory(profileManager);

-        File profileFile = new File(profilesDirectory, fileName);

-        FileWriter writer = new FileWriter(profileFile);

-        writer.write(contents.toString());

-        writer.close();

-        LOG.info("Wrote user defined profile \"" + profileFile

-                + "\", with size " + contents.length() + ".");

-        if (isSomeProfileDirectoryConfigured(profileManager))

-            profileManager.refreshRegisteredProfiles();

-        else

-            profileManager.addSearchPathDirectory(profilesDirectory

-                    .getAbsolutePath());

-        profile = getMatchingUserDefinedProfile(fileName, profileManager);

-        assert profile != null : "Profile should be found now.";

-        return profile;

-    }

-

-    private Profile getMatchingUserDefinedProfile(String fileName, 

-            ProfileManager profileManager) {

-        for (Profile candidateProfile 

-            : profileManager.getRegisteredProfiles()) {

-            if (candidateProfile instanceof UserDefinedProfile) {

-                UserDefinedProfile userProfile = 

-                    (UserDefinedProfile) candidateProfile;

-                if (userProfile.getDisplayName().equals(fileName)) {

-                    return userProfile;

-                }

-            }

-        }

-        return null;

-    }

-

-    private File getProfilesDirectory(ProfileManager profileManager) {

-        if (isSomeProfileDirectoryConfigured(profileManager)) {

-            List<String> directories = 

-                profileManager.getSearchPathDirectories();

-            return new File(directories.get(0));

-        } else {

-            File userSettingsFile = new File(

-                Configuration.getFactory().getConfigurationHandler().

-                    getDefaultPath());

-            return userSettingsFile.getParentFile();

-        }

-    }

-

-    private boolean isSomeProfileDirectoryConfigured(

-            ProfileManager profileManager) {

-        return profileManager.getSearchPathDirectories().size() > 0;

-    }

-

-    /*

-     * @see 
org.argouml.persistence.MemberFilePersister#save(org.argouml.kernel.ProjectMember,
 java.io.Writer, boolean)

-     */

-    @Override

-    @Deprecated

-    @SuppressWarnings("deprecation")

-    public void save(ProjectMember member, Writer writer, boolean xmlFragment)

-        throws SaveException {

-        PrintWriter w = new PrintWriter(writer);

-        saveProjectMember(member, w);

-    }

-

-    /*

-     * @see 
org.argouml.persistence.MemberFilePersister#save(org.argouml.kernel.ProjectMember,
 java.io.OutputStream)

-     */

-    public void save(ProjectMember member, OutputStream stream)

-       throws SaveException {

-       

-        PrintWriter w = new PrintWriter(stream);

-       saveProjectMember(member, w);

-        w.flush();

-    }

-

-    private void saveProjectMember(ProjectMember member, PrintWriter w)

-       throws SaveException {

-       

-        try {

-           if (member instanceof ProfileConfiguration) {

-               ProfileConfiguration pc = (ProfileConfiguration) member;

-

-               w.println("<?xml version = \"1.0\" encoding = \"UTF-8\" ?>");

-               w.println("<!DOCTYPE profile SYSTEM \"profile.dtd\" >");

-               w.println("<profile>");

-

-               Iterator it = pc.getProfiles().iterator();

-               while (it.hasNext()) {

-                    Profile profile = (Profile) it.next();

-

-                    if (profile instanceof UserDefinedProfile) {

-                        UserDefinedProfile uprofile = 

-                            (UserDefinedProfile) profile;

-                        w.println("\t\t<userDefined>");

-                        w.println("\t\t\t<filename>"

-                                + uprofile.getModelFile().getName()

-                                + "</filename>");

-                        w.println("\t\t\t<model>");

-

-                        final Collection profilePackages = 

-                            uprofile.getProfilePackages();

-                        final Object model = profilePackages.iterator().next();

-                        printModelXMI(w, model);

-

-                        w.println("\t\t\t</model>");

-                        w.println("\t\t</userDefined>");

-                    } else {

-                        w.println("\t\t<plugin>");

-                        w.println("\t\t\t" + profile.getClass().getName());

-                        w.println("\t\t</plugin>");

-                    }

-                }

-

-               w.println("</profile>");

-           }

-       } catch (Exception e) {

-           e.printStackTrace();

-           throw new SaveException(e);

-       }

-    }

-

-    private void printModelXMI(PrintWriter w, Object model) 

-        throws UmlException {

-        

-        StringWriter myWriter = new StringWriter();

-        XmiWriter xmiWriter = Model.getXmiWriter(model, myWriter,

-                ApplicationVersion.getVersion() + "("

-                        + UmlFilePersister.PERSISTENCE_VERSION + ")");

-        xmiWriter.write();

-

-        myWriter.flush();

-        w.println("" + myWriter.toString());

-    }

-

-

-    @Override

-    public void load(Project project, URL url) throws OpenException {

-        try {

-            load(project, url.openStream());

-        } catch (IOException e) {

-            throw new OpenException(e);

-        }

-    }

-

-}

+// $Id$
+// Copyright (c) 2007-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.persistence;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.argouml.application.helpers.ApplicationVersion;
+import org.argouml.configuration.Configuration;
+import org.argouml.kernel.ProfileConfiguration;
+import org.argouml.kernel.Project;
+import org.argouml.kernel.ProjectMember;
+import org.argouml.model.Model;
+import org.argouml.model.UmlException;
+import org.argouml.model.XmiWriter;
+import org.argouml.profile.Profile;
+import org.argouml.profile.ProfileFacade;
+import org.argouml.profile.ProfileManager;
+import org.argouml.profile.UserDefinedProfile;
+
+/**
+ * Persister for project's profile configuration.
+ *
+ * @author maurelio1234
+ */
+public class ProfileConfigurationFilePersister extends MemberFilePersister {
+    
+    private static final Logger LOG = 
+        Logger.getLogger(ProfileConfigurationFilePersister.class);
+
+    /*
+     * @see org.argouml.persistence.MemberFilePersister#getMainTag()
+     */
+    public String getMainTag() {
+        return "profile";
+    }
+
+    /*
+     * @see 
org.argouml.persistence.MemberFilePersister#load(org.argouml.kernel.Project, 
java.io.InputStream)
+     */
+    public void load(Project project, InputStream inputStream)
+        throws OpenException {
+        try {
+            BufferedReader br = new BufferedReader(new InputStreamReader(
+                    inputStream));
+
+            String line = null;
+            while (true) {
+                line = br.readLine();
+                if (line.trim().equals("<profile>")) {
+                    break;
+                }
+            }
+            Collection<Profile> profiles = new ArrayList<Profile>();
+            while (true) {
+                line = br.readLine().trim();
+                if (line.equals("</profile>")) {
+                    break;
+                }
+                
+                Profile profile = null;
+
+                if (line.equals("<userDefined>")) {
+                    profile = handleUserDefinedProfile(br);
+                    // consumes the </userDefined>
+                    br.readLine();
+                } else if (line.equals("<plugin>")) {
+                    profile = handlePluginProfile(br);
+                    // consumes closing tag
+                    br.readLine();
+                }
+
+                if (profile != null) {
+                    profiles.add(profile);
+                }
+            }
+            ProfileConfiguration pc = new ProfileConfiguration(project, 
+                    profiles);
+            project.setProfileConfiguration(pc);
+        } catch (Exception e) {
+            if (e instanceof OpenException) {
+                throw (OpenException) e;
+            }
+            throw new OpenException(e);
+        }
+    }
+
+    private Profile handlePluginProfile(BufferedReader br) throws IOException,
+        XmiReferenceException {
+        Profile profile;
+        String className = br.readLine().trim();
+        profile = ProfileFacade.getManager().getProfileForClass(
+                className);
+        if (profile == null) 
+            throw new XmiReferenceException(
+                "Plugin profile \"" + className 
+                + "\" is not available in installation.", null);
+        return profile;
+    }
+
+    private Profile handleUserDefinedProfile(BufferedReader br)
+        throws IOException, XmiReferenceException {
+        String line;
+        Profile profile;
+        line = br.readLine().trim();
+        String fileName = line.substring(line.indexOf(">") + 1,
+                line.indexOf("</")).trim();
+
+        // consumes the <model> tag
+        br.readLine();
+
+        StringBuffer xmi = new StringBuffer();
+        
+        while (true) {
+            line = br.readLine();
+            if (line == null || line.contains("</model>")) {
+                break;
+            }
+            xmi.append(line + "\n");
+        }
+        ProfileManager profileManager = ProfileFacade.getManager();
+        profile = getMatchingUserDefinedProfile(fileName, 
+            profileManager);
+        if (profile == null) {
+            throw new XmiReferenceException(
+                "User defined profile \"" + fileName 
+                + "\" isn't available in the current configuration.",
+                    null);
+            // Use XMI as a fall back alternative when the 
+            // file for the user defined profile isn't found by the 
+            // profile manager.
+            // TODO: work in progress, see issue 5039
+//                        addUserDefinedProfile(fileName, xmi, profileManager);
+//                        profile = getMatchingUserDefinedProfile(fileName, 
+//                            profileManager);
+//                        assert profile != null 
+//                            : "Profile should have been found now.";
+        }
+        return profile;
+    }
+
+    /**
+     * Register a user defined profile in the profileManager, using the backup 
+     * XMI file from the project being loaded.
+     * <p>
+     * <em>NOTE:</em> This has the side effect of permanently registering the
+     * profile which may not be what the user wants.
+     * 
+     * @param fileName name of original XMI file that the author of the project
+     *                used when creating the UserDefinedProfile.
+     * @param xmi the contents of the XMI file.
+     * @param profileManager the [EMAIL PROTECTED] ProfileManager}.
+     * @throws IOException on any i/o error
+     */
+    private void addUserDefinedProfile(String fileName, StringBuffer xmi,
+            ProfileManager profileManager) throws IOException {
+        File profilesDirectory = getProfilesDirectory(profileManager);
+        File profileFile = new File(profilesDirectory, fileName);
+        FileWriter writer = new FileWriter(profileFile);
+        writer.write(xmi.toString());
+        writer.close();
+        LOG.info("Wrote user defined profile \"" + profileFile 
+            + "\", with size " + xmi.length() + ".");
+        if (isSomeProfileDirectoryConfigured(profileManager))
+            profileManager.refreshRegisteredProfiles();
+        else 
+            profileManager.addSearchPathDirectory(
+                profilesDirectory.getAbsolutePath());
+    }
+
+    private Profile getMatchingUserDefinedProfile(String fileName, 
+            ProfileManager profileManager) {
+        for (Profile candidateProfile 
+            : profileManager.getRegisteredProfiles()) {
+            if (candidateProfile instanceof UserDefinedProfile) {
+                UserDefinedProfile userProfile = 
+                    (UserDefinedProfile) candidateProfile;
+                if (userProfile.getDisplayName().equals(fileName)) {
+                    return userProfile;
+                }
+            }
+        }
+        return null;
+    }
+
+    private File getProfilesDirectory(ProfileManager profileManager) {
+        if (isSomeProfileDirectoryConfigured(profileManager)) {
+            List<String> directories = 
+                profileManager.getSearchPathDirectories();
+            return new File(directories.get(0));
+        } else {
+            File userSettingsFile = new File(
+                Configuration.getFactory().getConfigurationHandler().
+                    getDefaultPath());
+            return userSettingsFile.getParentFile();
+        }
+    }
+
+    private boolean isSomeProfileDirectoryConfigured(
+            ProfileManager profileManager) {
+        return profileManager.getSearchPathDirectories().size() > 0;
+    }
+
+    /*
+     * @see 
org.argouml.persistence.MemberFilePersister#save(org.argouml.kernel.ProjectMember,
 java.io.Writer, boolean)
+     */
+    @Override
+    @Deprecated
+    @SuppressWarnings("deprecation")
+    public void save(ProjectMember member, Writer writer, boolean xmlFragment)
+        throws SaveException {
+        PrintWriter w = new PrintWriter(writer);
+        saveProjectMember(member, w);
+    }
+
+    /*
+     * @see 
org.argouml.persistence.MemberFilePersister#save(org.argouml.kernel.ProjectMember,
 java.io.OutputStream)
+     */
+    public void save(ProjectMember member, OutputStream stream)
+       throws SaveException {
+       
+        PrintWriter w = new PrintWriter(stream);
+       saveProjectMember(member, w);
+        w.flush();
+    }
+
+    private void saveProjectMember(ProjectMember member, PrintWriter w)
+       throws SaveException {
+       
+        try {
+           if (member instanceof ProfileConfiguration) {
+               ProfileConfiguration pc = (ProfileConfiguration) member;
+
+               w.println("<?xml version = \"1.0\" encoding = \"UTF-8\" ?>");
+               w.println("<!DOCTYPE profile SYSTEM \"profile.dtd\" >");
+               w.println("<profile>");
+
+               Iterator it = pc.getProfiles().iterator();
+               while (it.hasNext()) {
+                    Profile profile = (Profile) it.next();
+
+                    if (profile instanceof UserDefinedProfile) {
+                        UserDefinedProfile uprofile = 
+                            (UserDefinedProfile) profile;
+                        w.println("\t\t<userDefined>");
+                        w.println("\t\t\t<filename>"
+                                + uprofile.getModelFile().getName()
+                                + "</filename>");
+                        w.println("\t\t\t<model>");
+
+                        printModelXMI(w, uprofile.getProfilePackages());
+
+                        w.println("\t\t\t</model>");
+                        w.println("\t\t</userDefined>");
+                    } else {
+                        w.println("\t\t<plugin>");
+                        w.println("\t\t\t" + profile.getClass().getName());
+                        w.println("\t\t</plugin>");
+                    }
+                }
+
+               w.println("</profile>");
+           }
+       } catch (Exception e) {
+           e.printStackTrace();
+           throw new SaveException(e);
+       }
+    }
+
+    private void printModelXMI(PrintWriter w, Collection profileModels) 
+        throws UmlException {
+        
+        if (true) return;
+        StringWriter myWriter = new StringWriter();
+        // FIXME: this is completely useless since the XMI writer won't 
+        // write the model it is given, but, a list of models which it 
+        // determines on its own. See XmiWriterMDRImpl.write() implementation 
+        // and the usage of the flag WRITE_ALL.
+        for (Object model : profileModels) {
+            XmiWriter xmiWriter = Model.getXmiWriter(model, 
+                (OutputStream) null, //myWriter, 
+                ApplicationVersion.getVersion() + "("
+                    + UmlFilePersister.PERSISTENCE_VERSION + ")");
+            xmiWriter.write();
+        }
+
+        myWriter.flush();
+        w.println("" + myWriter.toString());
+    }
+
+
+    @Override
+    public void load(Project project, URL url) throws OpenException {
+        try {
+            load(project, url.openStream());
+        } catch (IOException e) {
+            throw new OpenException(e);
+        }
+    }
+
+}

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=14716&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=14715&r2=14716
==============================================================================
--- 
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-12 16:48:51-0700
@@ -282,6 +282,8 @@
                                 registerProfile(udp);
                             } catch (ProfileException e) {
                                 // if an exception is raised file is unusable
+                                LOG.warn("Failed to load user defined profile "
+                                    + file.getAbsolutePath() + ".", e);
                             }
                         }
                     }

Modified: 
trunk/src/argouml-app/tests/org/argouml/kernel/TestProjectWithProfiles.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/tests/org/argouml/kernel/TestProjectWithProfiles.java?view=diff&rev=14716&p1=trunk/src/argouml-app/tests/org/argouml/kernel/TestProjectWithProfiles.java&p2=trunk/src/argouml-app/tests/org/argouml/kernel/TestProjectWithProfiles.java&r1=14715&r2=14716
==============================================================================
--- trunk/src/argouml-app/tests/org/argouml/kernel/TestProjectWithProfiles.java 
(original)
+++ trunk/src/argouml-app/tests/org/argouml/kernel/TestProjectWithProfiles.java 
2008-05-12 16:48:51-0700
@@ -145,7 +145,7 @@
                 javaProfile));
         // create a dependency from the project's model to the UML profile for 
         // Java
-        Object model = Model.getModelManagementFactory().getRootModel();
+        Object model = getModelManagementFactory().getRootModel();
         assertNotNull(model);
         Object fooClass = Model.getCoreFactory().buildClass("Foo", model);
         Object javaListType = project.findType("List", false);
@@ -307,8 +307,10 @@
      */
     public void testProjectWithRemovedUserDefinedProfilePersistency() 
         throws Exception {
+        final String testName = 
+            "testProjectWithRemovedUserDefinedProfilePersistency";
         File userDefinedProfileFile = createUserProfileFile(testCaseDir,
-            "testProjectWithRemovedUserDefinedProfile-TestUserProfile.xmi");
+            testName + "-TestUserProfile.xmi");
         // add it to the project configuration
         Profile userDefinedProfile = 
             new UserDefinedProfile(userDefinedProfileFile);
@@ -320,7 +322,8 @@
         // create a dependency between the project's model and the user 
defined 
         // profile
         Object model = getModelManagementFactory().getRootModel();
-        Object fooClass = getCoreFactory().buildClass("Foo", model);
+        final String className = "Foo4" + testName;
+        Object fooClass = getCoreFactory().buildClass(className, model);
         Collection stereotypes = getExtensionMechanismsHelper().getStereotypes(
                 project.getModels());
         Object stStereotype = null;
@@ -333,8 +336,7 @@
         }
         Model.getCoreHelper().addStereotype(fooClass, stStereotype);
         // save the project
-        File file = getFileInTestDir(
-            "testProjectWithUserDefinedProfilePersistency.zargo");
+        File file = getFileInTestDir(testName + ".zargo");
         AbstractFilePersister persister = getProjectPersister(file);
         project.setVersion(ApplicationVersion.getVersion());
         persister.save(project, file);
@@ -359,7 +361,6 @@
                     file.getAbsolutePath());
         return persister;
     }
-    
 
     private File createUserProfileFile(File directory, String filename)
         throws IOException {

Modified: 
trunk/src/argouml-app/tests/org/argouml/profile/TestProfileManager.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/tests/org/argouml/profile/TestProfileManager.java?view=diff&rev=14716&p1=trunk/src/argouml-app/tests/org/argouml/profile/TestProfileManager.java&p2=trunk/src/argouml-app/tests/org/argouml/profile/TestProfileManager.java&r1=14715&r2=14716
==============================================================================
--- trunk/src/argouml-app/tests/org/argouml/profile/TestProfileManager.java     
(original)
+++ trunk/src/argouml-app/tests/org/argouml/profile/TestProfileManager.java     
2008-05-12 16:48:51-0700
@@ -26,6 +26,7 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 
 import org.argouml.model.InitializeModel;
@@ -56,7 +57,7 @@
             @Override
             public Collection<Object> getProfilePackages() 
                 throws ProfileException {
-                return null;
+                return Collections.emptyList();
             }
         };
         manager = ProfileFacade.getManager();
@@ -69,11 +70,17 @@
         super.tearDown();
     }
 
+    /**
+     * Test the [EMAIL PROTECTED] ProfileManager#registerProfile(Profile)} 
method.
+     */
     public void testRegisterProfile() {
         manager.registerProfile(mockProfile);
         assertTrue(manager.getRegisteredProfiles().contains(mockProfile));
     }
     
+    /**
+     * Test the [EMAIL PROTECTED] ProfileManager#removeProfile(Profile)} 
method.
+     */
     public void testRemoveProfile() {
         assertFalse(manager.getRegisteredProfiles().contains(mockProfile));
         manager.registerProfile(mockProfile);
@@ -82,6 +89,9 @@
         assertFalse(manager.getRegisteredProfiles().contains(mockProfile));
     }
 
+    /**
+     * Test the [EMAIL PROTECTED] ProfileManager#getProfileForClass(String)} 
method.
+     */
     public void testGetProfileForClass() {
         mockProfileClassName = mockProfile.getClass().getName();
         assertNull(manager.getProfileForClass(mockProfileClassName));
@@ -92,6 +102,10 @@
         assertNull(manager.getProfileForClass(mockProfileClassName));
     }
     
+    /**
+     * Tests the methods of [EMAIL PROTECTED] ProfileManager} related to 
default profiles 
+     * management.
+     */
     public void testDefaultProfilesManagement() {
         List<Object> initialDefaultProfiles = 
             new ArrayList<Object>(manager.getDefaultProfiles());
@@ -106,7 +120,10 @@
         assertFalse(manager.getDefaultProfiles().contains(mockProfile));
     }
     
-    public void testGetUMLProfile() throws Exception {
+    /**
+     * Test the method [EMAIL PROTECTED] ProfileManager#getUMLProfile()}.
+     */
+    public void testGetUMLProfile() {
         Profile uml = manager.getUMLProfile();
         assertNotNull(uml);
         assertTrue(uml.getDisplayName().indexOf("UML") != -1);

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to