diff options
Diffstat (limited to 'java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context')
4 files changed, 0 insertions, 249 deletions
diff --git a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/InstanceFactory.java b/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/InstanceFactory.java deleted file mode 100644 index e2d99852d8..0000000000 --- a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/InstanceFactory.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.context; - -import org.apache.tuscany.sca.core.factory.InstanceWrapper; - -/** - * Interface for a factory that returns an injected component instance. - * This is used by a Component implementation to create new instances of - * application implementation objects as determined by the component scope's - * lifecycle. - * <p/> - * The implementation of this interface may be supplied by the user, - * may be generated during deployment, or may be dynamic. - * - * @version $Rev$ $Date$ - * @param <T> Type of the instance generated by the factory. - */ -public interface InstanceFactory<T> { - /** - * Creates a new instance of the component. - * All injected values must be set but any @Init methods must not have been invoked. - * - * @return A wrapper for the created component instance. - */ - InstanceWrapper<T> newInstance(); -} diff --git a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/InstanceFactoryProvider.java b/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/InstanceFactoryProvider.java deleted file mode 100644 index df21e013f1..0000000000 --- a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/InstanceFactoryProvider.java +++ /dev/null @@ -1,49 +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.context; - -import org.apache.tuscany.sca.core.factory.ObjectFactory; -import org.apache.tuscany.sca.implementation.java.JavaElementImpl; - -/** - * @version $Rev$ $Date$ - */ -public interface InstanceFactoryProvider<T> { - /** - * Return the implementation class. - * - * @return the implementation class. - */ - Class<T> getImplementationClass(); - - /** - * Sets an object factory for an injection site - * - * @param element the injection site name - * @param objectFactory the object factory - */ - void setObjectFactory(JavaElementImpl element, ObjectFactory<?> objectFactory); - - /** - * Create an instance factory that can be used to create component instances. - * - * @return a new instance factory - */ - InstanceFactory<T> createFactory(); -} diff --git a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/ReflectiveInstanceFactory.java b/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/ReflectiveInstanceFactory.java deleted file mode 100644 index 8189271ed5..0000000000 --- a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/ReflectiveInstanceFactory.java +++ /dev/null @@ -1,93 +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.context; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; - -import org.apache.tuscany.sca.core.factory.InstanceWrapper; -import org.apache.tuscany.sca.core.factory.ObjectCreationException; -import org.apache.tuscany.sca.core.factory.ObjectFactory; -import org.apache.tuscany.sca.implementation.java.injection.Injector; -import org.apache.tuscany.sca.implementation.java.invocation.EventInvoker; - -/** - * @version $Rev$ $Date$ - */ -public class ReflectiveInstanceFactory<T> implements InstanceFactory<T> { - private final Constructor<T> ctr; - private final ObjectFactory<?>[] ctrArgs; - private final Injector<T>[] injectors; - private final EventInvoker<T> initInvoker; - private final EventInvoker<T> destroyInvoker; - - public ReflectiveInstanceFactory(Constructor<T> ctr, - ObjectFactory<?>[] ctrArgs, - Injector<T>[] injectors, - EventInvoker<T> initInvoker, - EventInvoker<T> destroyInvoker) { - this.ctr = ctr; - this.ctrArgs = ctrArgs; - this.injectors = injectors; - this.initInvoker = initInvoker; - this.destroyInvoker = destroyInvoker; - } - - public InstanceWrapper<T> newInstance() { - T instance; - try { - if (ctrArgs != null) { - Object[] args = new Object[ctrArgs.length]; - for (int i = 0; i < args.length; i++) { - args[i] = ctrArgs[i].getInstance(); - } - instance = ctr.newInstance(args); - } else { - instance = ctr.newInstance(); - } - } catch (InstantiationException e) { - String name = ctr.getDeclaringClass().getName(); - throw new AssertionError("Class is not instantiable [" + name + "]"); - } catch (IllegalAccessException e) { - String name = ctr.getName(); - throw new AssertionError("Constructor is not accessible [" + name + "]"); - } catch ( - InvocationTargetException e) { - String name = ctr.getName(); - throw new ObjectCreationException("Exception thrown by constructor: " + name, e); - } - - if (injectors != null) { - for (Injector<T> injector : injectors) { - //FIXME Injectors should never be null - if (injector != null) - try { - injector.inject(instance); - } catch (Exception e) { - if (destroyInvoker != null) { - destroyInvoker.invokeEvent(instance); - } - throw new ObjectCreationException("Exception invoking injector", e); - } - } - } - - return new ReflectiveInstanceWrapper<T>(instance, initInvoker, destroyInvoker); - } -} diff --git a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/ReflectiveInstanceWrapper.java b/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/ReflectiveInstanceWrapper.java deleted file mode 100644 index 7c96606cf6..0000000000 --- a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/ReflectiveInstanceWrapper.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.context; - -import org.apache.tuscany.sca.core.factory.InstanceWrapper; -import org.apache.tuscany.sca.core.scope.TargetDestructionException; -import org.apache.tuscany.sca.core.scope.TargetInitializationException; -import org.apache.tuscany.sca.implementation.java.invocation.EventInvoker; - -/** - * @version $Rev$ $Date$ - */ -public class ReflectiveInstanceWrapper<T> implements InstanceWrapper<T> { - private final EventInvoker<T> initInvoker; - private final EventInvoker<T> destroyInvoker; - private final T instance; - - public ReflectiveInstanceWrapper(T instance, EventInvoker<T> initInvoker, EventInvoker<T> destroyInvoker) { - this.instance = instance; - this.initInvoker = initInvoker; - this.destroyInvoker = destroyInvoker; - } - - public T getInstance() { - return instance; - } - - public void start() throws TargetInitializationException { - if (initInvoker != null) { - try { - initInvoker.invokeEvent(instance); - } catch (Exception e) { - try { - stop(); - } catch (TargetDestructionException e1) { - throw new TargetInitializationException("TargetDestructionException while handling init exception", e); - } - throw new TargetInitializationException(e); - } - } - } - - public void stop() throws TargetDestructionException { - if (destroyInvoker != null) { - destroyInvoker.invokeEvent(instance); - } - } -} |