[144023] JS classpath improvements.
diff --git a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/ComponentCore.java b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/ComponentCore.java
index 243e84b..ba2b4b4 100644
--- a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/ComponentCore.java
+++ b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/ComponentCore.java
@@ -22,11 +22,11 @@
import org.eclipse.wst.common.componentcore.internal.StructureEdit;
import org.eclipse.wst.common.componentcore.internal.impl.ResourceTreeNode;
import org.eclipse.wst.common.componentcore.internal.resources.VirtualArchiveComponent;
-import org.eclipse.wst.common.componentcore.internal.resources.VirtualComponent;
import org.eclipse.wst.common.componentcore.internal.resources.VirtualFile;
import org.eclipse.wst.common.componentcore.internal.resources.VirtualFolder;
import org.eclipse.wst.common.componentcore.internal.resources.VirtualReference;
import org.eclipse.wst.common.componentcore.internal.resources.VirtualResource;
+import org.eclipse.wst.common.componentcore.internal.util.ComponentImplRegistryReader;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
import org.eclipse.wst.common.componentcore.resources.IVirtualContainer;
import org.eclipse.wst.common.componentcore.resources.IVirtualFile;
@@ -64,7 +64,7 @@
public static IVirtualComponent createComponent(IProject aProject) {
if (!ModuleCoreNature.isFlexibleProject(aProject))
return null;
- return new VirtualComponent(aProject, new Path("/")); //$NON-NLS-1$
+ return ComponentImplRegistryReader.instance().createComponent(aProject);
}
/**
diff --git a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/resources/VirtualComponent.java b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/resources/VirtualComponent.java
index 9d29fcf..3226de1 100644
--- a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/resources/VirtualComponent.java
+++ b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/resources/VirtualComponent.java
@@ -46,6 +46,9 @@
private int flag = 0;
+ protected VirtualComponent(){
+ }
+
public VirtualComponent(IProject aProject, IPath aRuntimePath) {
componentProject = aProject;
runtimePath = aRuntimePath;
diff --git a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/util/ComponentImplRegistryReader.java b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/util/ComponentImplRegistryReader.java
new file mode 100644
index 0000000..09d0c87
--- /dev/null
+++ b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/util/ComponentImplRegistryReader.java
@@ -0,0 +1,181 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2005 IBM 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.common.componentcore.internal.util;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.ISafeRunnable;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.SafeRunner;
+import org.eclipse.jem.util.RegistryReader;
+import org.eclipse.wst.common.componentcore.internal.ModulecorePlugin;
+import org.eclipse.wst.common.componentcore.internal.resources.VirtualComponent;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.IProjectFacet;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+
+public class ComponentImplRegistryReader extends RegistryReader {
+
+ private static final String COMPONENT_IMPL_EXTENSION_POINT = "componentimpl"; //$NON-NLS-1$
+ private static final String COMPONENT_IMPL = "componentimpl"; //$NON-NLS-1$
+ private static final String TYPE = "typeID"; //$NON-NLS-1$
+ private static final String CLASS = "class"; //$NON-NLS-1$
+
+ private static final ComponentImplRegistryReader instance = new ComponentImplRegistryReader();
+
+ private final Map/* <String, ComponentImplDescriptor> */descriptors = new HashMap();
+
+ private final Map/* <ArtifactEditDescriptor, IComponentImplFactory> */instances = new HashMap();
+
+ /**
+ * @return Returns the instance.
+ */
+ public static ComponentImplRegistryReader instance() {
+ /* already initialized and registry read by the time the class initializes */
+ return instance;
+ }
+
+ public ComponentImplRegistryReader() {
+ super(ModulecorePlugin.PLUGIN_ID, COMPONENT_IMPL_EXTENSION_POINT);
+ SafeRunner.run(new ISafeRunnable() {
+
+ public void handleException(Throwable exception) {
+ ModulecorePlugin.logError(0, exception.getMessage(), exception);
+ }
+
+ public void run() throws Exception {
+ readRegistry();
+ }
+
+ });
+ }
+
+ /**
+ * @see org.eclipse.wst.common.frameworks.internal.RegistryReader#readElement(org.eclipse.core.runtime.IConfigurationElement)
+ */
+ public boolean readElement(IConfigurationElement element) {
+ if (COMPONENT_IMPL.equals(element.getName())) {
+
+ /*
+ * Because the only instance of this type is created from a static singleton field, and
+ * the registry is initialized in the constructor of this type, other threads cannot
+ * compete with readElement() for access to <i>descriptors</i>
+ */
+ String type = element.getAttribute(TYPE);
+ if (type != null)
+ descriptors.put(element.getAttribute(TYPE), new ComponentImplDescriptor(element));
+ else
+ ModulecorePlugin.logError(0, "No type attribute is specified for " + //$NON-NLS-1$
+ ModulecorePlugin.PLUGIN_ID + "." + COMPONENT_IMPL_EXTENSION_POINT + //$NON-NLS-1$
+ " extension in " + element.getDeclaringExtension().getNamespaceIdentifier(), null); //$NON-NLS-1$
+ return true;
+ }
+ return false;
+ }
+
+ private synchronized IComponentImplFactory getComponentImplFactory(String typeID) {
+
+ ComponentImplDescriptor descriptor = (ComponentImplDescriptor) descriptors.get(typeID);
+ IComponentImplFactory factory = null;
+
+ if (descriptor != null) {
+
+ factory = (IComponentImplFactory) instances.get(descriptor);
+
+ if (factory == null) {
+
+ if ((factory = descriptor.createFactory()) != null) {
+ instances.put(descriptor, factory);
+ } else {
+ descriptors.remove(descriptor);
+ }
+ }
+ }
+ return factory;
+ }
+
+ // TODO Don't like this because it's going to cycle every project facet for each project
+ public IVirtualComponent createComponent(IProject project) {
+ try {
+ IFacetedProject facetedProject = ProjectFacetsManager.create(project);
+ Iterator keys = descriptors.keySet().iterator();
+ while (keys.hasNext()) {
+ String typeID = (String) keys.next();
+ try {
+ IProjectFacet projectFacet = ProjectFacetsManager.getProjectFacet(typeID);
+ if (projectFacet != null && facetedProject.hasProjectFacet(projectFacet)){
+ IComponentImplFactory factory = getComponentImplFactory(typeID);
+ if(null != factory){
+ return factory.createComponent(project);
+ }
+ }
+ } catch (Exception e) {
+ continue;
+ }
+ }
+ } catch (Exception e) {
+ // Just return a default component
+ }
+ return new VirtualComponent(project, new Path("/")); //$NON-NLS-1$
+ }
+
+ private class ComponentImplDescriptor {
+
+ private final IConfigurationElement element;
+ private final String type;
+
+ public ComponentImplDescriptor(IConfigurationElement configElement) {
+ element = configElement;
+ type = element.getAttribute(TYPE);
+ }
+
+ /**
+ * Create and return an {@link IArtifactEditFactory} for the given descriptor or <b>null</b>
+ * if there are problems instantiating the extension.
+ *
+ * @return An {@link IArtifactEditFactory} for the given descriptor or <b>null</b> if there
+ * are problems instantiating the extension.
+ */
+ public IComponentImplFactory createFactory() {
+
+ final IComponentImplFactory[] factory = new IComponentImplFactory[1];
+
+ SafeRunner.run(new ISafeRunnable() {
+
+ public void handleException(Throwable exception) {
+ ModulecorePlugin.logError(0, exception.getMessage(), exception);
+ }
+
+ public void run() throws Exception {
+ factory[0] = (IComponentImplFactory) element.createExecutableExtension(CLASS);
+ }
+
+ });
+
+ return factory[0];
+ }
+
+ /**
+ *
+ * @return The type id of this ArtifactEdit definition
+ */
+ public String getType() {
+ return type;
+ }
+
+ }
+
+}
diff --git a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/util/IComponentImplFactory.java b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/util/IComponentImplFactory.java
new file mode 100644
index 0000000..381f4d4
--- /dev/null
+++ b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/util/IComponentImplFactory.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2005 IBM 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.common.componentcore.internal.util;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+
+public interface IComponentImplFactory {
+
+ public IVirtualComponent createComponent(IProject project);
+
+}
diff --git a/plugins/org.eclipse.wst.common.modulecore/plugin.xml b/plugins/org.eclipse.wst.common.modulecore/plugin.xml
index dcd1dd0..80cfe70 100644
--- a/plugins/org.eclipse.wst.common.modulecore/plugin.xml
+++ b/plugins/org.eclipse.wst.common.modulecore/plugin.xml
@@ -50,6 +50,7 @@
</extension>
<extension-point id="ComponentProjectMigrator" name="ComponentProjectMigrator" schema="schema/ComponentProjectMigrator.exsd"/>
<extension-point id="artifactedit" name="Component Artifact Edit" schema="schema/artifactedit.exsd"/>
+ <extension-point id="componentimpl" name="componentimpl" schema="schema/componentimpl.exsd"/>
<!-- Contribute a URIResolverExtension for flexible projects -->
<extension point="org.eclipse.wst.common.uriresolver.resolverExtensions">
diff --git a/plugins/org.eclipse.wst.common.modulecore/schema/componentimpl.exsd b/plugins/org.eclipse.wst.common.modulecore/schema/componentimpl.exsd
new file mode 100644
index 0000000..2ec75cf
--- /dev/null
+++ b/plugins/org.eclipse.wst.common.modulecore/schema/componentimpl.exsd
@@ -0,0 +1,114 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.wst.common.modulecore">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.wst.common.modulecore" id="componentimpl" name="componentimpl"/>
+ </appInfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <complexType>
+ <sequence>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="componentimpl">
+ <complexType>
+ <attribute name="typeID" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="class" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ <simpleType>
+ <restriction base="string">
+ <enumeration value="instanceof IVirtualComponent">
+ </enumeration>
+ </restriction>
+ </simpleType>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+
+ </documentation>
+ </annotation>
+
+</schema>