Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 143229 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.xml (+12 lines)
Lines 102-105 Link Here
102
            helperClass="org.eclipse.jst.j2ee.internal.webservice.helper.WSDLServiceHelperImpl">
102
            helperClass="org.eclipse.jst.j2ee.internal.webservice.helper.WSDLServiceHelperImpl">
103
      </wsdlHelper>
103
      </wsdlHelper>
104
   </extension>
104
   </extension>
105
   <extension
106
         point="org.eclipse.wst.common.modulecore.resourceFactories">
107
      <resourceFactory
108
            class="org.eclipse.jst.j2ee.webservice.internal.wsdd.WsddResourceFactory"
109
            shortSegment="webservices.xml"/>
110
      <resourceFactory
111
            class="org.eclipse.jst.j2ee.webservice.internal.wsdd.WsddResourceFactory"
112
            shortSegment="webservices-temp.xml"/>
113
      <resourceFactory
114
            class="org.eclipse.jst.j2ee.webservice.wsclient.internal.impl.WebServicesClientResourceFactory"
115
            shortSegment="webservicesclient.xml"/> 
116
   </extension>
105
</plugin>
117
</plugin>
(-)webservice/org/eclipse/jst/j2ee/internal/webservice/plugin/WebServicePlugin.java (-2 lines)
Lines 206-213 Link Here
206
	 */
206
	 */
207
	public void start(BundleContext context) throws Exception {
207
	public void start(BundleContext context) throws Exception {
208
		super.start(context);
208
		super.start(context);
209
		WsddResourceFactory.register(WTPResourceFactoryRegistry.INSTANCE);
210
		WebServicesClientResourceFactory.register(WTPResourceFactoryRegistry.INSTANCE);
211
	}
209
	}
212
210
213
	/**
211
	/**
(-)ejb/org/eclipse/jst/j2ee/ejb/internal/plugin/EjbPlugin.java (-2 / +1 lines)
Lines 175-182 Link Here
175
	}
175
	}
176
176
177
	public void start(BundleContext context) throws Exception {
177
	public void start(BundleContext context) throws Exception {
178
		super.start(context);
178
		super.start(context); 
179
		EJBJarResourceFactory.register(WTPResourceFactoryRegistry.INSTANCE);
180
	}
179
	}
181
180
182
	public String getString(String key, boolean translate) {
181
	public String getString(String key, boolean translate) {
(-)j2eeplugin/org/eclipse/jst/j2ee/internal/plugin/J2EEPlugin.java (-3 / +1 lines)
Lines 492-500 Link Here
492
		IAdapterManager manager = Platform.getAdapterManager();
492
		IAdapterManager manager = Platform.getAdapterManager();
493
		manager.registerAdapters(new EarEditAdapterFactory(), ArtifactEditModel.class);
493
		manager.registerAdapters(new EarEditAdapterFactory(), ArtifactEditModel.class);
494
		manager.registerAdapters(new AppClientEditAdapterFactory(), ArtifactEditModel.class);
494
		manager.registerAdapters(new AppClientEditAdapterFactory(), ArtifactEditModel.class);
495
		ApplicationResourceFactory.register(WTPResourceFactoryRegistry.INSTANCE);
495
 		WSDLServiceExtensionRegistry.getInstance();
496
		ApplicationClientResourceFactory.register(WTPResourceFactoryRegistry.INSTANCE);
497
		WSDLServiceExtensionRegistry.getInstance();
498
		
496
		
499
		manager.registerAdapters(new VirtualArchiveComponentAdapterFactory(), VirtualArchiveComponent.class );
497
		manager.registerAdapters(new VirtualArchiveComponentAdapterFactory(), VirtualArchiveComponent.class );
500
		
498
		
(-)mofj2ee/org/eclipse/jst/j2ee/application/internal/impl/ApplicationResourceFactory.java (+9 lines)
Lines 37-42 Link Here
37
		J2EEXmlDtDEntityResolver.registerDtD(J2EEConstants.J2EE_1_4_XSD_SHORT_NAME, J2EEConstants.J2EE_1_4_XSD_SHORT_NAME); 
37
		J2EEXmlDtDEntityResolver.registerDtD(J2EEConstants.J2EE_1_4_XSD_SHORT_NAME, J2EEConstants.J2EE_1_4_XSD_SHORT_NAME); 
38
	}
38
	}
39
39
40
	
41
42
    /**
43
     * @param aRendererFactory
44
     */
45
    public ApplicationResourceFactory() {
46
        super(RendererFactory.getDefaultRendererFactory());
47
    }
48
	
40
    /**
49
    /**
41
     * @param aRendererFactory
50
     * @param aRendererFactory
42
     */
51
     */
(-)mofj2ee/org/eclipse/jst/j2ee/client/internal/impl/ApplicationClientResourceFactory.java (+7 lines)
Lines 38-43 Link Here
38
38
39
	/**
39
	/**
40
	 * Constructor for ApplicationClientResourceFactory.
40
	 * Constructor for ApplicationClientResourceFactory.
41
	 */
