Index: src/org/eclipse/bpel/model/resource/BPELResourceSetImpl.java =================================================================== --- src/org/eclipse/bpel/model/resource/BPELResourceSetImpl.java (revision 18174) +++ src/org/eclipse/bpel/model/resource/BPELResourceSetImpl.java (working copy) @@ -19,8 +19,6 @@ import org.eclipse.core.resources.IResourceChangeEvent; import org.eclipse.core.resources.IResourceChangeListener; import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.URIConverter; @@ -26,18 +24,16 @@ import org.eclipse.emf.ecore.resource.URIConverter; import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; - /** * @author Michal Chmielewski (michal.chmielewski@oracle.com) * @date Apr 17, 2007 - * + * */ - @SuppressWarnings("nls") +public class BPELResourceSetImpl extends ResourceSetImpl implements + IResourceChangeListener { -public class BPELResourceSetImpl extends ResourceSetImpl implements IResourceChangeListener { - public BPELResourceSetImpl() { super(); // FIX ME: This should not have dependency on running eclipse. @@ -42,7 +38,8 @@ super(); // FIX ME: This should not have dependency on running eclipse. // IWorkspace workspace = ResourcesPlugin.getWorkspace(); - // workspace.addResourceChangeListener(this, IResourceChangeEvent.POST_BUILD); + // workspace.addResourceChangeListener(this, + // IResourceChangeEvent.POST_BUILD); } /** @@ -49,28 +46,30 @@ * Used to force loading using the right resource loaders. */ static public final String SLIGHTLY_HACKED_KEY = "slightly.hacked.resource.set"; - - - + /** * Load the resource from the resource set, assuming that it is the kind - * indicated by the last argument. The "kind" parameter is the extension + * indicated by the last argument. The "kind" parameter is the extension * without the . of the resource. * - * This forces the right resource to be loaded even if the URI of the resource - * is "wrong". + * This forces the right resource to be loaded even if the URI of the + * resource is "wrong". * - * @param uri the URI of the resource. - * @param loadOnDemand load on demand - * @param kind the resource kind. It has to be of the form "*.wsdl", or "*.xsd", or "*.bpel" - * @return the loaded resource. + * @param uri + * the URI of the resource. + * @param loadOnDemand + * load on demand + * @param kind + * the resource kind. It has to be of the form "*.wsdl", or + * "*.xsd", or "*.bpel" + * @return the loaded resource. */ - + @SuppressWarnings("nls") - public Resource getResource(URI uri, boolean loadOnDemand, String kind) { + public Resource getResource(URI uri, boolean loadOnDemand, String kind) { Map map = getURIResourceMap(); - + if (map != null) { Resource resource = map.get(uri); if (resource != null) { @@ -77,7 +76,7 @@ if (loadOnDemand && !resource.isLoaded()) { demandLoadHelper(resource); } - + return resource; } } @@ -84,7 +83,7 @@ URIConverter theURIConverter = getURIConverter(); URI normalizedURI = theURIConverter.normalize(uri); - + for (Resource resource : getResources()) { if (theURIConverter.normalize(resource.getURI()).equals( normalizedURI)) { @@ -96,11 +95,17 @@ map.put(uri, resource); } return resource; - } + } } - + if (loadOnDemand) { - Resource resource = demandCreateResource(uri,kind); + Resource resource = null; + if (!uri.toString().endsWith("?wsdl")) { + resource = demandCreateResource(uri, kind); + } else { + resource = this.createResource(URI.createURI("*.wsdl")); + resource.setURI(uri); + } if (resource == null) { throw new RuntimeException("Cannot create a resource for '" + uri + "'; a registered resource factory is needed"); @@ -116,15 +121,14 @@ return null; } - - - protected Resource demandCreateResource ( URI uri, String kind ) { - return createResource ( uri, kind ); + + protected Resource demandCreateResource(URI uri, String kind) { + return createResource(uri, kind); } - - + /** * Create the resource based on the kind. + * * @param uri * @param kind * @return the created resource @@ -129,94 +133,96 @@ * @param kind * @return the created resource */ - - // TODO: ganymede [ this method apparently is already in the parent resource set ] + + // TODO: ganymede [ this method apparently is already in the parent resource + // set ] // we can strike it from this resourceset. - -// @SuppressWarnings("nls") -// public Resource createResource ( URI uri, String kind) { -// -// if (kind == null) { -// return super.createResource(uri); -// } -// -// Resource resource = createResource(URI.createURI("*." + kind)); -// resource.setURI(uri); -// return resource; -// } + // @SuppressWarnings("nls") + // public Resource createResource ( URI uri, String kind) { + // + // if (kind == null) { + // return super.createResource(uri); + // } + // + // Resource resource = createResource(URI.createURI("*." + kind)); + // resource.setURI(uri); + // return resource; + // } - - - - /** * @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent) */ - public void resourceChanged (IResourceChangeEvent event) { - - // System.out.println("IResourceChangeEvent: " + event + "; " + event.getType() ); - IResourceDelta[] deltas = event.getDelta().getAffectedChildren( IResourceDelta.CHANGED | IResourceDelta.REMOVED, IResource.FILE ); - processDeltas ( deltas ); + public void resourceChanged(IResourceChangeEvent event) { + + // System.out.println("IResourceChangeEvent: " + event + "; " + + // event.getType() ); + IResourceDelta[] deltas = event.getDelta() + .getAffectedChildren( + IResourceDelta.CHANGED | IResourceDelta.REMOVED, + IResource.FILE); + processDeltas(deltas); } - - void processDeltas ( IResourceDelta [] deltas ) { - - for(IResourceDelta delta : deltas) { - processDeltas( delta.getAffectedChildren(IResourceDelta.CHANGED | IResourceDelta.REMOVED, IResource.FILE) ); - + + void processDeltas(IResourceDelta[] deltas) { + + for (IResourceDelta delta : deltas) { + processDeltas(delta.getAffectedChildren(IResourceDelta.CHANGED + | IResourceDelta.REMOVED, IResource.FILE)); + IResource resource = delta.getResource(); - if (resource.getType () != IResource.FILE) { + if (resource.getType() != IResource.FILE) { continue; } - - if (delta.getKind() == IResourceDelta.REMOVED){ - resourceChanged((IFile)resource); + + if (delta.getKind() == IResourceDelta.REMOVED) { + resourceChanged((IFile) resource); continue; } - -// * @see IResourceDelta#CONTENT -// * @see IResourceDelta#DESCRIPTION -// * @see IResourceDelta#ENCODING -// * @see IResourceDelta#OPEN -// * @see IResourceDelta#MOVED_TO -// * @see IResourceDelta#MOVED_FROM -// * @see IResourceDelta#TYPE -// * @see IResourceDelta#SYNC -// * @see IResourceDelta#MARKERS -// * @see IResourceDelta#REPLACED - - if ((delta.getFlags() & IResourceDelta.CONTENT) == 0){ + + // * @see IResourceDelta#CONTENT + // * @see IResourceDelta#DESCRIPTION + // * @see IResourceDelta#ENCODING + // * @see IResourceDelta#OPEN + // * @see IResourceDelta#MOVED_TO + // * @see IResourceDelta#MOVED_FROM + // * @see IResourceDelta#TYPE + // * @see IResourceDelta#SYNC + // * @see IResourceDelta#MARKERS + // * @see IResourceDelta#REPLACED + + if ((delta.getFlags() & IResourceDelta.CONTENT) == 0) { continue; } - + // TODO: Temporary hack // Actually we should remove all resources from the resourceSet, // but for some reasons bpel files can't be removed now - if ("bpel".equals(((IFile) resource).getFileExtension())){ + if ("bpel".equals(((IFile) resource).getFileExtension())) { continue; } - + resourceChanged((IFile) resource); - } + } } - - public void setLoadOptions (Map options) { + + public void setLoadOptions(Map options) { loadOptions = options; } - + /** - * Resource has changed, remove it from the cache or list of loaded resources. + * Resource has changed, remove it from the cache or list of loaded + * resources. * * @param file */ - public void resourceChanged (IFile file) { - // System.out.println("ResourceChanged: " + file ); - URI uri = URI.createPlatformResourceURI( file.getFullPath().toString() ) ; - // System.out.println(" ResourceURI: " + uri ); + public void resourceChanged(IFile file) { + // System.out.println("ResourceChanged: " + file ); + URI uri = URI.createPlatformResourceURI(file.getFullPath().toString()); + // System.out.println(" ResourceURI: " + uri ); URIConverter theURIConverter = getURIConverter(); URI normalizedURI = theURIConverter.normalize(uri); - + if (uriResourceMap != null) { uriResourceMap.remove(uri); uriResourceMap.remove(normalizedURI); @@ -222,16 +228,16 @@ uriResourceMap.remove(normalizedURI); // System.out.println("Removed from Map: " + map ); } - + List resourceList = getResources(); if (resources.size() < 1) { - return ; + return; } - - for(Resource r : new ArrayList(resourceList) ) { - if (uri.equals(r.getURI()) || normalizedURI.equals(r.getURI() )) { + + for (Resource r : new ArrayList(resourceList)) { + if (uri.equals(r.getURI()) || normalizedURI.equals(r.getURI())) { resources.remove(r); - // System.out.println("Removed from List: " + r ); + // System.out.println("Removed from List: " + r ); } } }