Author: jmarino
Date: Sun May 14 01:21:10 2006
New Revision: 406281
URL: http://svn.apache.org/viewcvs?rev=406281&view=rev
Log:
extension api work
Added:
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler.java
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/ReferenceContextExtension.java
(contents, props changed)
- copied, changed from r406267,
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/ReferenceContextImpl.java
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/ServiceContextExtension.java
- copied, changed from r406267,
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/ServiceContextImpl.java
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/WireInvocationHandler.java
Removed:
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/ReferenceContextImpl.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/ServiceContextImpl.java
Modified:
incubator/tuscany/sandbox/jboynes/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/context/JavaAtomicContext.java
incubator/tuscany/sandbox/jboynes/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/invocation/ScopedJavaComponentInvoker.java
incubator/tuscany/sandbox/jboynes/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockFactory.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/system/context/AutowireSystemReferenceContext.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/system/context/SystemAtomicContext.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKSourceWire.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKTargetWire.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/mock/MockFactory.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/mock/context/MockReferenceContext.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/InvocationErrorTestCase.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerTestCase.java
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/AtomicContext.java
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/ReferenceContext.java
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/ComponentContextExtension.java
Modified:
incubator/tuscany/sandbox/jboynes/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/context/JavaAtomicContext.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/context/JavaAtomicContext.java?rev=406281&r1=406280&r2=406281&view=diff
==============================================================================
---
incubator/tuscany/sandbox/jboynes/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/context/JavaAtomicContext.java
(original)
+++
incubator/tuscany/sandbox/jboynes/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/context/JavaAtomicContext.java
Sun May 14 01:21:10 2006
@@ -26,7 +26,7 @@
import org.apache.tuscany.common.ObjectCreationException;
import org.apache.tuscany.common.ObjectFactory;
-import org.apache.tuscany.core.context.PojoAtomicContext;
+import org.apache.tuscany.container.java.invocation.ScopedJavaComponentInvoker;
import org.apache.tuscany.core.context.PojoInstanceWrapper;
import org.apache.tuscany.core.injection.ArrayMultiplicityObjectFactory;
import org.apache.tuscany.core.injection.EventInvoker;
@@ -37,41 +37,85 @@
import org.apache.tuscany.core.injection.MethodInjector;
import org.apache.tuscany.core.injection.NoAccessorException;
import org.apache.tuscany.core.injection.ProxyObjectFactory;
+import org.apache.tuscany.model.Scope;
import org.apache.tuscany.spi.context.InstanceWrapper;
import org.apache.tuscany.spi.context.TargetException;
+import org.apache.tuscany.spi.extension.AtomicContextExtension;
import org.apache.tuscany.spi.wire.SourceWire;
-import org.apache.tuscany.spi.wire.TargetWire;
import org.apache.tuscany.spi.wire.TargetInvoker;
-import org.apache.tuscany.container.java.invocation.ScopedJavaComponentInvoker;
+import org.apache.tuscany.spi.wire.TargetWire;
/**
* Provides a runtime context for Java component implementations
*
* @version $Rev$ $Date$
*/
-public class JavaAtomicContext<T> extends PojoAtomicContext<T> {
+public class JavaAtomicContext<T> extends AtomicContextExtension<T> {
- private Map<String, TargetWire> targetWires = new HashMap<String,
TargetWire>();
- private List<SourceWire> sourceWires = new ArrayList<SourceWire>();
private List<Injector> injectors;
private Map<String, Member> members;
+ protected boolean eagerInit;
+ protected EventInvoker<Object> initInvoker;
+ protected EventInvoker<Object> destroyInvoker;
+ protected ObjectFactory<?> objectFactory;
+ protected List<Class<?>> serviceInterfaces;
+
+
public JavaAtomicContext(String name, List<Class<?>> serviceInterfaces,
ObjectFactory<?> objectFactory, boolean eagerInit, EventInvoker<Object>
initInvoker,
EventInvoker<Object> destroyInvoker,
List<Injector> injectors, Map<String, Member> members) {
- super(name, serviceInterfaces, objectFactory, eagerInit, initInvoker,
destroyInvoker);
+ this.name = name;
this.injectors = injectors != null ? injectors : new
ArrayList<Injector>();
this.members = members != null ? members : new HashMap<String,
Member>();
+ this.objectFactory = objectFactory;
+ this.eagerInit = eagerInit;
+ this.initInvoker = initInvoker;
+ this.destroyInvoker = destroyInvoker;
+ this.serviceInterfaces = serviceInterfaces;
+ }
+
+ public List<Class<?>> getServiceInterfaces() {
+ return serviceInterfaces;
+ }
+
+ public Scope getScope() {
+ if (scopeContext == null) {
+ return null;
+ }
+ return scopeContext.getScope();
+ }
+
+ public boolean isEagerInit() {
+ return eagerInit;
+ }
+
+ public void init(Object instance) throws TargetException {
+ if (initInvoker != null) {
+ initInvoker.invokeEvent(instance);
+ }
+ }
+
+ public void destroy(Object instance) throws TargetException {
+ if (destroyInvoker != null) {
+ destroyInvoker.invokeEvent(instance);
+ }
}
+ @SuppressWarnings("unchecked")
+ public T getTargetInstance() throws TargetException {
+ return (T) scopeContext.getInstance(this);
+ }
+
+
public Object getService(String name) throws TargetException {
// TODO implement proxying
return getTargetInstance();
}
public T getService() throws TargetException {
- if (serviceInterfaces.size() == 1){
+ if (serviceInterfaces.size() == 1) {
return getTargetInstance();
- }else{
+ } else {
throw new TargetException("Context must contain exactly one
service");
}
}
@@ -87,29 +131,16 @@
return ctx;
}
- public void addTargetWire(TargetWire wire) {
- targetWires.put(wire.getServiceName(), wire);
- }
-
- public TargetWire getTargetWire(String serviceName) {
- return targetWires.get(serviceName);
- }
-
- public Map<String, TargetWire> getTargetWires() {
- return targetWires;
- }
-
- public void addSourceWire(SourceWire wire) {
+ public void onSourceWire(SourceWire wire) {
String referenceName = wire.getReferenceName();
Member member = members.get(referenceName);
if (member == null) {
throw new NoAccessorException(referenceName);
}
injectors.add(createInjector(member, wire));
- sourceWires.add(wire);
}
- public void addSourceWires(Class<?> multiplicityClass, List<SourceWire>
wires) {
+ public void onSourceWires(Class<?> multiplicityClass, List<SourceWire>
wires) {
assert(wires.size() > 0): "Wire wires was empty";
String referenceName = wires.get(0).getReferenceName();
Member member = members.get(referenceName);
@@ -117,11 +148,11 @@
throw new NoAccessorException(referenceName);
}
injectors.add(createMultiplicityInjector(member, multiplicityClass,
wires));
- sourceWires.addAll(wires);
}
- public List<SourceWire> getSourceWires() {
- return sourceWires;
+
+ public void onTargetWire(TargetWire wire) {
+
}
public TargetInvoker createTargetInvoker(String serviceName, Method
operation) {
Modified:
incubator/tuscany/sandbox/jboynes/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/invocation/ScopedJavaComponentInvoker.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/invocation/ScopedJavaComponentInvoker.java?rev=406281&r1=406280&r2=406281&view=diff
==============================================================================
---
incubator/tuscany/sandbox/jboynes/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/invocation/ScopedJavaComponentInvoker.java
(original)
+++
incubator/tuscany/sandbox/jboynes/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/invocation/ScopedJavaComponentInvoker.java
Sun May 14 01:21:10 2006
@@ -18,17 +18,17 @@
import java.lang.reflect.Method;
-import org.apache.tuscany.spi.context.AtomicContext;
+import org.apache.tuscany.container.java.context.JavaAtomicContext;
import org.apache.tuscany.spi.context.TargetException;
/**
- * Uses a scope container to resolve an implementation instance based on the
current thread context
+ * Uses a scope context to resolve an implementation instance based on the
current thread context
*
* @version $Rev$ $Date$
*/
public class ScopedJavaComponentInvoker extends AbstractJavaComponentInvoker {
- private AtomicContext container;
+ private JavaAtomicContext context;
private Object target;
public boolean cacheable;
@@ -36,13 +36,13 @@
/**
* Creates a new invoker
*
- * @param operation the operation the invoker is associated with
- * @param scopeContext the scope context the component is resolved in
+ * @param operation the operation the invoker is associated with
+ * @param context the scope context the component is resolved in
*/
- public ScopedJavaComponentInvoker(Method operation, AtomicContext
scopeContext) {
+ public ScopedJavaComponentInvoker(Method operation, JavaAtomicContext
context) {
super(operation);
- assert (scopeContext != null) : "No scope scopeContext specified";
- this.container = scopeContext;
+ assert (context != null) : "No atomic context specified";
+ this.context = context;
}
public boolean isCacheable() {
@@ -58,10 +58,10 @@
*/
protected Object getInstance() throws TargetException {
if (!cacheable) {
- return container.getTargetInstance();
+ return context.getTargetInstance();
} else {
if (target == null) {
- target = container.getTargetInstance();
+ target = context.getTargetInstance();
}
return target;
}
@@ -71,7 +71,7 @@
ScopedJavaComponentInvoker invoker = (ScopedJavaComponentInvoker)
super.clone();
invoker.target = null;
invoker.cacheable = this.cacheable;
- invoker.container = this.container;
+ invoker.context = this.context;
return invoker;
}
}
Modified:
incubator/tuscany/sandbox/jboynes/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockFactory.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockFactory.java?rev=406281&r1=406280&r2=406281&view=diff
==============================================================================
---
incubator/tuscany/sandbox/jboynes/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockFactory.java
(original)
+++
incubator/tuscany/sandbox/jboynes/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockFactory.java
Sun May 14 01:21:10 2006
@@ -202,7 +202,7 @@
* @param cacheable
* @throws Exception
*/
- public static void connect(SourceWire<?> sourceWire, TargetWire<?>
targetWire, AtomicContext targetContext, boolean cacheable) throws Exception {
+ public static void connect(SourceWire<?> sourceWire, TargetWire<?>
targetWire, JavaAtomicContext targetContext, boolean cacheable) throws
Exception {
if (targetWire != null) {
// if null, the target side has no interceptors or handlers
Map<Method, TargetInvocationChain> targetInvocationConfigs =
targetWire.getInvocationChains();
Modified:
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/system/context/AutowireSystemReferenceContext.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/system/context/AutowireSystemReferenceContext.java?rev=406281&r1=406280&r2=406281&view=diff
==============================================================================
---
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/system/context/AutowireSystemReferenceContext.java
(original)
+++
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/system/context/AutowireSystemReferenceContext.java
Sun May 14 01:21:10 2006
@@ -9,6 +9,7 @@
import org.apache.tuscany.spi.context.ReferenceContext;
import org.apache.tuscany.spi.context.TargetException;
import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.TargetWire;
/**
* The default implementation of an external service context
@@ -44,5 +45,10 @@
public Class<T> getInterface() {
return referenceInterface;
}
+
+ public TargetWire getTargetWire() {
+ throw new UnsupportedOperationException();
+ }
+
}
Modified:
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/system/context/SystemAtomicContext.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/system/context/SystemAtomicContext.java?rev=406281&r1=406280&r2=406281&view=diff
==============================================================================
---
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/system/context/SystemAtomicContext.java
(original)
+++
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/system/context/SystemAtomicContext.java
Sun May 14 01:21:10 2006
@@ -1,9 +1,19 @@
package org.apache.tuscany.core.system.context;
import org.apache.tuscany.spi.context.AtomicContext;
+import org.apache.tuscany.spi.context.TargetException;
/**
* @version $$Rev$$ $$Date$$
*/
public interface SystemAtomicContext<T> extends AtomicContext<T> {
+
+ /**
+ * Returns the target instance associated with the context. A target
instance is the actual object a
+ * request is dispatched to sans wire chain.
+ *
+ * @throws org.apache.tuscany.spi.context.TargetException
+ */
+ Object getTargetInstance() throws TargetException;
+
}
Added:
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler.java?rev=406281&view=auto
==============================================================================
---
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler.java
(added)
+++
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler.java
Sun May 14 01:21:10 2006
@@ -0,0 +1,135 @@
+/**
+ *
+ * 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.wire.jdk;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.core.wire.MessageImpl;
+import org.apache.tuscany.spi.context.TargetException;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.WireInvocationHandler;
+
+/**
+ * Receives a request from a proxy and dispatches it to a target invoker or
source interceptor stack
+ *
+ * @version $Rev: 406016 $ $Date: 2006-05-12 22:45:22 -0700 (Fri, 12 May 2006)
$
+ */
+public class JDKInvocationHandler implements WireInvocationHandler {
+
+ /*
+ * an association of an operation to configuration holder. The holder
contains the master wire configuration
+ * and a locale clone of the master TargetInvoker. TargetInvokers will be
cloned by the handler and placed in the
+ * holder if they are cacheable. This allows optimizations such as
avoiding target resolution when a source refers
+ * to a target of greater scope since the target reference can be
maintained by the invoker. When a target invoker
+ * is not cacheable, the master associated with the wire configuration
will be used.
+ */
+ private Map<Method, ConfigHolder> configuration;
+
+ public JDKInvocationHandler() {
+ }
+
+ /**
+ * Dispatches a client request made on a proxy
+ */
+ public Object invoke(Object proxy, Method method, Object[] args) throws
Throwable {
+ Interceptor headInterceptor = null;
+ ConfigHolder holder = configuration.get(method);
+ if (holder == null) {
+ TargetException e = new TargetException("Operation not
configured");
+ e.setIdentifier(method.getName());
+ throw e;
+ }
+ InvocationChain config = holder.config;
+ if (config != null) {
+ headInterceptor = config.getHeadInterceptor();
+ }
+
+ TargetInvoker invoker;
+
+ if (holder.cachedInvoker == null) {
+ assert config != null;
+ if (config.getTargetInvoker() == null) {
+ TargetException e = new TargetException("No target invoker
configured for operation");
+ e.setIdentifier(config.getMethod().getName());
+ throw e;
+ }
+ if (config.getTargetInvoker().isCacheable()) {
+ // clone and store the invoker locally
+ holder.cachedInvoker = (TargetInvoker)
config.getTargetInvoker().clone();
+ invoker = holder.cachedInvoker;
+ } else {
+ invoker = config.getTargetInvoker();
+ }
+ } else {
+ assert config != null;
+ invoker = config.getTargetInvoker();
+ }
+ if (headInterceptor == null) {
+ try {
+ // short-circuit the dispatch and invoke the target directly
+ if (config.getTargetInvoker() == null) {
+ throw new AssertionError("No target invoker [" +
method.getName() + "]");
+ }
+ return config.getTargetInvoker().invokeTarget(args);
+ } catch (InvocationTargetException e) {
+ // the cause was thrown by the target so throw it
+ throw e.getCause();
+ }
+ } else {
+ Message msg = new MessageImpl();
+ msg.setTargetInvoker(invoker);
+ msg.setBody(args);
+ // dispatch the wire down the chain and get the response
+ Message resp = headInterceptor.invoke(msg);
+
+ Object body = resp.getBody();
+ if (body instanceof Throwable) {
+ throw (Throwable) body;
+ }
+ return body;
+ }
+ }
+
+ public void setConfiguration(Map<Method, ? extends InvocationChain>
configuration) {
+ this.configuration = new HashMap<Method,
ConfigHolder>(configuration.size());
+ for (Map.Entry<Method, ? extends InvocationChain> entry :
configuration.entrySet()) {
+ this.configuration.put(entry.getKey(), new
ConfigHolder(entry.getValue()));
+ }
+ }
+
+ /**
+ * A holder used to associate an wire configuration with a local copy of a
target invoker that was
+ * previously cloned from the configuration master
+ */
+ private class ConfigHolder {
+
+ InvocationChain config;
+ TargetInvoker cachedInvoker;
+
+ public ConfigHolder(InvocationChain config) {
+ this.config = config;
+ }
+
+ }
+
+}
\ No newline at end of file
Modified:
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKSourceWire.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKSourceWire.java?rev=406281&r1=406280&r2=406281&view=diff
==============================================================================
---
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKSourceWire.java
(original)
+++
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKSourceWire.java
Sun May 14 01:21:10 2006
@@ -13,7 +13,6 @@
*/
package org.apache.tuscany.core.wire.jdk;
-import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Map;
@@ -22,6 +21,7 @@
import org.apache.tuscany.spi.wire.SourceInvocationChain;
import org.apache.tuscany.spi.wire.SourceWire;
import org.apache.tuscany.spi.wire.WireFactoryInitException;
+import org.apache.tuscany.spi.wire.WireInvocationHandler;
/**
* Creates proxies that are injected on references using JDK dynamic proxy
facilities and front a wire. The
@@ -46,7 +46,8 @@
if (state != INITIALIZED) {
throw new IllegalStateException("Proxy factory not INITIALIZED ["
+ state + "]");
}
- InvocationHandler handler = new
JDKInvocationHandler(methodToInvocationConfig);
+ WireInvocationHandler handler = new JDKInvocationHandler();
+ handler.setConfiguration(methodToInvocationConfig);
return (T)
Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
businessInterfaceArray, handler);
}
Modified:
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKTargetWire.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKTargetWire.java?rev=406281&r1=406280&r2=406281&view=diff
==============================================================================
---
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKTargetWire.java
(original)
+++
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/jdk/JDKTargetWire.java
Sun May 14 01:21:10 2006
@@ -1,6 +1,5 @@
package org.apache.tuscany.core.wire.jdk;
-import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Map;
@@ -9,6 +8,7 @@
import org.apache.tuscany.spi.wire.TargetInvocationChain;
import org.apache.tuscany.spi.wire.TargetWire;
import org.apache.tuscany.spi.wire.WireFactoryInitException;
+import org.apache.tuscany.spi.wire.WireInvocationHandler;
/**
* Creates proxies that are returned to non-SCA clients using JDK dynamic
proxy facilities and front a wire.
@@ -50,7 +50,8 @@
if (state != INITIALIZED) {
throw new IllegalStateException("Proxy factory not INITIALIZED ["
+ state + "]");
}
- InvocationHandler handler = new
JDKInvocationHandler(methodToInvocationConfig);
+ WireInvocationHandler handler = new JDKInvocationHandler();
+ handler.setConfiguration(methodToInvocationConfig);
return (T)
Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
businessInterfaceArray, handler);
}
Modified:
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/mock/MockFactory.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/mock/MockFactory.java?rev=406281&r1=406280&r2=406281&view=diff
==============================================================================
---
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/mock/MockFactory.java
(original)
+++
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/mock/MockFactory.java
Sun May 14 01:21:10 2006
@@ -158,9 +158,9 @@
* Used for injecting references
*/
private static class AtomicContextInstanceFactory implements ObjectFactory
{
- private AtomicContext ctx;
+ private SystemAtomicContext ctx;
- public AtomicContextInstanceFactory(AtomicContext ctx) {
+ public AtomicContextInstanceFactory(SystemAtomicContext ctx) {
this.ctx = ctx;
}
Modified:
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/mock/context/MockReferenceContext.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/mock/context/MockReferenceContext.java?rev=406281&r1=406280&r2=406281&view=diff
==============================================================================
---
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/mock/context/MockReferenceContext.java
(original)
+++
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/mock/context/MockReferenceContext.java
Sun May 14 01:21:10 2006
@@ -7,6 +7,7 @@
import org.apache.tuscany.spi.context.ReferenceContext;
import org.apache.tuscany.spi.context.TargetException;
import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.TargetWire;
/**
* A mock reference context which returns a singleton
@@ -34,6 +35,10 @@
}
public InvocationHandler getHandler() throws TargetException {
+ throw new UnsupportedOperationException();
+ }
+
+ public TargetWire getTargetWire() {
throw new UnsupportedOperationException();
}
Modified:
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/InvocationErrorTestCase.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/InvocationErrorTestCase.java?rev=406281&r1=406280&r2=406281&view=diff
==============================================================================
---
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/InvocationErrorTestCase.java
(original)
+++
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/InvocationErrorTestCase.java
Sun May 14 01:21:10 2006
@@ -16,23 +16,23 @@
*/
package org.apache.tuscany.core.wire;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Map;
+
import junit.framework.TestCase;
+import org.apache.tuscany.core.util.MethodHashMap;
import org.apache.tuscany.core.wire.jdk.JDKInvocationHandler;
import org.apache.tuscany.core.wire.mock.MockHandler;
import org.apache.tuscany.core.wire.mock.MockStaticInvoker;
import org.apache.tuscany.core.wire.mock.MockSyncInterceptor;
-import org.apache.tuscany.core.util.MethodHashMap;
import org.apache.tuscany.spi.wire.InvocationChain;
import org.apache.tuscany.spi.wire.SourceInvocationChain;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.Map;
+import org.apache.tuscany.spi.wire.WireInvocationHandler;
/**
* Tests handling of exceptions thrown during an wire
- *
+ *
* @version $Rev: 377006 $ $Date: 2006-02-11 09:41:59 -0800 (Sat, 11 Feb 2006)
$
*/
public class InvocationErrorTestCase extends TestCase {
@@ -58,7 +58,8 @@
public void testCheckedException() throws Exception {
Map<Method, InvocationChain> config = new
MethodHashMap<InvocationChain>();
config.put(checkedMethod, getConfiguration(checkedMethod));
- InvocationHandler handler = new JDKInvocationHandler(config);
+ WireInvocationHandler handler = new JDKInvocationHandler();
+ handler.setConfiguration(config);
try {
TestBean proxy = (TestBean)
Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
new Class[]{TestBean.class}, handler);
@@ -72,7 +73,8 @@
public void testRuntimeException() throws Exception {
Map<Method, InvocationChain> config = new
MethodHashMap<InvocationChain>();
config.put(runtimeMethod, getConfiguration(runtimeMethod));
- InvocationHandler handler = new JDKInvocationHandler(config);
+ WireInvocationHandler handler = new JDKInvocationHandler();
+ handler.setConfiguration(config);
try {
TestBean proxy = (TestBean)
Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
new Class[]{TestBean.class}, handler);
@@ -85,7 +87,7 @@
private InvocationChain getConfiguration(Method m) {
MockStaticInvoker invoker = new MockStaticInvoker(m, new
TestBeanImpl());
- SourceInvocationChain invocationConfiguration=new
SourceInvocationChainImpl(m);
+ SourceInvocationChain invocationConfiguration = new
SourceInvocationChainImpl(m);
invocationConfiguration.addInterceptor(new MockSyncInterceptor());
invocationConfiguration.addRequestHandler(new MockHandler());
invocationConfiguration.setTargetInvoker(invoker);
Modified:
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerTestCase.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerTestCase.java?rev=406281&r1=406280&r2=406281&view=diff
==============================================================================
---
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerTestCase.java
(original)
+++
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerTestCase.java
Sun May 14 01:21:10 2006
@@ -15,6 +15,7 @@
import org.apache.tuscany.spi.wire.SourceInvocationChain;
import org.apache.tuscany.spi.wire.TargetInvocationChain;
import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.WireInvocationHandler;
import java.lang.reflect.Method;
import java.util.Map;
@@ -38,14 +39,16 @@
public void testBasicInvoke() throws Throwable {
Map<Method, InvocationChain> configs = new
MethodHashMap<InvocationChain>();
configs.put(hello, getInvocationHandler(hello));
- JDKInvocationHandler handler = new JDKInvocationHandler(configs);
+ WireInvocationHandler handler = new JDKInvocationHandler();
+ handler.setConfiguration(configs);
assertEquals("foo", handler.invoke(null, hello, new Object[] { "foo"
}));
}
public void testErrorInvoke() throws Throwable {
Map<Method, InvocationChain> configs = new
MethodHashMap<InvocationChain>();
configs.put(hello, getInvocationHandler(hello));
- JDKInvocationHandler handler = new JDKInvocationHandler(configs);
+ WireInvocationHandler handler = new JDKInvocationHandler();
+ handler.setConfiguration(configs);
try {
assertEquals("foo", handler.invoke(null, hello, new Object[] {}));
fail("Expected " + IllegalArgumentException.class.getName());
@@ -61,7 +64,8 @@
Map<Method, InvocationChain> configs = new
MethodHashMap<InvocationChain>();
configs.put(hello, source);
- JDKInvocationHandler handler = new JDKInvocationHandler(configs);
+ WireInvocationHandler handler = new JDKInvocationHandler();
+ handler.setConfiguration(configs);
try {
assertEquals("foo", handler.invoke(null, hello, new Object[] {}));
fail("Expected " + IllegalArgumentException.class.getName());
@@ -77,7 +81,8 @@
Map<Method, InvocationChainImpl> configs = new
MethodHashMap<InvocationChainImpl>();
configs.put(hello, source);
- JDKInvocationHandler handler = new JDKInvocationHandler(configs);
+ WireInvocationHandler handler = new JDKInvocationHandler();
+ handler.setConfiguration(configs);
assertEquals("foo", handler.invoke(null, hello, new Object[] { "foo"
}));
}
Modified:
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/AtomicContext.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/AtomicContext.java?rev=406281&r1=406280&r2=406281&view=diff
==============================================================================
---
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/AtomicContext.java
(original)
+++
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/AtomicContext.java
Sun May 14 01:21:10 2006
@@ -56,14 +56,6 @@
void destroy(Object instance) throws TargetException;
/**
- * Returns the target instance associated with the context. A target
instance is the actual object a
- * request is dispatched to sans wire chain.
- *
- * @throws TargetException
- */
- Object getTargetInstance() throws TargetException;
-
- /**
* Creates a new implementation instance, generally used as a callback by
a [EMAIL PROTECTED] ScopeContext}
*
* @throws ObjectCreationException
Modified:
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/ReferenceContext.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/ReferenceContext.java?rev=406281&r1=406280&r2=406281&view=diff
==============================================================================
---
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/ReferenceContext.java
(original)
+++
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/ReferenceContext.java
Sun May 14 01:21:10 2006
@@ -2,6 +2,8 @@
import java.lang.reflect.InvocationHandler;
+import org.apache.tuscany.spi.wire.TargetWire;
+
/**
* Manages a reference configured for a binding
*
@@ -10,6 +12,11 @@
public interface ReferenceContext<T> extends Context<T> {
/**
+ * Returns the service interface configured for the reference
+ */
+ public Class<T> getInterface();
+
+ /**
* Returns the handler responsible for flowing a request through the
reference
*
* @throws TargetException
@@ -17,10 +24,6 @@
*/
public InvocationHandler getHandler() throws TargetException;
- /**
- * Returns the service interface configured for the reference
- */
- public Class<T> getInterface();
-
+ public TargetWire getTargetWire();
}
Modified:
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/ComponentContextExtension.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/ComponentContextExtension.java?rev=406281&r1=406280&r2=406281&view=diff
==============================================================================
---
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/ComponentContextExtension.java
(original)
+++
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/ComponentContextExtension.java
Sun May 14 01:21:10 2006
@@ -20,6 +20,7 @@
public void addTargetWire(TargetWire wire) {
targetWires.put(wire.getServiceName(), wire);
+ onTargetWire(wire);
}
public TargetWire getTargetWire(String serviceName) {
@@ -32,20 +33,25 @@
public void addSourceWire(SourceWire wire) {
sourceWires.add(wire);
+ onSourceWire(wire);
}
public List<SourceWire> getSourceWires() {
return sourceWires;
}
- public void addSourceWires(Class multiplicityClass, List wires) {
- // TODO implement
+ public void addSourceWires(Class<?> multiplicityClass, List<SourceWire>
wires) {
+ sourceWires.addAll(wires);
+ onSourceWires(multiplicityClass,wires);
}
-
public void prepare() {
-
}
-
+
+ public abstract void onSourceWire(SourceWire wire);
+
+ public abstract void onSourceWires(Class<?> multiplicityClass,
List<SourceWire> wires);
+
+ public abstract void onTargetWire(TargetWire wire);
}
Copied:
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/ReferenceContextExtension.java
(from r406267,
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/ReferenceContextImpl.java)
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/ReferenceContextExtension.java?p2=incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/ReferenceContextExtension.java&p1=incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/ReferenceContextImpl.java&r1=406267&r2=406281&rev=406281&view=diff
==============================================================================
---
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/ReferenceContextImpl.java
(original)
+++
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/ReferenceContextExtension.java
Sun May 14 01:21:10 2006
@@ -11,49 +11,56 @@
* 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.context;
+package org.apache.tuscany.spi.extension;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Map;
-import org.apache.tuscany.core.wire.jdk.JDKInvocationHandler;
+import org.apache.tuscany.common.ObjectFactory;
+import org.apache.tuscany.spi.context.AbstractContext;
import org.apache.tuscany.spi.context.ReferenceContext;
import org.apache.tuscany.spi.context.TargetException;
-import org.apache.tuscany.spi.context.AbstractContext;
import org.apache.tuscany.spi.wire.ProxyCreationException;
import org.apache.tuscany.spi.wire.TargetInvocationChain;
import org.apache.tuscany.spi.wire.TargetWire;
-import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.WireInvocationHandler;
/**
* The default implementation of an external service context
*
* @version $Rev$ $Date$
*/
-public class ReferenceContextImpl<T> extends AbstractContext<T> implements
ReferenceContext<T> {
+public abstract class ReferenceContextExtension<T> extends AbstractContext<T>
implements ReferenceContext<T> {
- private TargetWire<T> targetWire;
- private Class<T> referenceInterface;
+ protected TargetWire<T> targetWire;
+ protected Class<T> referenceInterface;
+ protected ObjectFactory<WireInvocationHandler> handlerFactory;
/**
* Creates a reference context
- *
- * @param name the name of the reference context
- * @param targetWire the factory which creates proxies implementing the
configured service
- * interface for the reference context. There is
always only one proxy factory as
- * an reference context is configured with one
service
*/
- public ReferenceContextImpl(String name, Class<T> referenceInterface,
TargetWire<T> targetWire) {
- super(name);
- assert (targetWire != null) : "Target proxy factory was null";
- assert (referenceInterface != null) : "Reference interface was null";
+ public ReferenceContextExtension() {
+ }
+
+ public void setTargetWire(TargetWire<T> targetWire) {
this.targetWire = targetWire;
+ }
+
+ public TargetWire getTargetWire() {
+ return targetWire;
+ }
+
+ public Class<T> getInterface() {
+ return referenceInterface;
+ }
+
+ public void setInterface(Class<T> referenceInterface) {
this.referenceInterface = referenceInterface;
}
- public TargetInvoker createTargetInvoker(String serviceName, Method
operation) {
- return null; // TODO implements
+ public void setHandlerFactory(ObjectFactory<WireInvocationHandler>
handlerFactory) {
+ this.handlerFactory = handlerFactory;
}
public T getService() throws TargetException {
@@ -69,11 +76,10 @@
public InvocationHandler getHandler() throws TargetException {
Map<Method, TargetInvocationChain> configuration =
targetWire.getInvocationChains();
assert(configuration != null);
- return new JDKInvocationHandler(configuration);
+ WireInvocationHandler handler = handlerFactory.getInstance();
+ handler.setConfiguration(configuration);
+ return handler;
}
- public Class<T> getInterface() {
- return referenceInterface;
- }
}
Propchange:
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/ReferenceContextExtension.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Copied:
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/ServiceContextExtension.java
(from r406267,
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/ServiceContextImpl.java)
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/ServiceContextExtension.java?p2=incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/ServiceContextExtension.java&p1=incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/ServiceContextImpl.java&r1=406267&r2=406281&rev=406281&view=diff
==============================================================================
---
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/ServiceContextImpl.java
(original)
+++
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/ServiceContextExtension.java
Sun May 14 01:21:10 2006
@@ -1,47 +1,44 @@
-package org.apache.tuscany.core.context;
+package org.apache.tuscany.spi.extension;
import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import org.apache.tuscany.core.wire.jdk.JDKInvocationHandler;
+import org.apache.tuscany.common.ObjectFactory;
import org.apache.tuscany.spi.CoreRuntimeException;
import org.apache.tuscany.spi.context.AbstractContext;
import org.apache.tuscany.spi.context.ServiceContext;
import org.apache.tuscany.spi.context.TargetException;
import org.apache.tuscany.spi.wire.ProxyCreationException;
import org.apache.tuscany.spi.wire.SourceWire;
-import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.WireInvocationHandler;
/**
* The default implementation of an service context
*
* @version $Rev: 399161 $ $Date: 2006-05-02 23:09:37 -0700 (Tue, 02 May 2006)
$
*/
-public class ServiceContextImpl<T extends Class> extends AbstractContext<T>
implements ServiceContext<T> {
+public abstract class ServiceContextExtension<T> extends AbstractContext<T>
implements ServiceContext<T> {
private SourceWire<T> sourceWire;
- private InvocationHandler invocationHandler;
+
+ protected ObjectFactory<WireInvocationHandler> handlerFactory;
// a proxy implementing the service exposed by the context backed by the
invocation handler
private T proxy;
/**
* Creates a new service context
- *
- * @param name the bound service name
- * @param sourceWire the proxy factory containing the invocation chains
for the service
- * @throws CoreRuntimeException if an error occurs creating the service
context
*/
- public ServiceContextImpl(String name, SourceWire<T> sourceWire) throws
CoreRuntimeException {
- super(name);
- assert (sourceWire != null) : "Proxy factory was null";
+ public ServiceContextExtension() throws CoreRuntimeException {
+ }
+
+ public void setSourceWire(SourceWire<T> sourceWire) {
this.sourceWire = sourceWire;
- invocationHandler = new
JDKInvocationHandler(sourceWire.getInvocationChains());
}
- public TargetInvoker createTargetInvoker(String serviceName, Method
operation) {
- return null; //TODO implement
+ public void setHandlerFactory(ObjectFactory<WireInvocationHandler>
handlerFactory) {
+ this.handlerFactory = handlerFactory;
}
+
public T getService() throws TargetException {
if (proxy == null) {
try {
@@ -56,6 +53,8 @@
}
public InvocationHandler getHandler() {
+ WireInvocationHandler invocationHandler = handlerFactory.getInstance();
+ invocationHandler.setConfiguration(sourceWire.getInvocationChains());
return invocationHandler;
}
Added:
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/WireInvocationHandler.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/WireInvocationHandler.java?rev=406281&view=auto
==============================================================================
---
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/WireInvocationHandler.java
(added)
+++
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/wire/WireInvocationHandler.java
Sun May 14 01:21:10 2006
@@ -0,0 +1,13 @@
+package org.apache.tuscany.spi.wire;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationHandler;
+import java.util.Map;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public interface WireInvocationHandler extends InvocationHandler {
+
+ void setConfiguration(Map<Method, ? extends InvocationChain>
configuration);
+}