Author: rfeng
Date: Thu Aug 30 11:23:58 2007
New Revision: 571266
URL: http://svn.apache.org/viewvc?rev=571266&view=rev
Log:
Add injection support for @Callback of CallableReference type
Modified:
incubator/tuscany/java/sca/itest/callback-api/src/main/java/org/apache/tuscany/sca/test/CallBackApiClientImpl.java
incubator/tuscany/java/sca/itest/callback-api/src/main/java/org/apache/tuscany/sca/test/CallBackApiService.java
incubator/tuscany/java/sca/itest/callback-api/src/main/java/org/apache/tuscany/sca/test/CallBackApiServiceImpl.java
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.java
incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java
incubator/tuscany/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessor.java
incubator/tuscany/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceCallbackTestCase.java
Modified:
incubator/tuscany/java/sca/itest/callback-api/src/main/java/org/apache/tuscany/sca/test/CallBackApiClientImpl.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/callback-api/src/main/java/org/apache/tuscany/sca/test/CallBackApiClientImpl.java?rev=571266&r1=571265&r2=571266&view=diff
==============================================================================
---
incubator/tuscany/java/sca/itest/callback-api/src/main/java/org/apache/tuscany/sca/test/CallBackApiClientImpl.java
(original)
+++
incubator/tuscany/java/sca/itest/callback-api/src/main/java/org/apache/tuscany/sca/test/CallBackApiClientImpl.java
Thu Aug 30 11:23:58 2007
@@ -40,6 +40,8 @@
// Test3a is the basic callback where the target calls back prior to
// returning to the client.
test3a();
+
+ test3a1();
// Test3b is where the target does not call back to the client.
test3b();
@@ -71,6 +73,28 @@
Assert.assertEquals("CallBackApiITest - test3a", "Who's There",
this.getReturnMessage());
}
+
+ private void test3a1() {
+ aCallBackService.knockKnockByRef("Knock Knock");
+ int count = 0;
+
+ //
+ // If we cant get a response in 30 seconds consider this a failure
+ //
+
+ synchronized (monitor) {
+ while (returnMessage == null && count++ < 30) {
+ try {
+ monitor.wait(1000L);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ Assert.assertEquals("CallBackApiITest - test3a", "Who's There",
this.getReturnMessage());
+
+ }
private void test3b() {
aCallBackService.noCallBack("No Reply Desired");
Modified:
incubator/tuscany/java/sca/itest/callback-api/src/main/java/org/apache/tuscany/sca/test/CallBackApiService.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/callback-api/src/main/java/org/apache/tuscany/sca/test/CallBackApiService.java?rev=571266&r1=571265&r2=571266&view=diff
==============================================================================
---
incubator/tuscany/java/sca/itest/callback-api/src/main/java/org/apache/tuscany/sca/test/CallBackApiService.java
(original)
+++
incubator/tuscany/java/sca/itest/callback-api/src/main/java/org/apache/tuscany/sca/test/CallBackApiService.java
Thu Aug 30 11:23:58 2007
@@ -29,7 +29,7 @@
public interface CallBackApiService {
public void knockKnock(String aString);
-
+ public void knockKnockByRef(String aString);
public void noCallBack(String aString);
public void multiCallBack(String aString);
Modified:
incubator/tuscany/java/sca/itest/callback-api/src/main/java/org/apache/tuscany/sca/test/CallBackApiServiceImpl.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/callback-api/src/main/java/org/apache/tuscany/sca/test/CallBackApiServiceImpl.java?rev=571266&r1=571265&r2=571266&view=diff
==============================================================================
---
incubator/tuscany/java/sca/itest/callback-api/src/main/java/org/apache/tuscany/sca/test/CallBackApiServiceImpl.java
(original)
+++
incubator/tuscany/java/sca/itest/callback-api/src/main/java/org/apache/tuscany/sca/test/CallBackApiServiceImpl.java
Thu Aug 30 11:23:58 2007
@@ -18,9 +18,10 @@
*/
package org.apache.tuscany.sca.test;
+import org.osoa.sca.CallableReference;
import org.osoa.sca.ComponentContext;
import org.osoa.sca.RequestContext;
-import org.osoa.sca.ServiceReference;
+import org.osoa.sca.annotations.Callback;
import org.osoa.sca.annotations.Context;
import org.osoa.sca.annotations.Service;
@@ -31,6 +32,9 @@
protected ComponentContext componentContext;
private CallBackApiCallBack callback;
+
+ @Callback
+ protected CallableReference<CallBackApiCallBack> callbackRef;
public void knockKnock(String aString) {
@@ -41,6 +45,15 @@
return;
}
+
+ public void knockKnockByRef(String aString) {
+
+ System.out.println("CallBackApiServiceImpl message received: " +
aString);
+ callbackRef.getService().callBackMessage("Who's There");
+ System.out.println("CallBackApiServiceImpl response sent");
+ return;
+
+ }
public void multiCallBack(String aString) {
Modified:
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.java?rev=571266&r1=571265&r2=571266&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.java
(original)
+++
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.java
Thu Aug 30 11:23:58 2007
@@ -47,6 +47,10 @@
RuntimeComponentReference reference)
{
this.callableReference =
component.getComponentContext().getServiceReference(businessInterface,
reference);
}
+
+ public CallableReferenceObjectFactory(CallableReference<?>
callableReference) {
+ this.callableReference = callableReference;
+ }
public CallableReference<?> getInstance() throws ObjectCreationException {
return callableReference;
Modified:
incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java?rev=571266&r1=571265&r2=571266&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java
(original)
+++
incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java
Thu Aug 30 11:23:58 2007
@@ -72,24 +72,24 @@
private ProxyFactory proxyFactory;
public JavaComponentContextProvider(RuntimeComponent component,
- JavaInstanceFactoryProvider configuration,
- DataBindingExtensionPoint
dataBindingExtensionPoint,
- JavaPropertyValueObjectFactory
propertyValueObjectFactory,
- ComponentContextFactory componentContextFactory,
- RequestContextFactory requestContextFactory) {
+ JavaInstanceFactoryProvider
configuration,
+ DataBindingExtensionPoint
dataBindingExtensionPoint,
+ JavaPropertyValueObjectFactory
propertyValueObjectFactory,
+ ComponentContextFactory
componentContextFactory,
+ RequestContextFactory
requestContextFactory) {
super();
this.instanceFactoryProvider = configuration;
this.proxyFactory = configuration.getProxyFactory();
-// if (componentContextFactory != null) {
-// this.componentContext =
componentContextFactory.createComponentContext(component,
requestContextFactory);
-// } else {
-// this.componentContext = new ComponentContextImpl(this,
requestContextFactory, this.proxyService);
-// }
+ // if (componentContextFactory != null) {
+ // this.componentContext =
componentContextFactory.createComponentContext(component,
requestContextFactory);
+ // } else {
+ // this.componentContext = new ComponentContextImpl(this,
requestContextFactory, this.proxyService);
+ // }
this.component = component;
this.dataBindingRegistry = dataBindingExtensionPoint;
this.propertyValueFactory = propertyValueObjectFactory;
}
-
+
InstanceWrapper<?> createInstanceWrapper() throws ObjectCreationException {
return instanceFactoryProvider.createFactory().newInstance();
}
@@ -101,13 +101,15 @@
}
private void configureProperty(ComponentProperty configuredProperty) {
- JavaElementImpl element =
instanceFactoryProvider.getImplementation().getPropertyMembers().get(configuredProperty.getName());
+ JavaElementImpl element =
+
instanceFactoryProvider.getImplementation().getPropertyMembers().get(configuredProperty.getName());
if (element != null && !(element.getAnchor() instanceof Constructor)
&& configuredProperty.getValue() != null) {
instanceFactoryProvider.getInjectionSites().add(element);
Class propertyJavaType =
JavaIntrospectionHelper.getBaseType(element.getType(),
element.getGenericType());
- ObjectFactory<?> propertyObjectFactory =
createPropertyValueFactory(configuredProperty, configuredProperty.getValue(),
propertyJavaType);
+ ObjectFactory<?> propertyObjectFactory =
+ createPropertyValueFactory(configuredProperty,
configuredProperty.getValue(), propertyJavaType);
instanceFactoryProvider.setObjectFactory(element,
propertyObjectFactory);
}
}
@@ -121,13 +123,14 @@
if (callbackReference != null) {
List<RuntimeWire> wires =
callbackReference.getRuntimeWires();
if (!wires.isEmpty()) {
-
callbackWires.put(wires.get(0).getSource().getInterfaceContract().getInterface().toString(),
wires);
+
callbackWires.put(wires.get(0).getSource().getInterfaceContract().getInterface().toString(),
+ wires);
}
}
}
- for (Map.Entry<String, JavaElementImpl> entry :
instanceFactoryProvider.getImplementation().getCallbackMembers()
- .entrySet()) {
+ for (Map.Entry<String, JavaElementImpl> entry :
instanceFactoryProvider.getImplementation()
+ .getCallbackMembers().entrySet()) {
List<RuntimeWire> wires = callbackWires.get(entry.getKey());
if (wires == null) {
// this can happen when there are no client wires to a
@@ -135,7 +138,16 @@
continue;
}
JavaElementImpl element = entry.getValue();
- ObjectFactory<?> factory = new
CallbackWireObjectFactory(element.getType(), proxyFactory, wires);
+ Class<?> businessInterface = element.getType();
+ ObjectFactory<?> factory = null;
+ if
(CallableReference.class.isAssignableFrom(element.getType())) {
+ businessInterface =
JavaIntrospectionHelper.getBusinessInterface(element.getType(),
element.getGenericType());
+ factory =
+ new CallableReferenceObjectFactory(new
CallbackWireObjectFactory(businessInterface,
+
proxyFactory, wires));
+ } else {
+ factory = new CallbackWireObjectFactory(businessInterface,
proxyFactory, wires);
+ }
if (!(element.getAnchor() instanceof Constructor)) {
instanceFactoryProvider.getInjectionSites().add(element);
}
@@ -143,7 +155,8 @@
}
}
for (Reference ref :
instanceFactoryProvider.getImplementation().getReferences()) {
- JavaElementImpl element =
instanceFactoryProvider.getImplementation().getReferenceMembers().get(ref.getName());
+ JavaElementImpl element =
+
instanceFactoryProvider.getImplementation().getReferenceMembers().get(ref.getName());
if (element != null) {
if (!(element.getAnchor() instanceof Constructor)) {
instanceFactoryProvider.getInjectionSites().add(element);
@@ -159,14 +172,18 @@
}
if (ref.getMultiplicity() == Multiplicity.ONE_N ||
ref.getMultiplicity() == Multiplicity.ZERO_N) {
List<ObjectFactory<?>> factories = new
ArrayList<ObjectFactory<?>>();
- Class<?> baseType =
JavaIntrospectionHelper.getBaseType(element.getType(),
element.getGenericType());
+ Class<?> baseType =
+ JavaIntrospectionHelper.getBaseType(element.getType(),
element.getGenericType());
for (int i = 0; i < wireList.size(); i++) {
ObjectFactory<?> factory = null;
- if(CallableReference.class.isAssignableFrom(baseType))
{
+ if
(CallableReference.class.isAssignableFrom(baseType)) {
Type callableRefType =
JavaIntrospectionHelper.getParameterType(element.getGenericType());
Type businessType =
JavaIntrospectionHelper.getParameterType(callableRefType);
- Class<?> businessInterface =
JavaIntrospectionHelper.getBusinessInterface(baseType, businessType);
- factory = new
CallableReferenceObjectFactory(businessInterface, component,
(RuntimeComponentReference) componentReference);
+ Class<?> businessInterface =
+
JavaIntrospectionHelper.getBusinessInterface(baseType, businessType);
+ factory =
+ new
CallableReferenceObjectFactory(businessInterface, component,
+
(RuntimeComponentReference)componentReference);
} else {
factory = createWireFactory(baseType,
wireList.get(i));
}
@@ -181,7 +198,8 @@
ObjectFactory<?> factory = null;
if
(CallableReference.class.isAssignableFrom(element.getType())) {
Class<?> businessInterface =
-
JavaIntrospectionHelper.getBusinessInterface(element.getType(),
element.getGenericType());
+
JavaIntrospectionHelper.getBusinessInterface(element.getType(), element
+ .getGenericType());
factory =
new
CallableReferenceObjectFactory(businessInterface, component,
(RuntimeComponentReference)componentReference);
@@ -196,8 +214,7 @@
}
void addResourceFactory(String name, ObjectFactory<?> factory) {
- JavaResourceImpl resource = instanceFactoryProvider.getImplementation()
- .getResources().get(name);
+ JavaResourceImpl resource =
instanceFactoryProvider.getImplementation().getResources().get(name);
if (resource != null && !(resource.getElement().getAnchor() instanceof
Constructor)) {
instanceFactoryProvider.getInjectionSites().add(resource.getElement());
@@ -240,8 +257,9 @@
try {
Method method = JavaInterfaceUtil.findMethod(implClass, operation);
- boolean passByValue = operation.getInterface().isRemotable() &&
(!instanceFactoryProvider.getImplementation()
- .isAllowsPassByReference(method));
+ boolean passByValue =
+ operation.getInterface().isRemotable() &&
(!instanceFactoryProvider.getImplementation()
+ .isAllowsPassByReference(method));
Invoker invoker = new JavaImplementationInvoker(method, component);
if (passByValue) {
@@ -259,9 +277,7 @@
return new WireObjectFactory<B>(interfaze, wire, proxyFactory);
}
- private ObjectFactory<?> createPropertyValueFactory(ComponentProperty
property,
- Object propertyValue,
- Class javaType) {
+ private ObjectFactory<?> createPropertyValueFactory(ComponentProperty
property, Object propertyValue, Class javaType) {
return propertyValueFactory.createValueFactory(property,
propertyValue, javaType);
}
Modified:
incubator/tuscany/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessor.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessor.java?rev=571266&r1=571265&r2=571266&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessor.java
(original)
+++
incubator/tuscany/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessor.java
Thu Aug 30 11:23:58 2007
@@ -22,6 +22,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
+import java.lang.reflect.Type;
import java.util.Set;
import org.apache.tuscany.sca.assembly.AssemblyFactory;
@@ -33,6 +34,7 @@
import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.osoa.sca.CallableReference;
import org.osoa.sca.annotations.Callback;
import org.osoa.sca.annotations.Remotable;
@@ -104,18 +106,8 @@
if (method.getParameterTypes().length != 1) {
throw new IllegalCallbackReferenceException("Setter must have one
parameter", method);
}
- Service callbackService = null;
- Class<?> callbackClass = method.getParameterTypes()[0];
- for (Service service : type.getServices()) {
- JavaInterface javaInterface =
(JavaInterface)service.getInterfaceContract().getCallbackInterface();
- if (callbackClass == javaInterface.getJavaClass()) {
- callbackService = service;
- }
- }
- if (callbackService == null) {
- throw new IllegalCallbackReferenceException("Callback type does
not match a service callback interface");
- }
- type.getCallbackMembers().put(callbackClass.getName(), new
JavaElementImpl(method, 0));
+ JavaElementImpl element = new JavaElementImpl(method, 0);
+ createCallback(type, element);
}
@Override
@@ -125,18 +117,36 @@
if (annotation == null) {
return;
}
+ JavaElementImpl element = new JavaElementImpl(field);
+ createCallback(type, element);
+ }
+
+ /**
+ * @param type
+ * @param element
+ * @throws IllegalCallbackReferenceException
+ */
+ private void createCallback(JavaImplementation type, JavaElementImpl
element)
+ throws IllegalCallbackReferenceException {
Service callbackService = null;
- Class<?> callbackClass = field.getType();
+ Class<?> callbackClass = element.getType();
+ Type genericType = element.getGenericType();
+ Class<?> baseType = callbackClass;
+ if(CallableReference.class.isAssignableFrom(baseType)) {
+ // @Callback protected CallableReference<MyCallback> callback;
+ // The base type will be MyCallback
+ baseType = JavaIntrospectionHelper.getBusinessInterface(baseType,
genericType);
+ }
for (Service service : type.getServices()) {
JavaInterface javaInterface =
(JavaInterface)service.getInterfaceContract().getCallbackInterface();
- if (callbackClass == javaInterface.getJavaClass()) {
+ if (baseType == javaInterface.getJavaClass()) {
callbackService = service;
}
}
if (callbackService == null) {
throw new IllegalCallbackReferenceException("Callback type does
not match a service callback interface");
}
- type.getCallbackMembers().put(callbackClass.getName(), new
JavaElementImpl(field));
+ type.getCallbackMembers().put(baseType.getName(), element);
}
public Service createService(Class<?> interfaze) throws
InvalidInterfaceException {
Modified:
incubator/tuscany/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceCallbackTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceCallbackTestCase.java?rev=571266&r1=571265&r2=571266&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceCallbackTestCase.java
(original)
+++
incubator/tuscany/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceCallbackTestCase.java
Thu Aug 30 11:23:58 2007
@@ -32,6 +32,7 @@
import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
import org.apache.tuscany.sca.interfacedef.InvalidCallbackException;
import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
+import org.osoa.sca.CallableReference;
import org.osoa.sca.annotations.Callback;
import org.osoa.sca.annotations.Service;
@@ -68,6 +69,17 @@
assertEquals(field,
type.getCallbackMembers().get(FooCallback.class.getName()).getAnchor());
}
+ public void testFieldCallbackInterface1() throws Exception {
+ JavaImplementation type =
javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(FooImpl1.class, type);
+ org.apache.tuscany.sca.assembly.Service service = getService(type,
Foo.class.getSimpleName());
+ assertNotNull(service);
+ Field field1 = FooImpl1.class.getDeclaredField("callbackRef");
+ processor.visitField(field1, type);
+ assertEquals(field1,
type.getCallbackMembers().get(FooCallback.class.getName()).getAnchor());
+
+ }
+
public void testMethodDoesNotMatchCallback() throws Exception {
JavaImplementation type =
javaImplementationFactory.createJavaImplementation();
processor.visitClass(BadBarImpl.class, type);
@@ -129,12 +141,18 @@
@Callback
protected FooCallback callback;
-
+
@Callback
public void setCallback(FooCallback cb) {
}
}
+
+ @Service(Foo.class)
+ private static class FooImpl1 implements Foo {
+ @Callback
+ protected CallableReference<FooCallback> callbackRef;
+ }
private static class BadBarImpl implements Foo {
@Callback
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]