42
	public ApplicationClientResourceFactory() {
43
		super(RendererFactory.getDefaultRendererFactory());
44
	}
45
	
46
	/**
47
	 * Constructor for ApplicationClientResourceFactory.
41
	 * @param aRendererFactory
48
	 * @param aRendererFactory
42
	 */
49
	 */
43
	public ApplicationClientResourceFactory(RendererFactory aRendererFactory) {
50
	public ApplicationClientResourceFactory(RendererFactory aRendererFactory) {
(-)mofj2ee/org/eclipse/jst/j2ee/ejb/internal/impl/EJBJarResourceFactory.java (+6 lines)
Lines 39-44 Link Here
39
		J2EEXmlDtDEntityResolver.registerDtD(J2EEConstants.EJB_JAR_SCHEMA_LOC_2_1, "ejb-jar_2_1.xsd"); //$NON-NLS-1$
39
		J2EEXmlDtDEntityResolver.registerDtD(J2EEConstants.EJB_JAR_SCHEMA_LOC_2_1, "ejb-jar_2_1.xsd"); //$NON-NLS-1$
40
	}
40
	}
41
41
42
	/**  
43
	 */
44
	public EJBJarResourceFactory() {
45
		super(RendererFactory.getDefaultRendererFactory());
46
	}
47
42
	/**
48
	/**
43
	 * @param aRendererFactory
49
	 * @param aRendererFactory
44
	 */
50
	 */
(-)mofj2ee/org/eclipse/jst/j2ee/webapplication/internal/impl/WebAppResourceFactory.java (-3 / +11 lines)
Lines 48-58 Link Here
48
		J2EEXmlDtDEntityResolver.registerDtD(J2EEConstants.JSP_SCHEMA_LOC_2_0, "jsp_2_0.xsd"); //$NON-NLS-1$
48
		J2EEXmlDtDEntityResolver.registerDtD(J2EEConstants.JSP_SCHEMA_LOC_2_0, "jsp_2_0.xsd"); //$NON-NLS-1$
49
	}
49
	}
50
50
51
	/** 
52
	 */
53
	public WebAppResourceFactory() {
54
		super(RendererFactory.getDefaultRendererFactory()); 
55
	}
56
51
	/**
57
	/**
52
	 * @param aRendererFactory
58
	 * @param aRendererFactory
53
	 */
59
	 */
54
	public WebAppResourceFactory(RendererFactory aRendererFactory) {
60
	public WebAppResourceFactory(RendererFactory aRendererFactory) {
55
		super(aRendererFactory);
61
		super(aRendererFactory); 
56
	}
62
	}
57
63
58
	/* (non-Javadoc)
64
	/* (non-Javadoc)
Lines 65-71 Link Here
65
	/**
71
	/**
66
	 * Register myself with the Resource.Factory.Registry
72
	 * Register myself with the Resource.Factory.Registry
67
	 */
73
	 */
68
	public static void registerWith(RendererFactory aRendererFactory) {
74
	public static void registerWith(RendererFactory aRendererFactory) { 
69
		J2EEResourceFactoryRegistry.INSTANCE.registerLastFileSegment(J2EEConstants.WEBAPP_DD_SHORT_NAME, new WebAppResourceFactory(aRendererFactory));
75
		J2EEResourceFactoryRegistry.INSTANCE.registerLastFileSegment(J2EEConstants.WEBAPP_DD_SHORT_NAME, new WebAppResourceFactory(aRendererFactory));
70
	}
76
	}
71
	
77
	
Lines 81-91 Link Here
81
	 * register using the default renderer factory.
87
	 * register using the default renderer factory.
82
	 * @see #registerWith(RendererFactory)
88
	 * @see #registerWith(RendererFactory)
83
	 */
89
	 */
84
	public static void register(FileNameResourceFactoryRegistry aRegistry) {
90
	public static void register(FileNameResourceFactoryRegistry aRegistry) {		
85
		aRegistry.registerLastFileSegment(J2EEConstants.WEBAPP_DD_SHORT_NAME, new WebAppResourceFactory(RendererFactory.getDefaultRendererFactory()));
91
		aRegistry.registerLastFileSegment(J2EEConstants.WEBAPP_DD_SHORT_NAME, new WebAppResourceFactory(RendererFactory.getDefaultRendererFactory()));
86
	}
92
	}
87
	
93
	
88
	public static Resource.Factory getRegisteredFactory() {
94
	public static Resource.Factory getRegisteredFactory() {
95
96
		System.err.println("fetching registered factory for web app uri");
89
		return J2EEResourceFactoryRegistry.INSTANCE.getFactory(J2EEConstants.WEBAPP_DD_URI_OBJ);
97
		return J2EEResourceFactoryRegistry.INSTANCE.getFactory(J2EEConstants.WEBAPP_DD_URI_OBJ);
90
	}
98
	}
