Author: maurelio1234 Date: 2008-04-29 01:50:39-0700 New Revision: 14505 Added: branches/gsoc2008_maurelio1234_profiles/profile/plugin/ branches/gsoc2008_maurelio1234_profiles/profile/plugin/ErrorLoadingProfile.java branches/gsoc2008_maurelio1234_profiles/profile/plugin/PluginProfile.java branches/gsoc2008_maurelio1234_profiles/profile/plugin/PluginProfileImpl.java branches/gsoc2008_maurelio1234_profiles/profile/plugin/PluginProfileLoader.java branches/gsoc2008_maurelio1234_profiles/profile/plugin/PluginProfileLoaderImpl.java branches/gsoc2008_maurelio1234_profiles/profile/plugin/PluginProfileModule.java
Log: commiting current code Added: branches/gsoc2008_maurelio1234_profiles/profile/plugin/ErrorLoadingProfile.java Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008_maurelio1234_profiles/profile/plugin/ErrorLoadingProfile.java?view=auto&rev=14505 ============================================================================== --- (empty file) +++ branches/gsoc2008_maurelio1234_profiles/profile/plugin/ErrorLoadingProfile.java 2008-04-29 01:50:39-0700 @@ -0,0 +1,22 @@ +package org.argouml.profile.plugin; + [EMAIL PROTECTED]("serial") +public class ErrorLoadingProfile extends Exception { + + public ErrorLoadingProfile() { + super(); + } + + public ErrorLoadingProfile(String message, Throwable cause) { + super(message, cause); + } + + public ErrorLoadingProfile(String message) { + super(message); + } + + public ErrorLoadingProfile(Throwable cause) { + super(cause); + } + +} Added: branches/gsoc2008_maurelio1234_profiles/profile/plugin/PluginProfile.java Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008_maurelio1234_profiles/profile/plugin/PluginProfile.java?view=auto&rev=14505 ============================================================================== --- (empty file) +++ branches/gsoc2008_maurelio1234_profiles/profile/plugin/PluginProfile.java 2008-04-29 01:50:39-0700 @@ -0,0 +1,41 @@ +package org.argouml.profile.plugin; + +import org.argouml.profile.Profile; + +/** + * This class represents a User Defined Profile defined as a Plug-in + * It allows the loading code to abstract from the internal format used + * to store these informations into the JAR archive + * + * @author maas + */ +public interface PluginProfile { + + /** + * @return the description for this profile + */ + String getDescription(); + + /** + * @return the author of this profile + */ + String getAuthor(); + + /** + * @return the version of this profile + */ + String getVersion(); + + /** + * @return the download site for this profile + */ + String getDownloadSite(); + + /** + * @return the name for this profile + */ + String getName(); + + Profile getProfile(); + +} Added: branches/gsoc2008_maurelio1234_profiles/profile/plugin/PluginProfileImpl.java Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008_maurelio1234_profiles/profile/plugin/PluginProfileImpl.java?view=auto&rev=14505 ============================================================================== --- (empty file) +++ branches/gsoc2008_maurelio1234_profiles/profile/plugin/PluginProfileImpl.java 2008-04-29 01:50:39-0700 @@ -0,0 +1,90 @@ +package org.argouml.profile.plugin; + +import org.argouml.profile.Profile; + +/** + * Default implementation for the [EMAIL PROTECTED] PluginProfile} interface + * + * @author maas + */ +public class PluginProfileImpl implements PluginProfile { + private String author; + private String description; + private String name; + private String version; + private String downloadsite; + private Profile profile; + /** + * @return the author + */ + public String getAuthor() { + return author; + } + /** + * @param author the author to set + */ + public void setAuthor(String author) { + this.author = author; + } + /** + * @return the description + */ + public String getDescription() { + return description; + } + /** + * @param description the description to set + */ + public void setDescription(String description) { + this.description = description; + } + /** + * @return the downloadsite + */ + public String getDownloadSite() { + return downloadsite; + } + /** + * @param downloadsite the downloadsite to set + */ + public void setDownloadSite(String downloadsite) { + this.downloadsite = downloadsite; + } + /** + * @return the name + */ + public String getName() { + return name; + } + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + /** + * @return the version + */ + public String getVersion() { + return version; + } + /** + * @param version the version to set + */ + public void setVersion(String version) { + this.version = version; + } + /** + * @return the profile + */ + public Profile getProfile() { + return profile; + } + /** + * @param profile the profile to set + */ + public void setProfile(Profile profile) { + this.profile = profile; + } + +} Added: branches/gsoc2008_maurelio1234_profiles/profile/plugin/PluginProfileLoader.java Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008_maurelio1234_profiles/profile/plugin/PluginProfileLoader.java?view=auto&rev=14505 ============================================================================== --- (empty file) +++ branches/gsoc2008_maurelio1234_profiles/profile/plugin/PluginProfileLoader.java 2008-04-29 01:50:39-0700 @@ -0,0 +1,18 @@ +package org.argouml.profile.plugin; + +/** + * This interface abstracts the process used to load the + * plugin descriptor. + * + * @author maas + */ +public interface PluginProfileLoader { + /** + * Loads the profile + * + * @param cl the reference class (used in order to find the needed resources) + * @return the profile descriptor + * @throws ErrorLoadingProfile + */ + PluginProfile loadProfile(Class cl) throws ErrorLoadingProfile; +} Added: branches/gsoc2008_maurelio1234_profiles/profile/plugin/PluginProfileLoaderImpl.java Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008_maurelio1234_profiles/profile/plugin/PluginProfileLoaderImpl.java?view=auto&rev=14505 ============================================================================== --- (empty file) +++ branches/gsoc2008_maurelio1234_profiles/profile/plugin/PluginProfileLoaderImpl.java 2008-04-29 01:50:39-0700 @@ -0,0 +1,142 @@ +package org.argouml.profile.plugin; + +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; + +import org.argouml.model.Model; +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; +import org.xml.sax.Attributes; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; +import org.xml.sax.helpers.DefaultHandler; +import org.xml.sax.helpers.XMLReaderFactory; + +/** + * Reads the profile descriptor from a file called "profile.xml" + * in the same directory as the reference class + * + * @author maas + */ +public class PluginProfileLoaderImpl extends DefaultHandler implements PluginProfileLoader { + + PluginProfileImpl plugin = null; + Collection profileModel = null; + + Profile profile = new Profile() { + @Override + public String getDisplayName() { + return plugin.getName(); + } + + @Override + public Collection getProfilePackages() throws ProfileException { + return profileModel; + } + }; + + private Class referenceClass; + + private interface Tags { + static final String PROFILE = "profile"; + static final String MODEL = "model"; + } + + private interface Atts { + static final String PROFILE_AUTHOR = "author"; + static final String PROFILE_DESCRIPTION = "description"; + static final String PROFILE_NAME = "name"; + static final String PROFILE_VERSION = "version"; + static final String PROFILE_DOWNLOADSITE = "downloadsite"; + static final String MODEL_XMI = "xmi"; + } + + public PluginProfile loadProfile(Class cl) throws ErrorLoadingProfile { + try { + this.referenceClass = cl; + + XMLReader xr = XMLReaderFactory.createXMLReader(); + + xr.setContentHandler(this); + xr.setErrorHandler(this); + + xr.parse(new InputSource(new InputStreamReader(cl.getResourceAsStream("profile.xml")))); + + } catch (SAXException e) { + throw new ErrorLoadingProfile(); + } catch (IOException e) { + throw new ErrorLoadingProfile(); + } + + return plugin; + } + + public void startDocument() { + plugin = new PluginProfileImpl(); + } + + public void startElement(String uri, String name, String qName, Attributes atts) { + for(int i=0;i<atts.getLength();++i) { + if (name.equalsIgnoreCase(Tags.PROFILE)) { + if (atts.getLocalName(i).equalsIgnoreCase(Atts.PROFILE_AUTHOR)) { + plugin.setAuthor(atts.getValue(i)); + } else if (atts.getLocalName(i).equalsIgnoreCase(Atts.PROFILE_DESCRIPTION)) { + plugin.setDescription(atts.getValue(i)); + } else if (atts.getLocalName(i).equalsIgnoreCase(Atts.PROFILE_NAME)) { + plugin.setName(atts.getValue(i)); + } else if (atts.getLocalName(i).equalsIgnoreCase(Atts.PROFILE_VERSION)) { + plugin.setVersion(atts.getValue(i)); + } else if (atts.getLocalName(i).equalsIgnoreCase(Atts.PROFILE_DOWNLOADSITE)) { + plugin.setDownloadSite(atts.getValue(i)); + } + } else if (name.equalsIgnoreCase(Tags.MODEL)) { + if (atts.getLocalName(i).equalsIgnoreCase(Atts.MODEL_XMI)) { + try { + loadProfileModel(atts.getValue(i)); + } catch (ProfileException e) { + e.printStackTrace(); + } + } + } + } + } + + @SuppressWarnings("unchecked") + private void loadProfileModel(String profile) throws ProfileException { + ProfileModelLoader profileModelLoader = new ResourceModelLoader(referenceClass); + try { + profileModel = profileModelLoader.loadModel(new ProfileReference( + profile, new URL("http://example.com/argouml/userprofiles/" + + profile))); + } catch (Exception e) { + e.printStackTrace(); + } + + if (profileModel == null) { + profileModel = new ArrayList(); + profileModel.add(Model.getModelManagementFactory().createModel()); + } + } + + public void endElement(String uri, String name, String qName) { + if (name.equalsIgnoreCase(Tags.PROFILE)) { + plugin.setProfile(profile); + } + } + + private static PluginProfileLoaderImpl instance = null; + public static PluginProfileLoader getInstance() { + if (instance == null) { + instance = new PluginProfileLoaderImpl(); + } + return instance; + } + +} Added: branches/gsoc2008_maurelio1234_profiles/profile/plugin/PluginProfileModule.java Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008_maurelio1234_profiles/profile/plugin/PluginProfileModule.java?view=auto&rev=14505 ============================================================================== --- (empty file) +++ branches/gsoc2008_maurelio1234_profiles/profile/plugin/PluginProfileModule.java 2008-04-29 01:50:39-0700 @@ -0,0 +1,84 @@ +package org.argouml.profile.plugin; + +import org.apache.log4j.Logger; +import org.argouml.moduleloader.ModuleInterface; +import org.argouml.profile.ProfileFacade; +import org.tigris.gef.undo.UndoableAction; + +/** + * General superclass for module User Defined profiles defined as plug-in + * + * @author maas + */ [EMAIL PROTECTED]("serial") +public abstract class PluginProfileModule extends UndoableAction implements ModuleInterface { + + /** + * Logger. + */ + private static final Logger LOG = Logger.getLogger(PluginProfileModule.class); + + private PluginProfile profile; + + /** + * + */ + public PluginProfileModule() { + super("plugin profile"); + registerProfile(this.getClass()); + } + + protected void registerProfile(Class cl) { + try { + PluginProfileLoader loader = PluginProfileLoaderImpl.getInstance(); + + profile = loader.loadProfile(cl); + } catch (ErrorLoadingProfile e) { + LOG.error("Error loading profile", e); + } + } + + public boolean disable() { + ProfileFacade.getManager().removeProfile(profile.getProfile()); + return true; + } + + public boolean enable() { + ProfileFacade.getManager().registerProfile(profile.getProfile()); + return true; + } + + public String getInfo(int type) { + if (profile == null) { + LOG.debug("Empty Plugin Profile detected!"); + + return "Empty Plug-in"; + } else { + switch (type) { + case DESCRIPTION: + return profile.getDescription(); + case AUTHOR: + return profile.getAuthor(); + case VERSION: + return profile.getVersion(); + case DOWNLOADSITE: + return profile.getDownloadSite(); + default: + return null; + } + } + } + + public String getName() { + String ret = null; + if (profile == null) { + LOG.debug("Empty Plugin Profile detected!"); + + ret = "Empty Plug-in"; + } else { + ret = profile.getName(); + } + return ret; + } + +} --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
