Author: slaws
Date: Thu Apr 30 12:29:50 2009
New Revision: 770201

URL: http://svn.apache.org/viewvc?rev=770201&view=rev
Log:
TUSCANY-2996 - Add support for wrapSingle attribute that, when set true, 
ensures that single parameters are wrapped in an array on the wire. When set 
false single parameters will not be wrapped on the wire. Multiple parameters 
will always be wrapped. 

Modified:
    
tuscany/branches/sca-java-1.x/itest/jms-format/src/main/java/org/apache/tuscany/sca/binding/jms/format/jmsobject/helloworld/HelloWorldReference.java
    
tuscany/branches/sca-java-1.x/itest/jms-format/src/main/java/org/apache/tuscany/sca/binding/jms/format/jmsobject/helloworld/HelloWorldReferenceImpl.java
    
tuscany/branches/sca-java-1.x/itest/jms-format/src/main/java/org/apache/tuscany/sca/binding/jms/format/jmsobject/helloworld/HelloWorldService.java
    
tuscany/branches/sca-java-1.x/itest/jms-format/src/main/java/org/apache/tuscany/sca/binding/jms/format/jmsobject/helloworld/HelloWorldServiceImpl.java
    
tuscany/branches/sca-java-1.x/itest/jms-format/src/main/resources/jmsobject/helloworld.composite
    
tuscany/branches/sca-java-1.x/itest/jms-format/src/test/java/org/apache/tuscany/sca/binding/jms/format/FormatJMSObjectTestCase.java
    
tuscany/branches/sca-java-1.x/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-jms.xsd
    
tuscany/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/ObjectMessageProcessor.java
    
tuscany/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceInterceptor.java
    
tuscany/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceProvider.java
    
tuscany/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceInterceptor.java
    
tuscany/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceProvider.java
    
tuscany/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/WireFormatJMSObject.java
    
tuscany/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/WireFormatJMSObjectProcessor.java

Modified: 
tuscany/branches/sca-java-1.x/itest/jms-format/src/main/java/org/apache/tuscany/sca/binding/jms/format/jmsobject/helloworld/HelloWorldReference.java
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/itest/jms-format/src/main/java/org/apache/tuscany/sca/binding/jms/format/jmsobject/helloworld/HelloWorldReference.java?rev=770201&r1=770200&r2=770201&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.x/itest/jms-format/src/main/java/org/apache/tuscany/sca/binding/jms/format/jmsobject/helloworld/HelloWorldReference.java
 (original)
+++ 
tuscany/branches/sca-java-1.x/itest/jms-format/src/main/java/org/apache/tuscany/sca/binding/jms/format/jmsobject/helloworld/HelloWorldReference.java
 Thu Apr 30 12:29:50 2009
@@ -26,7 +26,7 @@
 @Remotable
 public interface HelloWorldReference {
 
-    public String getGreetings(String firstName, String lastName);
-    
+    public String getGreetingsWrapSingle(String firstName, String lastName);
+    public String getGreetingsDontWrapSingle(String firstName, String 
lastName);
 }
 

Modified: 
tuscany/branches/sca-java-1.x/itest/jms-format/src/main/java/org/apache/tuscany/sca/binding/jms/format/jmsobject/helloworld/HelloWorldReferenceImpl.java
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/itest/jms-format/src/main/java/org/apache/tuscany/sca/binding/jms/format/jmsobject/helloworld/HelloWorldReferenceImpl.java?rev=770201&r1=770200&r2=770201&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.x/itest/jms-format/src/main/java/org/apache/tuscany/sca/binding/jms/format/jmsobject/helloworld/HelloWorldReferenceImpl.java
 (original)
+++ 
tuscany/branches/sca-java-1.x/itest/jms-format/src/main/java/org/apache/tuscany/sca/binding/jms/format/jmsobject/helloworld/HelloWorldReferenceImpl.java
 Thu Apr 30 12:29:50 2009
