diff options
Diffstat (limited to 'tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/loader/impl')
4 files changed, 0 insertions, 479 deletions
diff --git a/tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/loader/impl/JNDIPropertyFactory.java b/tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/loader/impl/JNDIPropertyFactory.java deleted file mode 100644 index 763c88295c..0000000000 --- a/tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/loader/impl/JNDIPropertyFactory.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * - * Copyright 2006 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.tuscany.core.loader.impl; - -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamException; -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; - -import org.apache.tuscany.core.loader.StAXPropertyFactory; -import org.apache.tuscany.core.builder.ObjectFactory; -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.core.injection.JNDIObjectFactory; -import org.apache.tuscany.model.assembly.Property; - -/** - * A StAXPropertyFactory that creates property values by looking them - * up in the default JNDI InitialContext. - * - * This can be used to locate resources in a J2EE environment and inject - * them as configuration properties. For example, to access a database - * a component could write: - * <code> - * &at;Property DataSource myDB; - * </code> - * and configure with - * <code> - * <properties> - * <v:myDb>java:comp/env/jdbc/MyDatabase</v:myDB> - * </properties> - * </code> - * - * @version $Rev$ $Date$ - */ -public class JNDIPropertyFactory implements StAXPropertyFactory { - public ObjectFactory<?> createObjectFactory(XMLStreamReader reader, Property property) throws XMLStreamException, ConfigurationLoadException { - Class<?> type = property.getType(); - assert type != null : "property type is null"; - String text = reader.getElementText(); - try { - Context context = new InitialContext(); - return new JNDIObjectFactory(context, text); - } catch (NamingException e) { - throw new ConfigurationLoadException(e); - } - } -} diff --git a/tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/loader/impl/StAXLoaderRegistryImpl.java b/tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/loader/impl/StAXLoaderRegistryImpl.java deleted file mode 100644 index 1e9e8ec8fb..0000000000 --- a/tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/loader/impl/StAXLoaderRegistryImpl.java +++ /dev/null @@ -1,105 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.tuscany.core.loader.impl; - -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.core.loader.StAXElementLoader; -import org.apache.tuscany.core.loader.StAXLoaderRegistry; -import org.apache.tuscany.core.loader.LoaderContext; -import org.apache.tuscany.model.assembly.AssemblyContext; -import org.apache.tuscany.model.assembly.AssemblyObject; -import org.osoa.sca.annotations.Scope; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import java.util.HashMap; -import java.util.Map; - -/** - * @version $Rev$ $Date$ - */ -@Scope("MODULE") -public class StAXLoaderRegistryImpl implements StAXLoaderRegistry { - private final Map<QName, StAXElementLoader<? extends AssemblyObject>> loaders = new HashMap<QName, StAXElementLoader<? extends AssemblyObject>>(); - - private Monitor monitor; - - @org.apache.tuscany.core.system.annotation.Monitor - public void setMonitor(Monitor monitor) { - this.monitor = monitor; - } - - public <T extends AssemblyObject> void registerLoader(QName element, StAXElementLoader<T> loader) { - monitor.registeringLoader(element); - loaders.put(element, loader); - } - - public <T extends AssemblyObject> void unregisterLoader(QName element, StAXElementLoader<T> loader) { - monitor.unregisteringLoader(element); - loaders.remove(element); - } - - public AssemblyObject load(XMLStreamReader reader, LoaderContext loaderContext) throws XMLStreamException, ConfigurationLoadException { - QName name = reader.getName(); - monitor.elementLoad(name); - StAXElementLoader<? extends AssemblyObject> loader = loaders.get(name); - if (loader == null) { - ConfigurationLoadException e = new ConfigurationLoadException("Unrecognized element"); - e.setIdentifier(name.toString()); - throw e; - } else { - return loader.load(reader, loaderContext); - } - } - - - private final ThreadLocal<AssemblyContext> modelContext = new ThreadLocal<AssemblyContext>(); - - @Deprecated - public AssemblyContext getContext() { - return modelContext.get(); - } - - @Deprecated - public void setContext(AssemblyContext context) { - modelContext.set(context); - } - - public static interface Monitor { - /** - * Event emitted when a StAX element loader is registered. - * - * @param xmlType the QName of the element the loader will handle - */ - void registeringLoader(QName xmlType); - - /** - * Event emitted when a StAX element loader is unregistered. - * - * @param xmlType the QName of the element the loader will handle - */ - void unregisteringLoader(QName xmlType); - - /** - * Event emitted when a request is made to load an element. - * - * @param xmlType the QName of the element that should be loaded - */ - void elementLoad(QName xmlType); - } -} diff --git a/tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/loader/impl/StringParserPropertyFactory.java b/tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/loader/impl/StringParserPropertyFactory.java deleted file mode 100644 index 2ed33f895c..0000000000 --- a/tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/loader/impl/StringParserPropertyFactory.java +++ /dev/null @@ -1,110 +0,0 @@ -/** - * - * Copyright 2006 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.tuscany.core.loader.impl; - -import org.apache.tuscany.core.builder.ObjectFactory; -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.core.injection.SingletonObjectFactory; -import org.apache.tuscany.core.loader.StAXPropertyFactory; -import org.apache.tuscany.model.assembly.Property; - -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import java.beans.PropertyEditor; -import java.beans.PropertyEditorManager; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; - -import org.osoa.sca.annotations.Scope; -import org.osoa.sca.annotations.Service; - -/** - * @version $Rev$ $Date$ - */ -@Scope("MODULE") -@Service(interfaces = {StAXPropertyFactory.class}) -public class StringParserPropertyFactory implements StAXPropertyFactory { - public ObjectFactory<?> createObjectFactory(XMLStreamReader reader, Property property) throws XMLStreamException, ConfigurationLoadException { - Class<?> type = property.getType(); - assert type != null : "property type is null"; - String text = reader.getElementText(); - - // degenerate case where we are returning a String - if (String.class.equals(type)) { - return new SingletonObjectFactory(text); - } - - // special handler to convert hexBinary to a byte[] - if (byte[].class.equals(type)) { - byte[] instance = new byte[text.length() >> 1]; - for (int i = 0; i < instance.length; i++) { - instance[i] = (byte) (Character.digit(text.charAt(i << 1), 16) << 4 | Character.digit(text.charAt((i << 1) + 1), 16)); - } - return new SingletonObjectFactory(instance); - } - - // does this type have a static valueOf(String) method? - try { - Method valueOf = type.getMethod("valueOf", String.class); - if (Modifier.isStatic(valueOf.getModifiers())) { - try { - return new SingletonObjectFactory(valueOf.invoke(null, text)); - } catch (IllegalAccessException e) { - throw new AssertionError("getMethod returned an inaccessible method"); - } catch (InvocationTargetException e) { - // FIXME we should throw something better - throw new ConfigurationLoadException(e.getCause()); - } - } - } catch (NoSuchMethodException e) { - // try something else - } - - // does this type have a constructor that takes a String? - try { - Constructor<?> ctr = type.getConstructor(String.class); - return new SingletonObjectFactory(ctr.newInstance(text)); - } catch (NoSuchMethodException e) { - // try something else - } catch (IllegalAccessException e) { - throw new AssertionError("getConstructor returned an inaccessible method"); - } catch (InstantiationException e) { - throw new ConfigurationLoadException("Property type cannot be instantiated: " + type.getName()); - } catch (InvocationTargetException e) { - // FIXME we should throw something better - throw new ConfigurationLoadException(e.getCause()); - } - - // do we have a property editor for it? - PropertyEditor editor = PropertyEditorManager.findEditor(type); - if (editor != null) { - try { - editor.setAsText(text); - return new SingletonObjectFactory(editor.getValue()); - } catch (IllegalArgumentException e) { - // FIXME we should throw something better - throw new ConfigurationLoadException(e); - - } - } - - // FIXME we should throw something better - throw new ConfigurationLoadException("Do not have a way to parse a String into a " + type.getName()); - } -} diff --git a/tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/loader/impl/WSDLDefinitionRegistryImpl.java b/tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/loader/impl/WSDLDefinitionRegistryImpl.java deleted file mode 100644 index 1063dec3fc..0000000000 --- a/tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/loader/impl/WSDLDefinitionRegistryImpl.java +++ /dev/null @@ -1,202 +0,0 @@ -/** - * - * Copyright 2006 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.tuscany.core.loader.impl; - -import java.io.IOException; -import java.net.URL; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.WeakHashMap; - -import javax.wsdl.Definition; -import javax.wsdl.PortType; -import javax.wsdl.Service; -import javax.wsdl.WSDLException; -import javax.wsdl.extensions.ExtensionRegistry; -import javax.wsdl.factory.WSDLFactory; -import javax.wsdl.xml.WSDLReader; -import javax.xml.namespace.QName; - -import org.apache.tuscany.common.resource.ResourceLoader; -import org.apache.tuscany.core.loader.WSDLDefinitionRegistry; -import org.osoa.sca.annotations.Scope; - -/** - * @version $Rev$ $Date$ - */ -@org.osoa.sca.annotations.Service(interfaces = {WSDLDefinitionRegistry.class}) -@Scope("MODULE") -public class WSDLDefinitionRegistryImpl implements WSDLDefinitionRegistry { - private final WSDLFactory wsdlFactory; - private final ExtensionRegistry registry; - - private final Map<ResourceLoader,Map<URL, Definition>> definitionsByLocationByLoader = new WeakHashMap<ResourceLoader,Map<URL, Definition>>(); - private final Map<ResourceLoader,Map<String, List<Definition>>> definitionsByNamespaceByLoader = new WeakHashMap<ResourceLoader,Map<String, List<Definition>>>(); - - private Monitor monitor; - - public WSDLDefinitionRegistryImpl() throws WSDLException { - wsdlFactory = WSDLFactory.newInstance(); - registry = wsdlFactory.newPopulatedExtensionRegistry(); - } - - @org.apache.tuscany.core.system.annotation.Monitor - public void setMonitor(Monitor monitor) { - this.monitor = monitor; - } - - public ExtensionRegistry getExtensionRegistry() { - return registry; - } - - public Definition loadDefinition(String wsdlLocation, ResourceLoader resourceLoader) throws IOException, WSDLException { - int index = wsdlLocation.indexOf(' '); - if (index == -1) { - throw new WSDLException(WSDLException.CONFIGURATION_ERROR, "Invalid wsdlLocation: " + wsdlLocation); - } - String namespace = wsdlLocation.substring(0, index).trim(); - URL url; - URI uri; - try { - uri = new URI(wsdlLocation.substring(index + 1).trim()); - } catch (URISyntaxException e) { - throw new WSDLException(WSDLException.CONFIGURATION_ERROR, "Invalid wsdlLocation: " + wsdlLocation); - } - if (uri.isAbsolute()) { - url = uri.toURL(); - } else { - url = resourceLoader.getResource(uri.toString()); - if (url == null) { - throw new WSDLException(WSDLException.CONFIGURATION_ERROR, "Resource not found: " + uri); - } - } - return loadDefinition(namespace, url, resourceLoader); - } - - public Definition loadDefinition(String namespace, URL location, ResourceLoader resourceLoader) throws IOException, WSDLException { - Map<URL, Definition> definitionsByLocation = getDefinitionsByLocation(resourceLoader); - Map<String, List<Definition>> definitionsByNamespace = getDefinitionsByNamespace(resourceLoader); - - Definition definition = definitionsByLocation.get(location); - if (definition != null) { - // return cached copy - return definition; - } - - monitor.readingWSDL(namespace, location); - WSDLReader reader = wsdlFactory.newWSDLReader(); - reader.setFeature("javax.wsdl.verbose", false); - reader.setExtensionRegistry(registry); - - definition = reader.readWSDL(location.toString()); - String definitionNamespace = definition.getTargetNamespace(); - if (namespace != null && !namespace.equals(definitionNamespace)) { - throw new WSDLException(WSDLException.CONFIGURATION_ERROR, namespace + " != " + definition.getTargetNamespace()); - } - - monitor.cachingDefinition(definitionNamespace, location); - definitionsByLocation.put(location, definition); - List<Definition> definitions = definitionsByNamespace.get(definitionNamespace); - if (definitions == null) { - definitions = new ArrayList<Definition>(); - definitionsByNamespace.put(definitionNamespace, definitions); - } - definitions.add(definition); - - return definition; - } - - public List<Definition> getDefinitionsForNamespace(String namespace, ResourceLoader resourceLoader) { - Map<String, List<Definition>> definitionsByNamespace = getDefinitionsByNamespace(resourceLoader); - return definitionsByNamespace.get(namespace); - } - - public PortType getPortType(QName name, ResourceLoader resourceLoader) { - Map<String, List<Definition>> definitionsByNamespace = getDefinitionsByNamespace(resourceLoader); - String namespace = name.getNamespaceURI(); - List<Definition> definitions = definitionsByNamespace.get(namespace); - if (definitions == null) { - return null; - } - for (Definition definition : definitions) { - PortType portType = definition.getPortType(name); - if (portType != null) { - return portType; - } - } - return null; - } - - public Service getService(QName name, ResourceLoader resourceLoader) { - Map<String, List<Definition>> definitionsByNamespace = getDefinitionsByNamespace(resourceLoader); - String namespace = name.getNamespaceURI(); - List<Definition> definitions = definitionsByNamespace.get(namespace); - if (definitions == null) { - return null; - } - for (Definition definition : definitions) { - Service service = definition.getService(name); - if (service != null) { - return service; - } - } - return null; - } - - private Map<String, List<Definition>> getDefinitionsByNamespace(ResourceLoader resourceLoader) { - Map<String, List<Definition>> map = definitionsByNamespaceByLoader.get(resourceLoader); - if (map == null) { - map = new HashMap<String, List<Definition>>(); - definitionsByNamespaceByLoader.put(resourceLoader, map); - } - return map; - } - - private Map<URL, Definition> getDefinitionsByLocation(ResourceLoader resourceLoader) { - Map<URL, Definition> map = definitionsByLocationByLoader.get(resourceLoader); - if (map == null) { - map = new HashMap<URL, Definition>(); - definitionsByLocationByLoader.put(resourceLoader, map); - } - return map; - } - - public static interface Monitor { - /** - * Monitor event emitted immediately before an attempt is made to - * read WSDL for the supplied namespace from the supplied location. - * - * @param namespace the target namespace expected in the WSDL; may be null - * @param location the location where we will attempt to read the WSDL definition from - */ - void readingWSDL(String namespace, URL location); - - /** - * Monitor event emitted immediately before registering a WSDL definition - * in the cache. - * - * @param namespace the target namespace for the WSDL - * @param location the location where the WSDL definition was read from - */ - void cachingDefinition(String namespace, URL location); - } - -} |