Author: rfeng
Date: Fri Aug 31 11:54:28 2007
New Revision: 571538

URL: http://svn.apache.org/viewvc?rev=571538&view=rev
Log:
Apply Simon Nash's patch 4 for TUSCANY-1500. I made the following changes on 
top of the patch:

1) Remove ImplementationProvider2 and use RuntimeWireProcessorExtensionPoint 
instead to add the interceptor
2) Keep the CallableReference to the Message instead of a flag for the callback 
object
3) Use InterfaceContractMapper to test if the source implementation 
"implements" the callback interface

Added:
    
incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaCallbackRuntimeWireProcessor.java
   (with props)
Modified:
    
incubator/tuscany/java/sca/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCalbackService.java
    
incubator/tuscany/java/sca/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackClientImpl.java
    
incubator/tuscany/java/sca/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackServiceImpl.java
    
incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Message.java
    
incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWire.java
    
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java
    
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java
    
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageImpl.java
    
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java
    
incubator/tuscany/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/CallbackInterfaceInterceptorTestCase.java
    
incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/module/JavaRuntimeModuleActivator.java
    
incubator/tuscany/java/sca/modules/implementation-notification/src/main/java/org/apache/tuscany/sca/implementation/notification/ImmutableMessage.java
    
incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java

Modified: 
incubator/tuscany/java/sca/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCalbackService.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCalbackService.java?rev=571538&r1=571537&r2=571538&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCalbackService.java
 (original)
+++ 
incubator/tuscany/java/sca/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCalbackService.java
 Fri Aug 31 11:54:28 2007
@@ -29,6 +29,6 @@
 
     public void knockKnock(String aString);
 
-    public void setCallbackIllegally(String aString);
+    public boolean setCallbackIllegally(String aString);
 
 }

Modified: 
incubator/tuscany/java/sca/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackClientImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackClientImpl.java?rev=571538&r1=571537&r2=571538&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackClientImpl.java
 (original)
+++ 
incubator/tuscany/java/sca/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackClientImpl.java
 Fri Aug 31 11:54:28 2007
@@ -54,8 +54,7 @@
          * NoRegisteredCallbackException is thrown.
          */
 
-        //FIXME: disabled for now as the runtime does not currently implement 
this check
-        //test5();
+        test5();
 
         /*
          * test6() The client calls setCallback() with an object that is not a
@@ -161,7 +160,7 @@
         //
         // This should catch an appropriate exception.
         //
-        catch (NoRegisteredCallbackException NotRegEx) {
+        catch (IllegalArgumentException goodEx) {
             correctException = true;
         } catch (Exception ex) {
             ex.printStackTrace();
@@ -169,31 +168,23 @@
 
         Assert.assertEquals("CallBackSetCallback - Test6", true, 
correctException);
 
-        aCallBackService.setCallback(null);  // leave this in the default 
state for next test
-
     }
 
     private void test10() {
+
         //
-        // Since callbacks do not synchronously return and this test results in
-        // a failure on the service
-        // side of the fence I am using a marker file to determine the outcome.
-        // The presence of the marker
-        // file will be used for the Assertion test. If it exists then all is
-        // good.
+        // The appropriate exception should be thrown and caught on the 
service side.
+        // If this happens, the setCallbackIllegally() method will return true.
+        // If not, this method will return false.
         //
 
-        // Make sure the marker file is not present before starting the test.
-        File aFile = new File("target/test10_marker");
-        if (aFile.exists())
-            aFile.delete();
+        aCallBackService.setCallback(callBack);  // ensure no client-side 
exception
 
-        aCallBackService.getService().setCallbackIllegally("Try to set 
callback on your own service reference");
+        boolean result = aCallBackService.getService().setCallbackIllegally
+                             ("Try to set callback on your own service 
reference");
 
-        // FIXME: [rfeng] Not sure why this is illegal, comment out the 
following test
-        Assert.assertEquals("CallBackSetCallback - Test10", true, 
aFile.exists());
+        Assert.assertEquals("CallBackSetCallback - Test10", true, result);
 
-        return;
     }
 
 }

Modified: 
incubator/tuscany/java/sca/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackServiceImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackServiceImpl.java?rev=571538&r1=571537&r2=571538&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackServiceImpl.java
 (original)
+++ 
incubator/tuscany/java/sca/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackServiceImpl.java
 Fri Aug 31 11:54:28 2007
@@ -48,7 +48,7 @@
 
     }
 
-    public void setCallbackIllegally(String aString) {
+    public boolean setCallbackIllegally(String aString) {
 
         System.out.println("CallBackBasicServiceImpl.setCallbackIllegally() 
message received: " + aString);
 
@@ -66,20 +66,10 @@
         } catch (Exception badEx) {
             
System.out.println("CallBackBasicServiceImpl.setCallbackIllegally()  " + 
badEx.toString());
             badEx.printStackTrace();
-            return;
         }
 
-        // If we get the exception we are looking for then create the marker
-        // file.
-        if (exceptionProduced == true) {
-            File aFile = new File("target/test10_marker");
-            try {
-                aFile.createNewFile();
-            } catch (Exception ex) {
-                System.out.println("Error Creating target/test10_marker marker 
file");
-                ex.printStackTrace();
-            }
-        }
+        // Return a flag indicating whether we got the exception we are 
looking for
+        return exceptionProduced;
 
     }
 }

Modified: 
incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Message.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Message.java?rev=571538&r1=571537&r2=571538&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Message.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Message.java
 Fri Aug 31 11:54:28 2007
@@ -21,6 +21,7 @@
 import org.apache.tuscany.sca.interfacedef.ConversationSequence;
 import org.apache.tuscany.sca.interfacedef.Operation;
 import org.apache.tuscany.sca.runtime.EndpointReference;
+import org.osoa.sca.CallableReference;
 
 /**
  * Represents a request, response, or exception flowing through a wire
@@ -143,5 +144,19 @@
      * @param op The operation that created the message
      */
     void setOperation(Operation op);