@@ -24,22 +24,77 @@
 public class HelloWorldReferenceImpl implements HelloWorldReference {
     
     @Reference
-    protected HelloWorldService helloWorldService;
+    protected HelloWorldService helloWorldServiceWrapSingle;
     
-    public String getGreetings(String firstName, String lastName){ 
+    @Reference
+    protected HelloWorldService helloWorldServiceDontWrapSingle;
+    
+    public String getGreetingsWrapSingle(String firstName, String lastName){ 
        Person person = new Person();
        person.setFirstName(firstName);
        person.setLastName(lastName);
-        Person returnPerson =  helloWorldService.getGreetings(person); 
-        Person returnNullPerson = helloWorldService.getNullGreetings(person); 
+       
+       String returnString = "";
+       
+        Person returnPerson =  
helloWorldServiceWrapSingle.getPersonGreetings(person);
+        returnString = returnPerson.getFirstName() + " " + 
returnPerson.getLastName();
         
-        String returnString = returnPerson.getFirstName() + " " + 
returnPerson.getLastName();
+        Person returnNullPerson = 
helloWorldServiceWrapSingle.getNullReturnGreetings(person); 
         
         if (returnNullPerson == null){
-            returnString += " null";
+            returnString += " Hello2 null";
         }
         
+        String returnGreeting = 
helloWorldServiceWrapSingle.getArrayGreeting(new String[]{firstName, lastName});
+        returnString += " " + returnGreeting;
+        
+        returnGreeting = 
helloWorldServiceWrapSingle.getMultiArrayGreetings(new String[]{firstName, 
firstName},new String[]{lastName, lastName});
+        returnString += " " + returnGreeting;
+        
+        returnGreeting = 
helloWorldServiceWrapSingle.getMultiGreetings(firstName, lastName);
+        returnString += " " + returnGreeting;        
+
+        returnGreeting = helloWorldServiceWrapSingle.getObjectGreeting(person);
+        returnString += " " + returnGreeting; 
+        
+        returnGreeting = 
helloWorldServiceWrapSingle.getObjectArrayGreeting(new Object[]{person});
+        returnString += " " + returnGreeting; 
+        
+        return returnString;
+    }  
+    
+    public String getGreetingsDontWrapSingle(String firstName, String 
lastName){ 
+        Person person = new Person();
+        person.setFirstName(firstName);
+        person.setLastName(lastName);
+        
+        String returnString = "";
+        
+        Person returnPerson =  
helloWorldServiceDontWrapSingle.getPersonGreetings(person);
+        returnString = returnPerson.getFirstName() + " " + 
returnPerson.getLastName();
+        
+        Person returnNullPerson = 
helloWorldServiceDontWrapSingle.getNullReturnGreetings(person); 
+        
+        if (returnNullPerson == null){
+            returnString += " Hello2 null";
+        }
+        
+        String returnGreeting = 
helloWorldServiceDontWrapSingle.getArrayGreeting(new String[]{firstName, 
lastName});
+        returnString += " " + returnGreeting;
+        
+        returnGreeting = 
helloWorldServiceDontWrapSingle.getMultiArrayGreetings(new String[]{firstName, 
firstName},new String[]{lastName, lastName});
+        returnString += " " + returnGreeting;
+        
+        returnGreeting = 
helloWorldServiceDontWrapSingle.getMultiGreetings(firstName, lastName);
+        returnString += " " + returnGreeting;        
+
+        returnGreeting = 
helloWorldServiceDontWrapSingle.getObjectGreeting(person);
+        returnString += " " + returnGreeting; 
+        
+        returnGreeting = 
helloWorldServiceDontWrapSingle.getObjectArrayGreeting(new Object[]{person});
+        returnString += " " + returnGreeting; 
+        
         return returnString;
-    }    
+    }     
 }
 

Modified: 
tuscany/branches/sca-java-1.x/itest/jms-format/src/main/java/org/apache/tuscany/sca/binding/jms/format/jmsobject/helloworld/HelloWorldService.java
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/itest/jms-format/src/main/java/org/apache/tuscany/sca/binding/jms/format/jmsobject/helloworld/HelloWorldService.java?rev=770201&r1=770200&r2=770201&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.x/itest/jms-format/src/main/java/org/apache/tuscany/sca/binding/jms/format/jmsobject/helloworld/HelloWorldService.java
 (original)
+++ 
tuscany/branches/sca-java-1.x/itest/jms-format/src/main/java/org/apache/tuscany/sca/binding/jms/format/jmsobject/helloworld/HelloWorldService.java
 Thu Apr 30 12:29:50 2009
@@ -26,8 +26,13 @@
 @Remotable
 public interface HelloWorldService {
 
-    public Person getGreetings(Person person);
-    public Person getNullGreetings(Person person);
-    
+    public Person getPersonGreetings(Person person);
+    public Person getNullReturnGreetings(Person person);
+    public String getArrayGreeting(String[] names);
+    public String getMultiArrayGreetings(String[] firstName, String[] 
lastName);
+    public String getMultiGreetings(String firstName, String lastName);
+    public String getObjectGreeting(Object person);
+    public String getObjectArrayGreeting(Object[] pearson);
+  
 }
 

Modified: 
tuscany/branches/sca-java-1.x/itest/jms-format/src/main/java/org/apache/tuscany/sca/binding/jms/format/jmsobject/helloworld/HelloWorldServiceImpl.java
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/itest/jms-format/src/main/java/org/apache/tuscany/sca/binding/jms/format/jmsobject/helloworld/HelloWorldServiceImpl.java?rev=770201&r1=770200&r2=770201&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.x/itest/jms-format/src/main/java/org/apache/tuscany/sca/binding/jms/format/jmsobject/helloworld/HelloWorldServiceImpl.java
 (original)
