Loading plugins/org.eclipse.sphinx.emf/schema/resourceHandlers.exsd +2 −1 Original line number Diff line number Diff line Loading @@ -6,7 +6,7 @@ <meta.schema plugin="org.eclipse.sphinx.emf" id="resourceHandlers" name="Resource Handlers"/> </appInfo> <documentation> [Enter description of this extension point.] All registered Resource Handlers will be called in undefined order. </documentation> </annotation> Loading Loading @@ -118,6 +118,7 @@ http://www.eclipse.org/legal/epl-v10.html Contributors: See4sys - Initial API and implementation Siemens - Use all applicable Resource Handlers, not just the first one </documentation> </annotation> Loading plugins/org.eclipse.sphinx.emf/src/org/eclipse/sphinx/emf/resource/ResourceHandlerRegistry.java +65 −4 Original line number Diff line number Diff line Loading @@ -10,18 +10,24 @@ * Contributors: * See4sys - Initial API and implementation * BMW Car IT - Added/Updated javadoc * Siemens - [577068] Call all registered resource handlers * * </copyright> */ package org.eclipse.sphinx.emf.resource; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.core.runtime.Platform; import org.eclipse.emf.ecore.xmi.XMLResource; import org.eclipse.emf.ecore.xmi.XMLResource.ResourceHandler; import org.eclipse.sphinx.emf.Activator; import org.eclipse.sphinx.platform.util.ExtendedPlatform; Loading Loading @@ -92,7 +98,9 @@ public class ResourceHandlerRegistry { } /** * Creates a ResourceHandler of the type registered for the given namespace URI. * Creates a ResourceHandler of the type registered for the given namespace URI. If there is more than one * applicable, then a {@link DelegatingResourceHandler} will be created and returned which will delegate all calls * to each handler. * * @param nsURI * The URI of the namespace for which a ResourceHandler is to be retrieved. Loading @@ -100,18 +108,28 @@ public class ResourceHandlerRegistry { * @see #addHandlerType(String, Class) */ public ResourceHandler getHandler(String nsURI) { List<ResourceHandler> resourceHandlers = new ArrayList<>(); for (ResourceHandlerDescriptor descriptor : getDescriptors()) { if (descriptor.isHandlerFor(nsURI)) { return descriptor.createResourceHandler(); ResourceHandler resourceHandlerInstance = descriptor.createResourceHandler(); if (resourceHandlerInstance != null) { resourceHandlers.add(resourceHandlerInstance); } } } if (resourceHandlers.isEmpty()) { return null; } if (resourceHandlers.size() == 1) { return resourceHandlers.get(0); } return new DelegatingResourceHandler(resourceHandlers); } /** * Registers a ResourceHandler type with namespaces. A ResourceHandle of the specified type will be created if * {@link #getHandler(String)} is called with a namespace URI matching the namespace URI pattern passed to this * method. * method. Note that, if there is more than one handler for the same namespace URI, then all of them will be used. * * @param nsURIPattern * A namespace URI pattern describing for which namespaces a ResourceHandler of the given type is to be Loading Loading @@ -165,4 +183,47 @@ public class ResourceHandlerRegistry { return nsURI.matches(nsURIPattern); } } public static class DelegatingResourceHandler implements ResourceHandler { private final List<ResourceHandler> resourceHandlers; public DelegatingResourceHandler(List<ResourceHandler> resourceHandlers) { this.resourceHandlers = Collections.unmodifiableList(resourceHandlers); } public List<ResourceHandler> getResourceHandlers() { return resourceHandlers; } @Override public void preLoad(XMLResource resource, InputStream inputStream, Map<?, ?> options) { for (ResourceHandler handler : resourceHandlers) { handler.preLoad(resource, inputStream, options); } } @Override public void postLoad(XMLResource resource, InputStream inputStream, Map<?, ?> options) { for (ResourceHandler handler : resourceHandlers) { handler.postLoad(resource, inputStream, options); } } @Override public void preSave(XMLResource resource, OutputStream outputStream, Map<?, ?> options) { for (ResourceHandler handler : resourceHandlers) { handler.preSave(resource, outputStream, options); } } @Override public void postSave(XMLResource resource, OutputStream outputStream, Map<?, ?> options) { for (ResourceHandler handler : resourceHandlers) { handler.postSave(resource, outputStream, options); } } } } tests/org.eclipse.sphinx.tests.emf/build.properties +2 −1 Original line number Diff line number Diff line Loading @@ -4,5 +4,6 @@ bin.includes = META-INF/,\ .,\ plugin.properties,\ resources/input/,\ about.html about.html,\ plugin.xml src.includes = about.html tests/org.eclipse.sphinx.tests.emf/plugin.xml 0 → 100644 +12 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.4"?> <plugin> <extension point="org.eclipse.sphinx.emf.resourceHandlers"> <handler class="org.eclipse.sphinx.tests.emf.resource.Hummingbird20ResourceHandler" nsURIPattern="http://www.eclipse.org/sphinx/examples/hummingbird/2\.0\.\d(/\w+)*"> </handler> </extension> </plugin> tests/org.eclipse.sphinx.tests.emf/src/org/eclipse/sphinx/tests/emf/resource/Hummingbird20ResourceHandler.java 0 → 100644 +67 −0 Original line number Diff line number Diff line /** * <copyright> * * Copyright (c) 2021 Siemens 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: * Siemens - Initial API and implementation * * </copyright> */ package org.eclipse.sphinx.tests.emf.resource; import java.io.InputStream; import java.io.OutputStream; import java.util.Map; import org.eclipse.emf.ecore.xmi.XMLResource; import org.eclipse.emf.ecore.xmi.XMLResource.ResourceHandler; public class Hummingbird20ResourceHandler implements ResourceHandler { private boolean isPreLoadCalled; private boolean isPostLoadCalled; private boolean isPreSaveCalled; private boolean isPostSaveCalled; public boolean isPreLoadCalled() { return isPreLoadCalled; } public boolean isPostLoadCalled() { return isPostLoadCalled; } public boolean isPreSaveCalled() { return isPreSaveCalled; } public boolean isPostSaveCalled() { return isPostSaveCalled; } @Override public void preLoad(XMLResource resource, InputStream inputStream, Map<?, ?> options) { isPreLoadCalled = true; } @Override public void postLoad(XMLResource resource, InputStream inputStream, Map<?, ?> options) { isPostLoadCalled = true; } @Override public void preSave(XMLResource resource, OutputStream outputStream, Map<?, ?> options) { isPreSaveCalled = true; } @Override public void postSave(XMLResource resource, OutputStream outputStream, Map<?, ?> options) { isPostSaveCalled = true; } } Loading
plugins/org.eclipse.sphinx.emf/schema/resourceHandlers.exsd +2 −1 Original line number Diff line number Diff line Loading @@ -6,7 +6,7 @@ <meta.schema plugin="org.eclipse.sphinx.emf" id="resourceHandlers" name="Resource Handlers"/> </appInfo> <documentation> [Enter description of this extension point.] All registered Resource Handlers will be called in undefined order. </documentation> </annotation> Loading Loading @@ -118,6 +118,7 @@ http://www.eclipse.org/legal/epl-v10.html Contributors: See4sys - Initial API and implementation Siemens - Use all applicable Resource Handlers, not just the first one </documentation> </annotation> Loading
plugins/org.eclipse.sphinx.emf/src/org/eclipse/sphinx/emf/resource/ResourceHandlerRegistry.java +65 −4 Original line number Diff line number Diff line Loading @@ -10,18 +10,24 @@ * Contributors: * See4sys - Initial API and implementation * BMW Car IT - Added/Updated javadoc * Siemens - [577068] Call all registered resource handlers * * </copyright> */ package org.eclipse.sphinx.emf.resource; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.core.runtime.Platform; import org.eclipse.emf.ecore.xmi.XMLResource; import org.eclipse.emf.ecore.xmi.XMLResource.ResourceHandler; import org.eclipse.sphinx.emf.Activator; import org.eclipse.sphinx.platform.util.ExtendedPlatform; Loading Loading @@ -92,7 +98,9 @@ public class ResourceHandlerRegistry { } /** * Creates a ResourceHandler of the type registered for the given namespace URI. * Creates a ResourceHandler of the type registered for the given namespace URI. If there is more than one * applicable, then a {@link DelegatingResourceHandler} will be created and returned which will delegate all calls * to each handler. * * @param nsURI * The URI of the namespace for which a ResourceHandler is to be retrieved. Loading @@ -100,18 +108,28 @@ public class ResourceHandlerRegistry { * @see #addHandlerType(String, Class) */ public ResourceHandler getHandler(String nsURI) { List<ResourceHandler> resourceHandlers = new ArrayList<>(); for (ResourceHandlerDescriptor descriptor : getDescriptors()) { if (descriptor.isHandlerFor(nsURI)) { return descriptor.createResourceHandler(); ResourceHandler resourceHandlerInstance = descriptor.createResourceHandler(); if (resourceHandlerInstance != null) { resourceHandlers.add(resourceHandlerInstance); } } } if (resourceHandlers.isEmpty()) { return null; } if (resourceHandlers.size() == 1) { return resourceHandlers.get(0); } return new DelegatingResourceHandler(resourceHandlers); } /** * Registers a ResourceHandler type with namespaces. A ResourceHandle of the specified type will be created if * {@link #getHandler(String)} is called with a namespace URI matching the namespace URI pattern passed to this * method. * method. Note that, if there is more than one handler for the same namespace URI, then all of them will be used. * * @param nsURIPattern * A namespace URI pattern describing for which namespaces a ResourceHandler of the given type is to be Loading Loading @@ -165,4 +183,47 @@ public class ResourceHandlerRegistry { return nsURI.matches(nsURIPattern); } } public static class DelegatingResourceHandler implements ResourceHandler { private final List<ResourceHandler> resourceHandlers; public DelegatingResourceHandler(List<ResourceHandler> resourceHandlers) { this.resourceHandlers = Collections.unmodifiableList(resourceHandlers); } public List<ResourceHandler> getResourceHandlers() { return resourceHandlers; } @Override public void preLoad(XMLResource resource, InputStream inputStream, Map<?, ?> options) { for (ResourceHandler handler : resourceHandlers) { handler.preLoad(resource, inputStream, options); } } @Override public void postLoad(XMLResource resource, InputStream inputStream, Map<?, ?> options) { for (ResourceHandler handler : resourceHandlers) { handler.postLoad(resource, inputStream, options); } } @Override public void preSave(XMLResource resource, OutputStream outputStream, Map<?, ?> options) { for (ResourceHandler handler : resourceHandlers) { handler.preSave(resource, outputStream, options); } } @Override public void postSave(XMLResource resource, OutputStream outputStream, Map<?, ?> options) { for (ResourceHandler handler : resourceHandlers) { handler.postSave(resource, outputStream, options); } } } }
tests/org.eclipse.sphinx.tests.emf/build.properties +2 −1 Original line number Diff line number Diff line Loading @@ -4,5 +4,6 @@ bin.includes = META-INF/,\ .,\ plugin.properties,\ resources/input/,\ about.html about.html,\ plugin.xml src.includes = about.html
tests/org.eclipse.sphinx.tests.emf/plugin.xml 0 → 100644 +12 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.4"?> <plugin> <extension point="org.eclipse.sphinx.emf.resourceHandlers"> <handler class="org.eclipse.sphinx.tests.emf.resource.Hummingbird20ResourceHandler" nsURIPattern="http://www.eclipse.org/sphinx/examples/hummingbird/2\.0\.\d(/\w+)*"> </handler> </extension> </plugin>
tests/org.eclipse.sphinx.tests.emf/src/org/eclipse/sphinx/tests/emf/resource/Hummingbird20ResourceHandler.java 0 → 100644 +67 −0 Original line number Diff line number Diff line /** * <copyright> * * Copyright (c) 2021 Siemens 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: * Siemens - Initial API and implementation * * </copyright> */ package org.eclipse.sphinx.tests.emf.resource; import java.io.InputStream; import java.io.OutputStream; import java.util.Map; import org.eclipse.emf.ecore.xmi.XMLResource; import org.eclipse.emf.ecore.xmi.XMLResource.ResourceHandler; public class Hummingbird20ResourceHandler implements ResourceHandler { private boolean isPreLoadCalled; private boolean isPostLoadCalled; private boolean isPreSaveCalled; private boolean isPostSaveCalled; public boolean isPreLoadCalled() { return isPreLoadCalled; } public boolean isPostLoadCalled() { return isPostLoadCalled; } public boolean isPreSaveCalled() { return isPreSaveCalled; } public boolean isPostSaveCalled() { return isPostSaveCalled; } @Override public void preLoad(XMLResource resource, InputStream inputStream, Map<?, ?> options) { isPreLoadCalled = true; } @Override public void postLoad(XMLResource resource, InputStream inputStream, Map<?, ?> options) { isPostLoadCalled = true; } @Override public void preSave(XMLResource resource, OutputStream outputStream, Map<?, ?> options) { isPreSaveCalled = true; } @Override public void postSave(XMLResource resource, OutputStream outputStream, Map<?, ?> options) { isPostSaveCalled = true; } }