+
+    /**
+     * Get the associated callable reference
+     * @param <B>
+     * @return The callable reference
+     */
+    <B> CallableReference<B> getCallableReference();
+    
+    /**
+     * Set the callable reference
+     * @param <B>
+     * @param callableReference
+     */
+    <B> void setCallableReference(CallableReference<B> callableReference);
 
 }

Modified: 
incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWire.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWire.java?rev=571538&r1=571537&r2=571538&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWire.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWire.java
 Fri Aug 31 11:54:28 2007
@@ -50,7 +50,7 @@
      * @param target The target endpoint reference
      */
     void setTarget(EndpointReference target);
-    
+
     /**
      * Returns the invocation chains for service operations associated with the
      * wire
@@ -59,9 +59,10 @@
      *         wire
      */
     List<InvocationChain> getInvocationChains();
+
     /**
-     * @return
+     * @return a clone of the runtime wire
      * @throws CloneNotSupportedException
      */
-    Object clone() throws CloneNotSupportedException;   
+    Object clone() throws CloneNotSupportedException;
 }

Modified: 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java?rev=571538&r1=571537&r2=571538&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java
 Fri Aug 31 11:54:28 2007
@@ -21,7 +21,9 @@
 import org.apache.tuscany.sca.invocation.Interceptor;
 import org.apache.tuscany.sca.invocation.Invoker;
 import org.apache.tuscany.sca.invocation.Message;
+import org.osoa.sca.CallableReference;
 import org.osoa.sca.NoRegisteredCallbackException;