+++ 
tuscany/branches/sca-java-1.x/itest/jms-format/src/main/java/org/apache/tuscany/sca/binding/jms/format/jmsobject/helloworld/HelloWorldServiceImpl.java
 Thu Apr 30 12:29:50 2009
@@ -21,16 +21,36 @@
 
 public class HelloWorldServiceImpl implements HelloWorldService {
     
-    public Person getGreetings(Person person){
+    public Person getPersonGreetings(Person person){
          
-       person.setFirstName("Hello " + person.getFirstName());
-       person.setLastName("Hello " + person.getLastName());
+       person.setFirstName("Hello1 " + person.getFirstName());
+       person.setLastName("Hello1 " + person.getLastName());
        
         return person;
     }
     
-    public Person getNullGreetings(Person person){      
+    public Person getNullReturnGreetings(Person person){      
         return null;
     }    
+    
+    public String getArrayGreeting(String[] names) {
+        return "Hello3 " + names[0];
+    }
+    
+    public String getMultiArrayGreetings(String[] firstName, String[] 
lastName) {
+        return "Hello4 " + firstName[0] + " " + lastName[0];
+    }
+    
+    public String getMultiGreetings(String firstName, String lastName) {
+        return "Hello5 " + firstName + " " + lastName;
+    }
+    
+    public String getObjectGreeting(Object person) {
+        return "Hello6 " + ((Person)person).getFirstName() + " " + 
((Person)person).getLastName();
+    }
+    
+    public String getObjectArrayGreeting(Object[] person) {
+        return "Hello7 " + ((Person)person[0]).getFirstName() + " " + 
((Person)person[0]).getLastName();
+    }
 }
 

Modified: 
tuscany/branches/sca-java-1.x/itest/jms-format/src/main/resources/jmsobject/helloworld.composite
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/itest/jms-format/src/main/resources/jmsobject/helloworld.composite?rev=770201&r1=770200&r2=770201&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.x/itest/jms-format/src/main/resources/jmsobject/helloworld.composite
 (original)
+++ 
tuscany/branches/sca-java-1.x/itest/jms-format/src/main/resources/jmsobject/helloworld.composite
 Thu Apr 30 12:29:50 2009
@@ -25,12 +25,18 @@
 
     <component name="HelloWorldReferenceComponent">
         <implementation.java 
class="org.apache.tuscany.sca.binding.jms.format.jmsobject.helloworld.HelloWorldReferenceImpl"
 />
-        <reference name="helloWorldService" >
+        <reference name="helloWorldServiceWrapSingle" >
             <binding.jms>
                 <destination name="HelloWorldService1"/>
-                 <tuscany:wireFormat.jmsObject/>
+                 <tuscany:wireFormat.jmsObject wrapSingle="true"/>
             </binding.jms>
-        </reference>  
+        </reference> 
+        <reference name="helloWorldServiceDontWrapSingle" >
+            <binding.jms>
+                <destination name="HelloWorldService2"/>
+                 <tuscany:wireFormat.jmsObject wrapSingle="false" />
+            </binding.jms>
+        </reference>          
     </component>
     
     <component name="HelloWorldServiceComponent1">
@@ -38,8 +44,18 @@
         <service name="HelloWorldService">
             <binding.jms>
                 <destination name="HelloWorldService1"/>
-                 <tuscany:wireFormat.jmsObject/>
+                 <tuscany:wireFormat.jmsObject wrapSingle="true"/>
             </binding.jms>
         </service>
     </component> 
+    
+    <component name="HelloWorldServiceComponent2">
+        <implementation.java 
class="org.apache.tuscany.sca.binding.jms.format.jmsobject.helloworld.HelloWorldServiceImpl"
 />
+        <service name="HelloWorldService">
+            <binding.jms>
+                <destination name="HelloWorldService2"/>
+                <tuscany:wireFormat.jmsObject /> <!-- test that wrapSingle 
default works -->
+            </binding.jms>
+        </service>
+    </component>     
 </composite>
\ No newline at end of file

Modified: 
tuscany/branches/sca-java-1.x/itest/jms-format/src/test/java/org/apache/tuscany/sca/binding/jms/format/FormatJMSObjectTestCase.java
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/itest/jms-format/src/test/java/org/apache/tuscany/sca/binding/jms/format/FormatJMSObjectTestCase.java?rev=770201&r1=770200&r2=770201&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.x/itest/jms-format/src/test/java/org/apache/tuscany/sca/binding/jms/format/FormatJMSObjectTestCase.java
 (original)
+++ 
tuscany/branches/sca-java-1.x/itest/jms-format/src/test/java/org/apache/tuscany/sca/binding/jms/format/FormatJMSObjectTestCase.java
 Thu Apr 30 12:29:50 2009
@@ -52,8 +52,11 @@
         HelloWorldReference helloWorldService = ((SCAClient) node).getService(
                 HelloWorldReference.class, "HelloWorldReferenceComponent");
 
-        assertEquals("Hello Fred Hello Bloggs null", 
-                     helloWorldService.getGreetings("Fred", "Bloggs"));
+        assertEquals("Hello1 Fred Hello1 Bloggs Hello2 null Hello3 Fred Hello4 
Fred Bloggs Hello5 Fred Bloggs Hello6 Fred Bloggs Hello7 Fred Bloggs", 
+                     helloWorldService.getGreetingsWrapSingle("Fred", 
"Bloggs"));
+        
+        assertEquals("Hello1 Fred Hello1 Bloggs Hello2 null Hello3 Fred Hello4 
Fred Bloggs Hello5 Fred Bloggs Hello6 Fred Bloggs Hello7 Fred Bloggs", 
+                helloWorldService.getGreetingsDontWrapSingle("Fred", 
"Bloggs"));        
 
     }
 

Modified: 
tuscany/branches/sca-java-1.x/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-jms.xsd
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-jms.xsd?rev=770201&r1=770200&r2=770201&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.x/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-jms.xsd
 (original)
+++ 
tuscany/branches/sca-java-1.x/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-jms.xsd
 Thu Apr 30 12:29:50 2009
@@ -92,9 +92,18 @@
    
    <complexType name="WireFormatJMSObjectType">
       <complexContent>
-         <extension base="t:WireFormat"/>
+         <extension base="t:WireFormat">
+             <attribute name="wrapSingle" default="false">
+                  <simpleType>
+                      <restriction base="string">
+                         <enumeration value="true"/>
+                         <enumeration value="false"/>
+                      </restriction>
+                  </simpleType>             
+             </attribute>
+         </extension>
       </complexContent>
-   </complexType>
+   </complexType>       
    <element name="wireFormat.jmsObject" 
             type="t:WireFormatJMSObjectType"
             substitutionGroup="t:wireFormat"/>   

Modified: 
tuscany/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/ObjectMessageProcessor.java
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/ObjectMessageProcessor.java?rev=770201&r1=770200&r2=770201&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/ObjectMessageProcessor.java
 (original)
+++ 
tuscany/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/ObjectMessageProcessor.java
 Thu Apr 30 12:29:50 2009
@@ -34,7 +34,6 @@
 /**
  * MessageProcessor for sending/receiving Serializable objects with the 
JMSBinding.
  * 
- * @version $Rev$ $Date$
  */
 public class ObjectMessageProcessor extends AbstractMessageProcessor {
     private static final Logger logger = 
Logger.getLogger(ObjectMessageProcessor.class.getName());
@@ -44,17 +43,6 @@
     }
 
     @Override
-    protected Object extractPayload(Message msg) {
-        try {
-
-            return ((ObjectMessage)msg).getObject();
-
-        } catch (JMSException e) {
-            throw new JMSBindingException(e);
-        }
-    }
-
-    @Override
     protected Message createJMSMessage(Session session, Object o) {
         if (session == null) {
             logger.fine("no response session to create message: " + 
String.valueOf(o));
@@ -96,4 +84,147 @@
         return extractPayload(msg);
     }
     
+    @Override
+    protected Object extractPayload(Message msg) {
+        try {
+
+            return ((ObjectMessage)msg).getObject();
+
+        } catch (JMSException e) {
+            throw new JMSBindingException(e);
+        }
+    }    
+    
+    // special methods for handling operations with single parameters
+    
+    public Message createJMSMessageForSingleParamOperation(Session session, 
Object o, boolean wrapSingleInput) {
+        if (session == null) {
+            logger.fine("no response session to create message: " + 
String.valueOf(o));
+            return null;
+        }
+        try {
+
+            ObjectMessage message = session.createObjectMessage();
+
+            if (o != null) {
+                if (!(o instanceof Serializable)) {
+                    throw new IllegalStateException("JMS ObjectMessage payload 
not Serializable: " + o);
+                }
+
+                // If the user has specifically requests that single parameters
+                // be wrapped then leave is as is as it will have already been 
+                // wrapped by Tuscany. Otherwise unwrap it.
+                if (wrapSingleInput) {
+                    message.setObject((Serializable) o);
+                } else { // unwrap from array
+                    message.setObject((Serializable) ((Object[]) o)[0]);
+                }
+
+            }
+
+            return message;
+
+        } catch (JMSException e) {
+            throw new JMSBindingException(e);
+        }
+    }
+
+    public Object extractPayloadFromJMSMessageForSingleParamOperation(Message 
msg, Class<?> argType, boolean wrapSingle) {
+        // We always have a one arg operation if this method is called so we 
need to 
+        // decide if the data on the wire is wrapped or not. This is the 
algorithm.
+        //
+        // If the payload is null then create an empty array and pass it on
+        // If the payload is not an array then it must represent an unwrapped 
+        //    single arg. Wrap it up and pass it on
+        // If the payload is an array then determine if it's a wrapped single 
arg or not
+        //    If the service interface arg type matches the type of the array 
and not it's contents
+        //      then it's an unwrapped argument so wrap it and pass it on
+        //    If the service interface arg type matches the type of the 
contents and not the type
+        //      of the array then the parameter is already wrapped so pass it 
on as is 
+        //    If the service interface arg type matches both the type of the 
+        //      array and the type of its contents then assume that the whole 
array is the
+        //      parameter and decide whether to unwrap it or pass it on as is 
based on the 
+        //      setting of the wrapSingle attribute
+        //
+        
+        try {
+            Object payload = ((ObjectMessage) msg).getObject();
+            
+            if (payload instanceof Throwable) {
+                if (payload instanceof RuntimeException) {
+                    throw new ServiceRuntimeException("remote service 
exception, see nested exception", (RuntimeException) payload);
+                } else {
+                    return new InvocationTargetException((Throwable) payload);
+                }
+            }
+            
+            if (payload == null) {
+                // methodA(null) was not wrapped on wire so wrap it here in 
order
+                // that it passes through the rest of the Tuscany wire 
successfully
+                return new Object[] { payload }; 
+            }
+
+            boolean payloadIsArray = payload.getClass().isArray();
+
+            // Non-array payload is single arg
+            if (!payloadIsArray) {
+                // methodB(arg) wasn't wrapped on wire so wrap it here in order
+                // that it passes through the rest of the Tuscany wire 
successfully
+                return new Object[] { payload }; 
+            } else {
+                int size = ((Object[]) payload).length;
+                
+                // An initial quick check to determine whether the payload is 
not 
+                // wrapped. If the array has anything other than a single entry
+                // then it's not the result of reference side wrapping so wrap 
it 
+                // here and pass it on
+                if (size != 1) { 
+                    return new Object[] { payload };
+                }
+
+                // we know the array has only one entry now so get it
+                Object arrayContents = ((Object[]) payload)[0];
+
+                // Is the operation argument the same type as the array itself?
+                if (argType.isAssignableFrom(payload.getClass())) {
+                    
+                    // So we believe that the whole array is the argument but 
need
+                    // to check what is in the array to be sure
+                    if (arrayContents == null) {
+                        // There is nothing in the array so it could be an 
accident that
+                        // the array type matches the argument type, e.g. 
op(Object)
+                        // so rely on the wrapSingle setting to choose
+                        if (wrapSingle) {
+                            return payload;
+                        } else {
+                            return new Object[] { payload };
+                        }
+                    } else if 
(argType.isAssignableFrom(arrayContents.getClass())) { 
+                        // We can't tell as the argument type matches both the 
array type and 
+                        // the array contents type so use the wrapSingle 
setting to choose
+                        if (wrapSingle) {
+                            return payload;
+                        } else {
+                            return new Object[] { payload };
+                        }
+                    } else {
+                        // So by now we know the whole array is intended to be 
the 
+                        // parameter to wrap it and send it on
+                        return new Object[] { payload }; 
+                    }
+
+                } else {
+                    // The array type doesn't match the argument type so 
assume that the 
+                    // array contents will match the argument type and that 
hence the
+                    // parameter is already wrapped so just send it as is. If 
the contents
+                    // type doesn't match the argument type a exception will 
be thrown further
+                    // along the wire
+                    return payload;
+                }
+            }            
+        } catch (JMSException e) {
+            throw new JMSBindingException(e);
+        }
+    }
+
 }

Modified: 
tuscany/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceInterceptor.java
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceInterceptor.java?rev=770201&r1=770200&r2=770201&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceInterceptor.java
 (original)
+++ 
tuscany/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceInterceptor.java
 Thu Apr 30 12:29:50 2009
@@ -20,6 +20,8 @@
 
 
 import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+
 import javax.jms.JMSException;
 import javax.jms.Session;
 
@@ -31,6 +33,7 @@
 import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor;
 import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil;
 import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.binding.jms.provider.ObjectMessageProcessor;
 import 
org.apache.tuscany.sca.binding.jms.wireformat.jmsobject.WireFormatJMSObject;
 import org.apache.tuscany.sca.invocation.Interceptor;
 import org.apache.tuscany.sca.invocation.Invoker;
@@ -50,13 +53,16 @@
     private JMSMessageProcessor requestMessageProcessor;
     private JMSMessageProcessor responseMessageProcessor;
 
-    public WireFormatJMSObjectReferenceInterceptor(JMSBinding jmsBinding, 
JMSResourceFactory jmsResourceFactory, RuntimeWire runtimeWire) {
+    private HashMap<String, String> singleArgMap;
+
+    public WireFormatJMSObjectReferenceInterceptor(JMSBinding jmsBinding, 
JMSResourceFactory jmsResourceFactory, RuntimeWire runtimeWire, HashMap<String, 
String> hashMap) {
         super();
         this.jmsBinding = jmsBinding;
         this.runtimeWire = runtimeWire;
         this.jmsResourceFactory = jmsResourceFactory;
         this.requestMessageProcessor = 
JMSMessageProcessorUtil.getRequestMessageProcessor(jmsBinding);
         this.responseMessageProcessor = 
JMSMessageProcessorUtil.getResponseMessageProcessor(jmsBinding); 
+        this.singleArgMap = hashMap;
     }
 
     public Message invoke(Message msg) {
@@ -78,8 +84,27 @@
             // get the jms context
             JMSBindingContext context = msg.getBindingContext();
             Session session = context.getJmsSession();
-            
-            javax.jms.Message requestMsg = 
requestMessageProcessor.insertPayloadIntoJMSMessage(session, msg.getBody());
+
+            javax.jms.Message requestMsg;
+                        
+            // Tuscany automatically wraps operation arguments in an array 
before we
+            // get to this point so here we need to decide how they are going 
to appear 
+            // on the wire.
+            //
+            // If the operation has a single parameter and the user has set 
@wrapSingle=false
+            // then
+            //    send the single parameter out onto the wire unwrapped
+            // else 
+            //    send out the message as is
+            //
+            if (singleArgMap.get(msg.getOperation().getName()) == null) {
+                requestMsg = 
requestMessageProcessor.insertPayloadIntoJMSMessage(session, msg.getBody());
+            } else {
+                // we know that wrapSinle is set to false here as the provider 
only
+                // populates singleArgMap if it is set false
+                requestMsg = ((ObjectMessageProcessor) 
requestMessageProcessor).createJMSMessageForSingleParamOperation(session, 
msg.getBody(), false);
+            }
+
             msg.setBody(requestMsg);
             
             requestMsg.setJMSReplyTo(context.getReplyToDestination());

Modified: 
tuscany/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceProvider.java
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceProvider.java?rev=770201&r1=770200&r2=770201&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceProvider.java
 (original)
+++ 
tuscany/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceProvider.java
 Thu Apr 30 12:29:50 2009
@@ -19,12 +19,16 @@
 
 package org.apache.tuscany.sca.binding.jms.wireformat.jmsobject.runtime;
 
+import java.util.HashMap;
+import java.util.List;
+
 import org.apache.tuscany.sca.assembly.Binding;
 import org.apache.tuscany.sca.binding.jms.impl.JMSBinding;
 import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants;
 import 
org.apache.tuscany.sca.binding.jms.wireformat.jmsobject.WireFormatJMSObject;
 import org.apache.tuscany.sca.core.ExtensionPointRegistry;
 import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.Operation;
 import org.apache.tuscany.sca.invocation.Interceptor;
 import org.apache.tuscany.sca.invocation.Phase;
 import org.apache.tuscany.sca.provider.WireFormatProvider;
@@ -40,6 +44,8 @@
     private RuntimeComponentReference reference;
     private JMSBinding binding;
     private InterfaceContract interfaceContract; 
+    
+    private HashMap<String,String> singleArgMap; //map of one arg operations, 
leave empty if wrapSingleInput is true
 
     public WireFormatJMSObjectReferenceProvider(ExtensionPointRegistry 
registry,
                                                RuntimeComponent component,
@@ -51,6 +57,8 @@
         this.reference = reference;
         this.binding = (JMSBinding)binding;
         
+        this.singleArgMap = new HashMap<String,String>();
+        
         // configure the reference based on this wire format
         
         // currently maintaining the message processor structure which 
@@ -58,10 +66,21 @@
         // any message processors specified in the SCDL in this case
         if (this.binding.getRequestWireFormat() instanceof 
WireFormatJMSObject){
             
this.binding.setRequestMessageProcessorName(JMSBindingConstants.OBJECT_MP_CLASSNAME);
+            
+            //we don't need to create this map if wrapSingleInput is true
+            if (!((WireFormatJMSObject) 
this.binding.getRequestWireFormat()).isWrappedSingleInput()){
+                List<Operation> opList = 
reference.getReference().getInterfaceContract().getInterface().getOperations();
+                
+                for (Operation op: opList) {
+                    if (op.getInputType().getLogical().size() == 1){
+                        this.singleArgMap.put(op.getName(), "");
+                    }
+                }
+            } 
         }
         if (this.binding.getResponseWireFormat() instanceof 
WireFormatJMSObject){
             
this.binding.setResponseMessageProcessorName(JMSBindingConstants.OBJECT_MP_CLASSNAME);
-        } 
+        }
         
         // just point to the reference interface contract so no 
         // databinding transformation takes place
@@ -87,7 +106,7 @@
     public Interceptor createInterceptor() {
         return new WireFormatJMSObjectReferenceInterceptor(binding, 
                                                           null, 
-                                                          
reference.getRuntimeWire(binding));
+                                                          
reference.getRuntimeWire(binding), this.singleArgMap);
     }
 
     public String getPhase() {

Modified: 
tuscany/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceInterceptor.java
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceInterceptor.java?rev=770201&r1=770200&r2=770201&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceInterceptor.java
 (original)
+++ 
tuscany/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceInterceptor.java
 Thu Apr 30 12:29:50 2009
@@ -18,6 +18,8 @@
  */
 package org.apache.tuscany.sca.binding.jms.wireformat.jmsobject.runtime;
 
+import java.util.HashMap;
+
 import javax.jms.Session;
 
 import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext;
@@ -25,6 +27,7 @@
 import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor;
 import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil;
 import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.binding.jms.provider.ObjectMessageProcessor;
 import 
org.apache.tuscany.sca.binding.jms.wireformat.jmsobject.WireFormatJMSObject;
 import org.apache.tuscany.sca.interfacedef.Operation;
 import org.apache.tuscany.sca.invocation.Interceptor;
@@ -45,14 +48,19 @@
     private JMSBinding jmsBinding;
     private JMSMessageProcessor requestMessageProcessor;
     private JMSMessageProcessor responseMessageProcessor;
+    private HashMap<String,Class<?>> singleArgMap;
+    private boolean wrapSingle;
 
-    public WireFormatJMSObjectServiceInterceptor(JMSBinding jmsBinding, 
JMSResourceFactory jmsResourceFactory, RuntimeWire runtimeWire) {
+    public WireFormatJMSObjectServiceInterceptor(JMSBinding jmsBinding, 
JMSResourceFactory jmsResourceFactory, 
+            RuntimeWire runtimeWire, HashMap<String, Class<?>> singleArgMap, 
boolean wrapSingle) {
         super();
         this.jmsBinding = jmsBinding;
         this.runtimeWire = runtimeWire;
         this.jmsResourceFactory = jmsResourceFactory;
         this.requestMessageProcessor = 
JMSMessageProcessorUtil.getRequestMessageProcessor(jmsBinding);
         this.responseMessageProcessor = 
JMSMessageProcessorUtil.getResponseMessageProcessor(jmsBinding);
+        this.singleArgMap = singleArgMap;
+        this.wrapSingle = wrapSingle;
     }
 
     public Message invoke(Message msg) {
@@ -79,8 +87,18 @@
         // get the jms context
         JMSBindingContext context = msg.getBindingContext();
         javax.jms.Message jmsMsg = context.getJmsMsg();
-
-        Object requestPayload = 
requestMessageProcessor.extractPayloadFromJMSMessage(jmsMsg);
+        Object requestPayload;
+        
+        // If the service interface has a single argument then we need 
+        // to check if the object from the wire is expected  
+        // to be unwrapped or not
+        // 
+        Class<?> argType = this.singleArgMap.get(msg.getOperation().getName());
+        if (argType == null) {
+            requestPayload = 
requestMessageProcessor.extractPayloadFromJMSMessage(jmsMsg);    
+        }else {
+            requestPayload = 
((ObjectMessageProcessor)requestMessageProcessor).extractPayloadFromJMSMessageForSingleParamOperation(jmsMsg,
 argType, wrapSingle);
+        }
         
         if (requestPayload != null && requestPayload.getClass().isArray()) {
             msg.setBody(requestPayload);

Modified: 
tuscany/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceProvider.java
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceProvider.java?rev=770201&r1=770200&r2=770201&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceProvider.java
 (original)
+++ 
tuscany/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceProvider.java
 Thu Apr 30 12:29:50 2009
@@ -20,12 +20,16 @@
 package org.apache.tuscany.sca.binding.jms.wireformat.jmsobject.runtime;
 
 
+import java.util.HashMap;
+import java.util.List;
+
 import org.apache.tuscany.sca.assembly.Binding;
 import org.apache.tuscany.sca.binding.jms.impl.JMSBinding;
 import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants;
 import 
org.apache.tuscany.sca.binding.jms.wireformat.jmsobject.WireFormatJMSObject;
 import org.apache.tuscany.sca.core.ExtensionPointRegistry;
 import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.Operation;
 import org.apache.tuscany.sca.invocation.Interceptor;
 import org.apache.tuscany.sca.invocation.Phase;
 import org.apache.tuscany.sca.provider.WireFormatProvider;
@@ -41,6 +45,8 @@
     private RuntimeComponentService service;
     private JMSBinding binding;
     private InterfaceContract interfaceContract; 
+    private HashMap<String,Class<?>> singleArgMap;
+    private boolean wrapSingle = true;
 
     public WireFormatJMSObjectServiceProvider(ExtensionPointRegistry registry,
                                              RuntimeComponent component, 
@@ -51,6 +57,7 @@
         this.component = component;
         this.service = service;
         this.binding = (JMSBinding)binding;
+        this.singleArgMap = new HashMap<String,Class<?>>();
         
         // configure the service based on this wire format
         
@@ -59,6 +66,17 @@
         // any message processors specified in the SCDL in this case
         if (this.binding.getRequestWireFormat() instanceof 
WireFormatJMSObject){
             
this.binding.setRequestMessageProcessorName(JMSBindingConstants.OBJECT_MP_CLASSNAME);
+            
+            List<Operation> opList = 
service.getService().getInterfaceContract().getInterface().getOperations();
+            
+            for (Operation op: opList) {
+                if (op.getInputType().getLogical().size() == 1){
+                    this.singleArgMap.put(op.getName(), 
op.getInputType().getLogical().get(0).getPhysical());
+                }
+            }
+            
+            wrapSingle = ((WireFormatJMSObject) 
this.binding.getRequestWireFormat()).isWrappedSingleInput();
+            
         }
         if (this.binding.getResponseWireFormat() instanceof 
WireFormatJMSObject){
             
this.binding.setResponseMessageProcessorName(JMSBindingConstants.OBJECT_MP_CLASSNAME);
@@ -67,6 +85,8 @@
         // just point to the reference interface contract so no 
         // databinding transformation takes place
         interfaceContract = service.getInterfaceContract();
+
+        
     }
     
     public InterfaceContract 
configureWireFormatInterfaceContract(InterfaceContract interfaceContract){
@@ -88,9 +108,9 @@
     /**
      */
     public Interceptor createInterceptor() {
-        return new WireFormatJMSObjectServiceInterceptor((JMSBinding)binding,
-                                                         null,
-                                                        
service.getRuntimeWire(binding));
+        
+        return new WireFormatJMSObjectServiceInterceptor((JMSBinding)binding, 
null,service.getRuntimeWire(binding), 
+                this.singleArgMap, wrapSingle );
     }
 
     /**

Modified: 
tuscany/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/WireFormatJMSObject.java
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/WireFormatJMSObject.java?rev=770201&r1=770200&r2=770201&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/WireFormatJMSObject.java
 (original)
+++ 
tuscany/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/WireFormatJMSObject.java
 Thu Apr 30 12:29:50 2009
@@ -32,6 +32,10 @@
 public class WireFormatJMSObject implements WireFormat {
     public static final QName WIRE_FORMAT_JMS_BYTES_QNAME = new 
QName(Constants.SCA10_TUSCANY_NS, "wireFormat.jmsObject");
     
+    public static final String WIRE_FORMAT_JMS_OBJECT_WRAP_SINGLE_ATTR = 
"wrapSingle";
+    
+    private boolean wrappedSingleInput = false;
+    
     public QName getSchemaName() {
         return WIRE_FORMAT_JMS_BYTES_QNAME;
     }
@@ -42,4 +46,12 @@
 
     public void setUnresolved(boolean unresolved) {
     }
+
+    public void setWrappedSingleInput(boolean wrappedSingleInput) {
+        this.wrappedSingleInput = wrappedSingleInput;
+    }
+
+    public boolean isWrappedSingleInput() {
+        return wrappedSingleInput;
+    }
 }

Modified: 
tuscany/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/WireFormatJMSObjectProcessor.java
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/WireFormatJMSObjectProcessor.java?rev=770201&r1=770200&r2=770201&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/WireFormatJMSObjectProcessor.java
 (original)
+++ 
tuscany/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/WireFormatJMSObjectProcessor.java
 Thu Apr 30 12:29:50 2009
@@ -52,7 +52,13 @@
     
     public WireFormatJMSObject read(XMLStreamReader reader) throws 
ContributionReadException, XMLStreamException {
         WireFormatJMSObject wireFormat = new WireFormatJMSObject();
-         
+        
+        String wrappedSingleInput = reader.getAttributeValue(null, 
WireFormatJMSObject.WIRE_FORMAT_JMS_OBJECT_WRAP_SINGLE_ATTR);
+        if (wrappedSingleInput != null && wrappedSingleInput.length() > 0) {
+            if ("true".equalsIgnoreCase(wrappedSingleInput)) {
+                wireFormat.setWrappedSingleInput(true);
+            }
+        }
         return wireFormat;
     }
 
@@ -64,6 +70,8 @@
                                  getArtifactType().getNamespaceURI());
         writer.writeNamespace("tuscany", Constants.SCA10_TUSCANY_NS); 
         
+        
writer.writeAttribute(WireFormatJMSObject.WIRE_FORMAT_JMS_OBJECT_WRAP_SINGLE_ATTR,
 String.valueOf(wireFormat.isWrappedSingleInput()));
+        
         writer.writeEndElement();
     }
 


Reply via email to