diff options
Diffstat (limited to 'tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection')
16 files changed, 0 insertions, 746 deletions
diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/ContextObjectFactory.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/ContextObjectFactory.java deleted file mode 100644 index 6facd25e59..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/ContextObjectFactory.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * 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.injection; - -import org.apache.tuscany.core.builder.ContextResolver; -import org.apache.tuscany.core.builder.ObjectFactory; -import org.apache.tuscany.core.context.CompositeContext; - -/** - * An implementation of <code>ObjectFactory</code> that resolves the current parent context - * - * @version $Rev: 380903 $ $Date: 2006-02-25 00:53:26 -0800 (Sat, 25 Feb 2006) $ - */ -public class ContextObjectFactory implements ObjectFactory<CompositeContext> { - - private final ContextResolver resolver; - - public ContextObjectFactory(ContextResolver resolver) { - assert (resolver != null) : "Resolver cannot be null"; - this.resolver = resolver; - } - - public CompositeContext getInstance() { - return resolver.getCurrentContext(); - } - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/EventInvoker.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/EventInvoker.java deleted file mode 100644 index 6f5de43b96..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/EventInvoker.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * 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.injection; - -/** - * Performs an wire on an instance - * - * @version $Rev$ $Date$ - * @see MethodEventInvoker - */ -public interface EventInvoker<T> { - - /** - * Performs the wire on a given instance - * - * @throws ObjectCallbackException - */ - void invokeEvent(T instance) throws ObjectCallbackException; -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/FactoryInitException.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/FactoryInitException.java deleted file mode 100644 index 589ae796ac..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/FactoryInitException.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * 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.injection; - -/** - * Denotes an exception initializing an object factory - * - * @version $Rev$ $Date$ - */ -public class FactoryInitException extends InjectionRuntimeException { - - public FactoryInitException(String message, Throwable cause) { - super(message, cause); - } - - public FactoryInitException(String message) { - super(message); - } - - public FactoryInitException(Throwable cause) { - super(cause); - } - - public FactoryInitException() { - super(); - } - -} - diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/FieldInjector.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/FieldInjector.java deleted file mode 100644 index 7be73462d3..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/FieldInjector.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * 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.injection; - -import org.apache.tuscany.core.builder.ObjectFactory; - -import java.lang.reflect.Field; - -/** - * Injects a value created by an {@link 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 field, ObjectFactory<?> objectFactory) { - this.field = field; - this.objectFactory = objectFactory; - } - - /** - * Inject a new value on the given isntance - */ - public void inject(T instance) throws ObjectCreationException { - try { - field.set(instance, objectFactory.getInstance()); - } catch (IllegalAccessException e) { - throw new AssertionError("Field is not accessible [" + field + "]"); - } - } -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/InjectionRuntimeException.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/InjectionRuntimeException.java deleted file mode 100644 index 2c26f3c4b1..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/InjectionRuntimeException.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * 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.injection; - -import org.apache.tuscany.common.TuscanyRuntimeException; - -/** - * Root unchecked exception for the injection package - * - * @version $Rev$ $Date$ - */ -public abstract class InjectionRuntimeException extends TuscanyRuntimeException { - - public InjectionRuntimeException() { - super(); - } - - public InjectionRuntimeException(String message) { - super(message); - } - - public InjectionRuntimeException(String message, Throwable cause) { - super(message, cause); - } - - public InjectionRuntimeException(Throwable cause) { - super(cause); - } - -} - diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/Injector.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/Injector.java deleted file mode 100644 index 306dab3e98..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/Injector.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * 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.injection; - -/** - * Implementations inject a pre-configured value on an instance - * - * @version $Rev$ $Date$ - * @see MethodInjector - * @see FieldInjector - */ -public interface Injector<T> { - - /** - * Inject a value on the given instance - */ - void inject(T instance) throws ObjectCreationException; - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/InterCompositeReferenceFactory.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/InterCompositeReferenceFactory.java deleted file mode 100644 index 55d8a88790..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/InterCompositeReferenceFactory.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * 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.injection; - -import org.apache.tuscany.core.builder.ContextResolver; -import org.apache.tuscany.core.builder.ObjectFactory; -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.context.Context; -import org.apache.tuscany.core.context.QualifiedName; -import org.apache.tuscany.core.context.TargetException; - -/** - * Returns a direct reference to a target service exposed in another composite, i.e. the factory avoids creating proxies - * and returns the actual target instance - * - * @version $Rev: 384135 $ $Date: 2006-03-07 22:53:58 -0800 (Tue, 07 Mar 2006) $ - */ -public class InterCompositeReferenceFactory<T> implements ObjectFactory<T> { - - private ContextResolver resolver; - - private QualifiedName targetQualifiedName; - - /** - * Reference source is an external service, target is in another module - * - * @param targetName the name of the target service - */ - public InterCompositeReferenceFactory(String targetName) { - targetQualifiedName = new QualifiedName(targetName); - } - - public void setContextResolver(ContextResolver resolver){ - this.resolver = resolver; - } - - public T getInstance() throws ObjectCreationException { - // only return entry points since this is an inter-module wire - Object o = resolver.getCurrentContext().getInstance(targetQualifiedName); - if (o != null) { - return (T) o; - } else { - // walk up the hierarchy of composite contexts - CompositeContext ctx = resolver.getCurrentContext(); - do { - if (ctx == null) { - break; // reached top of context hierarchy - } - Context compContext = ctx.getContext(targetQualifiedName.getPartName()); - if (compContext != null) { - o = compContext.getInstance(targetQualifiedName); - if (o != null) { - return (T) o; - } - } - ctx = ctx.getParent(); - } while (ctx != null); - TargetException e = new TargetException("Target reference not found"); - e.setIdentifier(targetQualifiedName.getQualifiedName()); - throw e; - } - } - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/JNDIObjectFactory.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/JNDIObjectFactory.java deleted file mode 100644 index bed7db887a..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/JNDIObjectFactory.java +++ /dev/null @@ -1,46 +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.injection; - -import javax.naming.Context; -import javax.naming.NamingException; - -import org.apache.tuscany.core.builder.ObjectFactory; - -/** - * An implementation of ObjectFactory that creates instances - * by looking them up in a JNDI context. - * - * @version $Rev$ $Date$ - */ -public class JNDIObjectFactory<T> implements ObjectFactory<T> { - private final Context context; - private final String name; - - public JNDIObjectFactory(Context context, String name) { - this.context = context; - this.name = name; - } - - public T getInstance() throws ObjectCreationException { - try { - return (T) context.lookup(name); - } catch (NamingException e) { - throw new ObjectCreationException(e); - } - } -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/MethodEventInvoker.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/MethodEventInvoker.java deleted file mode 100644 index 69c7670c03..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/MethodEventInvoker.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * 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.injection; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -/** - * Performs an wire on a method of a given instance - * - * @version $Rev$ $Date$ - */ -public class MethodEventInvoker<T> implements EventInvoker<T> { - private final Method method; - - /** - * Intantiates an invoker for the given method - */ - public MethodEventInvoker(Method method) { - this.method = method; - } - - public void invokeEvent(T instance) throws ObjectCallbackException { - try { - method.invoke(instance, (Object[]) null); - } catch (IllegalAccessException e) { - throw new AssertionError("Method is not accessible [" + method + "]"); - } catch (InvocationTargetException e) { - throw new ObjectCallbackException("Exception thrown by callback method [" + method + "]", e); - } - } - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/MethodInjector.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/MethodInjector.java deleted file mode 100644 index 6095061872..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/MethodInjector.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * 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.injection; - -import org.apache.tuscany.core.builder.ObjectFactory; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -/** - * Injects a value created by an {@link 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 method, ObjectFactory<?> objectFactory) { - this.method = method; - this.objectFactory = objectFactory; - } - - public void inject(T instance) throws ObjectCreationException { - try { - method.invoke(instance, objectFactory.getInstance()); - } catch (IllegalAccessException e) { - throw new AssertionError("Method is not accessible [" + method + "]"); - } catch (InvocationTargetException e) { - ObjectCreationException oce= new ObjectCreationException("Exception thrown by setter", e); - oce.setIdentifier(method.getName()); - throw oce; - } - } -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/NonProxiedTargetFactory.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/NonProxiedTargetFactory.java deleted file mode 100644 index 7f7a307433..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/NonProxiedTargetFactory.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * 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.injection; - -import org.apache.tuscany.core.builder.ContextResolver; -import org.apache.tuscany.core.builder.ObjectFactory; -import org.apache.tuscany.core.context.QualifiedName; -import org.apache.tuscany.model.assembly.ConfiguredService; - -/** - * Returns a direct reference to a target within the same composite, i.e. the factory avoids creating proxies and - * returns the actual target instance - * - * @version $Rev$ $Date$ - */ -public class NonProxiedTargetFactory<T> implements ObjectFactory<T> { - - private ContextResolver resolver; - - // the name of the target component/service for this reference - private QualifiedName targetName; - private QualifiedName qualifiedServiceName; - - /** - * Constructs a reference object factory from a configured reference on a type - * - * @throws FactoryInitException - */ - public NonProxiedTargetFactory(ConfiguredService targetService, ContextResolver resolver) throws FactoryInitException { - assert (targetService != null) : "Target service was null"; - assert (resolver != null) : "Context resolver was null"; - - this.resolver = resolver; - targetName = new QualifiedName(targetService.getPart().getName()); - qualifiedServiceName = new QualifiedName("./"+targetName.getPortName()); - } - - public T getInstance() throws ObjectCreationException { - return (T) resolver.getCurrentContext().getContext(targetName.getPartName()).getInstance(qualifiedServiceName); //locateInstance(targetName); //locateInstance(targetName); - } - - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/NullEventInvoker.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/NullEventInvoker.java deleted file mode 100644 index e8f109f2d8..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/NullEventInvoker.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * 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.injection; - -/** - * A no-op invoker - * - * @version $Rev$ $Date$ - */ -public final class NullEventInvoker<T> implements EventInvoker<T> { - public static final EventInvoker<?> NULL_INVOKER = new NullEventInvoker(); - - public void invokeEvent(T instance) { - // does nothing - } -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/ObjectCallbackException.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/ObjectCallbackException.java deleted file mode 100644 index 44edee43eb..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/ObjectCallbackException.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * 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.injection; - -/** - * Denotes an error when invoking on an object - * - * @version $Rev$ $Date$ - */ -public class ObjectCallbackException extends InjectionRuntimeException { - - public ObjectCallbackException() { - super(); - } - - public ObjectCallbackException(String message) { - super(message); - } - - public ObjectCallbackException(String message, Throwable cause) { - super(message, cause); - } - - public ObjectCallbackException(Throwable cause) { - super(cause); - } - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/ObjectCreationException.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/ObjectCreationException.java deleted file mode 100644 index 875eda3680..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/ObjectCreationException.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * 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.injection; - -/** - * Denotes an error creating a new object instance - * - * @version $Rev$ $Date$ - */ -public class ObjectCreationException extends InjectionRuntimeException { - - public ObjectCreationException() { - super(); - } - - public ObjectCreationException(String message) { - super(message); - } - - public ObjectCreationException(String message, Throwable cause) { - super(message, cause); - } - - public ObjectCreationException(Throwable cause) { - super(cause); - } - -} - diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/PojoObjectFactory.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/PojoObjectFactory.java deleted file mode 100644 index fac8248b0c..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/PojoObjectFactory.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * 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.injection; - -import org.apache.tuscany.core.builder.ObjectFactory; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.util.Collections; -import java.util.List; - -/** - * Creates new instances of a Java class, calling a given set of injectors to configure the instance - * - * @version $Rev$ $Date$ - * @see Injector - */ -public class PojoObjectFactory<T> implements ObjectFactory<T> { - - private static final ObjectFactory[] NO_INIT_PARAM = {}; - - private static final List<Injector> NO_SETTER_PARAM = Collections.emptyList(); - - private final Constructor<T> ctr; - - private final ObjectFactory<?>[] initParamsArray; - - private final List<Injector> setters; - - public PojoObjectFactory(Constructor<T> ctr, List<ObjectFactory> initParams, List<Injector> setters) { - this.ctr = ctr; - if (initParams != null && initParams.size() > 0) { - initParamsArray = initParams.toArray(new ObjectFactory[initParams.size()]); - } else { - initParamsArray = NO_INIT_PARAM; - } - this.setters = setters != null ? setters : NO_SETTER_PARAM; - } - - public T getInstance() throws ObjectCreationException { - Object[] initargs = new Object[initParamsArray.length]; - // create the constructor arg array - for (int i = 0; i < initParamsArray.length; i++) { - ObjectFactory<?> objectFactory = initParamsArray[i]; - initargs[i] = objectFactory.getInstance(); - } - try { - T instance = ctr.newInstance(initargs); - // interate through the injectors and inject the instance - for (Injector<T> setter : setters) { - setter.inject(instance); - } - return instance; - } catch (InstantiationException e) { - throw new AssertionError("Class is not instantiable [" + ctr.getDeclaringClass().getName() + "]"); - } catch (IllegalAccessException e) { - throw new AssertionError("Constructor is not accessible [" + ctr + "]"); - } catch (InvocationTargetException e) { - throw new ObjectCreationException("Exception thrown by constructor [" + ctr + "]", e); - } - } -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/SingletonObjectFactory.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/SingletonObjectFactory.java deleted file mode 100644 index 8a7e0bf782..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/injection/SingletonObjectFactory.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * 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.injection; - -import org.apache.tuscany.core.builder.ObjectFactory; - -/** - * Implementation of ObjectFactory that returns a single instance, typically an immutable type. - * - * @version $Rev$ $Date$ - */ -public class SingletonObjectFactory<T> implements ObjectFactory<T> { - private final T instance; - - public SingletonObjectFactory(T instance) { - this.instance = instance; - } - - public T getInstance() { - return instance; - } - -} |