+import org.osoa.sca.ServiceReference;
 
 /**
  * An interceptor applied to the forward direction of a wire that ensures the 
callback target implements the required
@@ -30,18 +32,17 @@
  * @version $Rev$ $Date$
  */
 public class CallbackInterfaceInterceptor implements Interceptor {
-    private boolean invokingServiceImplements;
     private Invoker next;
 
-    public CallbackInterfaceInterceptor(boolean invokingServiceImplements) {
-        this.invokingServiceImplements = invokingServiceImplements;
+    public CallbackInterfaceInterceptor() {
     }
 
     public Message invoke(Message msg) {
-        // TODO check in the context if a callback object is set, if so invoke 
next since the setCallback will
-        // perform the check
-        if (!invokingServiceImplements) {
-            throw new NoRegisteredCallbackException("Callback target does not 
implement the callback interface");
+        CallableReference<?> callableReference = msg.getCallableReference();
+        if (callableReference instanceof ServiceReference) {
+            if (((ServiceReference<?>)callableReference).getCallback() == 
null) {
+                throw new NoRegisteredCallbackException("Callback target does 
not implement the callback interface");
+            }
         }
         return next.invoke(msg);
     }

Modified: 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java?rev=571538&r1=571537&r2=571538&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java
 Fri Aug 31 11:54:28 2007
@@ -28,7 +28,6 @@
 
 import org.apache.tuscany.sca.core.context.CallableReferenceImpl;
 import org.apache.tuscany.sca.core.context.ConversationImpl;
-import org.apache.tuscany.sca.core.scope.ConversationalScopeContainer;
 import org.apache.tuscany.sca.core.scope.Scope;
 import org.apache.tuscany.sca.core.scope.ScopeContainer;
 import org.apache.tuscany.sca.core.scope.ScopedRuntimeComponent;
@@ -45,7 +44,6 @@
 import org.apache.tuscany.sca.runtime.RuntimeComponent;
 import org.apache.tuscany.sca.runtime.RuntimeWire;
 import org.osoa.sca.CallableReference;
-import org.osoa.sca.NoRegisteredCallbackException;
 import org.osoa.sca.ServiceReference;
 
 /**
@@ -249,25 +247,28 @@
                 }
             }
         }
+        msg.setCallableReference(callableReference);
         msg.setBody(args);
-        if (wire.getSource() != null && wire.getSource().getCallbackEndpoint() 
!= null) {
-            if (callbackObject != null) {
-                if (callbackObject instanceof ServiceReference) {
-                    
msg.setFrom(((CallableReferenceImpl)callbackObject).getRuntimeWire().getTarget());
-                } else {
-                    if (contract != null) {
-                        if (!contract.isConversational()) {
-                            throw new NoRegisteredCallbackException(
-                                                                    "Callback 
object for stateless callback is not a ServiceReference");
-                        } else {
-                            //FIXME: add callback object to scope container
-                            
msg.setFrom(wire.getSource().getCallbackEndpoint());
+        if (wire.getSource() != null) {
+            EndpointReference callbackEndpoint = 
wire.getSource().getCallbackEndpoint();
+            if (callbackEndpoint != null) {
+                if (callbackObject != null) {
+                    if (callbackObject instanceof ServiceReference) {
+                        
msg.setFrom(((CallableReferenceImpl)callbackObject).getRuntimeWire().getTarget());
+                    } else {
+                        if (contract != null) {
+                            if (!contract.isConversational()) {
+                                throw new IllegalArgumentException
+                                        ("Callback object for stateless 
callback is not a ServiceReference");
+                            } else {
+                                //FIXME: add callback object to scope container
+                                msg.setFrom(callbackEndpoint);
+                            }
                         }
                     }
+                } else {
+                    msg.setFrom(callbackEndpoint);
                 }
-            } else {
-                //FIXME: check that the source component implements the 
callback interface
-                msg.setFrom(wire.getSource().getCallbackEndpoint());
             }
         }
         if (endpoint != null) {

Modified: 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageImpl.java?rev=571538&r1=571537&r2=571538&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageImpl.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageImpl.java
 Fri Aug 31 11:54:28 2007
@@ -22,6 +22,7 @@
 import org.apache.tuscany.sca.interfacedef.Operation;
 import org.apache.tuscany.sca.invocation.Message;
 import org.apache.tuscany.sca.runtime.EndpointReference;
+import org.osoa.sca.CallableReference;
 
 /**
  * The default implementation of a message flowed through a wire during an 
invocation
@@ -36,6 +37,7 @@
     private ConversationSequence conversationSequence;
     private String conversationId;
     private Operation op;
+    private CallableReference<?> callableReference;
     
     private EndpointReference from;
     private EndpointReference to;
@@ -123,4 +125,19 @@
     public void setOperation(Operation op) {
         this.op = op;
     }
+
+    /**
+     * @see org.apache.tuscany.sca.invocation.Message#getCallableReference()
+     */
+    public <B> CallableReference<B> getCallableReference() {
+        return (CallableReference<B>) callableReference;
+    }
+
+    /**
+     * @see 
org.apache.tuscany.sca.invocation.Message#setCallableReference(org.osoa.sca.CallableReference)
+     */
+    public <B> void setCallableReference(CallableReference<B> 
callableReference) {
+        this.callableReference = callableReference;
+    }
+
 }

Modified: 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java?rev=571538&r1=571537&r2=571538&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java
 Fri Aug 31 11:54:28 2007
@@ -28,6 +28,7 @@
 import org.apache.tuscany.sca.runtime.EndpointReference;
 import org.apache.tuscany.sca.runtime.RuntimeWire;
 import org.apache.tuscany.sca.work.WorkScheduler;
+import org.osoa.sca.CallableReference;
 import org.osoa.sca.ServiceRuntimeException;
 
 /**
@@ -103,10 +104,6 @@
             throw new UnsupportedOperationException();
         }
 
-        public void setWire(RuntimeWire wire) {
-            throw new UnsupportedOperationException();
-        }
-
         @SuppressWarnings("unchecked")
         public Object getBody() {
             return null;
@@ -175,6 +172,20 @@
         }
 
         public void setOperation(Operation op) {
+            throw new UnsupportedOperationException();
+        }
+        
+        /**
+         * @see 
org.apache.tuscany.sca.invocation.Message#getCallableReference()
+         */
+        public <B> CallableReference<B> getCallableReference() {
+            return null;
+        }
+
+        /**
+         * @see 
org.apache.tuscany.sca.invocation.Message#setCallableReference(org.osoa.sca.CallableReference)
+         */
+        public <B> void setCallableReference(CallableReference<B> 
callableReference) {
             throw new UnsupportedOperationException();
         }
 

Modified: 
incubator/tuscany/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/CallbackInterfaceInterceptorTestCase.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/CallbackInterfaceInterceptorTestCase.java?rev=571538&r1=571537&r2=571538&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/CallbackInterfaceInterceptorTestCase.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/CallbackInterfaceInterceptorTestCase.java
 Fri Aug 31 11:54:28 2007
@@ -26,26 +26,37 @@
 import org.apache.tuscany.sca.invocation.Message;
 import org.easymock.EasyMock;
 import org.osoa.sca.NoRegisteredCallbackException;
+import org.osoa.sca.ServiceReference;
 
 /**
  * @version $Rev$ $Date$
  */
 public class CallbackInterfaceInterceptorTestCase extends TestCase {
 
-    public void testImplements() {
-        CallbackInterfaceInterceptor interceptor = new 
CallbackInterfaceInterceptor(true);
+    public void testHasCallbackObject() {
+        CallbackInterfaceInterceptor interceptor = new 
CallbackInterfaceInterceptor();
         Interceptor next = EasyMock.createMock(Interceptor.class);
         
EasyMock.expect(next.invoke(EasyMock.isA(Message.class))).andReturn(null);
         EasyMock.replay(next);
         interceptor.setNext(next);
-        interceptor.invoke(new MessageFactoryImpl().createMessage());
+        Message msg = new MessageFactoryImpl().createMessage();
+        ServiceReference callableReference = 
EasyMock.createMock(ServiceReference.class);
+        EasyMock.expect(callableReference.getCallback()).andReturn(new 
Object());
+        EasyMock.replay(callableReference);
+        msg.setCallableReference(callableReference);
+        interceptor.invoke(msg);
         EasyMock.verify(next);
     }
 
-    public void testDoesNotImplement() {
-        CallbackInterfaceInterceptor interceptor = new 
CallbackInterfaceInterceptor(false);
+    public void testNoCallbackObject() {
+        CallbackInterfaceInterceptor interceptor = new 
CallbackInterfaceInterceptor();
+        Message msg = new MessageFactoryImpl().createMessage();
+        ServiceReference callableReference = 
EasyMock.createMock(ServiceReference.class);
+        EasyMock.expect(callableReference.getCallback()).andReturn(null);
+        EasyMock.replay(callableReference);
+        msg.setCallableReference(callableReference);
         try {
-            interceptor.invoke(new MessageFactoryImpl().createMessage());
+            interceptor.invoke(msg);
             fail();
         } catch (NoRegisteredCallbackException e) {
             // expected

Added: 
incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaCallbackRuntimeWireProcessor.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/JavaCallbackRuntimeWireProcessor.java?rev=571538&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaCallbackRuntimeWireProcessor.java
 (added)
+++ 
incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaCallbackRuntimeWireProcessor.java
 Fri Aug 31 11:54:28 2007
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.implementation.java.invocation;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.tuscany.sca.assembly.Contract;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.core.invocation.CallbackInterfaceInterceptor;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.runtime.EndpointReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.apache.tuscany.sca.runtime.RuntimeWireProcessor;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JavaCallbackRuntimeWireProcessor implements RuntimeWireProcessor {
+    private final static Logger logger = 
Logger.getLogger(JavaCallbackRuntimeWireProcessor.class.getName());
+    private InterfaceContractMapper interfaceContractMapper;
+    private JavaInterfaceFactory javaInterfaceFactory;
+
+    /**
+     * @param interfaceContractMapper
+     * @param javaInterfaceFactory
+     */
+    public JavaCallbackRuntimeWireProcessor(InterfaceContractMapper 
interfaceContractMapper,
+                                            JavaInterfaceFactory 
javaInterfaceFactory) {
+        super();
+        this.interfaceContractMapper = interfaceContractMapper;
+        this.javaInterfaceFactory = javaInterfaceFactory;
+    }
+
+    public void process(RuntimeWire wire) {
+        addCallbackInterfaceInterceptors(wire);
+    }
+
+    private void addCallbackInterfaceInterceptors(RuntimeWire wire) {
+        Contract contract = wire.getSource().getContract();
+        if (!(contract instanceof RuntimeComponentReference)) {
+            return;
+        }
+        RuntimeComponent component = wire.getSource().getComponent();
+        Implementation implementation = component.getImplementation();
+        if (!(implementation instanceof JavaImplementation)) {
+            return;
+        }
+        JavaImplementation javaImpl = (JavaImplementation)implementation;
+        EndpointReference callbackEndpoint = 
wire.getSource().getCallbackEndpoint();
+        if (callbackEndpoint != null) {
+            Interface iface = 
callbackEndpoint.getContract().getInterfaceContract().getInterface();
+            if (!supportsCallbackInterface(iface, javaImpl)) {
+                // callback to this impl is not possible, so ensure a callback 
object is set
+                for (InvocationChain chain : wire.getInvocationChains()) {
+                    chain.addInterceptor(0, new 
CallbackInterfaceInterceptor());
+                }
+            }
+        }
+    }
+
+    private boolean supportsCallbackInterface(Interface iface, 
JavaImplementation impl) {
+        if (iface instanceof JavaInterface) {
+            Class<?> ifaceClass = ((JavaInterface)iface).getJavaClass();
+            if (ifaceClass.isAssignableFrom(impl.getJavaClass())) {
+                return true;
+            }
+        }
+        try {
+            Interface implType = 
javaInterfaceFactory.createJavaInterface(impl.getJavaClass());
+            // Ignore the remotable/conversational testing
+            implType.setRemotable(iface.isRemotable());
+            implType.setConversational(iface.isConversational());
+            return interfaceContractMapper.isCompatible(iface, implType);
+        } catch (InvalidInterfaceException e) {
+            logger.log(Level.WARNING, e.getMessage(), e);
+            return false;
+        }
+    }
+}

Propchange: 
incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaCallbackRuntimeWireProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaCallbackRuntimeWireProcessor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: 
incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/module/JavaRuntimeModuleActivator.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/module/JavaRuntimeModuleActivator.java?rev=571538&r1=571537&r2=571538&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/module/JavaRuntimeModuleActivator.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/module/JavaRuntimeModuleActivator.java
 Fri Aug 31 11:54:28 2007
@@ -51,11 +51,14 @@
 import 
org.apache.tuscany.sca.implementation.java.introspect.impl.ResourceProcessor;
 import 
org.apache.tuscany.sca.implementation.java.introspect.impl.ScopeProcessor;
 import 
org.apache.tuscany.sca.implementation.java.introspect.impl.ServiceProcessor;
+import 
org.apache.tuscany.sca.implementation.java.invocation.JavaCallbackRuntimeWireProcessor;
 import 
org.apache.tuscany.sca.implementation.java.invocation.JavaImplementationProviderFactory;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
 import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
 import org.apache.tuscany.sca.invocation.MessageFactory;
 import org.apache.tuscany.sca.policy.PolicyFactory;
 import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
+import org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint;
 
 /**
  * @version $Rev$ $Date$
@@ -115,7 +118,12 @@
         
         ProviderFactoryExtensionPoint providerFactories = 
registry.getExtensionPoint(ProviderFactoryExtensionPoint.class);
         
providerFactories.addProviderFactory(javaImplementationProviderFactory);
-        
+
+        InterfaceContractMapper interfaceContractMapper = 
registry.getExtensionPoint(InterfaceContractMapper.class);
+        RuntimeWireProcessorExtensionPoint wireProcessorExtensionPoint = 
registry.getExtensionPoint(RuntimeWireProcessorExtensionPoint.class);
+        if (wireProcessorExtensionPoint != null) {
+            wireProcessorExtensionPoint.addWireProcessor(new 
JavaCallbackRuntimeWireProcessor(interfaceContractMapper, javaFactory));
+        }        
     }
 
     public void stop(ExtensionPointRegistry registry) {

Modified: 
incubator/tuscany/java/sca/modules/implementation-notification/src/main/java/org/apache/tuscany/sca/implementation/notification/ImmutableMessage.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-notification/src/main/java/org/apache/tuscany/sca/implementation/notification/ImmutableMessage.java?rev=571538&r1=571537&r2=571538&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/implementation-notification/src/main/java/org/apache/tuscany/sca/implementation/notification/ImmutableMessage.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/implementation-notification/src/main/java/org/apache/tuscany/sca/implementation/notification/ImmutableMessage.java
 Fri Aug 31 11:54:28 2007
@@ -23,6 +23,7 @@
 import org.apache.tuscany.sca.invocation.Message;
 import org.apache.tuscany.sca.runtime.EndpointReference;
 import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.CallableReference;
 
 /**
  * @version $Rev$ $Date$
@@ -66,30 +67,35 @@
     }
 
     public <T> void setBody(T arg0) {
+        throw new UnsupportedOperationException();
     }
 
     public void setConversationID(String arg0) {
+        throw new UnsupportedOperationException();
     }
 
     public void setConversationSequence(ConversationSequence arg0) {
+        throw new UnsupportedOperationException();
     }
 
     public void setCorrelationID(Object arg0) {
+        throw new UnsupportedOperationException();
     }
 
     public <T> void setFaultBody(T arg0) {
+        throw new UnsupportedOperationException();
     }
 
     public void setFrom(EndpointReference arg0) {
+        throw new UnsupportedOperationException();
     }
 
     public void setMessageID(Object arg0) {
+        throw new UnsupportedOperationException();
     }
 
     public void setTo(EndpointReference arg0) {
-    }
-
-    public void setWire(RuntimeWire arg0) {
+        throw new UnsupportedOperationException();
     }
 
     public Operation getOperation() {
@@ -97,5 +103,20 @@
     }
 
     public void setOperation(Operation op) {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.invocation.Message#getCallableReference()
+     */
+    public <B> CallableReference<B> getCallableReference() {
+        return null;
+    }
+
+    /**
+     * @see 
org.apache.tuscany.sca.invocation.Message#setCallableReference(org.osoa.sca.CallableReference)
+     */
+    public <B> void setCallableReference(CallableReference<B> 
callableReference) {
+        throw new UnsupportedOperationException();
     }
 }

Modified: 
incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java?rev=571538&r1=571537&r2=571538&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java
 Fri Aug 31 11:54:28 2007
@@ -247,7 +247,7 @@
             if (targetOperation == null) {
                 return false;
             }
-            if (!operation.equals(targetOperation)) {
+            if (!isCompatible(operation, targetOperation, 
source.isRemotable())) {
                 return false;
             }
         }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to