91
99
(-)plugin.xml (+20 lines)
Lines 164-168 Link Here
164
            class="org.eclipse.jst.j2ee.core.internal.validation.xmlerrorcustomization.J2EEErrorMessageCustomizer"
164
            class="org.eclipse.jst.j2ee.core.internal.validation.xmlerrorcustomization.J2EEErrorMessageCustomizer"
165
            namespace="http://java.sun.com/xml/ns/j2ee"/>
165
            namespace="http://java.sun.com/xml/ns/j2ee"/>
166
   </extension>
166
   </extension>
167
   
168
   
169
  <extension
170
        point="org.eclipse.wst.common.modulecore.resourceFactories">
171
     <resourceFactory
172
           class="org.eclipse.jst.j2ee.webapplication.internal.impl.WebAppResourceFactory"
173
           shortSegment="web.xml"/>
174
     <resourceFactory
175
           class="org.eclipse.jst.j2ee.ejb.internal.impl.EJBJarResourceFactory"
176
           shortSegment="ejb-jar.xml"/>
177
     <resourceFactory
178
           class="org.eclipse.jst.j2ee.client.internal.impl.ApplicationClientResourceFactory"
179
           shortSegment="application-client.xml"/>
180
     <resourceFactory
181
           class="org.eclipse.jst.j2ee.application.internal.impl.ApplicationResourceFactory"
182
           shortSegment="application.xml"/>
183
     <resourceFactory
184
           class="org.eclipse.jst.j2ee.jca.internal.impl.ConnectorResourceFactory"
185
           shortSegment="ra.xml"/>
186
  </extension>
167
187
168
</plugin>
188
</plugin>
(-)mofj2ee/org/eclipse/jst/j2ee/jca/internal/impl/ConnectorResourceFactory.java (+10 lines)
Lines 31-36 Link Here
31
		J2EEXmlDtDEntityResolver.registerDtD(J2EEConstants.CONNECTOR_ALT_SYSTEMID_1_0, "connector_1.0.dtd"); //$NON-NLS-1$
31
		J2EEXmlDtDEntityResolver.registerDtD(J2EEConstants.CONNECTOR_ALT_SYSTEMID_1_0, "connector_1.0.dtd"); //$NON-NLS-1$
32
		J2EEXmlDtDEntityResolver.registerDtD(J2EEConstants.CONNECTOR_SCHEMA_LOC_1_5, "connector_1_5.xsd"); //$NON-NLS-1$
32
		J2EEXmlDtDEntityResolver.registerDtD(J2EEConstants.CONNECTOR_SCHEMA_LOC_1_5, "connector_1_5.xsd"); //$NON-NLS-1$
33
	} 
33
	} 
34
	
35
36
	 
37
	/**
38
	 * Constructor for ConnectorResourceFactory.
39
	 * @param aRendererFactory
40
	 */
41
	public ConnectorResourceFactory() {
42
		super(RendererFactory.getDefaultRendererFactory());
43
	}
34
 
44
 
35
	/**
45
	/**
36
	 * Constructor for ConnectorResourceFactory.
46
	 * Constructor for ConnectorResourceFactory.
(-)mofj2ee/org/eclipse/jst/j2ee/webservice/internal/wsdd/WsddResourceFactory.java (+9 lines)
Lines 25-30 Link Here
25
25
26
public class WsddResourceFactory extends TranslatorResourceFactory
26
public class WsddResourceFactory extends TranslatorResourceFactory
27
{
27
{
28
	
29
	  /**
30
	  * WsddResourceFactory constructor comment.
31
	  */
32
	  public WsddResourceFactory() 
33
	  {
34
		  super(RendererFactory.getDefaultRendererFactory());
35
	  }
36
	
28
  /**
37
  /**
29
  * WsddResourceFactory constructor comment.
38
  * WsddResourceFactory constructor comment.
30
  */
39
  */
