diff options
Diffstat (limited to 'tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection')
14 files changed, 0 insertions, 984 deletions
diff --git a/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ArrayMultiplicityObjectFactory.java b/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ArrayMultiplicityObjectFactory.java deleted file mode 100644 index 2513c63e38..0000000000 --- a/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ArrayMultiplicityObjectFactory.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.sca.implementation.java.injection; - -import java.lang.reflect.Array; -import java.util.List; - -import org.apache.tuscany.sca.core.factory.ObjectCreationException; -import org.apache.tuscany.sca.core.factory.ObjectFactory; - -/** - * Resolves targets configured in a multiplicity by delegating to object factories and returning an <code>Array</code> - * containing object instances - * - * @version $Rev$ $Date$ - */ -public class ArrayMultiplicityObjectFactory implements ObjectFactory<Object> { - - private ObjectFactory[] factories; - - private Class interfaceType; - - public ArrayMultiplicityObjectFactory(Class interfaceType, List<ObjectFactory<?>> factories) { - assert interfaceType != null : "Interface type was null"; - assert factories != null : "Object factories were null"; - this.interfaceType = interfaceType; - this.factories = factories.toArray(new ObjectFactory[factories.size()]); - } - - public Object getInstance() throws ObjectCreationException { - Object array = Array.newInstance(interfaceType, factories.length); - for (int i = 0; i < factories.length; i++) { - Array.set(array, i, factories[i].getInstance()); - } - return array; - } - -} diff --git a/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ContextInjector.java b/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ContextInjector.java deleted file mode 100644 index d8eef18c74..0000000000 --- a/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ContextInjector.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.sca.implementation.java.injection; - -import org.apache.tuscany.sca.core.factory.ObjectCreationException; - -/** - * Implementations inject a pre-configured context type (interface) on an instance. - * - * @version $Rev$ $Date$ - */ -public interface ContextInjector<S, T> extends Injector<T> { - - void setContext(S context) throws ObjectCreationException; - -} diff --git a/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/FieldInjector.java b/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/FieldInjector.java deleted file mode 100644 index dd454be7c5..0000000000 --- a/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/FieldInjector.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.sca.implementation.java.injection; - -import java.lang.reflect.Field; -import java.security.AccessController; -import java.security.PrivilegedAction; - -import org.apache.tuscany.sca.core.factory.ObjectCreationException; -import org.apache.tuscany.sca.core.factory.ObjectFactory; - -/** - * Injects a value created by an {@link org.apache.tuscany.sca.core.factory.ObjectFactory} on a given field - * - * @version $Rev$ $Date$ - */ -public class FieldInjector<T> implements Injector<T> { - - private final Field field; - - private final ObjectFactory<?> objectFactory; - - /** - * Create an injector and have it use the given <code>ObjectFactory</code> to inject a value on the instance using - * the reflected <code>Field</code> - */ - public FieldInjector(Field pField, ObjectFactory<?> objectFactory) { - field = pField; - // Allow privileged access to set accessibility. Requires ReflectPermission - // in security policy. - AccessController.doPrivileged(new PrivilegedAction<Object>() { - public Object run() { - field.setAccessible(true); // ignore Java accessibility - return null; - } - }); - - this.objectFactory = objectFactory; - } - - /** - * Inject a new value on the given instance - */ - public void inject(T instance) throws ObjectCreationException { - try { - field.set(instance, objectFactory.getInstance()); - } catch (IllegalAccessException e) { - throw new ObjectCreationException("Field is not accessible [" + field + "]", e); - } - } -} diff --git a/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/InjectionRuntimeException.java b/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/InjectionRuntimeException.java deleted file mode 100644 index fbc2ace341..0000000000 --- a/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/InjectionRuntimeException.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.sca.implementation.java.injection; - - -/** - * Root unchecked exception for the injection package - * - * @version $Rev$ $Date$ - */ -public abstract class InjectionRuntimeException extends RuntimeException { - private static final long serialVersionUID = -2264137603099898773L; - - public InjectionRuntimeException() { - super(); - } - - public InjectionRuntimeException(String message, Throwable cause) { - super(message, cause); - } - - public InjectionRuntimeException(String message) { - super(message); - } - - public InjectionRuntimeException(Throwable cause) { - super(cause); - } - -} diff --git a/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/Injector.java b/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/Injector.java deleted file mode 100644 index 4d062859b9..0000000000 --- a/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/Injector.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.sca.implementation.java.injection; - -import org.apache.tuscany.sca.core.factory.ObjectCreationException; - -/** - * Implementations inject a pre-configured value on an instance - * - * @version $Rev$ $Date$ - */ -public interface Injector<T> { - - /** - * Inject a value on the given instance - */ - void inject(T instance) throws ObjectCreationException; - -} diff --git a/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/InvalidAccessorException.java b/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/InvalidAccessorException.java deleted file mode 100644 index 5aeebcca36..0000000000 --- a/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/InvalidAccessorException.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.sca.implementation.java.injection; - -/** - * @version $Rev$ $Date$ - */ -public class InvalidAccessorException extends InjectionRuntimeException { - private static final long serialVersionUID = 9196299279363310978L; - - public InvalidAccessorException() { - super(); - } - - public InvalidAccessorException(String message, Throwable cause) { - super(message, cause); - } - - public InvalidAccessorException(String message) { - super(message); - } - - public InvalidAccessorException(Throwable cause) { - super(cause); - } - -} diff --git a/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java b/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java deleted file mode 100644 index 01c3b148f8..0000000000 --- a/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java +++ /dev/null @@ -1,327 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.sca.implementation.java.injection; - -import java.lang.reflect.Array; -import java.util.ArrayList; -import java.util.List; -import java.util.StringTokenizer; - -import org.apache.tuscany.sca.assembly.ComponentProperty; -import org.apache.tuscany.sca.assembly.Property; -import org.apache.tuscany.sca.common.xml.dom.DOMHelper; -import org.apache.tuscany.sca.context.PropertyValueFactory; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.UtilityExtensionPoint; -import org.apache.tuscany.sca.core.factory.ObjectCreationException; -import org.apache.tuscany.sca.core.factory.ObjectFactory; -import org.apache.tuscany.sca.databinding.Mediator; -import org.apache.tuscany.sca.databinding.SimpleTypeMapper; -import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl; -import org.apache.tuscany.sca.databinding.xml.DOMDataBinding; -import org.apache.tuscany.sca.implementation.java.JavaElementImpl; -import org.apache.tuscany.sca.implementation.java.introspect.JavaIntrospectionHelper; -import org.apache.tuscany.sca.interfacedef.DataType; -import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; -import org.apache.tuscany.sca.interfacedef.util.TypeInfo; -import org.apache.tuscany.sca.interfacedef.util.XMLType; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -/** - * - * @version $Rev$ $Date$ - */ -public class JavaPropertyValueObjectFactory implements PropertyValueFactory { - private Mediator mediator = null; - private SimpleTypeMapper simpleTypeMapper; - private boolean isSimpleType; - - public JavaPropertyValueObjectFactory(ExtensionPointRegistry registry) { - UtilityExtensionPoint utilityExtensionPoint = registry.getExtensionPoint(UtilityExtensionPoint.class); - this.mediator = utilityExtensionPoint.getUtility(Mediator.class); - this.simpleTypeMapper = utilityExtensionPoint.getUtility(SimpleTypeMapper.class); - } - - public JavaPropertyValueObjectFactory(Mediator mediator) { - this.mediator = mediator; - } - - /** - * Introspect the property - * @param javaElement - * @return - */ - private DataType<?> introspect(JavaElementImpl javaElement) { - DataType<XMLType> dt = - new DataTypeImpl<XMLType>(null, javaElement.getType(), javaElement.getGenericType(), XMLType.UNKNOWN); - mediator.getDataBindings().introspectType(dt, null); - return dt; - } - - public ObjectFactory createValueFactory(Property property, Object propertyValue, JavaElementImpl javaElement) { - Document doc = (Document)propertyValue; - List<Node> nodes = getValues(doc); - Class<?> javaType = JavaIntrospectionHelper.getBaseType(javaElement.getType(), javaElement.getGenericType()); - if (property.isMany()) { - if (javaElement.getType().isArray()) { - return new ArrayObjectFactoryImpl(property, nodes, javaType); - } else { - return new ListObjectFactoryImpl(property, nodes, javaType); - } - } else { - Object value = null; - if (!nodes.isEmpty()) { - value = nodes.get(0); - } - return new ObjectFactoryImpl(property, value, javaType); - - } - } - - public ObjectFactory createValueFactory(Property property, Object propertyValue, Class<?> javaType) { - Document doc = (Document)propertyValue; - List<Node> nodes = getValues(doc); - if (property.isMany()) { - return new ListObjectFactoryImpl(property, nodes, javaType); - } else { - Object value = null; - if (!nodes.isEmpty()) { - value = nodes.get(0); - } - return new ObjectFactoryImpl(property, value, javaType); - } - } - - public <B> B createPropertyValue(ComponentProperty property, Class<B> type) { - ObjectFactory<B> factory = this.createValueFactory(property, property.getValue(), type); - return factory.getInstance(); - } - - abstract class ObjectFactoryImplBase implements ObjectFactory { - protected SimpleTypeMapper simpleTypeMapper = new SimpleTypeMapperImpl(); - protected Property property; - protected Object propertyValue; - protected Class<?> javaType; - protected DataType<XMLType> sourceDataType; - protected DataType<?> targetDataType; - - public ObjectFactoryImplBase(Property property, Object propertyValue, Class<?> javaType) { - this.property = property; - this.propertyValue = propertyValue; - this.javaType = javaType; - sourceDataType = - new DataTypeImpl<XMLType>(DOMDataBinding.NAME, Node.class, - new XMLType(null, this.property.getXSDType())); - TypeInfo typeInfo = null; - if (this.property.getXSDType() != null) { - if (simpleTypeMapper.isSimpleXSDType(this.property.getXSDType())) { - typeInfo = new TypeInfo(property.getXSDType(), true, null); - } else { - typeInfo = new TypeInfo(property.getXSDType(), false, null); - } - } else { - typeInfo = new TypeInfo(property.getXSDType(), false, null); - } - - XMLType xmlType = new XMLType(typeInfo); - String dataBinding = null; // (String)property.getExtensions().get(DataBinding.class.getName()); - if (dataBinding != null) { - targetDataType = new DataTypeImpl<XMLType>(dataBinding, javaType, xmlType); - } else { - targetDataType = new DataTypeImpl<XMLType>(dataBinding, javaType, xmlType); - mediator.getDataBindings().introspectType(targetDataType, null); - } - } - } - - class ObjectFactoryImpl extends ObjectFactoryImplBase { - public ObjectFactoryImpl(Property property, Object propertyValue, Class<?> javaType) { - super(property, propertyValue, javaType); - } - - public Object getInstance() throws ObjectCreationException { - if (isSimpleType) { - try { - return simpleTypeMapper.toJavaObject(property.getXSDType(), (String)propertyValue, null); - } catch (NumberFormatException ex) { - throw new ObjectCreationException("Failed to create instance for property " + property.getName() - + " with value " - + propertyValue, ex); - } catch (IllegalArgumentException ex) { - throw new ObjectCreationException("Failed to create instance for property " + property.getName() - + " with value " - + propertyValue, ex); - } - } else { - return mediator.mediate(propertyValue, sourceDataType, targetDataType, null); - // return null; - } - } - } - - class ListObjectFactoryImpl extends ObjectFactoryImplBase { - public ListObjectFactoryImpl(Property property, List<?> propertyValues, Class<?> javaType) { - super(property, propertyValues, javaType); - } - - @SuppressWarnings("unchecked") - public List<?> getInstance() throws ObjectCreationException { - if (isSimpleType) { - List<Object> values = new ArrayList<Object>(); - for (String aValue : (List<String>)propertyValue) { - try { - values.add(simpleTypeMapper.toJavaObject(property.getXSDType(), aValue, null)); - } catch (NumberFormatException ex) { - throw new ObjectCreationException("Failed to create instance for property " + property - .getName() - + " with value " - + aValue - + " from value list of " - + propertyValue, ex); - } catch (IllegalArgumentException ex) { - throw new ObjectCreationException("Failed to create instance for property " + property - .getName() - + " with value " - + aValue - + " from value list of " - + propertyValue, ex); - } - } - return values; - } else { - List instances = new ArrayList(); - for (Node aValue : (List<Node>)propertyValue) { - instances.add(mediator.mediate(aValue, sourceDataType, targetDataType, null)); - } - return instances; - } - } - } - - class ArrayObjectFactoryImpl extends ObjectFactoryImplBase { - public ArrayObjectFactoryImpl(Property property, List<?> propertyValues, Class<?> javaType) { - super(property, propertyValues, javaType); - } - - @SuppressWarnings("unchecked") - public Object getInstance() throws ObjectCreationException { - if (isSimpleType) { - int count = 0; - Object values = Array.newInstance(javaType, ((List<Object>)propertyValue).size()); - for (String aValue : (List<String>)propertyValue) { - try { - Array.set(values, count++, simpleTypeMapper.toJavaObject(property.getXSDType(), aValue, null)); - } catch (NumberFormatException ex) { - throw new ObjectCreationException("Failed to create instance for property " + property - .getName() - + " with value " - + aValue - + " from value list of " - + propertyValue, ex); - } catch (IllegalArgumentException ex) { - throw new ObjectCreationException("Failed to create instance for property " + property - .getName() - + " with value " - + aValue - + " from value list of " - + propertyValue, ex); - } - } - return values; - } else { - Object instances = Array.newInstance(javaType, ((List<Object>)propertyValue).size()); - int count = 0; - for (Node aValue : (List<Node>)propertyValue) { - Array.set(instances, count++, mediator.mediate(aValue, sourceDataType, targetDataType, null)); - } - return instances; - } - } - } - - /** - * Utility methods - */ - - /** - * - * @param property - * @return - */ - private boolean isSimpleType(Property property) { - if (property.getXSDType() != null) { - return simpleTypeMapper.isSimpleXSDType(property.getXSDType()); - } else { - if (property instanceof Document) { - Document doc = (Document)property; - Element element = doc.getDocumentElement(); - if (element.getChildNodes().getLength() == 1 && element.getChildNodes().item(0).getNodeType() == Element.TEXT_NODE) { - return true; - } - } - } - return false; - } - - /** - * Retrieve list of simple property values - * @param concatenatedValue - * @param javaType - * @return - */ - private static List<String> getSimplePropertyValues(String concatenatedValue, Class<?> javaType) { - List<String> propValues = new ArrayList<String>(); - StringTokenizer st = null; - if (javaType.getName().equals("java.lang.String")) { - st = new StringTokenizer(concatenatedValue, "\""); - } else { - st = new StringTokenizer(concatenatedValue); - } - String aToken = null; - while (st.hasMoreTokens()) { - aToken = st.nextToken(); - if (aToken.trim().length() > 0) { - propValues.add(aToken); - } - } - return propValues; - } - - /** - * Retrieve the list of complex property values - * @param document - * @return - */ - private static List<Node> getValues(Document document) { - // The root is the property element - Element rootElement = document.getDocumentElement(); - List<Node> propValues = new ArrayList<Node>(); - NodeList nodes = rootElement.getChildNodes(); - for (int count = 0; count < nodes.getLength(); ++count) { - Node node = nodes.item(count); - if (node.getNodeType() == Document.ELEMENT_NODE) { - propValues.add(DOMHelper.promote(node)); - } - } - return propValues; - } -} diff --git a/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ListMultiplicityObjectFactory.java b/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ListMultiplicityObjectFactory.java deleted file mode 100644 index 2906897e96..0000000000 --- a/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ListMultiplicityObjectFactory.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.sca.implementation.java.injection; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.sca.core.factory.ObjectCreationException; -import org.apache.tuscany.sca.core.factory.ObjectFactory; - -/** - * Resolves targets configured in a multiplicity by delegating to object factories and returning an <code>List</code> - * containing object instances - * - * @version $Rev$ $Date$ - */ -public class ListMultiplicityObjectFactory implements ObjectFactory<List<?>> { - - private ObjectFactory[] factories; - - public ListMultiplicityObjectFactory(List<ObjectFactory<?>> factories) { - assert factories != null : "Object factories were null"; - this.factories = factories.toArray(new ObjectFactory[factories.size()]); - } - - public List<?> getInstance() throws ObjectCreationException { - List<Object> list = new ArrayList<Object>(); - for (ObjectFactory factory : factories) { - list.add(factory.getInstance()); - } - return list; - } - -} diff --git a/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/MethodInjector.java b/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/MethodInjector.java deleted file mode 100644 index baf9eb9cc1..0000000000 --- a/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/MethodInjector.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.sca.implementation.java.injection; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.security.AccessController; -import java.security.PrivilegedAction; - -import org.apache.tuscany.sca.core.factory.ObjectCreationException; -import org.apache.tuscany.sca.core.factory.ObjectFactory; - -/** - * Injects a value created by an {@link org.apache.tuscany.sca.core.factory.ObjectFactory} using a given method - * - * @version $Rev$ $Date$ - */ -public class MethodInjector<T> implements Injector<T> { - private final Method method; - private final ObjectFactory<?> objectFactory; - - public MethodInjector(Method aMethod, ObjectFactory<?> objectFactory) { - assert aMethod != null; - assert objectFactory != null; - this.method = aMethod; - // Allow privileged access to set accessibility. Requires ReflectPermission in security - // policy. - AccessController.doPrivileged(new PrivilegedAction<Object>() { - public Object run() { - method.setAccessible(true); - return null; - } - }); - this.objectFactory = objectFactory; - } - - public void inject(T instance) throws ObjectCreationException { - try { - method.invoke(instance, objectFactory.getInstance()); - } catch (IllegalAccessException e) { - throw new ObjectCreationException("Method is not accessible [" + method + "]", e); - } catch (IllegalArgumentException e) { - throw new ObjectCreationException("Exception thrown by setter: " + method.getName(), e); - } catch (InvocationTargetException e) { - throw new ObjectCreationException("Exception thrown by setter: " + method.getName(), e); - } - } -} diff --git a/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/RequestContextObjectFactory.java b/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/RequestContextObjectFactory.java deleted file mode 100644 index 43fb5d6170..0000000000 --- a/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/RequestContextObjectFactory.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.sca.implementation.java.injection; - -import org.apache.tuscany.sca.context.RequestContextFactory; -import org.apache.tuscany.sca.core.factory.ObjectCreationException; -import org.apache.tuscany.sca.core.factory.ObjectFactory; -import org.apache.tuscany.sca.runtime.RuntimeComponent; -import org.oasisopen.sca.RequestContext; - -/** - * Creates instances of RequestContext for injection on component implementation instances - * - * @version $Rev$ $Date$ - */ -public class RequestContextObjectFactory implements ObjectFactory<RequestContext> { - private RequestContextFactory factory; - private RuntimeComponent component; - - public RequestContextObjectFactory(RequestContextFactory factory, RuntimeComponent component) { - this.factory = factory; - this.component = component; - } - - public RequestContext getInstance() throws ObjectCreationException { - return factory.createRequestContext(component); - } -} diff --git a/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceHost.java b/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceHost.java deleted file mode 100644 index 70c368a0e6..0000000000 --- a/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceHost.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.sca.implementation.java.injection; - -/** - * Interface implemented by host environments that allow for resolution of component implementation resources, e.g. - * items bound in a JNDI tree. - * - * @version $Rev$ $Date$ - */ -public interface ResourceHost { - - /** - * Resolve a resource matching the given type - * - * @param type the type of the resources - * @throws ResourceResolutionException if an error is encountered during resolution - */ - <T> T resolveResource(Class<T> type) throws ResourceResolutionException; - - /** - * Resolve a resource matching the given type and name - * - * @param type the type of the resources - * @param mappedName the mapped name of the resource - * @throws ResourceResolutionException if an error is encountered during resolution - */ - <T> T resolveResource(Class<T> type, String mappedName) throws ResourceResolutionException; - -} diff --git a/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceNotFoundException.java b/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceNotFoundException.java deleted file mode 100644 index d5c1c7b69e..0000000000 --- a/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceNotFoundException.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.sca.implementation.java.injection; - -import org.apache.tuscany.sca.core.factory.ObjectCreationException; - -/** - * Denotes an exception thrown when a runtime resource is not found - * - * @version $Rev$ $Date$ - */ -public class ResourceNotFoundException extends ObjectCreationException { - private static final long serialVersionUID = 1L; - - public ResourceNotFoundException() { - super(); - } - - public ResourceNotFoundException(String message, Throwable cause) { - super(message, cause); - } - - public ResourceNotFoundException(String message) { - super(message); - } - - public ResourceNotFoundException(Throwable cause) { - super(cause); - } - -} diff --git a/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceObjectFactory.java b/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceObjectFactory.java deleted file mode 100644 index 8f55eb18bc..0000000000 --- a/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceObjectFactory.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.sca.implementation.java.injection; - -import org.apache.tuscany.sca.core.factory.ObjectCreationException; -import org.apache.tuscany.sca.core.factory.ObjectFactory; - -/** - * Resolves a runtime resource to be injected on a field or method of a Java component type marked with {@link - * javax.annotation.Resource}. If the mapped name of the resource is an absolute URI such as - * <code>sca://localhost</code> or <code>jndi://localhost</code> the host container namespace is searched; otherwise the - * URI is assumed to be relative and the parent composite is searched. If a mapped name is not provided, i.e. resolution - * is by type, the parent composite is first searched followed by the host namespace. - * - * @version $Rev$ $Date$ - */ -public class ResourceObjectFactory<T> implements ObjectFactory<T> { - - private Class<T> type; - private String mappedName; - private ResourceHost host; - private boolean optional; - - /** - * Instantiates a factory that resolves resources by type - * - * @param type the type of the resource to inject - * @param optional true if an error should be thrown if the resource is not found - * @param host the runtime resource provider - */ - public ResourceObjectFactory(Class<T> type, boolean optional, ResourceHost host) { - this(type, null, optional, host); - } - - /** - * Instantiates a factory that resolves resources by mapped name - * - * @param type the type of the resource to inject - * @param mappedName the resource name - * @param optional true if an error should be thrown if the resource is not found - * @param host the runtime resource provider - */ - public ResourceObjectFactory(Class<T> type, String mappedName, boolean optional, ResourceHost host) { - this.type = type; - this.host = host; - this.mappedName = mappedName; - this.optional = optional; - } - - public T getInstance() throws ObjectCreationException { - try { - T resource; - if (mappedName == null) { - resource = host.resolveResource(type); - if (!optional && resource == null) { - throw new ResourceNotFoundException("Resource not found: " + type.getName()); - } - } else { - resource = host.resolveResource(type, mappedName); - if (!optional && resource == null) { - throw new ResourceNotFoundException("Resource not found: " + mappedName); - } - } - return resource; - } catch (ResourceResolutionException e) { - throw new ObjectCreationException(e); - } - - } -} diff --git a/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceResolutionException.java b/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceResolutionException.java deleted file mode 100644 index f94b24762a..0000000000 --- a/tags/java/sca/2.0-M4-RC1/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceResolutionException.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.sca.implementation.java.injection; - - -/** - * @version $Rev$ $Date$ - */ -public class ResourceResolutionException extends Exception { - private static final long serialVersionUID = 13421352711315479L; - - public ResourceResolutionException() { - super(); - } - - public ResourceResolutionException(String message, Throwable cause) { - super(message, cause); - } - - public ResourceResolutionException(String message) { - super(message); - } - - public ResourceResolutionException(Throwable cause) { - super(cause); - } -} |