You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jm...@apache.org on 2006/01/12 17:00:18 UTC

svn commit: r368394 [1/2] - in /incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core: binding/ injection/ monitor/ system/annotation/ system/assembly/pojo/ system/builder/ system/injection/

Author: jmarino
Date: Thu Jan 12 08:00:12 2006
New Revision: 368394

URL: http://svn.apache.org/viewcvs?rev=368394&view=rev
Log:
checkin of remaining files that did not merge properly from patch; build will now work

Added:
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/binding/
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/binding/BindingChannel.java
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/binding/BindingHandler.java
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/binding/MessageContext.java
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/EventInvoker.java
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/FactoryInitException.java
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/FieldInjector.java
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/InjectionRuntimeException.java
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/Injector.java
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/MethodEventInvoker.java
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/MethodInjector.java
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/NullEventInvoker.java
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/ObjectCallbackException.java
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/ObjectCreationException.java
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/ObjectFactory.java
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/PojoObjectFactory.java
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/ReferenceTargetFactory.java
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/SDOObjectFactory.java
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/SingletonObjectFactory.java
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/monitor/
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/monitor/ConsoleMonitorFactory.java
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/annotation/
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/annotation/Autowire.java
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/annotation/ParentContext.java
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/assembly/pojo/
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/assembly/pojo/PojoSystemBinding.java
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/assembly/pojo/PojoSystemImplementation.java
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/builder/
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/builder/ProxyFactoryBuilder.java
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/builder/SystemComponentContextBuilder.java
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/builder/SystemEntryPointBuilder.java
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/builder/SystemExternalServiceBuilder.java
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/injection/
    incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/injection/AutowireFactory.java

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/binding/BindingChannel.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/binding/BindingChannel.java?rev=368394&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/binding/BindingChannel.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/binding/BindingChannel.java Thu Jan 12 08:00:12 2006
@@ -0,0 +1,25 @@
+/**
+ * 
+ * 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.binding;
+
+/**
+ * Represents a dispatch channel into an entry point context
+ * 
+ * @version $Rev$ $Date$
+ */
+public interface BindingChannel {
+
+    public void send(MessageContext ctx);
+
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/binding/BindingHandler.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/binding/BindingHandler.java?rev=368394&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/binding/BindingHandler.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/binding/BindingHandler.java Thu Jan 12 08:00:12 2006
@@ -0,0 +1,30 @@
+/**
+ * 
+ * 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.binding;
+
+/**
+ * Performs a mediation on an incoming or outgoing payload for a particular binding
+ * 
+ * @version $Rev$ $Date$
+ */
+public interface BindingHandler {
+
+    /**
+     * Perform processing on a message context
+     * 
+     * @return true to continue processing or false to abort
+     */
+    public boolean process(MessageContext ctx);
+
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/binding/MessageContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/binding/MessageContext.java?rev=368394&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/binding/MessageContext.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/binding/MessageContext.java Thu Jan 12 08:00:12 2006
@@ -0,0 +1,45 @@
+/**
+ * 
+ * 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.binding;
+
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.core.message.Message;
+
+/**
+ * Represents a processing context for a request comming through a a binding
+ * 
+ * @version $Rev$ $Date$
+ */
+public interface MessageContext {
+
+    /**
+     * The raw payload as it comes through the binding transport 
+     */
+    public Object getPayload();
+
+    /**
+     * Returns a marhsalled representation of the payload
+     */
+    public Message getMessage();
+
+    /**
+     * Sets a message to be used in marhsalling the payload
+     */
+    public void setMessage(Message msg);
+    
+    public Method getTargetMethod();
+    
+    public void setTargetMethod(Method m);
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/EventInvoker.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/EventInvoker.java?rev=368394&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/EventInvoker.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/EventInvoker.java Thu Jan 12 08:00:12 2006
@@ -0,0 +1,17 @@
+package org.apache.tuscany.core.injection;
+
+/**
+ * Performs an invocation on an instance
+ *
+ * @version $Rev$ $Date$
+ * @see MethodEventInvoker
+ */
+public interface EventInvoker<T> {
+
+    /**
+     * Performs the invocation on a given instance
+     *
+     * @throws ObjectCallbackException
+     */
+    void invokeEvent(T instance) throws ObjectCallbackException;
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/FactoryInitException.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/FactoryInitException.java?rev=368394&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/FactoryInitException.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/FactoryInitException.java Thu Jan 12 08:00:12 2006
@@ -0,0 +1,27 @@
+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();
+    }
+
+}
+

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/FieldInjector.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/FieldInjector.java?rev=368394&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/FieldInjector.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/FieldInjector.java Thu Jan 12 08:00:12 2006
@@ -0,0 +1,43 @@
+package org.apache.tuscany.core.injection;
+
+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;
+
+    // //----------------------------------
+    // Constructors
+    // ----------------------------------
+
+    /**
+     * 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;
+    }
+
+    // ----------------------------------
+    // Methods
+    // ----------------------------------
+
+    /**
+     * 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 + "]");
+        }
+    }
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/InjectionRuntimeException.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/InjectionRuntimeException.java?rev=368394&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/InjectionRuntimeException.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/InjectionRuntimeException.java Thu Jan 12 08:00:12 2006
@@ -0,0 +1,29 @@
+package org.apache.tuscany.core.injection;
+
+import org.apache.tuscany.core.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);
+    }
+
+}
+

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/Injector.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/Injector.java?rev=368394&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/Injector.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/Injector.java Thu Jan 12 08:00:12 2006
@@ -0,0 +1,17 @@
+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;
+
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/MethodEventInvoker.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/MethodEventInvoker.java?rev=368394&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/MethodEventInvoker.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/MethodEventInvoker.java Thu Jan 12 08:00:12 2006
@@ -0,0 +1,39 @@
+package org.apache.tuscany.core.injection;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * Performs an invocation on a method of a given instance
+ *
+ * @version $Rev$ $Date$
+ */
+public class MethodEventInvoker<T> implements EventInvoker<T> {
+    private final Method method;
+
+    //----------------------------------
+    // Constructors
+    //----------------------------------
+
+    /**
+     * Intantiates an  invoker for the given method
+     */
+    public MethodEventInvoker(Method method) {
+        this.method = method;
+    }
+
+    //----------------------------------
+    // Methods
+    //----------------------------------
+
+    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);
+        }
+    }
+
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/MethodInjector.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/MethodInjector.java?rev=368394&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/MethodInjector.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/MethodInjector.java Thu Jan 12 08:00:12 2006
@@ -0,0 +1,28 @@
+package org.apache.tuscany.core.injection;
+
+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, new Object[]{objectFactory.getInstance()});
+        } catch (IllegalAccessException e) {
+            throw new AssertionError("Method is not accessible [" + method + "]");
+        } catch (InvocationTargetException e) {
+            throw new ObjectCreationException("Exception thrown by setter [" + method + "]", e);
+        }
+    }
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/NullEventInvoker.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/NullEventInvoker.java?rev=368394&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/NullEventInvoker.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/NullEventInvoker.java Thu Jan 12 08:00:12 2006
@@ -0,0 +1,14 @@
+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
+    }
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/ObjectCallbackException.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/ObjectCallbackException.java?rev=368394&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/ObjectCallbackException.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/ObjectCallbackException.java Thu Jan 12 08:00:12 2006
@@ -0,0 +1,26 @@
+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);
+    }
+
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/ObjectCreationException.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/ObjectCreationException.java?rev=368394&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/ObjectCreationException.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/ObjectCreationException.java Thu Jan 12 08:00:12 2006
@@ -0,0 +1,27 @@
+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);
+    }
+
+}
+

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/ObjectFactory.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/ObjectFactory.java?rev=368394&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/ObjectFactory.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/ObjectFactory.java Thu Jan 12 08:00:12 2006
@@ -0,0 +1,20 @@
+package org.apache.tuscany.core.injection;
+
+/**
+ * Implementations create new instances of a particular type
+ *
+ * @version $Rev$ $Date$
+ * @see PojoObjectFactory
+ * @see SingletonObjectFactory
+ * @see SDOObjectFactory
+ */
+public interface ObjectFactory<T> {
+
+    /**
+     * Return a instance of the type that this factory creates.
+     *
+     * @return a instance from this factory
+     */
+    T getInstance() throws ObjectCreationException;
+
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/PojoObjectFactory.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/PojoObjectFactory.java?rev=368394&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/PojoObjectFactory.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/PojoObjectFactory.java Thu Jan 12 08:00:12 2006
@@ -0,0 +1,73 @@
+package org.apache.tuscany.core.injection;
+
+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> {
+
+    // ----------------------------------
+    // Constants
+    // ----------------------------------
+
+    private static final ObjectFactory[] NO_INIT_PARAM = {};
+
+    private static final List<Injector> NO_SETTER_PARAM = Collections.EMPTY_LIST;
+
+    // ----------------------------------
+    // Fields
+    // ----------------------------------
+
+    private final Constructor<T> ctr;
+
+    private final ObjectFactory<?>[] initParamsArray;
+
+    private final List<Injector> setters;
+
+    // ----------------------------------
+    // Constructors
+    // ----------------------------------
+
+    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;
+    } // ----------------------------------
+
+    // Methods
+    // ----------------------------------
+
+    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 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);
+        }
+    }
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/ReferenceTargetFactory.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/ReferenceTargetFactory.java?rev=368394&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/ReferenceTargetFactory.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/ReferenceTargetFactory.java Thu Jan 12 08:00:12 2006
@@ -0,0 +1,133 @@
+/**
+ * 
+ * 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.context.AggregateContext;
+import org.apache.tuscany.core.context.InstanceContext;
+import org.apache.tuscany.core.context.QualifiedName;
+import org.apache.tuscany.core.context.TargetException;
+import org.apache.tuscany.model.assembly.Component;
+import org.apache.tuscany.model.assembly.ConfiguredReference;
+import org.apache.tuscany.model.assembly.ConfiguredService;
+import org.apache.tuscany.model.assembly.EntryPoint;
+import org.apache.tuscany.model.assembly.ExternalService;
+
+/**
+ * Returns a direct reference to a target service, i.e. the factory avoids creating proxies and returns the actual
+ * target instance
+ * 
+ * @version $Rev$ $Date$
+ */
+public class ReferenceTargetFactory<T> implements ObjectFactory<T> {
+
+    private AggregateContext parentContext;
+
+    // the SCDL name of the target component/service for this reference
+    private String targetName;
+
+    private QualifiedName targetComponentName;
+
+    // the reference target is in another module
+    private boolean interModule;
+
+    // ----------------------------------
+    // Constructors
+    // ----------------------------------
+
+    /**
+     * Constructs a reference object factory from a configured reference on a type
+     */
+    public ReferenceTargetFactory(ConfiguredReference reference, AggregateContext parentContext)
+            throws FactoryInitException {
+        // FIXME how to handle a reference that is a list - may take different proxy factories for each entry
+        assert (reference != null) : "Reference was null";
+        assert (parentContext != null) : "Parent context was null";
+
+        this.parentContext = parentContext;
+        // targetName = reference.getReference().getName();
+
+        ConfiguredService targetService = reference.getConfiguredServices().get(0);
+        if (targetService.getPart() instanceof ExternalService) {
+            targetName = ((ExternalService) targetService.getPart()).getName();
+        } else if (targetService.getPart() instanceof Component) {
+            Component targetComponent = (Component) targetService.getPart();
+            targetName = targetComponent.getName();
+        } else if (targetService.getPart() instanceof EntryPoint) {
+            targetName = ((EntryPoint) targetService.getPart()).getName();
+        } else if (targetService.getPart() == null) {
+            // FIXME not correct
+            if (targetService.getService() == null) {
+                throw new FactoryInitException("No target service specified");
+            }
+            targetName = targetService.getService().getName();
+        } else {
+            FactoryInitException fie = new FactoryInitException("Unknown reference target type");
+            fie.setIdentifier(reference.getReference().getName());
+            throw fie;
+        }
+    }
+
+    /**
+     * Reference source is an external service, target is in another module
+     * 
+     * @param service
+     * @param parentContext
+     * @throws FactoryInitException
+     */
+    public ReferenceTargetFactory(ConfiguredService service, AggregateContext parentContext) throws FactoryInitException {
+        assert (service != null) : "Service was null";
+        assert (parentContext != null) : "Parent context was null";
+        interModule = true; // an external service with a reference target in another module
+        targetName = service.getPart().getName();
+        targetComponentName = new QualifiedName(targetName);
+        this.parentContext = parentContext;
+    }
+
+    // ----------------------------------
+    // Methods
+    // ----------------------------------
+
+    public T getInstance() throws ObjectCreationException {
+        if (interModule) {
+            // only return entry points since this is an inter-module wire
+            Object o = parentContext.getInstance(targetComponentName);
+            if (o != null) {
+                return (T) o;
+            } else {
+                // walk up the hierarchy of aggregate contexts
+                AggregateContext ctx = parentContext;
+                do {
+                    if (ctx == null) {
+                        break; // reached top of context hierarchy
+                    }
+                    InstanceContext compContext = ctx.getContext(targetComponentName.getPartName());
+                    if (compContext != null) {
+                        o = compContext.getInstance(targetComponentName);
+                        if (o != null) {
+                            return (T) o;
+                        }
+                    }
+                    ctx = ctx.getParent();
+                } while (ctx != null);
+                TargetException e= new TargetException("Target reference not found");
+                e.setIdentifier(targetName);
+                throw e;
+            }
+        } else {
+            // the target is in the same module, so just locate it
+            return (T) parentContext.locateInstance(targetName);
+        }
+    }
+
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/SDOObjectFactory.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/SDOObjectFactory.java?rev=368394&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/SDOObjectFactory.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/SDOObjectFactory.java Thu Jan 12 08:00:12 2006
@@ -0,0 +1,40 @@
+package org.apache.tuscany.core.injection;
+
+import org.apache.tuscany.core.deprecated.sdo.util.CopyHelper;
+import org.apache.tuscany.core.deprecated.sdo.util.impl.CopyHelperImpl;
+
+import commonj.sdo.DataObject;
+
+/**
+ * Creates new instances of an SDO
+ *
+ * @version $Rev$ $Date$
+ */
+public class SDOObjectFactory implements ObjectFactory<DataObject> {
+
+    private DataObject dataObject;
+
+    private CopyHelper helper;
+
+    //----------------------------------
+    // Constructors
+    //----------------------------------
+
+    public SDOObjectFactory(DataObject dataObject) {
+        this.dataObject = dataObject;
+        helper = new CopyHelperImpl();
+    }
+
+    //----------------------------------
+    // Methods
+    //----------------------------------
+
+    public DataObject getInstance() throws ObjectCreationException {
+        return helper.copy(dataObject);
+    }
+
+    public void releaseInstance(DataObject instance) {
+    }
+
+}
+

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/SingletonObjectFactory.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/SingletonObjectFactory.java?rev=368394&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/SingletonObjectFactory.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/injection/SingletonObjectFactory.java Thu Jan 12 08:00:12 2006
@@ -0,0 +1,27 @@
+package org.apache.tuscany.core.injection;
+
+/**
+ * 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;
+
+    // ----------------------------------
+    // Constructors
+    // ----------------------------------
+
+    public SingletonObjectFactory(T instance) {
+        this.instance = instance;
+    }
+
+    // ----------------------------------
+    // Methods
+    // ----------------------------------
+
+    public T getInstance() {
+        return instance;
+    }
+
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/monitor/ConsoleMonitorFactory.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/monitor/ConsoleMonitorFactory.java?rev=368394&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/monitor/ConsoleMonitorFactory.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/monitor/ConsoleMonitorFactory.java Thu Jan 12 08:00:12 2006
@@ -0,0 +1,65 @@
+/**
+ *
+ *  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.monitor;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+import org.apache.tuscany.common.monitor.MonitorFactory;
+import org.apache.tuscany.core.TuscanyException;
+import org.apache.tuscany.core.TuscanyRuntimeException;
+
+/**
+ * Implementation of a {@link MonitorFactory} which produces proxy-based instances that print contents to
+ * <code>System.out</code>.
+ * <p>
+ * Note that this implementation is not performant and is intended for non-production use.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class ConsoleMonitorFactory implements MonitorFactory {
+
+    public <T> T getMonitor(Class<T> monitorInterface) {
+        return monitorInterface.cast(Proxy.newProxyInstance(monitorInterface.getClassLoader(), new Class<?>[]{monitorInterface}, NULL_MONITOR));
+    }
+
+    /**
+     * Returns a proxy that prints logging information to <code>System.out</code>
+     */
+    private static final InvocationHandler NULL_MONITOR = new InvocationHandler() {
+        public Object invoke(Object proxy, Method method, Object[] args) {
+            if(args != null){
+               for (Object object : args) {
+                   if(object instanceof TuscanyRuntimeException){
+                       TuscanyRuntimeException e = (TuscanyRuntimeException)object;
+                       System.out.println("\nERROR: " +e.getMessage()+"\n");
+                       e.printStackTrace(System.out);
+                   }else if(object instanceof TuscanyException){
+                       TuscanyException e = (TuscanyException)object;
+                       System.out.println("\nERROR: " +e.getMessage()+"\n");
+                       e.printStackTrace(System.out);
+                   }else{
+                       System.out.println("\nMESSAGE: " +object+"\n");
+                   }
+               }
+            }
+            return null;
+        }
+    };
+    
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/annotation/Autowire.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/annotation/Autowire.java?rev=368394&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/annotation/Autowire.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/annotation/Autowire.java Thu Jan 12 08:00:12 2006
@@ -0,0 +1,21 @@
+package org.apache.tuscany.core.system.annotation;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * A system annotation to inject an autowired instance
+ * 
+ * @version $Rev$ $Date$
+ */
+@Target( { METHOD, FIELD })
+@Retention(RUNTIME)
+public @interface Autowire {
+    
+    public boolean required() default true;
+
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/annotation/ParentContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/annotation/ParentContext.java?rev=368394&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/annotation/ParentContext.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/annotation/ParentContext.java Thu Jan 12 08:00:12 2006
@@ -0,0 +1,33 @@
+/**
+ * 
+ * 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.system.annotation;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * A system annotation to inject the parent context
+ * 
+ * @version $Rev$ $Date$
+ */
+
+@Target( { METHOD, FIELD })
+@Retention(RUNTIME)
+public @interface ParentContext {
+
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/assembly/pojo/PojoSystemBinding.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/assembly/pojo/PojoSystemBinding.java?rev=368394&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/assembly/pojo/PojoSystemBinding.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/assembly/pojo/PojoSystemBinding.java Thu Jan 12 08:00:12 2006
@@ -0,0 +1,30 @@
+/**
+ * 
+ * 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.system.assembly.pojo;
+
+import org.apache.tuscany.core.system.assembly.SystemBinding;
+import org.apache.tuscany.model.assembly.pojo.PojoBinding;
+
+/**
+ * A marker implementation of the system binding
+ * 
+ * @version $Rev$ $Date$
+ */
+public class PojoSystemBinding extends PojoBinding implements SystemBinding {
+
+    public PojoSystemBinding() {
+    }
+
+}
+

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/assembly/pojo/PojoSystemImplementation.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/assembly/pojo/PojoSystemImplementation.java?rev=368394&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/assembly/pojo/PojoSystemImplementation.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/assembly/pojo/PojoSystemImplementation.java Thu Jan 12 08:00:12 2006
@@ -0,0 +1,41 @@
+/**
+ * 
+ * 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.system.assembly.pojo;
+
+import org.apache.tuscany.core.system.assembly.SystemImplementation;
+import org.apache.tuscany.model.assembly.pojo.PojoComponentImplementation;
+
+/**
+ * Implements a POJO-based representation of a system type component
+ * 
+ * @version $Rev$ $Date$
+ */
+public class PojoSystemImplementation extends PojoComponentImplementation implements SystemImplementation {
+
+    public PojoSystemImplementation() {
+    }
+
+    private String clazz;
+    
+    public String getClass_() {
+        return clazz;
+    }
+
+    public void setClass(String clazz) {
+        check();
+        this.clazz=clazz;
+    }
+
+}
+

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/builder/ProxyFactoryBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/builder/ProxyFactoryBuilder.java?rev=368394&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/builder/ProxyFactoryBuilder.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/builder/ProxyFactoryBuilder.java Thu Jan 12 08:00:12 2006
@@ -0,0 +1,270 @@
+/**
+ *
+ *  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.system.builder;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.tuscany.core.addressing.AddressingFactory;
+import org.apache.tuscany.core.addressing.EndpointReference;
+import org.apache.tuscany.core.builder.BuilderConfigException;
+import org.apache.tuscany.core.builder.BuilderException;
+import org.apache.tuscany.core.builder.BuilderInitException;
+import org.apache.tuscany.core.builder.RuntimeConfigurationBuilder;
+import org.apache.tuscany.core.config.JavaIntrospectionHelper;
+import org.apache.tuscany.core.context.AggregateContext;
+import org.apache.tuscany.core.context.ScopeAwareContext;
+import org.apache.tuscany.core.context.ScopeContext;
+import org.apache.tuscany.core.invocation.InvocationConfiguration;
+import org.apache.tuscany.core.invocation.ProxyConfiguration;
+import org.apache.tuscany.core.invocation.jdk.JDKProxyFactory;
+import org.apache.tuscany.core.invocation.spi.ProxyException;
+import org.apache.tuscany.core.invocation.spi.ProxyFactory;
+import org.apache.tuscany.core.invocation.spi.ProxyInitializationException;
+import org.apache.tuscany.core.message.Message;
+import org.apache.tuscany.core.message.MessageFactory;
+import org.apache.tuscany.core.message.handler.MessageHandler;
+import org.apache.tuscany.core.system.annotation.Autowire;
+import org.apache.tuscany.core.system.assembly.SystemImplementation;
+import org.apache.tuscany.core.system.context.RuntimeContext;
+import org.apache.tuscany.model.assembly.AssemblyModelObject;
+import org.apache.tuscany.model.assembly.Component;
+import org.apache.tuscany.model.assembly.ConfiguredReference;
+import org.apache.tuscany.model.assembly.ConfiguredService;
+import org.apache.tuscany.model.types.InterfaceType;
+import org.apache.tuscany.model.types.OperationType;
+import org.osoa.sca.annotations.ComponentName;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * A system component that configures proxy factories for references
+ * <p>
+ * FIXME integrate back with {@link org.apache.tuscany.core.builder.impl.PortRuntimeConfigurationBuilderImpl}
+ */
+
+@Scope("MODULE")
+public class ProxyFactoryBuilder implements RuntimeConfigurationBuilder<AggregateContext> {
+
+    @ComponentName
+    private String name;
+
+    @Autowire
+    RuntimeContext runtime;
+
+    @Autowire
+    private MessageHandler configurationPipeline;
+
+    @Autowire
+    private AddressingFactory addressingFactory;
+
+    @Autowire
+    private MessageFactory messageFactory;
+
+    @Property(required = false)
+    // the proxy factory, defaults to JDK proxies
+    private String proxyFactoryClass;
+
+    private Constructor proxyFactoryConstructor;
+
+    // ----------------------------------
+    // Constructors
+    // ----------------------------------
+
+    public ProxyFactoryBuilder() {
+    }
+
+    public ProxyFactoryBuilder(MessageHandler configPipeline, AddressingFactory addressingFactory, MessageFactory messageFactory,
+            Map<Integer, ScopeContext> scopeContainers) {
+    }
+
+    // ----------------------------------
+    // Methods
+    // ----------------------------------
+
+    @Init(eager = true)
+    public void init() throws BuilderInitException {
+        try {
+            if (proxyFactoryClass == null) {
+                proxyFactoryClass = JDKProxyFactory.class.getName();
+                proxyFactoryConstructor = JavaIntrospectionHelper.getDefaultConstructor(JDKProxyFactory.class);
+            } else {
+                proxyFactoryConstructor = JavaIntrospectionHelper.getDefaultConstructor(JavaIntrospectionHelper
+                        .loadClass(proxyFactoryClass));
+            }
+            runtime.addBuilder(this); // register the builder with the runtime
+        } catch (NoSuchMethodException e) {
+            BuilderInitException be = new BuilderInitException(e);
+            be.setIdentifier(proxyFactoryClass);
+            be.addContextName(name);
+            throw be;
+        } catch (ClassNotFoundException e) {
+            BuilderInitException be = new BuilderInitException(e);
+            be.addContextName(name);
+            throw be;
+        }
+    }
+
+    private AggregateContext parentContext;
+
+    // scope containers of the parent context
+    private Map<Integer, ScopeContext> scopeContexts;
+
+    public void setParentContext(AggregateContext context) {
+        assert (parentContext != null) : "Parent context was null";
+        parentContext = context;
+        if (!(parentContext instanceof ScopeAwareContext)) {
+            BuilderInitException e = new BuilderInitException("Parent context is not scope aware");
+            e.setIdentifier(parentContext.getName());
+            e.addContextName(name);
+            throw e;
+        }
+        scopeContexts = ((ScopeAwareContext) parentContext).getScopeContexts();
+    }
+
+    private AssemblyModelObject model;
+
+    public void setModelObject(AssemblyModelObject model) {
+        this.model = model;
+    }
+
+    public void build() throws BuilderException {
+        if (model instanceof Component) {
+            try {
+                Component component = (Component) model;
+                if (component.getComponentImplementation() instanceof SystemImplementation) {
+                    return; // system implementations do not use proxies
+                }
+                for (Iterator<ConfiguredService> i = component.getConfiguredServices().iterator(); i.hasNext();) {
+                    ConfiguredService configuredService = i.next();
+                    ProxyFactory proxyFactory = buildProxyFactory(configuredService);
+                    configuredService.setProxyFactory(proxyFactory);
+                }
+
+                for (Iterator<ConfiguredReference> i = component.getConfiguredReferences().iterator(); i.hasNext();) {
+                    ConfiguredReference configuredReference = i.next();
+                    InterfaceType interfaceType = configuredReference.getReference().getInterfaceContract().getInterfaceType();
+                    Class businessInterface = interfaceType.getInstanceClass();
+                    ProxyFactory proxyFactory = buildProxyFactory(configuredReference);
+                    configuredReference.setProxyFactory(proxyFactory);
+                }
+            } catch (ProxyException e) {
+                throw new BuilderConfigException(e);
+            }
+        }
+    }
+
+    private ProxyFactory buildProxyFactory(ConfiguredService configuredService) throws ProxyException {
+        InterfaceType interfaceType = configuredService.getService().getInterfaceContract().getInterfaceType();
+
+        // Create Proxy configuration
+        Map<OperationType, InvocationConfiguration> invocationConfigurations = new HashMap<OperationType, InvocationConfiguration>();
+        Class javaInterface = interfaceType.getInstanceClass();
+        ProxyConfiguration proxyConfiguration = new ProxyConfiguration(invocationConfigurations, javaInterface.getClassLoader(),
+                scopeContexts, messageFactory);
+
+        // Create invocation configurations for all the operations on the business interface
+        for (OperationType operationType : interfaceType.getOperationTypes()) {
+            invocationConfigurations.put(operationType, new InvocationConfiguration(operationType));
+        }
+
+        // Create a message
+        Message message = messageFactory.createMessage();
+        EndpointReference endpointReference = addressingFactory.createEndpointReference();
+        endpointReference.setConfiguredPort(configuredService);
+        message.setEndpointReference(endpointReference);
+        message.setBody(proxyConfiguration);
+
+        configurationPipeline.processMessage(message);
+        return createProxyFactory(javaInterface, proxyConfiguration);
+    }
+
+    private ProxyFactory buildProxyFactory(ConfiguredReference configuredReference) throws ProxyInitializationException {
+        InterfaceType interfaceType = configuredReference.getReference().getInterfaceContract().getInterfaceType();
+
+        ConfiguredService configuredService = configuredReference.getConfiguredServices().get(0);
+
+        // Create Proxy configuration
+        Map<OperationType, InvocationConfiguration> invocationConfigurations = new HashMap<OperationType, InvocationConfiguration>();
+        Class javaInterface = interfaceType.getInstanceClass();
+        ProxyConfiguration proxyConfiguration = new ProxyConfiguration(invocationConfigurations, javaInterface.getClassLoader(),
+                scopeContexts, messageFactory);
+
+        // Create invocation configurations for all the operations on the business interface
+        for (OperationType operationType : interfaceType.getOperationTypes()) {
+            invocationConfigurations.put(operationType, new InvocationConfiguration(operationType));
+        }
+
+        // Create a message
+        Message message = messageFactory.createMessage();
+        EndpointReference endpointReference = addressingFactory.createEndpointReference();
+        endpointReference.setConfiguredPort(configuredService);
+        message.setEndpointReference(endpointReference);
+        EndpointReference fromEndpointReference = addressingFactory.createEndpointReference();
+        fromEndpointReference.setConfiguredPort(configuredReference);
+        message.setFrom(fromEndpointReference);
+        message.setBody(proxyConfiguration);
+
+        // Send the message to the configuration pipeline
+        configurationPipeline.processMessage(message);
+
+        // Build the proxy configurations
+        for (InvocationConfiguration invocationConfiguration : invocationConfigurations.values()) {
+            invocationConfiguration.build();
+        }
+        return createProxyFactory(javaInterface, proxyConfiguration);
+    }
+
+    /**
+     * Creates the proxy factory for the given interface and proxy configuration
+     * 
+     * @throws ProxyInitializationException
+     */
+    private ProxyFactory createProxyFactory(Class javaInterface, ProxyConfiguration proxyConfiguration)
+            throws ProxyInitializationException {
+        try {
+            // Create a proxy factory
+            ProxyFactory proxyFactory = (ProxyFactory) proxyFactoryConstructor.newInstance((Object[]) null);
+            proxyFactory.initialize(javaInterface, proxyConfiguration);
+            return proxyFactory;
+        } catch (ProxyInitializationException e) {
+            e.addContextName(name);
+            throw e;
+        } catch (IllegalArgumentException e) {
+            ProxyInitializationException pe = new ProxyInitializationException(e);
+            pe.addContextName(name);
+            throw pe;
+        } catch (InstantiationException e) {
+            ProxyInitializationException pe = new ProxyInitializationException(e);
+            pe.addContextName(name);
+            throw pe;
+        } catch (IllegalAccessException e) {
+            ProxyInitializationException pe = new ProxyInitializationException(e);
+            pe.addContextName(name);
+            throw pe;
+        } catch (InvocationTargetException e) {
+            ProxyInitializationException pe = new ProxyInitializationException(e);
+            pe.addContextName(name);
+            throw pe;
+        }
+    }
+
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/builder/SystemComponentContextBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/builder/SystemComponentContextBuilder.java?rev=368394&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/builder/SystemComponentContextBuilder.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/builder/SystemComponentContextBuilder.java Thu Jan 12 08:00:12 2006
@@ -0,0 +1,375 @@
+/**
+ * 
+ * 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.system.builder;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.tuscany.common.monitor.MonitorFactory;
+import org.apache.tuscany.core.builder.BuilderConfigException;
+import org.apache.tuscany.core.builder.BuilderException;
+import org.apache.tuscany.core.builder.NoAccessorException;
+import org.apache.tuscany.core.builder.RuntimeConfigurationBuilder;
+import org.apache.tuscany.core.builder.UnknownTypeException;
+import org.apache.tuscany.core.config.JavaIntrospectionHelper;
+import org.apache.tuscany.core.context.AggregateContext;
+import org.apache.tuscany.core.context.AutowireContext;
+import org.apache.tuscany.core.context.ConfigurationContext;
+import org.apache.tuscany.core.context.SystemAggregateContext;
+import org.apache.tuscany.core.injection.EventInvoker;
+import org.apache.tuscany.core.injection.FieldInjector;
+import org.apache.tuscany.core.injection.Injector;
+import org.apache.tuscany.core.injection.MethodEventInvoker;
+import org.apache.tuscany.core.injection.MethodInjector;
+import org.apache.tuscany.core.injection.ObjectCreationException;
+import org.apache.tuscany.core.injection.ReferenceTargetFactory;
+import org.apache.tuscany.core.injection.SDOObjectFactory;
+import org.apache.tuscany.core.injection.SingletonObjectFactory;
+import org.apache.tuscany.core.system.annotation.Autowire;
+import org.apache.tuscany.core.system.annotation.ParentContext;
+import org.apache.tuscany.core.system.assembly.SystemImplementation;
+import org.apache.tuscany.core.system.config.SystemComponentRuntimeConfiguration;
+import org.apache.tuscany.core.system.context.RuntimeContext;
+import org.apache.tuscany.model.assembly.AssemblyModelObject;
+import org.apache.tuscany.model.assembly.Component;
+import org.apache.tuscany.model.assembly.ConfiguredProperty;
+import org.apache.tuscany.model.assembly.ConfiguredReference;
+import org.apache.tuscany.model.assembly.ConfiguredService;
+import org.apache.tuscany.model.assembly.ModuleComponent;
+import org.apache.tuscany.model.assembly.ScopeEnum;
+import org.osoa.sca.annotations.ComponentName;
+import org.osoa.sca.annotations.Context;
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.Init;
+
+import commonj.sdo.DataObject;
+
+/**
+ * Decorates components whose implementation type is a
+ * {@link org.apache.tuscany.core.system.assembly.SystemImplementation} with the appropriate runtime configuration
+ * 
+ * @version $Rev$ $Date$
+ */
+public class SystemComponentContextBuilder implements RuntimeConfigurationBuilder<AggregateContext> {
+
+    private final List<Injector> setters = new ArrayList();
+
+    private AssemblyModelObject modelObject;
+
+    private AggregateContext parentContext;
+
+    // ----------------------------------
+    // Constructors
+    // ----------------------------------
+
+    public SystemComponentContextBuilder() {
+    }
+
+    // ----------------------------------
+    // Methods
+    // ----------------------------------
+
+    public void setModelObject(AssemblyModelObject modelObject) {
+        this.modelObject = modelObject;
+    }
+
+    public void setParentContext(AggregateContext context) {
+        parentContext = context;
+    }
+
+    public void build() throws BuilderException {
+        if (!(modelObject instanceof Component) || (modelObject instanceof ModuleComponent)) {
+            return;
+        }
+        Component component = (Component) modelObject;
+        if (component.getComponentImplementation() instanceof SystemImplementation
+                && component.getComponentImplementation().getRuntimeConfiguration() == null) {
+            SystemImplementation javaImpl = (SystemImplementation) component.getComponentImplementation();
+            // FIXME scope
+            ScopeEnum scope = component.getComponentImplementation().getServices().get(0).getInterfaceContract().getScope();
+            Class implClass = null;
+            Set<Field> fields;
+            Set<Method> methods;
+            try {
+                implClass = JavaIntrospectionHelper.loadClass(javaImpl.getClass_());
+                fields = JavaIntrospectionHelper.getAllFields(implClass);
+                methods = JavaIntrospectionHelper.getAllUniqueMethods(implClass);
+                String name = component.getName();
+                Constructor ctr = implClass.getConstructor((Class[]) null);
+
+                List<Injector> injectors = new ArrayList();
+
+                // handle properties
+                List<ConfiguredProperty> configuredProperties = component.getConfiguredProperties();
+                // FIXME should return empty properties - does it?
+                if (configuredProperties != null) {
+                    for (ConfiguredProperty property : configuredProperties) {
+                        Injector injector = createPropertyInjector(property, fields, methods);
+                        injectors.add(injector);
+                    }
+                }
+
+                // handle references
+                List<ConfiguredReference> configuredReferences = component.getConfiguredReferences();
+                // FIXME should return empty refs - does it?
+                if (configuredReferences != null) {
+                    for (ConfiguredReference reference : configuredReferences) {
+                        Injector injector = createReferenceInjector(parentContext.getName(), component.getName(), reference,
+                                fields, methods);
+                        injectors.add(injector);
+                    }
+                }
+
+                /*
+                 * TODO if the specs support constructor injection, this would be determined here from the property
+                 * config
+                 */
+                // create factory for the component implementation type
+                EventInvoker initInvoker = null;
+                boolean eagerInit = false;
+                EventInvoker destroyInvoker = null;
+                // FIXME this should be run as part of the LCM load
+                for (Field field : fields) {
+                    ComponentName compName = field.getAnnotation(ComponentName.class);
+                    if (compName != null) {
+                        Injector injector = new FieldInjector(field, new SingletonObjectFactory(name));
+                        injectors.add(injector);
+                    }
+                    Context context = field.getAnnotation(Context.class);
+                    if (context != null) {
+                        Injector injector = new FieldInjector(field, new SingletonObjectFactory(parentContext));
+                        injectors.add(injector);
+                    }
+                    ParentContext parentField = field.getAnnotation(ParentContext.class);
+                    if (parentField != null) {
+                        if (!(parentContext instanceof AggregateContext)) {
+                            BuilderConfigException e = new BuilderConfigException("Component must be a child of");
+                            e.setIdentifier(AggregateContext.class.getName());
+                            throw e;
+                        }
+                        Injector injector = new FieldInjector(field, new SingletonObjectFactory((parentContext)));
+                        injectors.add(injector);
+                    }
+                    Autowire autowire = field.getAnnotation(Autowire.class);
+                    if (autowire != null) {
+                        if (!(parentContext instanceof AutowireContext)) {
+                            BuilderConfigException e = new BuilderConfigException("Parent context must implement");
+                            e.setIdentifier(AutowireContext.class.getName());
+                            throw e;
+                        }
+                        AutowireContext ctx = (AutowireContext) parentContext;
+                        // for system aggregate context types, only allow autowire of certain types, otherwise we have a
+                        // chicken-and-egg problem
+                        if (SystemAggregateContext.class.isAssignableFrom(implClass)
+                                && !(field.getType().equals(ConfigurationContext.class)
+                                        || field.getType().equals(MonitorFactory.class)
+                                        || field.getType().equals(RuntimeContext.class) || field.getType().equals(
+                                        AutowireContext.class))) {
+                            BuilderConfigException e = new BuilderConfigException("Illegal autowire type for system context");
+                            e.setIdentifier(field.getType().getName());
+                            throw e;
+                        }
+
+                        Object o = ctx.resolveInstance(field.getType());
+                        if (autowire.required() && o == null) {
+                            BuilderConfigException e = new BuilderConfigException("No autowire found for field");
+                            e.setIdentifier(field.getName());
+                            throw e;
+                        }
+                        Injector injector = new FieldInjector(field, new SingletonObjectFactory(o));
+                        injectors.add(injector);
+                    }
+                }
+                for (Method method : methods) {
+                    // FIXME Java5
+                    Init init = method.getAnnotation(Init.class);
+                    if (init != null && initInvoker == null) {
+                        initInvoker = new MethodEventInvoker(method);
+                        eagerInit = init.eager();
+                        continue;
+                    }
+                    Destroy destroy = method.getAnnotation(Destroy.class);
+                    if (destroy != null && destroyInvoker == null) {
+                        destroyInvoker = new MethodEventInvoker(method);
+                        continue;
+                    }
+                    ComponentName compName = method.getAnnotation(ComponentName.class);
+                    if (compName != null) {
+                        Injector injector = new MethodInjector(method, new SingletonObjectFactory(name));
+                        injectors.add(injector);
+                    }
+                    Context context = method.getAnnotation(Context.class);
+                    if (context != null) {
+                        Injector injector = new MethodInjector(method, new SingletonObjectFactory(parentContext));
+                        injectors.add(injector);
+                    }
+                    ParentContext parentMethod = method.getAnnotation(ParentContext.class);
+                    if (parentMethod != null) {
+                        if (!(parentContext instanceof AggregateContext)) {
+                            BuilderConfigException e = new BuilderConfigException("Component must be a child of ");
+                            e.setIdentifier(AggregateContext.class.getName());
+                            throw e;
+                        }
+                        Injector injector = new MethodInjector(method, new SingletonObjectFactory((parentContext)));
+                        injectors.add(injector);
+                    }
+                    Autowire autowire = method.getAnnotation(Autowire.class);
+                    if (autowire != null) {
+                        if (!(parentContext instanceof AutowireContext)) {
+                            BuilderConfigException e = new BuilderConfigException("Parent context must implement)");
+                            e.setIdentifier(AutowireContext.class.getName());
+                            throw e;
+                        }
+                        if (method.getParameterTypes() == null || method.getParameterTypes().length != 1) {
+                            BuilderConfigException e = new BuilderConfigException(
+                                    "Autowire setter methods must take one parameter");
+                            e.setIdentifier(method.getName());
+                            throw e;
+                        }
+                        AutowireContext ctx = (AutowireContext) parentContext;
+                        Class paramType = method.getParameterTypes()[0];
+                        // for system aggregate context types, only allow autowire of certain types, otherwise we have a
+                        // chicken-and-egg problem
+                        if (SystemAggregateContext.class.isAssignableFrom(implClass)
+                                && !(paramType.equals(ConfigurationContext.class) || paramType.equals(MonitorFactory.class)
+                                        || paramType.equals(RuntimeContext.class) || paramType.equals(AutowireContext.class))) {
+                            BuilderConfigException e = new BuilderConfigException("Illegal autowire type for system context");
+                            e.setIdentifier(paramType.getName());
+                            throw e;
+                        }
+                        Object o = ctx.resolveInstance(paramType);
+                        if (autowire.required() && o == null) {
+                            BuilderConfigException e = new BuilderConfigException("No autowire found for method ");
+                            e.setIdentifier(method.getName());
+                            throw e;
+                        }
+
+                        Injector injector = new MethodInjector(method, new SingletonObjectFactory(o));
+                        injectors.add(injector);
+                    }
+                }
+                // decorate the logical model
+                SystemComponentRuntimeConfiguration config = new SystemComponentRuntimeConfiguration(name,
+                        JavaIntrospectionHelper.getDefaultConstructor(implClass), injectors, eagerInit, initInvoker,
+                        destroyInvoker, scope.getValue());
+                component.getComponentImplementation().setRuntimeConfiguration(config);
+            } catch (BuilderConfigException e) {
+                e.addContextName(component.getName());
+                e.addContextName(parentContext.getName());
+                throw e;
+            } catch (ClassNotFoundException e) {
+                throw new BuilderConfigException(e);
+            } catch (NoSuchMethodException e) {
+                BuilderConfigException ce = new BuilderConfigException("Class does not have a no-arg constructor", e);
+                ce.setIdentifier(implClass.getName());
+                throw ce;
+            }
+        }
+    }
+
+    // ----------------------------------
+    // Private methods
+    // ----------------------------------
+
+    /**
+     * Creates an <code>Injector</code> for component properties
+     */
+    private Injector createPropertyInjector(ConfiguredProperty property, Set<Field> fields, Set<Method> methods)
+            throws NoAccessorException {
+        Object value = property.getValue();
+        String propName = property.getProperty().getName();
+        // @FIXME is this how to get property type of object
+        Class type = value.getClass();
+
+        // There is no efficient way to do this
+        Method method = null;
+        Field field = JavaIntrospectionHelper.findClosestMatchingField(propName, type, fields);
+        if (field == null) {
+            method = JavaIntrospectionHelper.findClosestMatchingMethod(propName, new Class[] { type }, methods);
+            if (method == null) {
+                throw new NoAccessorException(propName);
+            }
+        }
+        Injector injector = null;
+        // FIXME support types other than String
+        if (value instanceof DataObject) {
+            if (field != null) {
+                injector = new FieldInjector(field, new SDOObjectFactory((DataObject) value));
+            } else {
+                injector = new MethodInjector(method, new SDOObjectFactory((DataObject) value));
+            }
+        } else if (JavaIntrospectionHelper.isImmutable(type)) {
+            if (field != null) {
+                injector = new FieldInjector(field, new SingletonObjectFactory(value));
+            } else {
+                injector = new MethodInjector(method, new SingletonObjectFactory(value));
+            }
+        } else {
+            if (field != null) {
+                throw new UnknownTypeException(field.getName());
+            } else {
+                throw new UnknownTypeException(method.getName());
+            }
+        }
+        return injector;
+
+    }
+
+    /**
+     * Creates an <code>Injector</code> for service references
+     */
+    private Injector createReferenceInjector(String moduleName, String componentName, ConfiguredReference reference,
+            Set<Field> fields, Set<Method> methods) throws NoAccessorException, BuilderConfigException {
+        String refName = reference.getReference().getName();
+        List<ConfiguredService> services = reference.getConfiguredServices();
+        Class type;
+        // FIXME added the size check - do we need to do this?
+        if (services.size() == 1) {
+            // get the interface
+            type = reference.getReference().getInterfaceContract().getInterfaceType().getInstanceClass();
+        } else {
+            // FIXME do we support arrays?
+            type = List.class;
+        }
+
+        Method method = null;
+
+        Field field = JavaIntrospectionHelper.findClosestMatchingField(refName, type, fields);
+        if (field == null) {
+            method = JavaIntrospectionHelper.findClosestMatchingMethod(refName, new Class[] { type }, methods);
+            if (method == null) {
+                throw new NoAccessorException(refName);
+            }
+        }
+        Injector injector;
+        try {
+            if (field != null) {
+                injector = new FieldInjector(field, new ReferenceTargetFactory(reference, parentContext));
+            } else {
+                injector = new MethodInjector(method, new ReferenceTargetFactory(reference, parentContext));
+            }
+        } catch (ObjectCreationException e) {
+            BuilderConfigException ce = new BuilderConfigException("Error configuring reference", e);
+            ce.setIdentifier(refName);
+            throw ce;
+        }
+        return injector;
+
+    }
+
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/builder/SystemEntryPointBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/builder/SystemEntryPointBuilder.java?rev=368394&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/builder/SystemEntryPointBuilder.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/builder/SystemEntryPointBuilder.java Thu Jan 12 08:00:12 2006
@@ -0,0 +1,76 @@
+/**
+ * 
+ * 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.system.builder;
+
+import org.apache.tuscany.core.builder.BuilderException;
+import org.apache.tuscany.core.builder.RuntimeConfigurationBuilder;
+import org.apache.tuscany.core.context.AggregateContext;
+import org.apache.tuscany.core.injection.FactoryInitException;
+import org.apache.tuscany.core.injection.ReferenceTargetFactory;
+import org.apache.tuscany.core.system.assembly.SystemBinding;
+import org.apache.tuscany.core.system.config.SystemEntryPointRuntimeConfiguration;
+import org.apache.tuscany.model.assembly.AssemblyModelObject;
+import org.apache.tuscany.model.assembly.EntryPoint;
+
+/**
+ * Decorates the logical model with entry point context configuration builders
+ * 
+ * @version $Rev$ $Date$
+ */
+public class SystemEntryPointBuilder implements RuntimeConfigurationBuilder<AggregateContext> {
+
+    // ----------------------------------
+    // Constructors
+    // ----------------------------------
+
+    public SystemEntryPointBuilder() {
+    }
+
+    // ----------------------------------
+    // Methods
+    // ----------------------------------
+
+    private AssemblyModelObject modelObject;
+
+    private AggregateContext context;
+
+    public void setModelObject(AssemblyModelObject modelObject) {
+        this.modelObject = modelObject;
+    }
+
+    public void setParentContext(AggregateContext context) {
+        this.context = context;
+    }
+
+    public void build() throws BuilderException {
+        if (!(modelObject instanceof EntryPoint)) {
+            return;
+        }
+        EntryPoint entryPoint = (EntryPoint) modelObject;
+        if (!(entryPoint.getBindings().get(0) instanceof SystemBinding)
+                || entryPoint.getConfiguredReference().getRuntimeConfiguration() != null) {
+            return;
+        }
+        try {
+            SystemEntryPointRuntimeConfiguration config = new SystemEntryPointRuntimeConfiguration(entryPoint.getName(),
+                    new ReferenceTargetFactory(entryPoint.getConfiguredReference(), context));
+            // FIXME this should decorate the entry point
+            entryPoint.getConfiguredReference().setRuntimeConfiguration(config);
+        } catch (FactoryInitException e) {
+            e.addContextName(entryPoint.getName());
+            e.addContextName(context.getName());
+            throw e;
+        }
+    }
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/builder/SystemExternalServiceBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/builder/SystemExternalServiceBuilder.java?rev=368394&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/builder/SystemExternalServiceBuilder.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/main/java/org/apache/tuscany/core/system/builder/SystemExternalServiceBuilder.java Thu Jan 12 08:00:12 2006
@@ -0,0 +1,89 @@
+/**
+ * 
+ * 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.system.builder;
+
+import org.apache.tuscany.core.builder.BuilderConfigException;
+import org.apache.tuscany.core.builder.BuilderException;
+import org.apache.tuscany.core.builder.RuntimeConfigurationBuilder;
+import org.apache.tuscany.core.context.AggregateContext;
+import org.apache.tuscany.core.injection.ReferenceTargetFactory;
+import org.apache.tuscany.core.system.assembly.SystemBinding;
+import org.apache.tuscany.core.system.config.SystemExternalServiceRuntimeConfiguration;
+import org.apache.tuscany.core.system.injection.AutowireFactory;
+import org.apache.tuscany.model.assembly.AssemblyModelObject;
+import org.apache.tuscany.model.assembly.ExternalService;
+
+/**
+ * Creates runtime configurations for system type external services
+ * 
+ * @version $Rev$ $Date$
+ */
+public class SystemExternalServiceBuilder implements RuntimeConfigurationBuilder<AggregateContext> {
+
+    private AggregateContext context;
+
+    private AssemblyModelObject modelObject;
+
+    // ----------------------------------
+    // Constructors
+    // ----------------------------------
+
+    public SystemExternalServiceBuilder() {
+    }
+
+    // ----------------------------------
+    // Methods
+    // ----------------------------------
+
+    public void setModelObject(AssemblyModelObject modelObject) {
+        this.modelObject = modelObject;
+    }
+
+    public void setParentContext(AggregateContext context) {
+        this.context = context;
+    }
+
+    public void build() throws BuilderException {
+        if (!(modelObject instanceof ExternalService)) {
+            return;
+        }
+        ExternalService externalService = (ExternalService) modelObject;
+        if (externalService.getConfiguredService() != null
+                && externalService.getConfiguredService().getRuntimeConfiguration() != null) {
+            return;
+        } else if (externalService.getBindings() == null || externalService.getBindings().size() < 1
+                || !(externalService.getBindings().get(0) instanceof SystemBinding)) {
+            return;
+        }
+
+        if (externalService.getConfiguredService() != null && externalService.getConfiguredService().getPart() != null) {
+            SystemExternalServiceRuntimeConfiguration config = new SystemExternalServiceRuntimeConfiguration(externalService
+                    .getName(), new ReferenceTargetFactory(externalService.getConfiguredService(), context));
+            externalService.getConfiguredService().setRuntimeConfiguration(config);
+        } else if (externalService.getInterfaceContract().getInterfaceType() != null) {
+            // autowire
+            Class claz = externalService.getInterfaceContract().getInterfaceType().getInstanceClass();
+            if (claz == null) {
+                BuilderException e = new BuilderConfigException("Interface type not specified");
+                e.setIdentifier(externalService.getName());
+                e.addContextName(externalService.getName());
+                e.addContextName(context.getName());
+                throw e;
+            }
+            SystemExternalServiceRuntimeConfiguration config = new SystemExternalServiceRuntimeConfiguration(externalService
+                    .getName(), new AutowireFactory(claz, context));
+            externalService.getConfiguredService().setRuntimeConfiguration(config);
+        }
+    }
+}