Author: maurelio1234
Date: 2008-05-26 12:03:57-0700
New Revision: 14804
Added:
branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/UserDefinedProfile.java.mine
branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/UserDefinedProfile.java.r14801
branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/internal/ProfileMeta.java
- copied unchanged from r14800, /trunk/src/argouml-app/src/org/argouml/profile/internal/ProfileMeta.java
branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/profiles/uml14/metaprofile.xmi
- copied unchanged from r14800, /trunk/src/argouml-app/src/org/argouml/profile/profiles/uml14/metaprofile.xmi
Modified:
branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/moduleloader/ModuleLoader2.java
branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/URLModelLoader.java
branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/UserDefinedProfile.java
branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/internal/ProfileManagerImpl.java
Log:
implementing FigNode in UserDefinedProfile
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=14804&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=14803&r2=14804
==============================================================================
--- branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/moduleloader/ModuleLoader2.java (original)
+++ branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/moduleloader/ModuleLoader2.java 2008-05-26 12:03:57-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: branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/URLModelLoader.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/URLModelLoader.java?view=diff&rev=14804&p1=branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/URLModelLoader.java&p2=branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/URLModelLoader.java&r1=14803&r2=14804
==============================================================================
--- branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/URLModelLoader.java (original)
+++ branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/URLModelLoader.java 2008-05-26 12:03:57-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: 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=14804&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=14803&r2=14804
==============================================================================
--- branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/UserDefinedProfile.java (original)
+++ branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/UserDefinedProfile.java 2008-05-26 12:03:57-0700
@@ -24,15 +24,28 @@
package org.argouml.profile;
+import java.awt.Image;
+import java.io.BufferedInputStream;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
import java.io.Reader;
import java.net.MalformedURLException;
+import java.net.URL;
import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import javax.swing.ImageIcon;
+
+import org.argouml.model.Model;
+
/**
* Represents a profile defined by the user
*
- * @author Marcos Aurélio
+ * @author maurelio1234
*/
public class UserDefinedProfile extends Profile {
@@ -41,6 +54,43 @@
private Collection model;
private boolean fromZargo;
+ private UserDefinedFigNodeStrategy figNodeStrategy = new UserDefinedFigNodeStrategy();
+
+ private class UserDefinedFigNodeStrategy implements FigNodeStrategy {
+
+ private HashMap<String, Image> images = new HashMap<String, Image>();
+
+ public Image getIconForStereotype(Object stereotype) {
+ return images.get(Model.getFacade().getName(stereotype));
+ }
+
+ /**
+ * Adds a new descriptor to this strategy
+ *
+ * @param fnd
+ */
+ public void addDesrciptor(FigNodeDescriptor fnd) {
+ images.put(fnd.stereotype, fnd.img);
+ }
+ }
+
+ private class FigNodeDescriptor {
+ String stereotype;
+
+ Image img;
+
+ String src;
+
+ int length;
+
+ /**
+ * @return if this descriptor ir valid
+ */
+ public boolean isValid() {
+ return stereotype != null && src != null && length > 0;
+ }
+ }
+
/**
* The default constructor for this class
*
@@ -59,6 +109,7 @@
}
model = new FileModelLoader().loadModel(reference);
fromZargo = false;
+ finishLoading();
}
@@ -84,10 +135,93 @@
}
model = new ReaderModelLoader(reader).loadModel(reference);
fromZargo = true;
+ finishLoading();
}
/**
+ * A constructor that reads a file from an URL
+ *
+ * @param url the URL
+ * @throws ProfileException
+ */
+ public UserDefinedProfile(URL url) throws ProfileException {
+ ProfileReference reference = null;
+ reference = new UserProfileReference(url.getPath(), url);
+ model = new URLModelLoader().loadModel(reference);
+ fromZargo = false;
+
+ finishLoading();
+ }
+
+
+ /**
+ * Reads the informations defined as TaggedValues
+ */
+ private void finishLoading() {
+
+ 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());
+
+ }
+ }
+
+ // load fig nodes
+ Collection col = Model.getExtensionMechanismsHelper().getStereotypes(model);
+ for (Object mel : col) {
+ Collection tags = Model.getFacade().getTaggedValuesCollection(mel);
+
+ for (Object tag : tags) {
+ if (Model.getFacade().getTag(tag).toLowerCase().equals("figure")) {
+ String value = Model.getFacade().getValueOfTag(tag);
+ File f = new File(value);
+ FigNodeDescriptor fnd = null;
+ try {
+ fnd = loadImage(Model.getFacade().getName(mel).toString(), f);
+ figNodeStrategy.addDesrciptor(fnd);
+ } catch (IOException e) {
+ //LOG.error("Exception", e);
+ }
+ }
+ }
+ }
+ }
+
+ 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
* start (*) is placed on it if it comes from the currently opened
* zargo file.
@@ -112,7 +246,7 @@
*/
@Override
public FigNodeStrategy getFigureStrategy() {
- return null;
+ return figNodeStrategy;
}
/**
@@ -131,9 +265,30 @@
return super.toString() + " [" + getModelFile() + "]";
}
-
@Override
public Collection getProfilePackages() {
return model;
}
+
+ private FigNodeDescriptor loadImage(String stereotype, File f) throws IOException {
+ FigNodeDescriptor desc = new FigNodeDescriptor();
+ desc.length = (int) f.length();
+ desc.src = f.getPath();
+ desc.stereotype = stereotype;
+
+ BufferedInputStream bis = new BufferedInputStream(new FileInputStream(f));
+ //new BufferedInputStream(this.referenceClass.getResourceAsStream(desc.src));
+
+ byte[] buf = new byte[desc.length];
+ try {
+ bis.read(buf);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ // LOG.info("IMAGE READ: " + fileName);
+ desc.img = new ImageIcon(buf).getImage();// Toolkit.getDefaultToolkit().createImage(buf);
+
+ return desc;
+ }
}
Added: branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/UserDefinedProfile.java.mine
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/UserDefinedProfile.java.mine?view=auto&rev=14804
==============================================================================
--- (empty file)
+++ branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/UserDefinedProfile.java.mine 2008-05-26 12:03:57-0700
@@ -0,0 +1,296 @@
+// $Id: UserDefinedProfile.java 14800 2008-05-26 07:56:08Z maurelio1234 $
+// 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.profile;
+
+import java.awt.Image;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.Reader;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import javax.swing.ImageIcon;
+
+import org.argouml.model.Model;
+
+/**
+ * Represents a profile defined by the user
+ *
+ * @author maurelio1234
+ */
+public class UserDefinedProfile extends Profile {
+
+ private String displayName;
+ private File modelFile;
+ private Collection model;
+ private boolean fromZargo;
+
+ private UserDefinedFigNodeStrategy figNodeStrategy = new UserDefinedFigNodeStrategy();
+
+ private class UserDefinedFigNodeStrategy implements FigNodeStrategy {
+
+ private HashMap<String, Image> images = new HashMap<String, Image>();
+
+ public Image getIconForStereotype(Object stereotype) {
+ return images.get(Model.getFacade().getName(stereotype));
+ }
+
+ /**
+ * Adds a new descriptor to this strategy
+ *
+ * @param fnd
+ */
+ public void addDesrciptor(FigNodeDescriptor fnd) {
+ images.put(fnd.stereotype, fnd.img);
+ }
+ }
+
+ private class FigNodeDescriptor {
+ String stereotype;
+
+ Image img;
+
+ String src;
+
+ int length;
+
+ /**
+ * @return if this descriptor ir valid
+ */
+ public boolean isValid() {
+ return stereotype != null && src != null && length > 0;
+ }
+ }
+
+ /**
+ * The default constructor for this class
+ *
+ * @param file the file from where the model should be read
+ * @throws ProfileException if the profile could not be loaded
+ */
+ public UserDefinedProfile(File file) throws ProfileException {
+ displayName = file.getName();
+ modelFile = file;
+ ProfileReference reference = null;
+ try {
+ reference = new UserProfileReference(file.getPath());
+ } catch (MalformedURLException e) {
+ throw new ProfileException(
+ "Failed to create the ProfileReference.", e);
+ }
+ model = new FileModelLoader().loadModel(reference);
+ fromZargo = false;
+
+ finishLoading();
+ }
+
+
+ /**
+ * A constructor that takes a file name and a reader, being the reader the
+ * input method to get the profile model.
+ *
+ * @param fileName name of the profile model file.
+ * @param reader a reader opened from where the profile model will be
+ * loaded.
+ * @throws ProfileException if something goes wrong in initializing the
+ * profile.
+ */
+ public UserDefinedProfile(String fileName, Reader reader)
+ throws ProfileException {
+ displayName = fileName;
+ ProfileReference reference = null;
+ try {
+ reference = new UserProfileReference(fileName);
+ } catch (MalformedURLException e) {
+ throw new ProfileException(
+ "Failed to create the ProfileReference.", e);
+ }
+ model = new ReaderModelLoader(reader).loadModel(reference);
+ fromZargo = true;
+
+ finishLoading();
+ }
+
+
+ /**
+ * A constructor that reads a file from an URL
+ *
+ * @param url the URL
+ * @throws ProfileException
+ */
+ public UserDefinedProfile(URL url) throws ProfileException {
+ ProfileReference reference = null;
+ reference = new UserProfileReference(url.getPath(), url);
+ model = new URLModelLoader().loadModel(reference);
+ fromZargo = false;
+
+ finishLoading();
+ }
+
+
+ /**
+ * Reads the informations defined as TaggedValues
+ */
+ private void finishLoading() {
+
+ 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());
+
+ }
+ }
+
+ // load fig nodes
+ Collection col = Model.getExtensionMechanismsHelper().getStereotypes(model);
+ for (Object mel : col) {
+ Collection tags = Model.getFacade().getTaggedValuesCollection(mel);
+
+ for (Object tag : tags) {
+ if (Model.getFacade().getTag(tag).toLowerCase().equals("figure")) {
+ String value = Model.getFacade().getValueOfTag(tag);
+ File f = new File(value);
+ FigNodeDescriptor fnd = null;
+ try {
+ fnd = loadImage(Model.getFacade().getName(mel).toString(), f);
+ figNodeStrategy.addDesrciptor(fnd);
+ } catch (IOException e) {
+ //LOG.error("Exception", e);
+ }
+ }
+ }
+ }
+ }
+
+ 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
+ * start (*) is placed on it if it comes from the currently opened
+ * zargo file.
+ */
+ public String getDisplayName() {
+ return displayName + (fromZargo ? "*" : "");
+ }
+
+
+ /**
+ * Returns null. This profile has no formatting strategy.
+ * @return null.
+ */
+ @Override
+ public FormatingStrategy getFormatingStrategy() {
+ return null;
+ }
+
+ /**
+ * Returns null. This profile has no figure strategy.
+ * @return null.
+ */
+ @Override
+ public FigNodeStrategy getFigureStrategy() {
+ return figNodeStrategy;
+ }
+
+ /**
+ * @return the file passed at the constructor
+ */
+ public File getModelFile() {
+ return modelFile;
+ }
+
+ /**
+ * @return the name of the model and the file name
+ */
+ @Override
+ public String toString() {
+ // TODO: I18N
+ return super.toString() + " [" + getModelFile() + "]";
+ }
+
+ @Override
+ public Collection getProfilePackages() {
+ return model;
+ }
+
+ private FigNodeDescriptor loadImage(String stereotype, File f) throws IOException {
+ FigNodeDescriptor desc = new FigNodeDescriptor();
+ desc.length = (int) f.length();
+ desc.src = f.getPath();
+ desc.stereotype = stereotype;
+
+ BufferedInputStream bis = new BufferedInputStream(new FileInputStream(f));
+ //new BufferedInputStream(this.referenceClass.getResourceAsStream(desc.src));
+
+ byte[] buf = new byte[desc.length];
+ try {
+ bis.read(buf);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ // LOG.info("IMAGE READ: " + fileName);
+ desc.img = new ImageIcon(buf).getImage();// Toolkit.getDefaultToolkit().createImage(buf);
+
+ return desc;
+ }
+}
Added: branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/UserDefinedProfile.java.r14801
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/UserDefinedProfile.java.r14801?view=auto&rev=14804
==============================================================================
--- (empty file)
+++ branches/gsoc2008-maurelio1234-profiles-2/src/org/argouml/profile/UserDefinedProfile.java.r14801 2008-05-26 12:03:57-0700
@@ -0,0 +1,139 @@
+// $Id: UserDefinedProfile.java 14666 2008-05-08 16:18:39Z tfmorris $
+// 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.profile;
+
+import java.io.File;
+import java.io.Reader;
+import java.net.MalformedURLException;
+import java.util.Collection;
+
+/**
+ * Represents a profile defined by the user
+ *
+ * @author Marcos Aurélio
+ */
+public class UserDefinedProfile extends Profile {
+
+ private String displayName;
+ private File modelFile;
+ private Collection model;
+ private boolean fromZargo;
+
+ /**
+ * The default constructor for this class
+ *
+ * @param file the file from where the model should be read
+ * @throws ProfileException if the profile could not be loaded
+ */
+ public UserDefinedProfile(File file) throws ProfileException {
+ displayName = file.getName();
+ modelFile = file;
+ ProfileReference reference = null;
+ try {
+ reference = new UserProfileReference(file.getPath());
+ } catch (MalformedURLException e) {
+ throw new ProfileException(
+ "Failed to create the ProfileReference.", e);
+ }
+ model = new FileModelLoader().loadModel(reference);
+ fromZargo = false;
+ }
+
+
+ /**
+ * A constructor that takes a file name and a reader, being the reader the
+ * input method to get the profile model.
+ *
+ * @param fileName name of the profile model file.
+ * @param reader a reader opened from where the profile model will be
+ * loaded.
+ * @throws ProfileException if something goes wrong in initializing the
+ * profile.
+ */
+ public UserDefinedProfile(String fileName, Reader reader)
+ throws ProfileException {
+ displayName = fileName;
+ ProfileReference reference = null;
+ try {
+ reference = new UserProfileReference(fileName);
+ } catch (MalformedURLException e) {
+ throw new ProfileException(
+ "Failed to create the ProfileReference.", e);
+ }
+ model = new ReaderModelLoader(reader).loadModel(reference);
+ fromZargo = true;
+ }
+
+
+ /**
+ * @return the string that should represent this profile in the GUI. An
+ * start (*) is placed on it if it comes from the currently opened
+ * zargo file.
+ */
+ public String getDisplayName() {
+ return displayName + (fromZargo ? "*" : "");
+ }
+
+
+ /**
+ * Returns null. This profile has no formatting strategy.
+ * @return null.
+ */
+ @Override
+ public FormatingStrategy getFormatingStrategy() {
+ return null;
+ }
+
+ /**
+ * Returns null. This profile has no figure strategy.
+ * @return null.
+ */
+ @Override
+ public FigNodeStrategy getFigureStrategy() {
+ return null;
+ }
+
+ /**
+ * @return the file passed at the constructor
+ */
+ public File getModelFile() {
+ return modelFile;
+ }
+
+ /**
+ * @return the name of the model and the file name
+ */
+ @Override
+ public String toString() {
+ // TODO: I18N
+ return super.toString() + " [" + getModelFile() + "]";
+ }
+
+
+ @Override
+ public Collection getProfilePackages() {
+ return model;
+ }
+}
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=14804&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=14803&r2=14804
==============================================================================
--- 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-05-26 12:03:57-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);
}
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.