(-)mofj2ee/org/eclipse/jst/j2ee/webservice/wsclient/internal/impl/WebServicesClientResourceFactory.java (+8 lines)
Lines 30-35 Link Here
30
30
31
public class WebServicesClientResourceFactory
31
public class WebServicesClientResourceFactory
32
    extends TranslatorResourceFactory {
32
    extends TranslatorResourceFactory {
33
	
34
	/**
35
     * @param aRendererFactory
36
     */
37
    public WebServicesClientResourceFactory() {
38
        super(RendererFactory.getDefaultRendererFactory());
39
    }
40
	
33
		/**
41
		/**
34
		 * Method registerDtds.
42
		 * Method registerDtds.
35
		 */
43
		 */
(-)wtpemf/org/eclipse/wst/common/internal/emf/resource/FileNameResourceFactoryRegistry.java (-40 / +40 lines)
Lines 9-15 Link Here
9
package org.eclipse.wst.common.internal.emf.resource;
9
package org.eclipse.wst.common.internal.emf.resource;
10
10
11
import java.util.ArrayList;
11
import java.util.ArrayList;
12
import java.util.HashMap;
12
import java.util.List;
13
import java.util.List;
14
import java.util.Map;
13
15
14
import org.eclipse.emf.common.util.URI;
16
import org.eclipse.emf.common.util.URI;
15
import org.eclipse.emf.ecore.resource.Resource;
17
import org.eclipse.emf.ecore.resource.Resource;
Lines 18-28 Link Here
18
20
19
21
20
public abstract class FileNameResourceFactoryRegistry extends DefaultOverridableResourceFactoryRegistry {
22
public abstract class FileNameResourceFactoryRegistry extends DefaultOverridableResourceFactoryRegistry {
21
	//We are using two lists instead of a Map because we need to iterate
22
	//the list of simpleFileNames quite a lot.
23
	protected List simpleFileNames;
24
	protected List simpleFileNameFactories;
25
23
24
	private Map/*<String shortName, ResourceFactoryDescriptor>*/ descriptors = new HashMap(); 
25
	private Map/*<ResourceFactoryDescriptor, Resource.Factory>*/ factories = new HashMap();
26
	
26
	public FileNameResourceFactoryRegistry() {
27
	public FileNameResourceFactoryRegistry() {
27
		super();
28
		super();
28
	}
29
	}
Lines 33-90 Link Here
33
	 * @see org.eclipse.emf.ecore.resource.impl.ResourceFactoryRegistryImpl#getFactory(URI)
34
	 * @see org.eclipse.emf.ecore.resource.impl.ResourceFactoryRegistryImpl#getFactory(URI)
34
	 */
35
	 */
35
	protected Object getFileNameFactory(URI uri) {
36
	protected Object getFileNameFactory(URI uri) {
36
		if (simpleFileNames != null) {
37
37
			String fileName = uri.lastSegment();
38
		if(uri != null) {
38
			if (fileName != null) {
39
			ResourceFactoryDescriptor descriptor = getDescriptor(uri);
39
				String key;
40
			
40
				for (int i = 0; i < simpleFileNames.size(); i++) {
41
			if(descriptor != null) {
41
					key = (String) simpleFileNames.get(i);
42
				return getFactory(descriptor);	
42
					if (fileName.equals(key))
43
			}	
43
						return simpleFileNameFactories.get(i);
44
				}
45
			}
46
		}
44
		}
47
		return null;
45
		return null;
46
		
48
	}
47
	}
49
48
50
	public Resource.Factory getFactory(URI uri) {
49
	public synchronized Resource.Factory getFactory(URI uri) {
51
		Object resourceFactory = getFileNameFactory(uri);
50
52
		if (resourceFactory == null)
51
		Resource.Factory resourceFactory = null;
52
		if(uri != null && uri.lastSegment() != null) {
53
			ResourceFactoryDescriptor descriptor = getDescriptor(uri);
54
			
55
			if(descriptor != null) {
56
				resourceFactory = getFactory(descriptor);	
57
			}	
58
		}
59
		if(resourceFactory == null)
53
			resourceFactory = super.getFactory(uri);
60
			resourceFactory = super.getFactory(uri);
54
		return (Resource.Factory) resourceFactory;
61
		return resourceFactory; 
55
	}
62
	}
56
63
57
	/**
64
	/**
58
	 * Register a file name representing the last segment of a URI with the corresponding
65
	 * Register a file name representing the last segment of a URI with the corresponding
59
	 * Resource.Factory.
66
	 * Resource.Factory.
60
	 */
67
	 */
61
	public void registerLastFileSegment(String aSimpleFileName, Resource.Factory aFactory) {
68
	public synchronized void registerLastFileSegment(String aSimpleFileName, Resource.Factory aFactory) {
62
		URI uri = URI.createURI(aSimpleFileName);
69
		URI uri = URI.createURI(aSimpleFileName);
63
		String lastSegment = uri.lastSegment();
70
		String lastSegment = uri.lastSegment(); 
64
		int index = getFileNameIndexForAdd(lastSegment);
71
		addDescriptor(new StaticResourceFactoryDescriptor(lastSegment, aFactory));		
65
		setFileName(lastSegment, index);
72
	} 
66
		setFileNameFactory(aFactory, index);
73
74
	protected final synchronized ResourceFactoryDescriptor getDescriptor(URI uri) {
75
		return (ResourceFactoryDescriptor) descriptors.get(uri.lastSegment());
67
	}
76
	}
68
77
69
	private int getFileNameIndexForAdd(String aSimpleFileName) {
78
	protected final synchronized Resource.Factory getFactory(ResourceFactoryDescriptor descriptor) {  
70
		if (simpleFileNames != null) {
79
		Resource.Factory factory = (Factory) factories.get(descriptor);
71
			int i = simpleFileNames.indexOf(aSimpleFileName);
80
		if(factory == null) {
72
			if (i > -1)
81
			factories.put(descriptor, (factory = descriptor.createFactory()));
73
				return i;
74
			return simpleFileNames.size();
75
		}
82
		}
76
		return 0;
83
		return factory;
77
	}
78
79
	private void setFileNameFactory(Factory aFactory, int index) {
80
		if (simpleFileNameFactories == null)
81
			simpleFileNameFactories = new ArrayList();
82
		simpleFileNameFactories.add(index, aFactory);
83
	}
84
	}
84
85
85
	private void setFileName(String aSimpleFileName, int index) {
86
	protected final void addDescriptor(ResourceFactoryDescriptor descriptor) { 
86
		if (simpleFileNames == null)
87
		descriptors.put(descriptor.getShortSegment(), descriptor);
87
			simpleFileNames = new ArrayList();
88
		simpleFileNames.add(index, aSimpleFileName);
89
	}
88
	}
89
 
90
}
90
}
(-)META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 7-13 Link Here
7
Bundle-Vendor: %pluginProvider
7
Bundle-Vendor: %pluginProvider
8
Bundle-Localization: plugin
8
Bundle-Localization: plugin
9
Export-Package: org.eclipse.wst.common.internal.emf.plugin;x-internal:=true,
9
Export-Package: org.eclipse.wst.common.internal.emf.plugin;x-internal:=true,
10
 org.eclipse.wst.common.internal.emf.resource;x-internal:=true,
10
 org.eclipse.wst.common.internal.emf.resource;x-friends:="org.eclipse.wst.common.modulecore",
11
 org.eclipse.wst.common.internal.emf.utilities;x-internal:=true
11
 org.eclipse.wst.common.internal.emf.utilities;x-internal:=true
12
Require-Bundle: org.eclipse.emf.ecore.xmi,
12
Require-Bundle: org.eclipse.emf.ecore.xmi,
13
 org.eclipse.wst.common.frameworks,
13
 org.eclipse.wst.common.frameworks,
(-)wtpemf/org/eclipse/wst/common/internal/emf/resource/ResourceFactoryDescriptor.java (+60 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * IBM Corporation - initial API and implementation
10
 *******************************************************************************/ 
11
package org.eclipse.wst.common.internal.emf.resource;
12
13
import org.eclipse.emf.common.util.URI;
14
import org.eclipse.emf.ecore.resource.Resource;
15
16
public abstract class ResourceFactoryDescriptor {
17
	
18
	
19
	/**
20
	 * Returns true if the current descriptor is applicable to the given fileURI.
21
	 * 
22
	 * @param fileURI The URI of the file to be loaded
23
	 * @return True if the current descriptor declares a resource factory applicable to the given URI.
24
	 */
25
	public abstract boolean isEnabledFor(URI fileURI);
26
	
27
28
	/**
29
	 * The short segment is one possible way that a ResourceFactory
30
	 * might apply to a URI. Clients should call {@link isEnabledFor} 
31
	 * instead of comparing the short segments when searching for an
32
	 * applicable descriptor from a set.  
33
	 * 
34
	 * <p><b>Subclasses may NOT return null.</b></p>
35
	 *  
36
	 * @return The short segment that this descriptor is applicable to.
37
	 */
38
	public abstract String getShortSegment();
39
	
40
	
41
	/**
42
	 * The correct instance of Resource.Factory. The instance returned
43
	 * may or may not be unique, so if you require the same instance 
44
	 * for each call, you should cache the value returned the first
45
	 * time from this method. 
46
	 * 
47
	 * @return An instance of Resource.Factory.
48
	 */
49
	public abstract Resource.Factory createFactory();
50
	
51
	public int hashCode() {
52
		return getShortSegment().hashCode();
53
	}
54
	
55
	public boolean equals(Object o) {
56
		if(o instanceof ResourceFactoryDescriptor)
57
			return getShortSegment().equals(((ResourceFactoryDescriptor)o).getShortSegment());
58
		return false;
59
	}
60
}
(-)wtpemf/org/eclipse/wst/common/internal/emf/resource/StaticResourceFactoryDescriptor.java (+42 lines)
Added Link Here
1
package org.eclipse.wst.common.internal.emf.resource;
2
3
import org.eclipse.core.runtime.Assert;
4
import org.eclipse.emf.common.util.URI;
5
import org.eclipse.emf.ecore.resource.Resource;
6
7
/**
8
 * Declares a subclass to create Resource.Factory(ies) from an extension. 
9
 */
10
class StaticResourceFactoryDescriptor extends ResourceFactoryDescriptor {
11
	
12
	private final String shortSegment;
13
	private final Resource.Factory factory;
14
	
15
	/**
16
	 * 
17
	 * @param shortSegment A non-null name of the file associated with the given factory
18
	 * @param factory A non-null Resource.Factory that can load files of the given name
19
	 */
20
	public StaticResourceFactoryDescriptor(String shortSegment, Resource.Factory factory) {
21
		Assert.isNotNull(shortSegment);
22
		Assert.isNotNull(factory);
23
		this.shortSegment = shortSegment;
24
		this.factory = factory;
25
	}  
26
27
	public boolean isEnabledFor(URI fileURI) {
28
		/* shortSegment must be non-null for the descriptor to be created, 
29
		 * a validation check in init() verifies this requirement */
30
		if(fileURI != null && fileURI.lastSegment() != null)
31
			return shortSegment.equals(fileURI.lastSegment());
32
		return false;
33
	} 
34
	
35
	public Resource.Factory createFactory() {
36
		 return factory;			
37
	}
38
39
	public String getShortSegment() {
40
		return shortSegment;
41
	}  
42
}
(-)modulecore-src/org/eclipse/wst/common/componentcore/internal/impl/WTPResourceFactoryRegistry.java (+144 lines)
Lines 10-18 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.wst.common.componentcore.internal.impl;
11
package org.eclipse.wst.common.componentcore.internal.impl;
12
12
13
import org.eclipse.core.runtime.Assert;
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.IConfigurationElement;
16
import org.eclipse.core.runtime.ISafeRunnable;
17
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.Platform;
19
import org.eclipse.core.runtime.SafeRunner;
13
import org.eclipse.emf.common.util.URI;
20
import org.eclipse.emf.common.util.URI;
14
import org.eclipse.emf.ecore.resource.Resource;
21
import org.eclipse.emf.ecore.resource.Resource;
22
import org.eclipse.jem.util.RegistryReader;
23
import org.eclipse.wst.common.componentcore.internal.ModulecorePlugin;
15
import org.eclipse.wst.common.internal.emf.resource.FileNameResourceFactoryRegistry;
24
import org.eclipse.wst.common.internal.emf.resource.FileNameResourceFactoryRegistry;
25
import org.eclipse.wst.common.internal.emf.resource.ResourceFactoryDescriptor;
26
import org.eclipse.wst.common.internal.emf.utilities.DefaultOverridableResourceFactoryRegistry;
16
27
17
/**
28
/**
18
 * <p>
29
 * <p>
Lines 22-31 Link Here
22
public class WTPResourceFactoryRegistry extends FileNameResourceFactoryRegistry {
33
public class WTPResourceFactoryRegistry extends FileNameResourceFactoryRegistry {
23
34
24
	public static final WTPResourceFactoryRegistry INSTANCE = new WTPResourceFactoryRegistry();
35
	public static final WTPResourceFactoryRegistry INSTANCE = new WTPResourceFactoryRegistry();
36
	 
37
	private final static boolean LOG_WARNINGS = false;
38
	
39
	
40
	private WTPResourceFactoryRegistry() {
41
		new ResourceFactoryRegistryReader().readRegistry();
42
	}
25
	
43
	
26
	public Resource.Factory delegatedGetFactory(URI uri) {
44
	public Resource.Factory delegatedGetFactory(URI uri) {
27
		if (WTPResourceFactoryRegistry.INSTANCE == this)
45
		if (WTPResourceFactoryRegistry.INSTANCE == this)
28
			return super.delegatedGetFactory(uri);
46
			return super.delegatedGetFactory(uri);
29
		return WTPResourceFactoryRegistry.INSTANCE.getFactory(uri);	
47
		return WTPResourceFactoryRegistry.INSTANCE.getFactory(uri);	
48
	}   
49
50
	public synchronized Resource.Factory getFactory(URI uri) {
51
		
52
		Resource.Factory resourceFactory = null;
53
		if(uri != null && uri.lastSegment() != null) {
54
			ResourceFactoryDescriptor descriptor = getDescriptor(uri);
55
			
56
			if(descriptor != null) {
57
				resourceFactory = getFactory(descriptor);	
58
			}	
59
		}
60
		if(resourceFactory == null)
61
			resourceFactory = super.getFactory(uri);
62
		return resourceFactory; 
63
	}	
64
65
66
	/**
67
	 * Register a file name representing the last segment of a URI with the corresponding
68
	 * Resource.Factory.
69
	 */
70
	public synchronized void registerLastFileSegment(String aSimpleFileName, Resource.Factory aFactory) { 
71
		
72
		if(LOG_WARNINGS) {
73
			/* the third entry in the array is this stack frame, we walk back from there. */
74
			StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
75
			if(stackTrace.length > 4) {
76
				StringBuffer warningMessage = new StringBuffer("WTPResourceFactoryRegistry.registerLastFileSegment() was called explicitly from " + stackTrace[3]);
77
				warningMessage.append("\nThis happened around: \n");
78
				for (int i = 4; (i < stackTrace.length) && i < 8; i++) {
79
					warningMessage.append("\tnear ").append(stackTrace[i]).append('\n');
80
				}
81
				warningMessage.append(".\nClients should use the org.eclipse.wst.common.modulecore.resourceFactories extension point instead.");
82
				ModulecorePlugin.log(IStatus.INFO, 0, warningMessage.toString(), null);		
83
			}
84
		}
85
		
86
		super.registerLastFileSegment(aSimpleFileName, aFactory);
87
		
88
	}  
89
	
90
	/**
91
	 * Declares a subclass to create Resource.Factory(ies) from an extension. 
92
	 */
93
	private class ConfigurationResourceFactoryDescriptor extends ResourceFactoryDescriptor  implements IResourceFactoryExtPtConstants {
94
		
95
		private String shortSegment;
96
		private final IConfigurationElement element; 
97
		
98
		public ConfigurationResourceFactoryDescriptor(IConfigurationElement ext) throws CoreException {
99
			Assert.isNotNull(ext);
100
			element = ext;
101
			init();
102
		} 
103
		
104
		private void init() throws CoreException {
105
			shortSegment = element.getAttribute(ATT_SHORT_SEGMENT);
106
			if(shortSegment == null || shortSegment.trim().length() == 0)
107
				throw new CoreException(
108
							ModulecorePlugin.createErrorStatus(0, 
109
										"The shortSegment attribute of " + TAG_RESOURCE_FACTORY + //$NON-NLS-1$ 
110
										" must specify a valid, non-null, non-empty value in " +   //$NON-NLS-1$
111
										element.getNamespaceIdentifier(), null));
112
			
113
		} 
114
115
		public boolean isEnabledFor(URI fileURI) {
116
			/* shortSegment must be non-null for the descriptor to be created, 
117
			 * a validation check in init() verifies this requirement */
118
			if(fileURI != null && fileURI.lastSegment() != null)
119
				return shortSegment.equals(fileURI.lastSegment());
120
			return false;
121
		} 
122
		
123
		public Resource.Factory createFactory() {
124
			
125
			final Resource.Factory[] factory = new Resource.Factory[1];
126
			
127
			SafeRunner.run(new ISafeRunnable() {
128
				
129
				public void run() throws Exception {
130
					factory[0] = (Resource.Factory) element.createExecutableExtension(ATT_CLASS);					
131
				}
132
				
133
				public void handleException(Throwable exception) {
134
					ModulecorePlugin.log(ModulecorePlugin.createErrorStatus(0, exception.getMessage(), exception));					
135
				}
136
			});
137
			
138
			return factory[0] != null ? factory[0] : DefaultOverridableResourceFactoryRegistry.GLOBAL_FACTORY;
139
			
140
		}
141
142
		public String getShortSegment() {
143
			return shortSegment;
144
		}  
145
	}  
146
	 
147
	
148
	private class ResourceFactoryRegistryReader extends RegistryReader implements IResourceFactoryExtPtConstants { 
149
 		
150
		public ResourceFactoryRegistryReader() {
151
			super(Platform.getPluginRegistry(), ModulecorePlugin.PLUGIN_ID, EXTPT_RESOURCE_FACTORIES);
152
		}
153
154
		public boolean readElement(final IConfigurationElement element) {
155
			
156
			if(element != null && TAG_RESOURCE_FACTORY.equals(element.getName())) {
157
				final boolean[] success = new boolean[] { true }; 
158
				SafeRunner.run(new ISafeRunnable() {
159
					
160
					public void run() throws Exception {
161
						addDescriptor(new ConfigurationResourceFactoryDescriptor(element));
162
					} 
163
164
					public void handleException(Throwable exception) {
165
						ModulecorePlugin.log(ModulecorePlugin.createErrorStatus(0, exception.getMessage(), exception));
166
						success[0] = false;
167
					}
168
				});				
169
				return success[0];
170
			} else {
171
				return false;
172
			}	
173
		}
30
	}
174
	}
31
}
175
}
(-)plugin.xml (+1 lines)
Lines 50-55 Link Here
50
	</extension>
