summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-1.x/modules/implementation-java-runtime/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'branches/sca-java-1.x/modules/implementation-java-runtime/src/main')
-rw-r--r--branches/sca-java-1.x/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationInvoker.java148
1 files changed, 68 insertions, 80 deletions
diff --git a/branches/sca-java-1.x/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationInvoker.java b/branches/sca-java-1.x/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationInvoker.java
index fa40560f7e..f86d6c750c 100644
--- a/branches/sca-java-1.x/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationInvoker.java
+++ b/branches/sca-java-1.x/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationInvoker.java
@@ -6,22 +6,22 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.implementation.java.invocation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
import java.util.List;
-import java.util.Vector;
import javax.xml.ws.Holder;
@@ -45,7 +45,7 @@ import org.osoa.sca.ServiceRuntimeException;
/**
* Responsible for synchronously dispatching an invocation to a Java component
* implementation instance
- *
+ *
* @version $Rev$ $Date$
*/
public class JavaImplementationInvoker implements Invoker, DataExchangeSemantics {
@@ -65,7 +65,7 @@ public class JavaImplementationInvoker implements Invoker, DataExchangeSemantics
}
public JavaImplementationInvoker(Operation operation, RuntimeComponent component) {
- // used if the method can't be computed statically in advance
+ // used if the method can't be computed statically in advance
this.operation = operation;
this.scopeContainer = ((ScopedRuntimeComponent)component).getScopeContainer();
}
@@ -98,7 +98,7 @@ public class JavaImplementationInvoker implements Invoker, DataExchangeSemantics
}
try {
- // The following call might create a new conversation, as a result, the msg.getConversationID() might
+ // The following call might create a new conversation, as a result, the msg.getConversationID() might
// return a new value
InstanceWrapper wrapper = scopeContainer.getWrapper(contextId);
@@ -106,8 +106,8 @@ public class JavaImplementationInvoker implements Invoker, DataExchangeSemantics
// happen in the case that the component has conversational scope but only the
// callback interface is conversational. Or in the callback case if the service interface
// is conversational and the callback interface isn't. If we are in this situation we need
- // to get the contextId of this component and remove it after we have invoked the method on
- // it. It is possible that the component instance will not go away when it is removed below
+ // to get the contextId of this component and remove it after we have invoked the method on
+ // it. It is possible that the component instance will not go away when it is removed below
// because a callback conversation will still be holding a reference to it
boolean removeTemporaryConversationalComponentAfterCall = false;
if (parameters != null && (contextId == null) && (parameters.getConversationID() != null)) {
@@ -129,32 +129,33 @@ public class JavaImplementationInvoker implements Invoker, DataExchangeSemantics
throw new IllegalArgumentException("Callback object does not provide method " + e.getMessage());
}
}
-
+
// Holder pattern. Any payload parameters <T> which are should be in holders are placed in Holder<T>.
- if ( imethod != null) {
- Class<?> [] params = imethod.getParameterTypes();
- if ( params != null ) {
- for ( int i = 0; i < params.length; i++ ) {
- Class<?> parameter = params[ i ];
- if ( isHolder( parameter )) {
+ // Only check Holder for remotable interfaces
+ if (imethod != null && op.getInterface().isRemotable()) {
+ Class<?>[] params = imethod.getParameterTypes();
+ if (params != null) {
+ for (int i = 0; i < params.length; i++) {
+ Class<?> parameter = params[i];
+ if (Holder.class == parameter) {
// System.out.println( "JavaImplementationInvoker.invoke parameter " + i + " is Holder. Payload isArray=" + (payload != null ? payload.getClass().isArray() : "null" ));
if (payload != null && !payload.getClass().isArray()) {
// Promote single param from <T> to Holder<T>
- payload = new Holder( payload );
+ payload = new Holder(payload);
} else {
// Promote array params from [<T>] to [Holder<T>]
- Object [] payloadArray = (Object[]) payload;
- for ( int j = 0; j < payloadArray.length; j++ ) {
- Object item = payloadArray[ j ];
- payloadArray[ j ] = new Holder( item );
+ Object[] payloadArray = (Object[])payload;
+ for (int j = 0; payloadArray != null && j < payloadArray.length; j++) {
+ Object item = payloadArray[j];
+ payloadArray[j] = new Holder(item);
}
}
argumentHolderCount++;
}
}
- }
+ }
}
-
+
Object ret;
if (payload != null && !payload.getClass().isArray()) {
ret = imethod.invoke(instance, payload);
@@ -170,49 +171,49 @@ public class JavaImplementationInvoker implements Invoker, DataExchangeSemantics
scopeContainer.remove(contextId);
parameters.setConversationID(null);
}
-
+
if (argumentHolderCount > 0) {
// Holder pattern. Any payload Holder<T> types are returned as the message body.
- List returnArgs = new Vector<Object>();
+ List returnArgs = new ArrayList<Object>();
int foundHolders = 0;
- if ( imethod != null) {
- Class<?> [] params = imethod.getParameterTypes();
- if ( params != null ) {
- for ( int i = 0; i < params.length; i++ ) {
- Class<?> parameter = params[ i ];
+ if (imethod != null) {
+ Class<?>[] params = imethod.getParameterTypes();
+ if (params != null) {
+ for (int i = 0; i < params.length; i++) {
+ Class<?> parameter = params[i];
// System.out.println( "JavaImplementationInvoker.invoke return parameter " + i + " type=" + parameter.getClass().getName() );
- if ( isHolder( parameter )) {
+ if (Holder.class == parameter) {
if (payload != null && !payload.getClass().isArray()) {
// Demote params from Holder<T> to <T>.
- Holder<Object> holder = (Holder<Object>) payload;
- returnArgs.add( holder.value );
+ Holder<Object> holder = (Holder<Object>)payload;
+ returnArgs.add(holder.value);
foundHolders++;
} else {
// Demote array params from Holder<T> to <T>.
- Object [] payloadArray = (Object[]) payload;
- for ( int j = 0; j < payloadArray.length; j++ ) {
- Holder<Object> item = (Holder<Object>) payloadArray[ j ];
- payloadArray[ j ] = item.value;
- returnArgs.add( payloadArray[ j ] );
+ Object[] payloadArray = (Object[])payload;
+ for (int j = 0; j < payloadArray.length; j++) {
+ Holder<Object> item = (Holder<Object>)payloadArray[j];
+ payloadArray[j] = item.value;
+ returnArgs.add(payloadArray[j]);
}
foundHolders++;
}
}
}
- }
+ }
}
// Although payload items are returned in a list, currently only support 1 return type.
- if ( returnArgs.size() == 1 ) {
- Object value = returnArgs.get( 0 );
- if (( value != null ) && ( value.getClass().isArray() )) {
- Object [] values = (Object []) value;
- if (( values != null ) && ( values.length > 0 )) {
- msg.setBody( values[ 0 ] );
- }
- } else
- msg.setBody(value);
- } else
- msg.setBody(returnArgs.toArray());
+ if (returnArgs.size() == 1) {
+ Object value = returnArgs.get(0);
+ if ((value != null) && (value.getClass().isArray())) {
+ Object[] values = (Object[])value;
+ if ((values != null) && (values.length > 0)) {
+ msg.setBody(values[0]);
+ }
+ } else
+ msg.setBody(value);
+ } else
+ msg.setBody(returnArgs.toArray());
} else {
msg.setBody(ret);
}
@@ -227,27 +228,26 @@ public class JavaImplementationInvoker implements Invoker, DataExchangeSemantics
}
}
-
- if (sequence != ConversationSequence.CONVERSATION_NONE ){
+ if (sequence != ConversationSequence.CONVERSATION_NONE) {
try {
-// // If the exception is not a business exception then end the conversation
-// boolean businessException = false;
-//
-// for (DataType dataType : operation.getFaultTypes()){
-// if ((dataType.getPhysical() == e.getCause().getClass()) &&
-// (contextId != null) ){
-// businessException = true;
-// break;
-// }
-// }
-
+ // // If the exception is not a business exception then end the conversation
+ // boolean businessException = false;
+ //
+ // for (DataType dataType : operation.getFaultTypes()){
+ // if ((dataType.getPhysical() == e.getCause().getClass()) &&
+ // (contextId != null) ){
+ // businessException = true;
+ // break;
+ // }
+ // }
+
if (!isChecked && contextId != null) {
scopeContainer.remove(contextId);
parameters.setConversationID(null);
}
- } catch (Exception ex){
+ } catch (Exception ex) {
// TODO - sure what the best course of action is here. We have
- // a system exception in the middle of a business exception
+ // a system exception in the middle of a business exception
}
}
if (!isChecked) {
@@ -259,10 +259,10 @@ public class JavaImplementationInvoker implements Invoker, DataExchangeSemantics
} else {
throw new ServiceRuntimeException(cause.getMessage(), cause);
}
- }
-
+ }
+
} catch (Exception e) {
- msg.setFaultBody(e);
+ msg.setFaultBody(e);
}
return msg;
}
@@ -270,16 +270,4 @@ public class JavaImplementationInvoker implements Invoker, DataExchangeSemantics
public boolean allowsPassByReference() {
return allowsPBR;
}
-
- /**
- * Given a Class, tells if it is a Holder by comparing to "javax.xml.ws.Holder"
- * @param testClass
- * @return
- */
- public static boolean isHolder( Class testClass ) {
- if ( testClass.getName().equals( "javax.xml.ws.Holder" )) {
- return true;
- }
- return false;
- }
}