[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[List Home]
|
[dsdp-mtj-commit] r1458 - in trunk/plugins: org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/build org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/externallibrary/manager org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/externallibrary/model org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/project/midp org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/sdk/device org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/sign org.eclipse.mtj.ui/src/org/eclipse/mtj/internal/ui/devices org.eclipse.mtj.ui/src/org/eclipse/mtj/internal/ui/editors/jad/form org.eclipse.mtj.ui/src/org/eclipse/mtj/internal/ui/templates/midlets
|
- From: genie@xxxxxxxxxxx
- Date: Thu, 27 Aug 2009 16:57:58 -0400 (EDT)
- Delivered-to: dsdp-mtj-commit@eclipse.org
Author: dmarques
Date: 2009-08-27 16:57:57 -0400 (Thu, 27 Aug 2009)
New Revision: 1458
Modified:
trunk/plugins/org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/build/BuildHookInfo.java
trunk/plugins/org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/build/BuildHooksRegistry.java
trunk/plugins/org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/externallibrary/manager/ExternalLibraryManager.java
trunk/plugins/org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/externallibrary/model/MidletExternalLibrary.java
trunk/plugins/org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/project/midp/JADAttributesRegistry.java
trunk/plugins/org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/sdk/device/DeviceFinder.java
trunk/plugins/org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/sign/PermissionsGroupsRegistry.java
trunk/plugins/org.eclipse.mtj.ui/src/org/eclipse/mtj/internal/ui/devices/DeviceEditorRegistry.java
trunk/plugins/org.eclipse.mtj.ui/src/org/eclipse/mtj/internal/ui/editors/jad/form/JADFormEditor.java
trunk/plugins/org.eclipse.mtj.ui/src/org/eclipse/mtj/internal/ui/templates/midlets/MIDletTemplateRegistry.java
Log:
[276095][contributed] Implementing IRegistryChangeListener on all registries.
Modified: trunk/plugins/org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/build/BuildHookInfo.java
===================================================================
--- trunk/plugins/org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/build/BuildHookInfo.java 2009-08-27 16:53:12 UTC (rev 1457)
+++ trunk/plugins/org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/build/BuildHookInfo.java 2009-08-27 20:57:57 UTC (rev 1458)
@@ -8,6 +8,7 @@
*
* Contributors:
* David Marques (Motorola) - Initial version
+ * Rafael Amaral (Motorola) - Adding hookId
*/
package org.eclipse.mtj.internal.core.build;
@@ -22,30 +23,42 @@
* @author David Marques
*/
public class BuildHookInfo {
-
- private IConfigurationElement element;
- private IMTJBuildHook hook;
-
- /**
+
+ private String hookId;
+ private IConfigurationElement element;
+ private IMTJBuildHook hook;
+
+ /**
* Creates an instance of a BuildHookInfo associated
* to the specified extension.
- *
- * @param _element extension element.
- */
- public BuildHookInfo(IConfigurationElement _element) {
- this.element = _element;
- }
-
- /**
- * Gets the hook instance.
- *
- * @return the hook.
- * @throws CoreException If any core error occurred.
- */
- public IMTJBuildHook getHook() throws CoreException {
- if (this.hook == null) {
- this.hook = (IMTJBuildHook) this.element.createExecutableExtension("hook");
- }
- return this.hook;
- }
+ *
+ * @param _element extension element.
+ */
+ public BuildHookInfo(IConfigurationElement _element) {
+ this.element = _element;
+ this.hookId = this.element.getAttribute("hook");
+ }
+
+ /**
+ * Gets the hook instance.
+ *
+ * @return the hook.
+ * @throws CoreException If any core error occurred.
+ */
+ public IMTJBuildHook getHook() throws CoreException {
+ if (this.hook == null) {
+ this.hook = (IMTJBuildHook) this.element
+ .createExecutableExtension("hook");
+ }
+ return this.hook;
+ }
+
+ /**
+ * Gets the hook info id
+ *
+ * @return the hookId
+ */
+ public String getHookId() {
+ return hookId;
+ }
}
Modified: trunk/plugins/org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/build/BuildHooksRegistry.java
===================================================================
--- trunk/plugins/org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/build/BuildHooksRegistry.java 2009-08-27 16:53:12 UTC (rev 1457)
+++ trunk/plugins/org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/build/BuildHooksRegistry.java 2009-08-27 20:57:57 UTC (rev 1458)
@@ -8,6 +8,8 @@
*
* Contributors:
* David Marques (Motorola) - Initial version
+ * Rafael Amaral (Motorola) - Changing to make MTJ extension point handle
+ * dynamic add/remove of plugins
*/
package org.eclipse.mtj.internal.core.build;
@@ -15,8 +17,12 @@
import java.util.List;
import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionDelta;
import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.IRegistryChangeEvent;
+import org.eclipse.core.runtime.IRegistryChangeListener;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.mtj.core.MTJCore;
/**
* BuildHooksRegistry is a registry for the
@@ -25,51 +31,97 @@
*
* @author David Marques
*/
-public class BuildHooksRegistry {
+public class BuildHooksRegistry implements IRegistryChangeListener {
- private static final String EXT_ID = "org.eclipse.mtj.core.mtjbuildhook";
-
- private static BuildHooksRegistry instance;
- private List<BuildHookInfo> hooks;
-
- /**
- * Gets the single class instance.
- *
- * @return singleton instance.
- */
- public static synchronized BuildHooksRegistry getInstance() {
- if (BuildHooksRegistry.instance == null) {
- BuildHooksRegistry.instance = new BuildHooksRegistry();
- }
- return BuildHooksRegistry.instance;
- }
-
- /**
- * Loads the registry.
- */
- private BuildHooksRegistry() {
- IExtensionRegistry registry = null;
+ private static final String EXT_ID = "org.eclipse.mtj.core.mtjbuildhook";
+ private static final String EXT_MTJ_BUILD_HOOK = "mtjbuildhook";
+
+ private static BuildHooksRegistry instance;
+ private List<BuildHookInfo> hooks;
+
+ /**
+ * Gets the single class instance.
+ *
+ * @return singleton instance.
+ */
+ public static synchronized BuildHooksRegistry getInstance() {
+ if (BuildHooksRegistry.instance == null) {
+ BuildHooksRegistry.instance = new BuildHooksRegistry();
+ Platform.getExtensionRegistry().addRegistryChangeListener(
+ BuildHooksRegistry.instance);
+ }
+ return BuildHooksRegistry.instance;
+ }
+
+ /**
+ * Loads the registry.
+ */
+ private BuildHooksRegistry() {
+ IExtensionRegistry registry = null;
IConfigurationElement[] extensions = null;
- BuildHookInfo hooksInfo = null;
-
+ BuildHookInfo hooksInfo = null;
+
this.hooks = new ArrayList<BuildHookInfo>();
- registry = Platform.getExtensionRegistry();
+ registry = Platform.getExtensionRegistry();
extensions = registry.getConfigurationElementsFor(EXT_ID);
for (IConfigurationElement extension : extensions) {
hooksInfo = new BuildHookInfo(extension);
this.hooks.add(hooksInfo);
}
- }
-
- /**
- * Gets a list of the registered hooks hooks.
- *
- * @return hooks list.
- */
- public List<BuildHookInfo> getBuildHooks() {
- List<BuildHookInfo> result = new ArrayList<BuildHookInfo>();
- result.addAll(this.hooks);
- return result;
- }
-
+ }
+
+ /**
+ * Gets a list of the registered hooks hooks.
+ *
+ * @return hooks list.
+ */
+ public List<BuildHookInfo> getBuildHooks() {
+ List<BuildHookInfo> result = new ArrayList<BuildHookInfo>();
+ result.addAll(this.hooks);
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.core.runtime.IRegistryChangeListener#registryChanged(org.
+ * eclipse.core.runtime.IRegistryChangeEvent)
+ */
+ public void registryChanged(IRegistryChangeEvent event) {
+
+ String pluginId = MTJCore.getMTJCore().getBundle().getSymbolicName();
+ IExtensionDelta[] deltas = event.getExtensionDeltas(pluginId,
+ EXT_MTJ_BUILD_HOOK);
+
+ for (int i = 0; i < deltas.length; i++) {
+
+ if (deltas[i].getKind() == IExtensionDelta.ADDED) {
+
+ IConfigurationElement[] configurationElements = deltas[i]
+ .getExtension().getConfigurationElements();
+
+ for (IConfigurationElement configurationElement : configurationElements) {
+ BuildHookInfo hooksInfo = new BuildHookInfo(
+ configurationElement);
+ this.hooks.add(hooksInfo);
+ }
+ } else {
+
+ IConfigurationElement[] configurationElements = deltas[i]
+ .getExtension().getConfigurationElements();
+
+ for (IConfigurationElement configurationElement : configurationElements) {
+ BuildHookInfo hooksInfo = new BuildHookInfo(
+ configurationElement);
+ for (int j = 0; j < this.hooks.size(); j++) {
+ if(this.hooks.get(j).getHookId().equals(hooksInfo.getHookId())){
+ this.hooks.remove(j);
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+
}
Modified: trunk/plugins/org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/externallibrary/manager/ExternalLibraryManager.java
===================================================================
--- trunk/plugins/org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/externallibrary/manager/ExternalLibraryManager.java 2009-08-27 16:53:12 UTC (rev 1457)
+++ trunk/plugins/org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/externallibrary/manager/ExternalLibraryManager.java 2009-08-27 20:57:57 UTC (rev 1458)
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2008 Motorola.
+ * Copyright (c) 2008,2009 Motorola.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -12,6 +12,8 @@
* libraries from MIDlet projects
* David Aragïo (Motorola) - refactoring the add remove library methods
* David Marques (Motorola) - Avoiding adding an already existing library.
+ * Rafael Amaral (Motorola) - Changing to make MTJ extension point handle
+ * dynamic add/remove of plugins
*/
package org.eclipse.mtj.internal.core.externallibrary.manager;
@@ -26,8 +28,11 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionDelta;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IRegistryChangeEvent;
+import org.eclipse.core.runtime.IRegistryChangeListener;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
@@ -49,7 +54,7 @@
* @author Diego Madruga Sandin
* @since 0.9.1
*/
-public class ExternalLibraryManager {
+public class ExternalLibraryManager implements IRegistryChangeListener {
/**
* MIDPLibrary Extension point ID
@@ -69,6 +74,8 @@
public synchronized static ExternalLibraryManager getInstance() {
if (LibraryManagerInstance == null) {
LibraryManagerInstance = new ExternalLibraryManager();
+ Platform.getExtensionRegistry().addRegistryChangeListener(
+ LibraryManagerInstance);
}
return LibraryManagerInstance;
@@ -213,16 +220,71 @@
EXT_MIDLETLIBRARY);
for (IConfigurationElement element : elements) {
- MidletExternalLibrary midletLibrary = null;
- try {
- midletLibrary = new MidletExternalLibrary(element);
- } catch (Throwable e) {
- MTJLogger.log(IStatus.ERROR,
- "Failed to load MidletExternalLibrary", e); //$NON-NLS-1$
- }
+ MidletExternalLibrary midletLibrary = getMidletLibrary(element);
if (midletLibrary != null) {
midletLibraries.put(midletLibrary.getName(), midletLibrary);
}
}
}
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.core.runtime.IRegistryChangeListener#registryChanged(org.
+ * eclipse.core.runtime.IRegistryChangeEvent)
+ */
+ public void registryChanged(IRegistryChangeEvent event) {
+
+ IExtensionDelta[] deltas = event.getExtensionDeltas(
+ IMTJCoreConstants.PLUGIN_ID, EXT_MIDLETLIBRARY);
+
+ for (int i = 0; i < deltas.length; i++) {
+
+ if (deltas[i].getKind() == IExtensionDelta.ADDED) {
+
+ IConfigurationElement[] elements = deltas[i].getExtension()
+ .getConfigurationElements();
+
+ for (IConfigurationElement element : elements) {
+ MidletExternalLibrary midletLibrary = getMidletLibrary(element);
+ if (midletLibrary != null) {
+ midletLibraries.put(midletLibrary.getName(),
+ midletLibrary);
+ }
+ }
+ } else {
+
+ IConfigurationElement[] elements = deltas[i].getExtension()
+ .getConfigurationElements();
+
+ for (IConfigurationElement element : elements) {
+ String midletLibraryName = MidletExternalLibrary
+ .getMidletLibraryName(element);
+ if (midletLibraryName != null) {
+ midletLibraries.remove(midletLibraryName);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Takes the IConfigurationElement and returns the associated
+ * MidletExternalLibrary
+ *
+ * @param element the IConfigurationElement
+ * @return the associated MidletExternalLibrary
+ */
+ private MidletExternalLibrary getMidletLibrary(IConfigurationElement element) {
+
+ MidletExternalLibrary midletLibrary = null;
+
+ try {
+ midletLibrary = new MidletExternalLibrary(element);
+ } catch (Throwable e) {
+ MTJLogger.log(IStatus.ERROR,
+ "Failed to load MidletExternalLibrary", e); //$NON-NLS-1$
+ }
+ return midletLibrary;
+ }
}
Modified: trunk/plugins/org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/externallibrary/model/MidletExternalLibrary.java
===================================================================
--- trunk/plugins/org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/externallibrary/model/MidletExternalLibrary.java 2009-08-27 16:53:12 UTC (rev 1457)
+++ trunk/plugins/org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/externallibrary/model/MidletExternalLibrary.java 2009-08-27 20:57:57 UTC (rev 1458)
@@ -1,562 +1,576 @@
-/**
- * Copyright (c) 2008 Motorola.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Diego Sandin (Motorola) - Initial version
- */
-package org.eclipse.mtj.internal.core.externallibrary.model;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.jdt.core.IAccessRule;
-import org.eclipse.jdt.core.IClasspathAttribute;
-import org.eclipse.jdt.core.IClasspathEntry;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.mtj.internal.core.externallibrary.classpath.ClasspathAccessRule;
-import org.eclipse.mtj.internal.core.externallibrary.model.licence.LicenceInfo;
-import org.eclipse.mtj.internal.core.externallibrary.model.security.PermissionList;
-import org.eclipse.mtj.internal.core.externallibrary.model.security.ProtectionDomain;
-import org.eclipse.mtj.internal.core.externallibrary.model.security.SecurityInfo;
-import org.eclipse.mtj.internal.core.externallibrary.model.security.ProtectionDomain.ProtectionDomainType;
-import org.eclipse.mtj.internal.core.util.log.MTJLogger;
-import org.osgi.framework.Version;
-
-/**
- * Representation of the MIDlet libraries that are provided by 3rd party
- * vendors.
- *
- * @author Diego Madruga Sandin
- * @since 0.9.1
- */
-public final class MidletExternalLibrary implements IExternalLibrary {
-
- /* Extension Point Attributes */
- private static final String EP_ATTRIB_ACCESSRULE_KIND = "kind"; //$NON-NLS-1$
- private static final String EP_ATTRIB_ACCESSRULE_PATTERN = "pattern"; //$NON-NLS-1$
- private static final String EP_ATTRIB_CLASSPATHENTRY_JARFILE = "jarFile"; //$NON-NLS-1$
- private static final String EP_ATTRIB_CLASSPATHENTRY_JAVADOCPATH = "javadocPath"; //$NON-NLS-1$
- private static final String EP_ATTRIB_CLASSPATHENTRY_SRCPATH = "srcPath"; //$NON-NLS-1$
- private static final String EP_ATTRIB_LIBRARY_DESCRIPTION = "description"; //$NON-NLS-1$
- private static final String EP_ATTRIB_LIBRARY_NAME = "name"; //$NON-NLS-1$
- private static final String EP_ATTRIB_LIBRARY_VERSION = "version"; //$NON-NLS-1$
- private static final String EP_ATTRIB_LIBRARY_VISIBILITY = "visibility"; //$NON-NLS-1$
- private static final String EP_ATTRIB_LICENSE_NAME = "name"; //$NON-NLS-1$
- private static final String EP_ATTRIB_LICENSE_URL = "url"; //$NON-NLS-1$
- private static final String EP_ATTRIB_SECURITY_PD = "ProtectionDomain"; //$NON-NLS-1$
- private static final String EP_ATTRIB_SECURITY_PERMISSIONS = "Premissions"; //$NON-NLS-1$
-
- /* Extension Point Elements */
- private static final String EP_ELEMENT_ACCESSRULE = "AccessRule"; //$NON-NLS-1$
- private static final String EP_ELEMENT_CLASSPATHENTRY = "ClasspathEntry"; //$NON-NLS-1$
- private static final String EP_ELEMENT_LICENSE = "License"; //$NON-NLS-1$
- private static final String EP_ELEMENT_SECURITY = "Security"; //$NON-NLS-1$
-
- private static final String FILE_PROTOCOL = "file:/"; //$NON-NLS-1$
-
- /**
- * The list of ClasspathEntries available in this library
- */
- private List<IClasspathEntry> classpathEntryList;
-
- /**
- * The MIDPLibrary description
- */
- private String description;
-
- /**
- * The MIDPLibrary identifier
- */
- private String identifier;
-
- /**
- * Licensing information
- */
- private LicenceInfo licence;
-
- /**
- * The MIDPLibrary name
- */
- private String name;
-
- /**
- * Security information
- */
- private SecurityInfo security;
-
- /**
- * The MIDPLibrary version
- */
- private Version version;
-
- /**
- * The library visibility
- */
- private Visibility visibility;
-
- /**
- * Creates a new configurationElement based on the informed
- * {@link IConfigurationElement}.
- *
- * @param configurationElement
- * @throws IllegalArgumentException
- */
- public MidletExternalLibrary(IConfigurationElement configurationElement)
- throws IllegalArgumentException {
-
- String extImplAbsolutePath = getBundleAbsolutePath(configurationElement
- .getNamespaceIdentifier());
-
- classpathEntryList = new ArrayList<IClasspathEntry>();
-
- /* Get the library name [required] */
- name = configurationElement.getAttribute(EP_ATTRIB_LIBRARY_NAME);
-
- if (name == null) {
- throw new IllegalArgumentException("No library name defined.");
- }
-
- /* Get the library name [required] */
- visibility = Visibility.getFromString(configurationElement
- .getAttribute(EP_ATTRIB_LIBRARY_VISIBILITY));
-
- if (visibility == Visibility.INVALID) {
- visibility = Visibility.PUBLIC;
- }
-
- /* Get the library version [required] */
- String versionString = configurationElement
- .getAttribute(EP_ATTRIB_LIBRARY_VERSION);
- try {
- version = new Version(versionString);
- } catch (Exception e) {
- throw new IllegalArgumentException("The version for " + name
- + " is improperly formatted.", e);
- }
-
- /* Get the library version [optional] */
- description = configurationElement
- .getAttribute(EP_ATTRIB_LIBRARY_DESCRIPTION);
-
- /* Set the library identifier [required] */
- identifier = name.replace(" ", "_") + "_" + version.toString();
-
- /* Get the library ClasspathEntries [required] */
- IConfigurationElement[] ClasspathEntries = configurationElement
- .getChildren(EP_ELEMENT_CLASSPATHENTRY);
-
- for (IConfigurationElement classpathEntry : ClasspathEntries) {
-
- /* Get the library jar file path [required] */
- IPath jarPath = new Path(extImplAbsolutePath
- + File.separator
- + classpathEntry
- .getAttribute(EP_ATTRIB_CLASSPATHENTRY_JARFILE));
-
- /* Get the library source folder path [optional] */
- String sourceFolder = classpathEntry
- .getAttribute(EP_ATTRIB_CLASSPATHENTRY_SRCPATH);
-
- IPath srcPath = null;
-
- if (sourceFolder != null) {
- srcPath = new Path(extImplAbsolutePath + File.separator
- + sourceFolder);
- }
-
- /* Get the library javadoc folder path [optional] */
- String javadocFolder = classpathEntry
- .getAttribute(EP_ATTRIB_CLASSPATHENTRY_JAVADOCPATH);
-
- IClasspathAttribute[] extraAttributes = null;
-
- if (javadocFolder != null) {
- IPath javadocPath = new Path(extImplAbsolutePath
- + File.separator + javadocFolder);
-
- extraAttributes = new IClasspathAttribute[1];
- extraAttributes[0] = JavaCore.newClasspathAttribute(
- IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
- javadocPath.toOSString());
- } else {
- extraAttributes = new IClasspathAttribute[0];
- }
-
- /* Get the library access rules [optional] */
- IConfigurationElement[] accessRulesElements = classpathEntry
- .getChildren(EP_ELEMENT_ACCESSRULE);
-
- List<IAccessRule> accessRules = new ArrayList<IAccessRule>();
- for (IConfigurationElement accessRule : accessRulesElements) {
-
- ClasspathAccessRule rule = new ClasspathAccessRule(new Path(
- accessRule.getAttribute(EP_ATTRIB_ACCESSRULE_PATTERN)),
- accessRule.getAttribute(EP_ATTRIB_ACCESSRULE_KIND));
-
- accessRules.add(JavaCore.newAccessRule(rule.getPattern(), rule
- .getKind()));
- }
-
- /* Create a new classpath entry */
- IClasspathEntry entry = JavaCore.newLibraryEntry(jarPath, srcPath,
- null, accessRules.toArray(new IAccessRule[0]),
- extraAttributes, true);
-
- classpathEntryList.add(entry);
- }
-
- IConfigurationElement[] licenceCE = configurationElement
- .getChildren(EP_ELEMENT_LICENSE);
-
- try {
- URI uri = null;
-
- try {
- uri = URI.create(licenceCE[0]
- .getAttribute(EP_ATTRIB_LICENSE_URL));
- } catch (Throwable e) {
- /* No need to log */
- }
-
- licence = new LicenceInfo(licenceCE[0]
- .getAttribute(EP_ATTRIB_LICENSE_NAME), uri);
- } catch (Throwable e) {
- MTJLogger.log(IStatus.WARNING,
- "No Lincense information available for " + name, e);
- }
-
- /* Get the library Security info [optional] */
- IConfigurationElement[] securityCE = configurationElement
- .getChildren(EP_ELEMENT_SECURITY);
-
- ProtectionDomain domain = null;
-
- try {
-
- domain = new ProtectionDomain(securityCE[0]
- .getAttribute(EP_ATTRIB_SECURITY_PD));
-
- } catch (Throwable e) {
- domain = new ProtectionDomain(ProtectionDomainType.UNTRUSTED);
-
- MTJLogger.log(IStatus.WARNING,
- "No Protection Domain information available for " + name
- + ". the Untrusted domain will be used.", e);
- }
-
- PermissionList permissionList = null;
-
- try {
- permissionList = new PermissionList(securityCE[0]
- .getAttribute(EP_ATTRIB_SECURITY_PERMISSIONS));
- } catch (Throwable e) {
- permissionList = PermissionList.EMPTY;
- MTJLogger.log(IStatus.WARNING,
- "No permission information available for " + name, null);
- }
-
- security = new SecurityInfo(domain, permissionList);
-
- }
-
- /**
- * Creates a new MidletExternalLibrary
- *
- * @param identifier
- * @param name
- * @param description
- * @param version
- * @param licence
- * @throws IllegalArgumentException
- */
- public MidletExternalLibrary(String identifier, String name, String description,
- Visibility visibility, Version version, LicenceInfo licence,
- SecurityInfo security) throws IllegalArgumentException {
- super();
-
- if (name == null) {
- throw new IllegalArgumentException("No library name defined.");
- }
-
- if (version == null) {
- throw new IllegalArgumentException("No version was provided for "
- + name);
- }
-
- if (visibility == null) {
- throw new IllegalArgumentException(
- "No visibility was provided for " + name);
- }
-
- this.name = name;
- this.visibility = visibility;
- this.version = version;
- this.identifier = identifier;
- this.description = description;
- this.licence = licence;
- this.classpathEntryList = new ArrayList<IClasspathEntry>();
- this.security = security;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.mtj.core.library.model.ILibrary#addLibraryItem(org.eclipse.mtj.core.library.model.ILibraryItem)
- */
- public void addClasspathEntry(IClasspathEntry libraryItem) {
- this.classpathEntryList.add(libraryItem);
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- MidletExternalLibrary other = (MidletExternalLibrary) obj;
- if (classpathEntryList == null) {
- if (other.classpathEntryList != null) {
- return false;
- }
- } else if (!classpathEntryList.equals(other.classpathEntryList)) {
- return false;
- }
- if (description == null) {
- if (other.description != null) {
- return false;
- }
- } else if (!description.equals(other.description)) {
- return false;
- }
- if (identifier == null) {
- if (other.identifier != null) {
- return false;
- }
- } else if (!identifier.equals(other.identifier)) {
- return false;
- }
- if (licence == null) {
- if (other.licence != null) {
- return false;
- }
- } else if (!licence.equals(other.licence)) {
- return false;
- }
- if (name == null) {
- if (other.name != null) {
- return false;
- }
- } else if (!name.equals(other.name)) {
- return false;
- }
- if (security == null) {
- if (other.security != null) {
- return false;
- }
- } else if (!security.equals(other.security)) {
- return false;
- }
- if (version == null) {
- if (other.version != null) {
- return false;
- }
- } else if (!version.equals(other.version)) {
- return false;
- }
- if (visibility == null) {
- if (other.visibility != null) {
- return false;
- }
- } else if (!visibility.equals(other.visibility)) {
- return false;
- }
- return true;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.mtj.core.library.model.ILibrary#getLibraryItemList()
- */
- public List<IClasspathEntry> getClasspathEntryList() {
- return Collections.unmodifiableList(classpathEntryList);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.mtj.core.library.model.ILibrary#getDescription()
- */
- public String getDescription() {
- return description;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.mtj.core.library.model.ILibrary#getIdentifier()
- */
- public String getIdentifier() {
- return identifier;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.mtj.core.library.model.ILibrary#getLicence()
- */
- public LicenceInfo getLicence() {
- return licence;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.mtj.core.library.model.ILibrary#getName()
- */
- public String getName() {
- return name;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.mtj.core.library.model.ILibrary#getSecurity()
- */
- public SecurityInfo getSecurity() {
- return security;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.mtj.core.library.model.ILibrary#getVersion()
- */
- public Version getVersion() {
- return version;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.mtj.core.library.model.ILibrary#getVisibility()
- */
- public Visibility getVisibility() {
- return visibility;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime
- * result
- + ((classpathEntryList == null) ? 0 : classpathEntryList
- .hashCode());
- result = prime * result
- + ((description == null) ? 0 : description.hashCode());
- result = prime * result
- + ((identifier == null) ? 0 : identifier.hashCode());
- result = prime * result + ((licence == null) ? 0 : licence.hashCode());
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result
- + ((security == null) ? 0 : security.hashCode());
- result = prime * result + ((version == null) ? 0 : version.hashCode());
- result = prime * result
- + ((visibility == null) ? 0 : visibility.hashCode());
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.mtj.core.library.model.ILibrary#removeLibraryItem(org.eclipse.mtj.core.library.model.ILibraryItem)
- */
- public void removeClasspathEntry(IClasspathEntry libraryItem) {
- this.classpathEntryList.remove(libraryItem);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.mtj.core.library.model.ILibrary#setLibraryItemList(java.util.List)
- */
- public void setClasspathEntryList(List<IClasspathEntry> libraryItemList) {
- this.classpathEntryList = libraryItemList;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.mtj.core.library.model.ILibrary#setDescription(java.lang.String)
- */
- public void setDescription(String description) {
- this.description = description;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.mtj.core.library.model.ILibrary#setIdentifier(java.lang.String)
- */
- public void setIdentifier(String identifier) {
- this.identifier = identifier;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.mtj.core.library.model.ILibrary#setName(java.lang.String)
- */
- public void setName(String name) {
- this.name = name;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.mtj.core.library.model.ILibrary#setVersion(org.osgi.framework.Version)
- */
- public void setVersion(Version version) {
- this.version = version;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.mtj.core.library.model.ILibrary#setVisibility(org.eclipse.mtj.core.library.model.Visibility)
- */
- public void setVisibility(Visibility visibility) {
- this.visibility = visibility;
-
- }
-
- /**
- * @param bundleNamespaceIdentifier
- * @return
- */
- private String getBundleAbsolutePath(String bundleNamespaceIdentifier) {
-
- String absolutePath = new String();
- URL entry = Platform.getBundle(bundleNamespaceIdentifier).getEntry("/");
- String bundleLocation = "";
- try {
- bundleLocation = FileLocator.toFileURL(entry).getPath();
- } catch (IOException e1) {
- e1.printStackTrace();
- }
-
- URL bundleUrl = null;
- try {
- bundleUrl = new File(bundleLocation).toURL();
- } catch (MalformedURLException e) {
- e.printStackTrace();
- }
-
- if (bundleUrl != null) {
- absolutePath = bundleUrl.getFile();
- if (absolutePath.startsWith(FILE_PROTOCOL)) {
- absolutePath = absolutePath
- .substring(FILE_PROTOCOL.length() + 1);
- }
- }
-
- return absolutePath;
- }
-}
+/**
+ * Copyright (c) 2008,2009 Motorola.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Diego Sandin (Motorola) - Initial version
+ * Rafael Amaral (Motorola) - Adding getMidletLibraryName method
+ */
+package org.eclipse.mtj.internal.core.externallibrary.model;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jdt.core.IAccessRule;
+import org.eclipse.jdt.core.IClasspathAttribute;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.mtj.internal.core.externallibrary.classpath.ClasspathAccessRule;
+import org.eclipse.mtj.internal.core.externallibrary.model.licence.LicenceInfo;
+import org.eclipse.mtj.internal.core.externallibrary.model.security.PermissionList;
+import org.eclipse.mtj.internal.core.externallibrary.model.security.ProtectionDomain;
+import org.eclipse.mtj.internal.core.externallibrary.model.security.SecurityInfo;
+import org.eclipse.mtj.internal.core.externallibrary.model.security.ProtectionDomain.ProtectionDomainType;
+import org.eclipse.mtj.internal.core.util.log.MTJLogger;
+import org.osgi.framework.Version;
+
+/**
+ * Representation of the MIDlet libraries that are provided by 3rd party
+ * vendors.
+ *
+ * @author Diego Madruga Sandin
+ * @since 0.9.1
+ */
+public final class MidletExternalLibrary implements IExternalLibrary {
+
+ /* Extension Point Attributes */
+ private static final String EP_ATTRIB_ACCESSRULE_KIND = "kind"; //$NON-NLS-1$
+ private static final String EP_ATTRIB_ACCESSRULE_PATTERN = "pattern"; //$NON-NLS-1$
+ private static final String EP_ATTRIB_CLASSPATHENTRY_JARFILE = "jarFile"; //$NON-NLS-1$
+ private static final String EP_ATTRIB_CLASSPATHENTRY_JAVADOCPATH = "javadocPath"; //$NON-NLS-1$
+ private static final String EP_ATTRIB_CLASSPATHENTRY_SRCPATH = "srcPath"; //$NON-NLS-1$
+ private static final String EP_ATTRIB_LIBRARY_DESCRIPTION = "description"; //$NON-NLS-1$
+ private static final String EP_ATTRIB_LIBRARY_NAME = "name"; //$NON-NLS-1$
+ private static final String EP_ATTRIB_LIBRARY_VERSION = "version"; //$NON-NLS-1$
+ private static final String EP_ATTRIB_LIBRARY_VISIBILITY = "visibility"; //$NON-NLS-1$
+ private static final String EP_ATTRIB_LICENSE_NAME = "name"; //$NON-NLS-1$
+ private static final String EP_ATTRIB_LICENSE_URL = "url"; //$NON-NLS-1$
+ private static final String EP_ATTRIB_SECURITY_PD = "ProtectionDomain"; //$NON-NLS-1$
+ private static final String EP_ATTRIB_SECURITY_PERMISSIONS = "Premissions"; //$NON-NLS-1$
+
+ /* Extension Point Elements */
+ private static final String EP_ELEMENT_ACCESSRULE = "AccessRule"; //$NON-NLS-1$
+ private static final String EP_ELEMENT_CLASSPATHENTRY = "ClasspathEntry"; //$NON-NLS-1$
+ private static final String EP_ELEMENT_LICENSE = "License"; //$NON-NLS-1$
+ private static final String EP_ELEMENT_SECURITY = "Security"; //$NON-NLS-1$
+
+ private static final String FILE_PROTOCOL = "file:/"; //$NON-NLS-1$
+
+ /**
+ * The list of ClasspathEntries available in this library
+ */
+ private List<IClasspathEntry> classpathEntryList;
+
+ /**
+ * The MIDPLibrary description
+ */
+ private String description;
+
+ /**
+ * The MIDPLibrary identifier
+ */
+ private String identifier;
+
+ /**
+ * Licensing information
+ */
+ private LicenceInfo licence;
+
+ /**
+ * The MIDPLibrary name
+ */
+ private String name;
+
+ /**
+ * Security information
+ */
+ private SecurityInfo security;
+
+ /**
+ * The MIDPLibrary version
+ */
+ private Version version;
+
+ /**
+ * The library visibility
+ */
+ private Visibility visibility;
+
+ /**
+ * Creates a new configurationElement based on the informed
+ * {@link IConfigurationElement}.
+ *
+ * @param configurationElement
+ * @throws IllegalArgumentException
+ */
+ public MidletExternalLibrary(IConfigurationElement configurationElement)
+ throws IllegalArgumentException {
+
+ String extImplAbsolutePath = getBundleAbsolutePath(configurationElement
+ .getNamespaceIdentifier());
+
+ classpathEntryList = new ArrayList<IClasspathEntry>();
+
+ /* Get the library name [required] */
+ name = configurationElement.getAttribute(EP_ATTRIB_LIBRARY_NAME);
+
+ if (name == null) {
+ throw new IllegalArgumentException("No library name defined.");
+ }
+
+ /* Get the library name [required] */
+ visibility = Visibility.getFromString(configurationElement
+ .getAttribute(EP_ATTRIB_LIBRARY_VISIBILITY));
+
+ if (visibility == Visibility.INVALID) {
+ visibility = Visibility.PUBLIC;
+ }
+
+ /* Get the library version [required] */
+ String versionString = configurationElement
+ .getAttribute(EP_ATTRIB_LIBRARY_VERSION);
+ try {
+ version = new Version(versionString);
+ } catch (Exception e) {
+ throw new IllegalArgumentException("The version for " + name
+ + " is improperly formatted.", e);
+ }
+
+ /* Get the library version [optional] */
+ description = configurationElement
+ .getAttribute(EP_ATTRIB_LIBRARY_DESCRIPTION);
+
+ /* Set the library identifier [required] */
+ identifier = name.replace(" ", "_") + "_" + version.toString();
+
+ /* Get the library ClasspathEntries [required] */
+ IConfigurationElement[] ClasspathEntries = configurationElement
+ .getChildren(EP_ELEMENT_CLASSPATHENTRY);
+
+ for (IConfigurationElement classpathEntry : ClasspathEntries) {
+
+ /* Get the library jar file path [required] */
+ IPath jarPath = new Path(extImplAbsolutePath
+ + File.separator
+ + classpathEntry
+ .getAttribute(EP_ATTRIB_CLASSPATHENTRY_JARFILE));
+
+ /* Get the library source folder path [optional] */
+ String sourceFolder = classpathEntry
+ .getAttribute(EP_ATTRIB_CLASSPATHENTRY_SRCPATH);
+
+ IPath srcPath = null;
+
+ if (sourceFolder != null) {
+ srcPath = new Path(extImplAbsolutePath + File.separator
+ + sourceFolder);
+ }
+
+ /* Get the library javadoc folder path [optional] */
+ String javadocFolder = classpathEntry
+ .getAttribute(EP_ATTRIB_CLASSPATHENTRY_JAVADOCPATH);
+
+ IClasspathAttribute[] extraAttributes = null;
+
+ if (javadocFolder != null) {
+ IPath javadocPath = new Path(extImplAbsolutePath
+ + File.separator + javadocFolder);
+
+ extraAttributes = new IClasspathAttribute[1];
+ extraAttributes[0] = JavaCore.newClasspathAttribute(
+ IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
+ javadocPath.toOSString());
+ } else {
+ extraAttributes = new IClasspathAttribute[0];
+ }
+
+ /* Get the library access rules [optional] */
+ IConfigurationElement[] accessRulesElements = classpathEntry
+ .getChildren(EP_ELEMENT_ACCESSRULE);
+
+ List<IAccessRule> accessRules = new ArrayList<IAccessRule>();
+ for (IConfigurationElement accessRule : accessRulesElements) {
+
+ ClasspathAccessRule rule = new ClasspathAccessRule(new Path(
+ accessRule.getAttribute(EP_ATTRIB_ACCESSRULE_PATTERN)),
+ accessRule.getAttribute(EP_ATTRIB_ACCESSRULE_KIND));
+
+ accessRules.add(JavaCore.newAccessRule(rule.getPattern(), rule
+ .getKind()));
+ }
+
+ /* Create a new classpath entry */
+ IClasspathEntry entry = JavaCore.newLibraryEntry(jarPath, srcPath,
+ null, accessRules.toArray(new IAccessRule[0]),
+ extraAttributes, true);
+
+ classpathEntryList.add(entry);
+ }
+
+ IConfigurationElement[] licenceCE = configurationElement
+ .getChildren(EP_ELEMENT_LICENSE);
+
+ try {
+ URI uri = null;
+
+ try {
+ uri = URI.create(licenceCE[0]
+ .getAttribute(EP_ATTRIB_LICENSE_URL));
+ } catch (Throwable e) {
+ /* No need to log */
+ }
+
+ licence = new LicenceInfo(licenceCE[0]
+ .getAttribute(EP_ATTRIB_LICENSE_NAME), uri);
+ } catch (Throwable e) {
+ MTJLogger.log(IStatus.WARNING,
+ "No Lincense information available for " + name, e);
+ }
+
+ /* Get the library Security info [optional] */
+ IConfigurationElement[] securityCE = configurationElement
+ .getChildren(EP_ELEMENT_SECURITY);
+
+ ProtectionDomain domain = null;
+
+ try {
+
+ domain = new ProtectionDomain(securityCE[0]
+ .getAttribute(EP_ATTRIB_SECURITY_PD));
+
+ } catch (Throwable e) {
+ domain = new ProtectionDomain(ProtectionDomainType.UNTRUSTED);
+
+ MTJLogger.log(IStatus.WARNING,
+ "No Protection Domain information available for " + name
+ + ". the Untrusted domain will be used.", e);
+ }
+
+ PermissionList permissionList = null;
+
+ try {
+ permissionList = new PermissionList(securityCE[0]
+ .getAttribute(EP_ATTRIB_SECURITY_PERMISSIONS));
+ } catch (Throwable e) {
+ permissionList = PermissionList.EMPTY;
+ MTJLogger.log(IStatus.WARNING,
+ "No permission information available for " + name, null);
+ }
+
+ security = new SecurityInfo(domain, permissionList);
+
+ }
+
+ /**
+ * Creates a new MidletExternalLibrary
+ *
+ * @param identifier
+ * @param name
+ * @param description
+ * @param version
+ * @param licence
+ * @throws IllegalArgumentException
+ */
+ public MidletExternalLibrary(String identifier, String name, String description,
+ Visibility visibility, Version version, LicenceInfo licence,
+ SecurityInfo security) throws IllegalArgumentException {
+ super();
+
+ if (name == null) {
+ throw new IllegalArgumentException("No library name defined.");
+ }
+
+ if (version == null) {
+ throw new IllegalArgumentException("No version was provided for "
+ + name);
+ }
+
+ if (visibility == null) {
+ throw new IllegalArgumentException(
+ "No visibility was provided for " + name);
+ }
+
+ this.name = name;
+ this.visibility = visibility;
+ this.version = version;
+ this.identifier = identifier;
+ this.description = description;
+ this.licence = licence;
+ this.classpathEntryList = new ArrayList<IClasspathEntry>();
+ this.security = security;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.mtj.core.library.model.ILibrary#addLibraryItem(org.eclipse.mtj.core.library.model.ILibraryItem)
+ */
+ public void addClasspathEntry(IClasspathEntry libraryItem) {
+ this.classpathEntryList.add(libraryItem);
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ MidletExternalLibrary other = (MidletExternalLibrary) obj;
+ if (classpathEntryList == null) {
+ if (other.classpathEntryList != null) {
+ return false;
+ }
+ } else if (!classpathEntryList.equals(other.classpathEntryList)) {
+ return false;
+ }
+ if (description == null) {
+ if (other.description != null) {
+ return false;
+ }
+ } else if (!description.equals(other.description)) {
+ return false;
+ }
+ if (identifier == null) {
+ if (other.identifier != null) {
+ return false;
+ }
+ } else if (!identifier.equals(other.identifier)) {
+ return false;
+ }
+ if (licence == null) {
+ if (other.licence != null) {
+ return false;
+ }
+ } else if (!licence.equals(other.licence)) {
+ return false;
+ }
+ if (name == null) {
+ if (other.name != null) {
+ return false;
+ }
+ } else if (!name.equals(other.name)) {
+ return false;
+ }
+ if (security == null) {
+ if (other.security != null) {
+ return false;
+ }
+ } else if (!security.equals(other.security)) {
+ return false;
+ }
+ if (version == null) {
+ if (other.version != null) {
+ return false;
+ }
+ } else if (!version.equals(other.version)) {
+ return false;
+ }
+ if (visibility == null) {
+ if (other.visibility != null) {
+ return false;
+ }
+ } else if (!visibility.equals(other.visibility)) {
+ return false;
+ }
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.mtj.core.library.model.ILibrary#getLibraryItemList()
+ */
+ public List<IClasspathEntry> getClasspathEntryList() {
+ return Collections.unmodifiableList(classpathEntryList);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.mtj.core.library.model.ILibrary#getDescription()
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.mtj.core.library.model.ILibrary#getIdentifier()
+ */
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.mtj.core.library.model.ILibrary#getLicence()
+ */
+ public LicenceInfo getLicence() {
+ return licence;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.mtj.core.library.model.ILibrary#getName()
+ */
+ public String getName() {
+ return name;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.mtj.core.library.model.ILibrary#getSecurity()
+ */
+ public SecurityInfo getSecurity() {
+ return security;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.mtj.core.library.model.ILibrary#getVersion()
+ */
+ public Version getVersion() {
+ return version;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.mtj.core.library.model.ILibrary#getVisibility()
+ */
+ public Visibility getVisibility() {
+ return visibility;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime
+ * result
+ + ((classpathEntryList == null) ? 0 : classpathEntryList
+ .hashCode());
+ result = prime * result
+ + ((description == null) ? 0 : description.hashCode());
+ result = prime * result
+ + ((identifier == null) ? 0 : identifier.hashCode());
+ result = prime * result + ((licence == null) ? 0 : licence.hashCode());
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result
+ + ((security == null) ? 0 : security.hashCode());
+ result = prime * result + ((version == null) ? 0 : version.hashCode());
+ result = prime * result
+ + ((visibility == null) ? 0 : visibility.hashCode());
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.mtj.core.library.model.ILibrary#removeLibraryItem(org.eclipse.mtj.core.library.model.ILibraryItem)
+ */
+ public void removeClasspathEntry(IClasspathEntry libraryItem) {
+ this.classpathEntryList.remove(libraryItem);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.mtj.core.library.model.ILibrary#setLibraryItemList(java.util.List)
+ */
+ public void setClasspathEntryList(List<IClasspathEntry> libraryItemList) {
+ this.classpathEntryList = libraryItemList;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.mtj.core.library.model.ILibrary#setDescription(java.lang.String)
+ */
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.mtj.core.library.model.ILibrary#setIdentifier(java.lang.String)
+ */
+ public void setIdentifier(String identifier) {
+ this.identifier = identifier;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.mtj.core.library.model.ILibrary#setName(java.lang.String)
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.mtj.core.library.model.ILibrary#setVersion(org.osgi.framework.Version)
+ */
+ public void setVersion(Version version) {
+ this.version = version;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.mtj.core.library.model.ILibrary#setVisibility(org.eclipse.mtj.core.library.model.Visibility)
+ */
+ public void setVisibility(Visibility visibility) {
+ this.visibility = visibility;
+
+ }
+
+ /**
+ * @param bundleNamespaceIdentifier
+ * @return
+ */
+ private String getBundleAbsolutePath(String bundleNamespaceIdentifier) {
+
+ String absolutePath = new String();
+ URL entry = Platform.getBundle(bundleNamespaceIdentifier).getEntry("/");
+ String bundleLocation = "";
+ try {
+ bundleLocation = FileLocator.toFileURL(entry).getPath();
+ } catch (IOException e1) {
+ e1.printStackTrace();
+ }
+
+ URL bundleUrl = null;
+ try {
+ bundleUrl = new File(bundleLocation).toURL();
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+
+ if (bundleUrl != null) {
+ absolutePath = bundleUrl.getFile();
+ if (absolutePath.startsWith(FILE_PROTOCOL)) {
+ absolutePath = absolutePath
+ .substring(FILE_PROTOCOL.length() + 1);
+ }
+ }
+
+ return absolutePath;
+ }
+
+ /**
+ * Get the library name
+ *
+ * @param configurationElement that represents a library
+ * @return Returns the the midlet library name, or null if none
+ */
+ public static String getMidletLibraryName(
+ IConfigurationElement configurationElement) {
+ String midletLibraryName = configurationElement
+ .getAttribute(EP_ATTRIB_LIBRARY_NAME);
+ return midletLibraryName;
+ }
+}
Modified: trunk/plugins/org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/project/midp/JADAttributesRegistry.java
===================================================================
--- trunk/plugins/org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/project/midp/JADAttributesRegistry.java 2009-08-27 16:53:12 UTC (rev 1457)
+++ trunk/plugins/org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/project/midp/JADAttributesRegistry.java 2009-08-27 20:57:57 UTC (rev 1458)
@@ -1,293 +1,321 @@
-/**
- * Copyright (c) 2003,2008 Sybase Corporation and others.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Gang Ma (Sybase) - Initial implementation
- * Diego Sandin (Motorola) - Use Eclipse Message Bundles [Bug 255874]
- */
-package org.eclipse.mtj.internal.core.project.midp;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.mtj.core.MTJCore;
-import org.eclipse.mtj.core.project.midp.DescriptorPropertyDescription;
-import org.eclipse.mtj.core.project.midp.IJADDescriptorsProvider;
-import org.eclipse.mtj.core.sdk.device.midp.IMIDPDevice;
-import org.eclipse.mtj.internal.core.util.log.MTJLogger;
-
-
-
-/**
- * Provide registry functionality for getting JAD attributes according to the
- * specify device and editor page.
- *
- * @author Gang Ma
- */
-public class JADAttributesRegistry {
-
- /**
- * class wrapped IConfigurationElement instance for jadAttributes
- * extension-point extensions
- *
- * @author gma
- */
- static class JADAttributesConfigElement {
-
- private static final String JAD_ATTR_SHOW_PAGE = "pageID"; //$NON-NLS-1$
- private static final String JAD_DESCRIPTOR_PROVIDER_CLASS = "class"; //$NON-NLS-1$
- private static final String JAD_DESCRIPTOR_PROVIDER_ELEMENT = "jadDescriptorsProvider"; //$NON-NLS-1$
- private static final String VENDOR_SPEC_ATTR = "vendorSpec"; //$NON-NLS-1$
-
- private IConfigurationElement element;
-
- private IJADDescriptorsProvider jadDescriptorsProvider;
-
- /**
- * @param jadAttrElement
- */
- public JADAttributesConfigElement(IConfigurationElement jadAttrElement) {
- element = jadAttrElement;
- }
-
- /**
- * @return
- */
- public String getAttributesShowPage() {
- return element.getAttribute(JAD_ATTR_SHOW_PAGE);
- }
-
- /**
- * @return
- * @throws CoreException
- */
- public IJADDescriptorsProvider getJadDescriptorsProvider()
- throws CoreException {
- if (jadDescriptorsProvider == null) {
- IConfigurationElement[] providers = element
- .getChildren(JAD_DESCRIPTOR_PROVIDER_ELEMENT);
- if ((providers != null) && (providers.length > 0)) {
- jadDescriptorsProvider = (IJADDescriptorsProvider) providers[0]
- .createExecutableExtension(JAD_DESCRIPTOR_PROVIDER_CLASS);
- }
- }
- return jadDescriptorsProvider;
- }
-
- public boolean isVendorSpec() {
- String value = element.getAttribute(VENDOR_SPEC_ATTR);
- return value == null ? false : "true".equalsIgnoreCase(value); //$NON-NLS-1$
- }
-
- }
-
- /**
- * The JAD attributes extension point
- */
- private static final String JAD_ATTRIBUTE_EXTENSION = "jadattributes"; //$NON-NLS-1$
-
- /**
- * all JAD attributes configElements
- */
- private static JADAttributesConfigElement[] allJADAttrElements;
-
- /**
- * use to store generic JAD attributes(not vendor specific) for each page.
- */
- private static Map<String, JADAttributesConfigElement[]> genericPageJADAttrMap = new HashMap<String, JADAttributesConfigElement[]>();
-
- private static IJADDescriptorsProvider[] JADDescriptorproviders;
-
- public static IJADDescriptorsProvider[] getAllJADDescriptorProviders() {
- JADAttributesConfigElement[] configs = getAllJADAttributeElements();
-
- if (JADDescriptorproviders == null) {
- JADDescriptorproviders = new IJADDescriptorsProvider[configs.length];
- try {
- for (int i = 0; i < configs.length; i++) {
- JADDescriptorproviders[i] = configs[i]
- .getJadDescriptorsProvider();
- }
- } catch (CoreException ex) {
- MTJLogger.log( IStatus.WARNING,
- "Unable to read the JAD descriptor", ex); //$NON-NLS-1$
- }
- }
- return JADDescriptorproviders;
- }
-
- /**
- * @param pageID the target page's ID
- * @return the vendor specific JAD descriptors
- */
- public static DescriptorPropertyDescription[] getJADAttrDescriptorsByPage(
- String pageID) {
- JADAttributesConfigElement[] relatedElements = getRelatedAttrElements(pageID);
- DescriptorPropertyDescription[] resultAttributes = getDescriptorsFromElements(relatedElements);
- for (DescriptorPropertyDescription descriptorPropertyDescription : resultAttributes) {
- if (pageID.contains(".")) { //$NON-NLS-1$
- String[] ids = pageID.split("\\."); //$NON-NLS-1$
- descriptorPropertyDescription.setPageId(ids[0]);
- descriptorPropertyDescription.setSectionId(ids[1]);
- } else {
- descriptorPropertyDescription.setPageId(pageID);
- }
- }
- return resultAttributes;
- }
-
- /**
- * @param elements
- * @param device
- * @param pageID
- * @param excludeVendorSpec
- * @return
- */
- private static JADAttributesConfigElement[] filterElements(
- JADAttributesConfigElement[] elements, IMIDPDevice device,
- String pageID, boolean excludeVendorSpec) {
- ArrayList<JADAttributesConfigElement> resultDescriptorList = new ArrayList<JADAttributesConfigElement>();
- for (JADAttributesConfigElement element : elements) {
- boolean satisfied = true;
- if (device != null) {
- satisfied &= element.isVendorSpec()
- && isDeviceMatchVendor(device, element);
- }
- if (pageID != null) {
- satisfied &= element.getAttributesShowPage().equalsIgnoreCase(
- pageID);
- }
- if (excludeVendorSpec) {
- satisfied &= !element.isVendorSpec();
- }
-
- if (satisfied) {
- resultDescriptorList.add(element);
- }
-
- }
- return resultDescriptorList.toArray(new JADAttributesConfigElement[0]);
- }
-
- /**
- * @param elements
- * @param pageID
- * @param excludeVendorSpec
- * @return
- */
- private static JADAttributesConfigElement[] filterElementsByPageAndVendorSpec(
- JADAttributesConfigElement[] elements, String pageID,
- boolean excludeVendorSpec) {
- return filterElements(elements, null, pageID, excludeVendorSpec);
- }
-
- /**
- * Get all the JAD attributes registered. This includes elements that are
- * vendor specific as well as those coming from specifications.
- *
- * @return array of JADAttributesConfigElement
- */
- private static JADAttributesConfigElement[] getAllJADAttributeElements() {
- if (allJADAttrElements == null) {
- allJADAttrElements = readAllJADAttributes();
- }
-
- return allJADAttrElements;
- }
-
- /**
- * @param elements config elements
- * @param pageID editor page ID
- * @param device target device
- * @return DescriptorPropertyDescription array
- */
- private static DescriptorPropertyDescription[] getDescriptorsFromElements(
- JADAttributesConfigElement[] elements) {
- ArrayList<DescriptorPropertyDescription> descriptorList = new ArrayList<DescriptorPropertyDescription>();
- for (JADAttributesConfigElement element : elements) {
- try {
- IJADDescriptorsProvider provider = element
- .getJadDescriptorsProvider();
- DescriptorPropertyDescription[] descriptorArray = provider
- .getDescriptorPropertyDescriptions();
- descriptorList.addAll(Arrays.asList(descriptorArray));
-
- } catch (Exception e) {
- MTJLogger.log(IStatus.WARNING,
- "Errors happened while determining device/vendor specifc JAD attributes", //$NON-NLS-1$
- e);
- }
- }
-
- return descriptorList
- .toArray(new DescriptorPropertyDescription[descriptorList
- .size()]);
- }
-
- /**
- * @param pageID the JAD Editor page's ID
- * @return the generic jadAttributes configElements for specific page
- */
- private static JADAttributesConfigElement[] getGenericElements(String pageID) {
- JADAttributesConfigElement[] elements = getAllJADAttributeElements();
- return filterElementsByPageAndVendorSpec(elements, pageID, true);
-
- }
-
- /**
- * return the related jadAttributes configElements
- */
- private static JADAttributesConfigElement[] getRelatedAttrElements(
- String pageID) {
- JADAttributesConfigElement[] genericElements = null;
-
- // get the page's generic JAD attribute descriptors
- if (!genericPageJADAttrMap.containsKey(pageID)) {
- genericPageJADAttrMap.put(pageID, getGenericElements(pageID));
- }
- genericElements = genericPageJADAttrMap.get(pageID);
-
- return genericElements;
- }
-
- /**
- * judge whether the configuration element is for the device
- *
- * @param device
- * @param element
- * @return if matched return true else false
- */
- private static boolean isDeviceMatchVendor(IMIDPDevice device,
- JADAttributesConfigElement element) {
-
- return true;
- }
-
- /**
- * @return
- */
- private static JADAttributesConfigElement[] readAllJADAttributes() {
- String plugin = MTJCore.getMTJCore().getBundle().getSymbolicName();
- IConfigurationElement[] configElements = Platform
- .getExtensionRegistry().getConfigurationElementsFor(plugin,
- JAD_ATTRIBUTE_EXTENSION);
-
- JADAttributesConfigElement[] elements = new JADAttributesConfigElement[configElements.length];
- for (int i = 0; i < configElements.length; i++) {
- elements[i] = new JADAttributesConfigElement(configElements[i]);
- }
-
- return elements;
- }
-}
+/**
+ * Copyright (c) 2003,2009 Sybase Corporation and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Gang Ma (Sybase) - Initial implementation
+ * Diego Sandin (Motorola) - Use Eclipse Message Bundles [Bug 255874]
+ * Rafael Amaral (Motorola) - Changing to make MTJ extension point handle
+ * dynamic add/remove of plugins
+ */
+package org.eclipse.mtj.internal.core.project.midp;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionDelta;
+import org.eclipse.core.runtime.IRegistryChangeEvent;
+import org.eclipse.core.runtime.IRegistryChangeListener;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.mtj.core.MTJCore;
+import org.eclipse.mtj.core.project.midp.DescriptorPropertyDescription;
+import org.eclipse.mtj.core.project.midp.IJADDescriptorsProvider;
+import org.eclipse.mtj.core.sdk.device.midp.IMIDPDevice;
+import org.eclipse.mtj.internal.core.util.log.MTJLogger;
+
+
+
+/**
+ * Provide registry functionality for getting JAD attributes according to the
+ * specify device and editor page.
+ *
+ * @author Gang Ma
+ */
+public class JADAttributesRegistry implements IRegistryChangeListener {
+
+ /**
+ * class wrapped IConfigurationElement instance for jadAttributes
+ * extension-point extensions
+ *
+ * @author gma
+ */
+ static class JADAttributesConfigElement {
+
+ private static final String JAD_ATTR_SHOW_PAGE = "pageID"; //$NON-NLS-1$
+ private static final String JAD_DESCRIPTOR_PROVIDER_CLASS = "class"; //$NON-NLS-1$
+ private static final String JAD_DESCRIPTOR_PROVIDER_ELEMENT = "jadDescriptorsProvider"; //$NON-NLS-1$
+ private static final String VENDOR_SPEC_ATTR = "vendorSpec"; //$NON-NLS-1$
+
+ private IConfigurationElement element;
+
+ private IJADDescriptorsProvider jadDescriptorsProvider;
+
+ /**
+ * @param jadAttrElement
+ */
+ public JADAttributesConfigElement(IConfigurationElement jadAttrElement) {
+ element = jadAttrElement;
+ }
+
+ /**
+ * @return
+ */
+ public String getAttributesShowPage() {
+ return element.getAttribute(JAD_ATTR_SHOW_PAGE);
+ }
+
+ /**
+ * @return
+ * @throws CoreException
+ */
+ public IJADDescriptorsProvider getJadDescriptorsProvider()
+ throws CoreException {
+ if (jadDescriptorsProvider == null) {
+ IConfigurationElement[] providers = element
+ .getChildren(JAD_DESCRIPTOR_PROVIDER_ELEMENT);
+ if ((providers != null) && (providers.length > 0)) {
+ jadDescriptorsProvider = (IJADDescriptorsProvider) providers[0]
+ .createExecutableExtension(JAD_DESCRIPTOR_PROVIDER_CLASS);
+ }
+ }
+ return jadDescriptorsProvider;
+ }
+
+ public boolean isVendorSpec() {
+ String value = element.getAttribute(VENDOR_SPEC_ATTR);
+ return value == null ? false : "true".equalsIgnoreCase(value); //$NON-NLS-1$
+ }
+
+ }
+
+ /**
+ * The JAD attributes extension point
+ */
+ private static final String JAD_ATTRIBUTE_EXTENSION = "jadattributes"; //$NON-NLS-1$
+
+ /**
+ * all JAD attributes configElements
+ */
+ private static JADAttributesConfigElement[] allJADAttrElements;
+
+ /**
+ * use to store generic JAD attributes(not vendor specific) for each page.
+ */
+ private static Map<String, JADAttributesConfigElement[]> genericPageJADAttrMap = new HashMap<String, JADAttributesConfigElement[]>();
+
+ private static IJADDescriptorsProvider[] JADDescriptorproviders;
+
+ private static JADAttributesRegistry registryChangeListener;
+
+ public static IJADDescriptorsProvider[] getAllJADDescriptorProviders() {
+ JADAttributesConfigElement[] configs = getAllJADAttributeElements();
+
+ if (JADDescriptorproviders == null) {
+ JADDescriptorproviders = new IJADDescriptorsProvider[configs.length];
+ try {
+ for (int i = 0; i < configs.length; i++) {
+ JADDescriptorproviders[i] = configs[i]
+ .getJadDescriptorsProvider();
+ }
+ } catch (CoreException ex) {
+ MTJLogger.log( IStatus.WARNING,
+ "Unable to read the JAD descriptor", ex); //$NON-NLS-1$
+ }
+ }
+ return JADDescriptorproviders;
+ }
+
+ /**
+ * @param pageID the target page's ID
+ * @return the vendor specific JAD descriptors
+ */
+ public static DescriptorPropertyDescription[] getJADAttrDescriptorsByPage(
+ String pageID) {
+ JADAttributesConfigElement[] relatedElements = getRelatedAttrElements(pageID);
+ DescriptorPropertyDescription[] resultAttributes = getDescriptorsFromElements(relatedElements);
+ for (DescriptorPropertyDescription descriptorPropertyDescription : resultAttributes) {
+ if (pageID.contains(".")) { //$NON-NLS-1$
+ String[] ids = pageID.split("\\."); //$NON-NLS-1$
+ descriptorPropertyDescription.setPageId(ids[0]);
+ descriptorPropertyDescription.setSectionId(ids[1]);
+ } else {
+ descriptorPropertyDescription.setPageId(pageID);
+ }
+ }
+ return resultAttributes;
+ }
+
+ /**
+ * @param elements
+ * @param device
+ * @param pageID
+ * @param excludeVendorSpec
+ * @return
+ */
+ private static JADAttributesConfigElement[] filterElements(
+ JADAttributesConfigElement[] elements, IMIDPDevice device,
+ String pageID, boolean excludeVendorSpec) {
+ ArrayList<JADAttributesConfigElement> resultDescriptorList = new ArrayList<JADAttributesConfigElement>();
+ for (JADAttributesConfigElement element : elements) {
+ boolean satisfied = true;
+ if (device != null) {
+ satisfied &= element.isVendorSpec()
+ && isDeviceMatchVendor(device, element);
+ }
+ if (pageID != null) {
+ satisfied &= element.getAttributesShowPage().equalsIgnoreCase(
+ pageID);
+ }
+ if (excludeVendorSpec) {
+ satisfied &= !element.isVendorSpec();
+ }
+
+ if (satisfied) {
+ resultDescriptorList.add(element);
+ }
+
+ }
+ return resultDescriptorList.toArray(new JADAttributesConfigElement[0]);
+ }
+
+ /**
+ * @param elements
+ * @param pageID
+ * @param excludeVendorSpec
+ * @return
+ */
+ private static JADAttributesConfigElement[] filterElementsByPageAndVendorSpec(
+ JADAttributesConfigElement[] elements, String pageID,
+ boolean excludeVendorSpec) {
+ return filterElements(elements, null, pageID, excludeVendorSpec);
+ }
+
+ /**
+ * Get all the JAD attributes registered. This includes elements that are
+ * vendor specific as well as those coming from specifications.
+ *
+ * @return array of JADAttributesConfigElement
+ */
+ private static JADAttributesConfigElement[] getAllJADAttributeElements() {
+ if (allJADAttrElements == null) {
+ allJADAttrElements = readAllJADAttributes();
+ registryChangeListener = new JADAttributesRegistry();
+ Platform.getExtensionRegistry().addRegistryChangeListener(registryChangeListener);
+ }
+
+ return allJADAttrElements;
+ }
+
+ /**
+ * @param elements config elements
+ * @param pageID editor page ID
+ * @param device target device
+ * @return DescriptorPropertyDescription array
+ */
+ private static DescriptorPropertyDescription[] getDescriptorsFromElements(
+ JADAttributesConfigElement[] elements) {
+ ArrayList<DescriptorPropertyDescription> descriptorList = new ArrayList<DescriptorPropertyDescription>();
+ for (JADAttributesConfigElement element : elements) {
+ try {
+ IJADDescriptorsProvider provider = element
+ .getJadDescriptorsProvider();
+ DescriptorPropertyDescription[] descriptorArray = provider
+ .getDescriptorPropertyDescriptions();
+ descriptorList.addAll(Arrays.asList(descriptorArray));
+
+ } catch (Exception e) {
+ MTJLogger.log(IStatus.WARNING,
+ "Errors happened while determining device/vendor specifc JAD attributes", //$NON-NLS-1$
+ e);
+ }
+ }
+
+ return descriptorList
+ .toArray(new DescriptorPropertyDescription[descriptorList
+ .size()]);
+ }
+
+ /**
+ * @param pageID the JAD Editor page's ID
+ * @return the generic jadAttributes configElements for specific page
+ */
+ private static JADAttributesConfigElement[] getGenericElements(String pageID) {
+ JADAttributesConfigElement[] elements = getAllJADAttributeElements();
+ return filterElementsByPageAndVendorSpec(elements, pageID, true);
+
+ }
+
+ /**
+ * return the related jadAttributes configElements
+ */
+ private static JADAttributesConfigElement[] getRelatedAttrElements(
+ String pageID) {
+ JADAttributesConfigElement[] genericElements = null;
+
+ // get the page's generic JAD attribute descriptors
+ if (!genericPageJADAttrMap.containsKey(pageID)) {
+ genericPageJADAttrMap.put(pageID, getGenericElements(pageID));
+ }
+ genericElements = genericPageJADAttrMap.get(pageID);
+
+ return genericElements;
+ }
+
+ /**
+ * judge whether the configuration element is for the device
+ *
+ * @param device
+ * @param element
+ * @return if matched return true else false
+ */
+ private static boolean isDeviceMatchVendor(IMIDPDevice device,
+ JADAttributesConfigElement element) {
+
+ return true;
+ }
+
+ /**
+ * @return
+ */
+ private static JADAttributesConfigElement[] readAllJADAttributes() {
+ String plugin = MTJCore.getMTJCore().getBundle().getSymbolicName();
+ IConfigurationElement[] configElements = Platform
+ .getExtensionRegistry().getConfigurationElementsFor(plugin,
+ JAD_ATTRIBUTE_EXTENSION);
+
+ JADAttributesConfigElement[] elements = new JADAttributesConfigElement[configElements.length];
+ for (int i = 0; i < configElements.length; i++) {
+ elements[i] = new JADAttributesConfigElement(configElements[i]);
+ }
+
+ return elements;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.core.runtime.IRegistryChangeListener#registryChanged(org.
+ * eclipse.core.runtime.IRegistryChangeEvent)
+ */
+ public void registryChanged(IRegistryChangeEvent event) {
+
+ String plugin = MTJCore.getMTJCore().getBundle().getSymbolicName();
+ IExtensionDelta[] deltas = event.getExtensionDeltas(plugin,
+ JAD_ATTRIBUTE_EXTENSION);
+
+ if (deltas.length > 0) {
+ genericPageJADAttrMap.clear();
+ JADDescriptorproviders = null;
+ allJADAttrElements = readAllJADAttributes();
+ }
+ }
+}
Modified: trunk/plugins/org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/sdk/device/DeviceFinder.java
===================================================================
--- trunk/plugins/org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/sdk/device/DeviceFinder.java 2009-08-27 16:53:12 UTC (rev 1457)
+++ trunk/plugins/org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/sdk/device/DeviceFinder.java 2009-08-27 20:57:57 UTC (rev 1458)
@@ -1,276 +1,330 @@
-/**
- * Copyright (c) 2003,2009 Craig Setera and others.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Craig Setera (EclipseME) - Initial implementation
- * Diego Sandin (Motorola) - Refactoring package name to follow eclipse
- * standards
- * Diego Sandin (Motorola) - Refactoring after IDeviceFinder API creation
- */
-package org.eclipse.mtj.internal.core.sdk.device;
-
-import java.io.File;
-import java.io.FileFilter;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtensionRegistry;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.SubProgressMonitor;
-import org.eclipse.mtj.core.MTJCore;
-import org.eclipse.mtj.core.sdk.device.IDevice;
-import org.eclipse.mtj.core.sdk.device.IDeviceFinder;
-import org.eclipse.mtj.core.sdk.device.IDeviceImporter;
-import org.eclipse.mtj.internal.core.Messages;
-import org.eclipse.mtj.internal.core.util.log.MTJLogger;
-import org.eclipse.osgi.util.NLS;
-
-/**
- * The device finder allows to find the list of devices available in a specified
- * directory. This finder uses the available registered device importers to find
- * these devices.
- *
- * @author Craig Setera
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class DeviceFinder implements IDeviceFinder {
-
- /**
- * Map of registered {@link IDeviceImporter Device Importers's}.
- */
- private static Map<String, IDeviceImporter> deviceImportersMap;
-
- /**
- * The Unique DeviceFinder instance.
- */
- private static DeviceFinder finder = null;
-
- /**
- * Return the unique {@link DeviceFinder} instance.
- *
- * @return the single {@link DeviceFinder} instance.
- */
- public static synchronized IDeviceFinder getInstance() {
- if (finder == null) {
- finder = new DeviceFinder();
- }
- return finder;
- }
-
- /**
- * Creates a new instance of DeviceFinder.
- */
- private DeviceFinder() {
- super();
-
- deviceImportersMap = Collections
- .synchronizedMap(new HashMap<String, IDeviceImporter>());
-
- try {
- readDeviceImporters();
- } catch (CoreException e) {
- MTJLogger.log(IStatus.ERROR, Messages.DeviceFinder_0, e);
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.mtj.core.sdk.device.IDeviceFinder#findDevices(java.io.File, org.eclipse.core.runtime.IProgressMonitor)
- */
- public synchronized List<IDevice> findDevices(File directory,
- IProgressMonitor monitor) throws CoreException,
- InterruptedException {
-
- ArrayList<IDevice> foundDevices = new ArrayList<IDevice>();
-
- try {
-
- monitor
- .beginTask(Messages.DeviceFinder_1,
- IProgressMonitor.UNKNOWN);
-
- for (Iterator<Entry<String, IDeviceImporter>> iterator = deviceImportersMap
- .entrySet().iterator(); iterator.hasNext();) {
-
- List<IDevice> list = searchDevicesInDirectory(directory,
- iterator.next().getValue(), new SubProgressMonitor(
- monitor, 1));
- if (list != null) {
- foundDevices.addAll(list);
- }
- }
- } finally {
- monitor.done();
- }
- return foundDevices;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.mtj.core.sdk.device.IDeviceFinder#findDevices(java.lang.String, java.io.File, org.eclipse.core.runtime.IProgressMonitor)
- */
- public synchronized List<IDevice> findDevices(String deviceImporterID,
- File directory, IProgressMonitor monitor) throws CoreException,
- InterruptedException {
-
- ArrayList<IDevice> foundDevices = new ArrayList<IDevice>();
-
- try {
-
- monitor
- .beginTask(Messages.DeviceFinder_1,
- IProgressMonitor.UNKNOWN);
-
- if (deviceImporterID != null) {
- IDeviceImporter deviceImporter = deviceImportersMap
- .get(deviceImporterID);
-
- if (deviceImporter != null) {
-
- List<IDevice> list = searchDevicesInDirectory(directory,
- deviceImporter, new SubProgressMonitor(monitor, 1));
- if (list != null) {
- foundDevices.addAll(list);
- }
- }
- }
-
- } finally {
- monitor.done();
- }
- return foundDevices;
- }
-
- /**
- * Read the device importers from the registered extensions to the
- * "deviceImporters" extension point.
- *
- * @return
- * @throws CoreException
- */
- private void readDeviceImporters() throws CoreException {
-
- if (deviceImportersMap != null) {
-
- String pluginId = MTJCore.getMTJCore().getBundle()
- .getSymbolicName();
-
- // check if this bundle does not have a specified symbolic name
- if (pluginId != null) {
-
- IExtensionRegistry registry = Platform.getExtensionRegistry();
- IConfigurationElement[] elements = registry
- .getConfigurationElementsFor(pluginId,
- IDeviceImporter.EXT_DEVICE_IMPORTERS);
-
- // Check if the extension point has at least one extension
- // configured
- if (elements.length >= 0) {
-
- DeviceImporterElement[] deviceElements = new DeviceImporterElement[elements.length];
-
- for (int i = 0; i < elements.length; i++) {
- deviceElements[i] = new DeviceImporterElement(
- elements[i]);
- }
-
- // sort the device importers according to their priority
- Arrays.sort(deviceElements, new Comparator<Object>() {
- public int compare(Object o1, Object o2) {
- DeviceImporterElement element1 = (DeviceImporterElement) o1;
- DeviceImporterElement element2 = (DeviceImporterElement) o2;
- return element1.getPriority()
- - element2.getPriority();
- }
- });
-
- for (int i = 0; i < deviceElements.length; i++) {
- deviceImportersMap.put(deviceElements[i].getId(),
- deviceElements[i].getDeviceImporter());
- }
- }
- }
- }
- }
-
- /**
- * Search for devices in the specified directory or sub directories given
- * the specified {@link IDeviceImporter} instance.
- *
- * @param directory
- * @param importer
- * @param monitor
- * @return
- * @throws InterruptedException if the user cancels the operation.
- * @throws CoreException
- */
- private List<IDevice> searchDevicesInDirectory(File directory,
- IDeviceImporter importer, IProgressMonitor monitor)
- throws InterruptedException, CoreException {
-
- // Give the user the chance to bail out during the search
- if (monitor.isCanceled()) {
- throw new InterruptedException();
- }
-
- ArrayList<IDevice> foundDevices = null;
- try {
- if (directory.canRead()) {
- foundDevices = new ArrayList<IDevice>();
-
- monitor.setTaskName(NLS
- .bind(Messages.DeviceFinder_2, directory));
-
- SubProgressMonitor subMonitor = new SubProgressMonitor(monitor,
- 1);
-
- // First find any devices in the current directory
- List<IDevice> localFoundDevices = importer.importDevices(
- directory, subMonitor);
-
- if (localFoundDevices != null) {
- foundDevices.addAll(localFoundDevices);
- }
-
- // Now recurse to sub directories
- File[] subdirectories = directory.listFiles(new FileFilter() {
- public boolean accept(File pathname) {
- return pathname.isDirectory();
- }
- });
-
- if (subdirectories != null) {
- for (File element : subdirectories) {
-
- List<IDevice> subdirectFoundDevices = searchDevicesInDirectory(
- element, importer, monitor);
-
- if (subdirectFoundDevices != null) {
- foundDevices.addAll(subdirectFoundDevices);
- }
- }
- }
- }
- } catch (SecurityException e) {
- MTJLogger.log(IStatus.ERROR, NLS.bind(Messages.DeviceFinder_3,
- directory.getPath()), e);
- }
- monitor.worked(1);
-
- return foundDevices;
- }
-}
+/**
+ * Copyright (c) 2003,2009 Craig Setera and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Craig Setera (EclipseME) - Initial implementation
+ * Diego Sandin (Motorola) - Refactoring package name to follow eclipse
+ * standards
+ * Diego Sandin (Motorola) - Refactoring after IDeviceFinder API creation
+ * Rafael Amaral (Motorola) - Changing to make MTJ extension point handle
+ * dynamic add/remove of plugins
+ */
+package org.eclipse.mtj.internal.core.sdk.device;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionDelta;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IRegistryChangeEvent;
+import org.eclipse.core.runtime.IRegistryChangeListener;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.mtj.core.MTJCore;
+import org.eclipse.mtj.core.sdk.device.IDevice;
+import org.eclipse.mtj.core.sdk.device.IDeviceFinder;
+import org.eclipse.mtj.core.sdk.device.IDeviceImporter;
+import org.eclipse.mtj.internal.core.Messages;
+import org.eclipse.mtj.internal.core.util.log.MTJLogger;
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * The device finder allows to find the list of devices available in a specified
+ * directory. This finder uses the available registered device importers to find
+ * these devices.
+ *
+ * @author Craig Setera
+ * @noextend This class is not intended to be subclassed by clients.
+ */
+public class DeviceFinder implements IDeviceFinder, IRegistryChangeListener {
+
+ /**
+ * Map of registered {@link IDeviceImporter Device Importers's}.
+ */
+ private static Map<String, IDeviceImporter> deviceImportersMap;
+
+ /**
+ * The Unique DeviceFinder instance.
+ */
+ private static DeviceFinder finder = null;
+
+ /**
+ * Return the unique {@link DeviceFinder} instance.
+ *
+ * @return the single {@link DeviceFinder} instance.
+ */
+ public static synchronized IDeviceFinder getInstance() {
+ if (finder == null) {
+ finder = new DeviceFinder();
+ Platform.getExtensionRegistry().addRegistryChangeListener(finder);
+ }
+ return finder;
+ }
+
+ /**
+ * Creates a new instance of DeviceFinder.
+ */
+ private DeviceFinder() {
+ super();
+
+ deviceImportersMap = Collections
+ .synchronizedMap(new HashMap<String, IDeviceImporter>());
+
+ try {
+ readDeviceImporters();
+ } catch (CoreException e) {
+ MTJLogger.log(IStatus.ERROR, Messages.DeviceFinder_0, e);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.mtj.core.sdk.device.IDeviceFinder#findDevices(java.io.File, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public synchronized List<IDevice> findDevices(File directory,
+ IProgressMonitor monitor) throws CoreException,
+ InterruptedException {
+
+ ArrayList<IDevice> foundDevices = new ArrayList<IDevice>();
+
+ try {
+
+ monitor
+ .beginTask(Messages.DeviceFinder_1,
+ IProgressMonitor.UNKNOWN);
+
+ for (Iterator<Entry<String, IDeviceImporter>> iterator = deviceImportersMap
+ .entrySet().iterator(); iterator.hasNext();) {
+
+ List<IDevice> list = searchDevicesInDirectory(directory,
+ iterator.next().getValue(), new SubProgressMonitor(
+ monitor, 1));
+ if (list != null) {
+ foundDevices.addAll(list);
+ }
+ }
+ } finally {
+ monitor.done();
+ }
+ return foundDevices;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.mtj.core.sdk.device.IDeviceFinder#findDevices(java.lang.String, java.io.File, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public synchronized List<IDevice> findDevices(String deviceImporterID,
+ File directory, IProgressMonitor monitor) throws CoreException,
+ InterruptedException {
+
+ ArrayList<IDevice> foundDevices = new ArrayList<IDevice>();
+
+ try {
+
+ monitor
+ .beginTask(Messages.DeviceFinder_1,
+ IProgressMonitor.UNKNOWN);
+
+ if (deviceImporterID != null) {
+ IDeviceImporter deviceImporter = deviceImportersMap
+ .get(deviceImporterID);
+
+ if (deviceImporter != null) {
+
+ List<IDevice> list = searchDevicesInDirectory(directory,
+ deviceImporter, new SubProgressMonitor(monitor, 1));
+ if (list != null) {
+ foundDevices.addAll(list);
+ }
+ }
+ }
+
+ } finally {
+ monitor.done();
+ }
+ return foundDevices;
+ }
+
+ /**
+ * Read the device importers from the registered extensions to the
+ * "deviceImporters" extension point.
+ *
+ * @return
+ * @throws CoreException
+ */
+ private void readDeviceImporters() throws CoreException {
+
+ if (deviceImportersMap != null) {
+
+ String pluginId = MTJCore.getMTJCore().getBundle()
+ .getSymbolicName();
+
+ // check if this bundle does not have a specified symbolic name
+ if (pluginId != null) {
+
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IConfigurationElement[] elements = registry
+ .getConfigurationElementsFor(pluginId,
+ IDeviceImporter.EXT_DEVICE_IMPORTERS);
+
+ // Check if the extension point has at least one extension
+ // configured
+ if (elements.length >= 0) {
+
+ DeviceImporterElement[] deviceElements = new DeviceImporterElement[elements.length];
+
+ for (int i = 0; i < elements.length; i++) {
+ deviceElements[i] = new DeviceImporterElement(
+ elements[i]);
+ }
+
+ // sort the device importers according to their priority
+ Arrays.sort(deviceElements, new Comparator<Object>() {
+ public int compare(Object o1, Object o2) {
+ DeviceImporterElement element1 = (DeviceImporterElement) o1;
+ DeviceImporterElement element2 = (DeviceImporterElement) o2;
+ return element1.getPriority()
+ - element2.getPriority();
+ }
+ });
+
+ for (int i = 0; i < deviceElements.length; i++) {
+ deviceImportersMap.put(deviceElements[i].getId(),
+ deviceElements[i].getDeviceImporter());
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Search for devices in the specified directory or sub directories given
+ * the specified {@link IDeviceImporter} instance.
+ *
+ * @param directory
+ * @param importer
+ * @param monitor
+ * @return
+ * @throws InterruptedException if the user cancels the operation.
+ * @throws CoreException
+ */
+ private List<IDevice> searchDevicesInDirectory(File directory,
+ IDeviceImporter importer, IProgressMonitor monitor)
+ throws InterruptedException, CoreException {
+
+ // Give the user the chance to bail out during the search
+ if (monitor.isCanceled()) {
+ throw new InterruptedException();
+ }
+
+ ArrayList<IDevice> foundDevices = null;
+ try {
+ if (directory.canRead()) {
+ foundDevices = new ArrayList<IDevice>();
+
+ monitor.setTaskName(NLS
+ .bind(Messages.DeviceFinder_2, directory));
+
+ SubProgressMonitor subMonitor = new SubProgressMonitor(monitor,
+ 1);
+
+ // First find any devices in the current directory
+ List<IDevice> localFoundDevices = importer.importDevices(
+ directory, subMonitor);
+
+ if (localFoundDevices != null) {
+ foundDevices.addAll(localFoundDevices);
+ }
+
+ // Now recurse to sub directories
+ File[] subdirectories = directory.listFiles(new FileFilter() {
+ public boolean accept(File pathname) {
+ return pathname.isDirectory();
+ }
+ });
+
+ if (subdirectories != null) {
+ for (File element : subdirectories) {
+
+ List<IDevice> subdirectFoundDevices = searchDevicesInDirectory(
+ element, importer, monitor);
+
+ if (subdirectFoundDevices != null) {
+ foundDevices.addAll(subdirectFoundDevices);
+ }
+ }
+ }
+ }
+ } catch (SecurityException e) {
+ MTJLogger.log(IStatus.ERROR, NLS.bind(Messages.DeviceFinder_3,
+ directory.getPath()), e);
+ }
+ monitor.worked(1);
+
+ return foundDevices;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.core.runtime.IRegistryChangeListener#registryChanged(org.
+ * eclipse.core.runtime.IRegistryChangeEvent)
+ */
+ public void registryChanged(IRegistryChangeEvent event) {
+
+ String pluginId = MTJCore.getMTJCore().getBundle().getSymbolicName();
+ IExtensionDelta[] deltas = event.getExtensionDeltas(pluginId,
+ IDeviceImporter.EXT_DEVICE_IMPORTERS);
+
+ for (int i = 0; i < deltas.length; i++) {
+ if (deltas[i].getKind() == IExtensionDelta.ADDED) {
+ try {
+ DeviceImporterElement[] deviceElements = getDeviceImporterElements(deltas[i]
+ .getExtension());
+ for (int j = 0; j < deviceElements.length; j++) {
+ deviceImportersMap.put(deviceElements[j].getId(),
+ deviceElements[j].getDeviceImporter());
+ }
+ } catch (CoreException e) {
+ MTJLogger.log(IStatus.ERROR, e);
+ }
+ } else {
+ DeviceImporterElement[] deviceElements = getDeviceImporterElements(deltas[i]
+ .getExtension());
+ for (int j = 0; j < deviceElements.length; j++) {
+ deviceImportersMap.remove(deviceElements[j].getId());
+ }
+ }
+ }
+ }
+
+ private DeviceImporterElement[] getDeviceImporterElements(
+ IExtension extension) {
+
+ IConfigurationElement[] elements = extension.getConfigurationElements();
+ DeviceImporterElement[] deviceElements = new DeviceImporterElement[elements.length];
+
+ for (int j = 0; j < deviceElements.length; j++) {
+ deviceElements[j] = new DeviceImporterElement(elements[j]);
+ }
+
+ return deviceElements;
+ }
+}
Modified: trunk/plugins/org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/sign/PermissionsGroupsRegistry.java
===================================================================
--- trunk/plugins/org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/sign/PermissionsGroupsRegistry.java 2009-08-27 16:53:12 UTC (rev 1457)
+++ trunk/plugins/org.eclipse.mtj.core/src/org/eclipse/mtj/internal/core/sign/PermissionsGroupsRegistry.java 2009-08-27 20:57:57 UTC (rev 1458)
@@ -8,6 +8,8 @@
*
* Contributors:
* David Marques (Motorola) - Initial version
+ * Rafael Amaral (Motorola) - Changing to make MTJ extension point handle
+ * dynamic add/remove of plugins
*/
package org.eclipse.mtj.internal.core.sign;
@@ -15,8 +17,12 @@
import java.util.List;
import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionDelta;
import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.IRegistryChangeEvent;
+import org.eclipse.core.runtime.IRegistryChangeListener;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.mtj.core.MTJCore;
/**
* PermissionsGroupsRegistry class provides a registry for the
@@ -26,13 +32,13 @@
* @author David Marques
* @since 1.0
*/
-public class PermissionsGroupsRegistry {
+public class PermissionsGroupsRegistry implements IRegistryChangeListener {
// Constants -----------------------------------------------------
- private static final String NAME = "name"; //$NON-NLS-1$
-
- private static final String EXT_ID = "org.eclipse.mtj.core.securitypermission"; //$NON-NLS-1$
+ private static final String NAME = "name"; //$NON-NLS-1$
+ private static final String EXT_SECURITY_PERMISSION = "securitypermission"; //$NON-NLS-1$
+ private static final String EXT_ID = "org.eclipse.mtj.core.securitypermission"; //$NON-NLS-1$
// Attributes ----------------------------------------------------
@@ -50,6 +56,8 @@
public static synchronized PermissionsGroupsRegistry getInstance() {
if (PermissionsGroupsRegistry.instance == null) {
PermissionsGroupsRegistry.instance = new PermissionsGroupsRegistry();
+ Platform.getExtensionRegistry().addRegistryChangeListener(
+ PermissionsGroupsRegistry.instance);
}
return PermissionsGroupsRegistry.instance;
}
@@ -59,7 +67,7 @@
/**
* Loads all permissions found in the extension registry.
*/
- public PermissionsGroupsRegistry() {
+ private PermissionsGroupsRegistry() {
IExtensionRegistry registry = null;
IConfigurationElement[] extensions = null;
@@ -100,6 +108,45 @@
copy.addAll(this.permissions);
return copy;
}
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.core.runtime.IRegistryChangeListener#registryChanged(org.
+ * eclipse.core.runtime.IRegistryChangeEvent)
+ */
+ public void registryChanged(IRegistryChangeEvent event) {
+
+ String plugin = MTJCore.getMTJCore().getBundle().getSymbolicName();
+ IExtensionDelta[] deltas = event.getExtensionDeltas(plugin,
+ EXT_SECURITY_PERMISSION);
+
+ for (int i = 0; i < deltas.length; i++) {
+
+ IConfigurationElement[] elements = deltas[i].getExtension()
+ .getConfigurationElements();
+
+ for (IConfigurationElement element : elements) {
+
+ String className = element.getAttribute(NAME);
+ List<String> classPermissions = getClassPermissions(element
+ .getChildren());
+
+ if (deltas[i].getKind() == IExtensionDelta.ADDED) {
+ permissions.add(new PermissionsGroup(className,
+ classPermissions));
+ } else {
+ for (int index = 0; i < permissions.size(); index++) {
+ if (className.equals(permissions.get(index)
+ .getClassName())) {
+ permissions.remove(index);
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
// X implementation ----------------------------------------------
Modified: trunk/plugins/org.eclipse.mtj.ui/src/org/eclipse/mtj/internal/ui/devices/DeviceEditorRegistry.java
===================================================================
--- trunk/plugins/org.eclipse.mtj.ui/src/org/eclipse/mtj/internal/ui/devices/DeviceEditorRegistry.java 2009-08-27 16:53:12 UTC (rev 1457)
+++ trunk/plugins/org.eclipse.mtj.ui/src/org/eclipse/mtj/internal/ui/devices/DeviceEditorRegistry.java 2009-08-27 20:57:57 UTC (rev 1458)
@@ -1,130 +1,155 @@
-/**
- * Copyright (c) 2003,2008 Craig Setera and others.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Craig Setera (EclipseME) - Initial implementation
- * Diego Sandin (Motorola) - Refactoring package name to follow eclipse
- * standards
- */
-package org.eclipse.mtj.internal.ui.devices;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.mtj.core.sdk.device.IDevice;
-import org.eclipse.mtj.internal.ui.MTJUIPlugin;
-
-/**
- * Provides registry functionality for attaching editors to particular device
- * types.
- *
- * @author Craig Setera
- */
-public class DeviceEditorRegistry {
-
- /**
- * The extension point
- */
- public static final String ID_EXTENSION = "deviceeditor";
-
- private static DeviceEditorConfigElement[] editors;
-
- /**
- * Return the editor configuration element for editing the specified device
- * or <code>null</code> if no editor element can be found.
- *
- * @param device
- * @return
- */
- public static DeviceEditorConfigElement findEditorElement(IDevice device) {
- DeviceEditorConfigElement element = null;
-
- DeviceEditorConfigElement[] elements = getEditors();
- Class<? extends IDevice> deviceClass = (Class<? extends IDevice>) device.getClass();
- for (DeviceEditorConfigElement element2 : elements) {
- String matchClassName = element2.getDeviceClass();
- if (isMatchingType(deviceClass, matchClassName)) {
- element = element2;
- break;
- }
- }
-
- return element;
- }
-
- /**
- * Return the editor extensions as an array of DeviceEditorConfigElement
- * instances.
- *
- * @return
- */
- private static DeviceEditorConfigElement[] getEditors() {
- if (editors == null) {
- editors = readEditors();
- }
-
- return editors;
- }
-
- /**
- * Return a boolean if the specified class matches the specified class name
- * directly or via super types and interfaces.
- *
- * @param type
- * @param matchClassName
- * @return
- */
- private static boolean isMatchingType(Class<?> type, String matchClassName) {
- boolean matches = false;
-
- if (type != null) {
- matches = type.getName().equals(matchClassName);
-
- // Test super classes
- if (!matches) {
- matches = isMatchingType(type.getSuperclass(), matchClassName);
- }
-
- // Test interfaces
- if (!matches) {
- Class<?>[] interfaces = type.getInterfaces();
- for (int i = 0; !matches && (i < interfaces.length); i++) {
- matches = isMatchingType(interfaces[i], matchClassName);
- }
- }
- }
-
- return matches;
- }
-
- /**
- * Return the editor extensions as a list of DeviceEditorConfigElement
- * instances.
- *
- * @return
- */
- private static DeviceEditorConfigElement[] readEditors() {
- String plugin = MTJUIPlugin.getDefault().getBundle().getSymbolicName();
- IConfigurationElement[] configElements = Platform
- .getExtensionRegistry().getConfigurationElementsFor(plugin,
- ID_EXTENSION);
-
- DeviceEditorConfigElement[] elements = new DeviceEditorConfigElement[configElements.length];
- for (int i = 0; i < configElements.length; i++) {
- elements[i] = new DeviceEditorConfigElement(configElements[i]);
- }
-
- return elements;
- }
-
- /**
- * Static-only access.
- */
- private DeviceEditorRegistry() {
- super();
- }
-}
+/**
+ * Copyright (c) 2003,2009 Craig Setera and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Craig Setera (EclipseME) - Initial implementation
+ * Diego Sandin (Motorola) - Refactoring package name to follow eclipse
+ * standards
+ * Rafael Amaral (Motorola) - Changing to make MTJ extension point handle
+ * dynamic add/remove of plugins
+ */
+package org.eclipse.mtj.internal.ui.devices;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionDelta;
+import org.eclipse.core.runtime.IRegistryChangeEvent;
+import org.eclipse.core.runtime.IRegistryChangeListener;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.mtj.core.sdk.device.IDevice;
+import org.eclipse.mtj.internal.ui.MTJUIPlugin;
+
+/**
+ * Provides registry functionality for attaching editors to particular device
+ * types.
+ *
+ * @author Craig Setera
+ */
+public class DeviceEditorRegistry implements IRegistryChangeListener {
+
+ /**
+ * The extension point
+ */
+ public static final String ID_EXTENSION = "deviceeditor";
+
+ private static DeviceEditorConfigElement[] editors;
+
+ private static DeviceEditorRegistry registryChangeListener;
+
+ /**
+ * Return the editor configuration element for editing the specified device
+ * or <code>null</code> if no editor element can be found.
+ *
+ * @param device
+ * @return
+ */
+ public static DeviceEditorConfigElement findEditorElement(IDevice device) {
+ DeviceEditorConfigElement element = null;
+
+ DeviceEditorConfigElement[] elements = getEditors();
+ Class<? extends IDevice> deviceClass = (Class<? extends IDevice>) device.getClass();
+ for (DeviceEditorConfigElement element2 : elements) {
+ String matchClassName = element2.getDeviceClass();
+ if (isMatchingType(deviceClass, matchClassName)) {
+ element = element2;
+ break;
+ }
+ }
+
+ return element;
+ }
+
+ /**
+ * Return the editor extensions as an array of DeviceEditorConfigElement
+ * instances.
+ *
+ * @return
+ */
+ private static DeviceEditorConfigElement[] getEditors() {
+ if (editors == null) {
+ editors = readEditors();
+ registryChangeListener = new DeviceEditorRegistry();
+ Platform.getExtensionRegistry().addRegistryChangeListener(registryChangeListener);
+ }
+ return editors;
+ }
+
+ /**
+ * Return a boolean if the specified class matches the specified class name
+ * directly or via super types and interfaces.
+ *
+ * @param type
+ * @param matchClassName
+ * @return
+ */
+ private static boolean isMatchingType(Class<?> type, String matchClassName) {
+ boolean matches = false;
+
+ if (type != null) {
+ matches = type.getName().equals(matchClassName);
+
+ // Test super classes
+ if (!matches) {
+ matches = isMatchingType(type.getSuperclass(), matchClassName);
+ }
+
+ // Test interfaces
+ if (!matches) {
+ Class<?>[] interfaces = type.getInterfaces();
+ for (int i = 0; !matches && (i < interfaces.length); i++) {
+ matches = isMatchingType(interfaces[i], matchClassName);
+ }
+ }
+ }
+
+ return matches;
+ }
+
+ /**
+ * Return the editor extensions as a list of DeviceEditorConfigElement
+ * instances.
+ *
+ * @return
+ */
+ private static DeviceEditorConfigElement[] readEditors() {
+ String plugin = MTJUIPlugin.getDefault().getBundle().getSymbolicName();
+ IConfigurationElement[] configElements = Platform
+ .getExtensionRegistry().getConfigurationElementsFor(plugin,
+ ID_EXTENSION);
+
+ DeviceEditorConfigElement[] elements = new DeviceEditorConfigElement[configElements.length];
+ for (int i = 0; i < configElements.length; i++) {
+ elements[i] = new DeviceEditorConfigElement(configElements[i]);
+ }
+
+ return elements;
+ }
+
+ /**
+ * Static-only access.
+ */
+ private DeviceEditorRegistry() {
+ super();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.core.runtime.IRegistryChangeListener#registryChanged(org.
+ * eclipse.core.runtime.IRegistryChangeEvent)
+ */
+ public void registryChanged(IRegistryChangeEvent event) {
+
+ String plugin = MTJUIPlugin.getDefault().getBundle().getSymbolicName();
+ IExtensionDelta[] deltas = event.getExtensionDeltas(plugin,
+ ID_EXTENSION);
+
+ if (deltas.length > 0) {
+ editors = readEditors();
+ }
+ }
+}
Modified: trunk/plugins/org.eclipse.mtj.ui/src/org/eclipse/mtj/internal/ui/editors/jad/form/JADFormEditor.java
===================================================================
--- trunk/plugins/org.eclipse.mtj.ui/src/org/eclipse/mtj/internal/ui/editors/jad/form/JADFormEditor.java 2009-08-27 16:53:12 UTC (rev 1457)
+++ trunk/plugins/org.eclipse.mtj.ui/src/org/eclipse/mtj/internal/ui/editors/jad/form/JADFormEditor.java 2009-08-27 20:57:57 UTC (rev 1458)
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2003,2008 Craig Setera and others.
+ * Copyright (c) 2003,2009 Craig Setera and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -26,6 +26,8 @@
* David Marques (Motorola) - Renaming PermissionsPage to SigningJADEditorPage.
* David Marques (Motorola) - Adding build properties page.
* David Marques (Motorola) - Refactoring build.properties
+ * Rafael Amaral (Motorola) - Changing to make MTJ extension point handle
+ * dynamic add/remove of plugins
*/
package org.eclipse.mtj.internal.ui.editors.jad.form;
@@ -44,8 +46,11 @@
import org.eclipse.core.resources.ResourceAttributes;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionDelta;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IRegistryChangeEvent;
+import org.eclipse.core.runtime.IRegistryChangeListener;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.core.IJavaProject;
@@ -81,8 +86,12 @@
*
* @author Craig Setera
*/
-public class JADFormEditor extends FormEditor implements IInPlaceEditor {
+public class JADFormEditor extends FormEditor implements IInPlaceEditor,
+ IRegistryChangeListener {
+ //Instance to listen registry changes
+ private static JADFormEditor registryChangeListener;
+
// all JAD editor page configuration elements
private static JADEditorPageConfigElement[] jadEditorPageConfigElements;
@@ -105,7 +114,9 @@
// The source editor page in the editor
private JADSourceEditorPage sourceEditor;
- private IFormPage[] buildPropertiesPages;
+ private IFormPage[] buildPropertiesPages;
+
+ private static final String EXT_JAD_EDITOR_PAGE = "jadeditorpage";
/* (non-Javadoc)
* @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
@@ -328,6 +339,8 @@
private JADEditorPageConfigElement[] getAllEditorPageConfigElements() {
if (jadEditorPageConfigElements == null) {
jadEditorPageConfigElements = readAllVendorSpecJADAttributes();
+ registryChangeListener = new JADFormEditor();
+ Platform.getExtensionRegistry().addRegistryChangeListener(registryChangeListener);
}
return jadEditorPageConfigElements;
}
@@ -353,7 +366,7 @@
String plugin = MTJUIPlugin.getDefault().getBundle().getSymbolicName();
IConfigurationElement[] configElements = Platform
.getExtensionRegistry().getConfigurationElementsFor(plugin,
- "jadeditorpage"); //$NON-NLS-1$
+ EXT_JAD_EDITOR_PAGE); //$NON-NLS-1$
JADEditorPageConfigElement[] resultElements = new JADEditorPageConfigElement[configElements.length];
for (int i = 0; i < configElements.length; i++) {
resultElements[i] = new JADEditorPageConfigElement(
@@ -522,4 +535,21 @@
}
}
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.core.runtime.IRegistryChangeListener#registryChanged(org.
+ * eclipse.core.runtime.IRegistryChangeEvent)
+ */
+ public void registryChanged(IRegistryChangeEvent event) {
+
+ String plugin = MTJUIPlugin.getDefault().getBundle().getSymbolicName();
+ IExtensionDelta[] deltas = event.getExtensionDeltas(plugin,
+ EXT_JAD_EDITOR_PAGE);
+
+ if (deltas.length > 0) {
+ jadEditorPageConfigElements = readAllVendorSpecJADAttributes();
+ }
+ }
+
}
Modified: trunk/plugins/org.eclipse.mtj.ui/src/org/eclipse/mtj/internal/ui/templates/midlets/MIDletTemplateRegistry.java
===================================================================
--- trunk/plugins/org.eclipse.mtj.ui/src/org/eclipse/mtj/internal/ui/templates/midlets/MIDletTemplateRegistry.java 2009-08-27 16:53:12 UTC (rev 1457)
+++ trunk/plugins/org.eclipse.mtj.ui/src/org/eclipse/mtj/internal/ui/templates/midlets/MIDletTemplateRegistry.java 2009-08-27 20:57:57 UTC (rev 1458)
@@ -1,103 +1,149 @@
-/**
- * Copyright (c) 2009 Motorola.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * David Marques (Motorola) - Initial Verison.
- */
-package org.eclipse.mtj.internal.ui.templates.midlets;
-
-import java.util.Collection;
-import java.util.Hashtable;
-import java.util.Map;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtensionRegistry;
-import org.eclipse.core.runtime.Platform;
-
-/**
- * MIDletTemplateRegistry class is the registry for the extensions
- * of the org.eclipse.mtj.ui.midletTemplate extension point.
- *
- * @author David Marques
- * @since 1.0
- */
-public class MIDletTemplateRegistry {
-
- // Constants -----------------------------------------------------
-
- private static final String TEMPLATE_EXT_ID = "org.eclipse.mtj.ui.midlettemplate";
-
- // Attributes ----------------------------------------------------
-
- private static MIDletTemplateRegistry instance;
- private Map<String, MIDletTemplateObject> extensions;
-
- // Static --------------------------------------------------------
-
- /**
- * Gets the single instance of this class.
- *
- * @return the singleton.
- */
- public static synchronized MIDletTemplateRegistry getInstance() {
- if (MIDletTemplateRegistry.instance == null) {
- MIDletTemplateRegistry.instance = new MIDletTemplateRegistry();
- }
- return MIDletTemplateRegistry.instance;
- }
-
- // Constructors --------------------------------------------------
-
- /**
- * Create a MIDletTemplateRegistry.
- */
- private MIDletTemplateRegistry() {
- IExtensionRegistry registry = null;
- IConfigurationElement[] extensions = null;
- MIDletTemplateObject object = null;
-
- this.extensions = new Hashtable<String, MIDletTemplateObject>();
- registry = Platform.getExtensionRegistry();
- extensions = registry.getConfigurationElementsFor(TEMPLATE_EXT_ID);
- for (IConfigurationElement extension : extensions) {
- object = new MIDletTemplateObject(extension);
- this.extensions.put(object.getName(), object);
- }
- }
-
- // Public --------------------------------------------------------
-
- /**
- * Gets all registered templates.
- *
- * @return template collection.
- */
- public Collection<MIDletTemplateObject> getTemplates() {
- return this.extensions.values();
- }
-
- /**
- * Gets the template with the specified name.
- *
- * @param name - template name.
- * @return the template.
- */
- public MIDletTemplateObject getTemplate(String name) {
- return this.extensions.get(name);
- }
-
- // X implementation ----------------------------------------------
-
- // Y overrides ---------------------------------------------------
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-}
+/**
+ * Copyright (c) 2009 Motorola.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * David Marques (Motorola) - Initial Verison.
+ * Rafael Amaral (Motorola) - Changing to make MTJ extension point handle
+ * dynamic add/remove of plugins
+ */
+package org.eclipse.mtj.internal.ui.templates.midlets;
+
+import java.util.Collection;
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionDelta;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.IRegistryChangeEvent;
+import org.eclipse.core.runtime.IRegistryChangeListener;
+import org.eclipse.core.runtime.Platform;
+
+/**
+ * MIDletTemplateRegistry class is the registry for the extensions
+ * of the org.eclipse.mtj.ui.midletTemplate extension point.
+ *
+ * @author David Marques
+ * @since 1.0
+ */
+public class MIDletTemplateRegistry implements IRegistryChangeListener{
+
+ // Constants -----------------------------------------------------
+
+ private static final String TEMPLATE_EXT_ID = "org.eclipse.mtj.ui.midlettemplate";
+ private static final String PLUGIN_ID = "org.eclipse.mtj.ui";
+ private static final String EXT_TEMPLATE = "midlettemplate";
+
+ // Attributes ----------------------------------------------------
+
+ private static MIDletTemplateRegistry instance;
+ private Map<String, MIDletTemplateObject> extensions;
+
+ // Static --------------------------------------------------------
+
+ /**
+ * Gets the single instance of this class.
+ *
+ * @return the singleton.
+ */
+ public static synchronized MIDletTemplateRegistry getInstance() {
+ if (MIDletTemplateRegistry.instance == null) {
+ MIDletTemplateRegistry.instance = new MIDletTemplateRegistry();
+ Platform.getExtensionRegistry().addRegistryChangeListener(
+ MIDletTemplateRegistry.instance);
+ }
+ return MIDletTemplateRegistry.instance;
+ }
+
+ // Constructors --------------------------------------------------
+
+ /**
+ * Create a MIDletTemplateRegistry.
+ */
+ private MIDletTemplateRegistry() {
+ IExtensionRegistry registry = null;
+ IConfigurationElement[] extensions = null;
+ MIDletTemplateObject object = null;
+
+ this.extensions = new Hashtable<String, MIDletTemplateObject>();
+ registry = Platform.getExtensionRegistry();
+ extensions = registry.getConfigurationElementsFor(TEMPLATE_EXT_ID);
+ for (IConfigurationElement extension : extensions) {
+ object = new MIDletTemplateObject(extension);
+ this.extensions.put(object.getName(), object);
+ }
+ }
+
+ // Public --------------------------------------------------------
+
+ /**
+ * Gets all registered templates.
+ *
+ * @return template collection.
+ */
+ public Collection<MIDletTemplateObject> getTemplates() {
+ return this.extensions.values();
+ }
+
+ /**
+ * Gets the template with the specified name.
+ *
+ * @param name - template name.
+ * @return the template.
+ */
+ public MIDletTemplateObject getTemplate(String name) {
+ return this.extensions.get(name);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.core.runtime.IRegistryChangeListener#registryChanged(org.
+ * eclipse.core.runtime.IRegistryChangeEvent)
+ */
+ public void registryChanged(IRegistryChangeEvent event) {
+
+ IExtensionDelta[] deltas = event.getExtensionDeltas(PLUGIN_ID,
+ EXT_TEMPLATE);
+
+ for (int i = 0; i < deltas.length; i++) {
+
+ if (deltas[i].getKind() == IExtensionDelta.ADDED) {
+
+ IConfigurationElement[] elements = deltas[i].getExtension()
+ .getConfigurationElements();
+
+ for (IConfigurationElement element : elements) {
+ MIDletTemplateObject object = new MIDletTemplateObject(
+ element);
+ this.extensions.put(object.getName(), object);
+ }
+ } else {
+
+ IConfigurationElement[] elements = deltas[i].getExtension()
+ .getConfigurationElements();
+
+ for (IConfigurationElement element : elements) {
+ MIDletTemplateObject object = new MIDletTemplateObject(
+ element);
+ this.extensions.remove(object.getName());
+ }
+ }
+ }
+ }
+
+ // X implementation ----------------------------------------------
+
+ // Y overrides ---------------------------------------------------
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+}