50
	</extension>
51
	<extension-point id="ComponentProjectMigrator" name="ComponentProjectMigrator" schema="schema/ComponentProjectMigrator.exsd"/>
51
	<extension-point id="ComponentProjectMigrator" name="ComponentProjectMigrator" schema="schema/ComponentProjectMigrator.exsd"/>
52
	<extension-point id="artifactedit" name="Component Artifact Edit" schema="schema/artifactedit.exsd"/>
52
	<extension-point id="artifactedit" name="Component Artifact Edit" schema="schema/artifactedit.exsd"/>
53
 <extension-point id="resourceFactories" name="Resource Factory Association (Internal)" schema="schema/resourceFactories.exsd"/>
53
	
54
	
54
	<!-- Contribute a URIResolverExtension for flexible projects -->
55
	<!-- Contribute a URIResolverExtension for flexible projects -->
55
	<extension point="org.eclipse.wst.common.uriresolver.resolverExtensions">
56
	<extension point="org.eclipse.wst.common.uriresolver.resolverExtensions">
(-)modulecore-src/org/eclipse/wst/common/componentcore/internal/impl/IResourceFactoryExtPtConstants.java (+25 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * IBM Corporation - initial API and implementation
10
 *******************************************************************************/ 
11
package org.eclipse.wst.common.componentcore.internal.impl;
12
13
public interface IResourceFactoryExtPtConstants {
14
	
15
16
	String EXTPT_RESOURCE_FACTORIES = "resourceFactories"; //$NON-NLS-1$
17
	
18
	String TAG_RESOURCE_FACTORY = "resourceFactory"; //$NON-NLS-1$
19
	
20
	String ATT_CLASS = "class"; //$NON-NLS-1$
21
	
22
	String ATT_SHORT_SEGMENT = "shortSegment"; //$NON-NLS-1$ 
23
		
24
25
}
(-)schema/resourceFactories.exsd (+117 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.wst.common.modulecore">
4
<annotation>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.wst.common.modulecore" id="resourceFactories" name="Resource Factory Association (Internal)"/>
7
      </appInfo>
8
      <documentation>
9
         An *internal* extension point that declares an association between a short-segment filename and a Resource.Factory.
10
      </documentation>
11
   </annotation>
12
13
   <element name="extension">
14
      <complexType>
15
         <sequence>
16
            <element ref="resourceFactory"/>
17
         </sequence>
18
         <attribute name="point" type="string" use="required">
19
            <annotation>
20
               <documentation>
21
                  
22
               </documentation>
23
            </annotation>
24
         </attribute>
25
         <attribute name="id" type="string">
26
            <annotation>
27
               <documentation>
28
                  
29
               </documentation>
30
            </annotation>
31
         </attribute>
32
         <attribute name="name" type="string">
33
            <annotation>
34
               <documentation>
35
                  
36
               </documentation>
37
               <appInfo>
38
                  <meta.attribute translatable="true"/>
39
               </appInfo>
40
            </annotation>
41
         </attribute>
42
      </complexType>
43
   </element>
44
45
   <element name="resourceFactory">
46
      <annotation>
47
         <documentation>
48
            Associates a short name (e.g. &quot;web.xml&quot;) with the appropriate Resource.Factory to create the Resource type when loading files of the declared shortname. 
49
         </documentation>
50
      </annotation>
51
      <complexType>
52
         <attribute name="class" type="string" use="required">
53
            <annotation>
54
               <documentation>
55
                  Declares an implementation of &lt;code&gt;org.eclipse.emf.ecore.resource.Resource.Factory&lt;/code&gt;.
56
               </documentation>
57
               <appInfo>
58
                  <meta.attribute kind="java" basedOn="org.eclipse.emf.ecore.resource.Resource.Factory"/>
59
               </appInfo>
60
            </annotation>
61
         </attribute>
62
         <attribute name="shortSegment" type="string" use="required">
63
            <annotation>
64
               <documentation>
65
                  Declares the short segment of a filename that the resource factory applies to (e.g. &quot;web.xml&quot;).
66
               </documentation>
67
            </annotation>
68
         </attribute>
69
      </complexType>
70
   </element>
71
72
   <annotation>
73
      <appInfo>
74
         <meta.section type="since"/>
75
      </appInfo>
76
      <documentation>
77
         [Enter the first release in which this extension point appears.]
78
      </documentation>
79
   </annotation>
80
81
   <annotation>
82
      <appInfo>
83
         <meta.section type="examples"/>
84
      </appInfo>
85
      <documentation>
86
         [Enter extension point usage example here.]
87
      </documentation>
88
   </annotation>
89
90
   <annotation>
91
      <appInfo>
92
         <meta.section type="apiInfo"/>
93
      </appInfo>
94
      <documentation>
95
         [Enter API information here.]
96
      </documentation>
97
   </annotation>
98
99
   <annotation>
100
      <appInfo>
101
         <meta.section type="implementation"/>
102
      </appInfo>
103
      <documentation>
104
         [Enter information about supplied implementation of this extension point.]
105
      </documentation>
106
   </annotation>
107
108
   <annotation>
109
      <appInfo>
110
         <meta.section type="copyright"/>
111
      </appInfo>
112
      <documentation>
113
         
114
      </documentation>
115
   </annotation>
116
117
</schema>
(-)web/org/eclipse/jst/j2ee/internal/web/plugin/WebPlugin.java (-1 / +1 lines)
Lines 262-268 Link Here
262
262
263
	public void start(BundleContext context) throws Exception {
263
	public void start(BundleContext context) throws Exception {
264
		super.start(context);
264
		super.start(context);
265
		WebAppResourceFactory.register(WTPResourceFactoryRegistry.INSTANCE);
265
		//WebAppResourceFactory.register(WTPResourceFactoryRegistry.INSTANCE);
266
		IAdapterManager manager = Platform.getAdapterManager();
266
		IAdapterManager manager = Platform.getAdapterManager();
267
		manager.registerAdapters(new WebEditAdapterFactory(), ArtifactEditModel.class);
267
		manager.registerAdapters(new WebEditAdapterFactory(), ArtifactEditModel.class);
268
	}
268
	}

Return to bug 143229