summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/databinding
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2010-02-11 04:21:00 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2010-02-11 04:21:00 +0000
commit45f532168598a09d523eb051fa78c6416f913b2a (patch)
tree5f2b518acfca5ae0a285f1ace69b5af7ebcd8dd7 /sca-java-2.x/trunk/modules/databinding
parentfd16cfb3af0bb7063dcc59210b475dbc98bc3424 (diff)
TUSCANY-2586: Fix pass-by-value copies as described in the JIRA with the SCA binding doing the necessary copies. Also update the copy code so that the new copy is in the correct class loader so that invocations across Nodes in the same JVM work
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@908835 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/databinding')
-rw-r--r--sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBinding.java10
-rw-r--r--sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java4
-rw-r--r--sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Mediator.java34
-rw-r--r--sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseDataBinding.java4
-rw-r--r--sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java44
-rw-r--r--sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java8
6 files changed, 91 insertions, 13 deletions
diff --git a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBinding.java b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBinding.java
index 7c4ed35eb3..95de3a02f0 100644
--- a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBinding.java
+++ b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBinding.java
@@ -83,6 +83,16 @@ public interface DataBinding {
Object copy(Object object, DataType dataType, Operation operation);
/**
+ * Make a copy of the object for "pass-by-value" semantics and cross classloader invocations.
+ *
+ * @param object source object to copy
+ * @param dataType The data type
+ * @param operation The operation
+ * @return copy of the object passed in as argument
+ */
+ Object copy(Object object, DataType dataType, Operation operation, DataType targetdataType);
+
+ /**
* Get the XML type helper for Java types
* @return The databinding-specific XML type helper class
*/
diff --git a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java
index 19455fcd29..b9ed72203e 100644
--- a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java
+++ b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java
@@ -169,6 +169,10 @@ public class DefaultDataBindingExtensionPoint implements DataBindingExtensionPoi
return getDataBinding().copy(object, dataType, operation);
}
+ public Object copy(Object object, DataType dataType, Operation operation, DataType targetdataType) {
+ return getDataBinding().copy(object, dataType, operation, targetdataType);
+ }
+
public String getName() {
return name;
}
diff --git a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Mediator.java b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Mediator.java
index 8184d739a8..5bffa477bb 100644
--- a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Mediator.java
+++ b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Mediator.java
@@ -100,6 +100,15 @@ public interface Mediator {
Object copy(Object data, DataType dataType);
/**
+ * Copy the data
+ * @param data The orginal data
+ * @param dataType The data type
+ * @param targetDataType The target data type
+ * @return The copy
+ */
+ Object copy(Object data, DataType dataType, DataType targetDataType);
+
+ /**
* Copy an array of data objects passed to an operation
* @param data array of objects to copy
* @return the copy
@@ -107,6 +116,13 @@ public interface Mediator {
public Object copyInput(Object input, Operation operation);
/**
+ * Copy an array of data objects passed to an operation
+ * @param data array of objects to copy
+ * @return the copy
+ */
+ public Object copyInput(Object input, Operation operation, Operation targetOperation);
+
+ /**
* Copy the output data
* @param data The orginal output
* @param operation The operation
@@ -115,6 +131,15 @@ public interface Mediator {
Object copyOutput(Object data, Operation operation);
/**
+ * Copy the output data
+ * @param data The orginal output
+ * @param operation The operation
+ * @param targetOperation The target operation
+ * @return The copy
+ */
+ Object copyOutput(Object data, Operation operation, Operation targetOperation);
+
+ /**
* Copy the fault data
* @param fault The orginal fault data
* @param operation The operation
@@ -123,6 +148,15 @@ public interface Mediator {
Object copyFault(Object fault, Operation operation);
/**
+ * Copy the fault data
+ * @param fault The orginal fault data
+ * @param operation The operation
+ * @param targetOperation The target operation
+ * @return The copy
+ */
+ Object copyFault(Object fault, Operation operation, Operation targetOperation);
+
+ /**
* Get the DataBindings used by this mediator.
* @return
*/
diff --git a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseDataBinding.java b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseDataBinding.java
index cb9f2969e2..3877fd50f7 100644
--- a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseDataBinding.java
+++ b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseDataBinding.java
@@ -100,6 +100,10 @@ public abstract class BaseDataBinding implements DataBinding {
}
public Object copy(Object object, DataType dataType, Operation operation) {
+ return copy(object, dataType, operation, dataType);
+ }
+
+ public Object copy(Object object, DataType dataType, Operation operation, DataType targetDataType) {
return object;
}
diff --git a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java
index 195c04e9c2..48515f8f0f 100644
--- a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java
+++ b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java
@@ -443,7 +443,11 @@ public class MediatorImpl implements Mediator {
}
public Object copy(Object data, DataType dataType) {
- return copy(data, dataType, null);
+ return copy(data, dataType, null, null);
+ }
+
+ public Object copy(Object data, DataType dataType, DataType targetDataType) {
+ return copy(data, dataType, null, targetDataType);
}
/**
@@ -452,7 +456,7 @@ public class MediatorImpl implements Mediator {
* @param dataType
* @return a copy of the data
*/
- private Object copy(Object data, DataType dataType, Operation operation) {
+ private Object copy(Object data, DataType dataType, Operation operation, DataType targetDataType) {
if (data == null) {
return null;
}
@@ -515,11 +519,11 @@ public class MediatorImpl implements Mediator {
}
}
- if (dataBinding != null) {
- return dataBinding.copy(data, dataType, operation);
- } else {
+ if (dataBinding == null) {
return data;
}
+
+ return dataBinding.copy(data, dataType, operation, targetDataType);
}
/**
@@ -528,11 +532,15 @@ public class MediatorImpl implements Mediator {
* @return the copy
*/
public Object copyInput(Object input, Operation operation) {
+ return copyInput(input, operation, null);
+ }
+ public Object copyInput(Object input, Operation operation, Operation targetOperation) {
if (input == null) {
return null;
}
Object[] data = (input instanceof Object[]) ? (Object[])input : new Object[] {input};
List<DataType> inputTypes = operation.getInputType().getLogical();
+ List<DataType> inputTypesTarget = targetOperation == null ? null : targetOperation.getInputType().getLogical();
Object[] copy = new Object[data.length];
Map<Object, Object> map = new IdentityHashMap<Object, Object>();
for (int i = 0, size = inputTypes.size(); i < size; i++) {
@@ -544,7 +552,7 @@ public class MediatorImpl implements Mediator {
if (copiedArg != null) {
copy[i] = copiedArg;
} else {
- copiedArg = copy(arg, inputTypes.get(i));
+ copiedArg = copy(arg, inputTypes.get(i), inputTypesTarget == null ? null : inputTypesTarget.get(i));
map.put(arg, copiedArg);
copy[i] = copiedArg;
}
@@ -554,14 +562,22 @@ public class MediatorImpl implements Mediator {
}
public Object copyOutput(Object data, Operation operation) {
- return copy(data, operation.getOutputType(), operation);
+ return copyOutput(data, operation, null);
+ }
+ public Object copyOutput(Object data, Operation operation, Operation targetOperation) {
+ return copy(data, operation.getOutputType(), operation, targetOperation.getOutputType());
}
public Object copyFault(Object fault, Operation operation) {
+ return copyFault(fault, operation, null);
+ }
+ public Object copyFault(Object fault, Operation operation, Operation targetOperation) {
if (faultExceptionMapper == null) {
return fault;
}
- for (DataType et : operation.getFaultTypes()) {
+ List<DataType> fts = operation.getFaultTypes();
+ for (int i=0; i<fts.size(); i++) {
+ DataType et = fts.get(i);
if (et.getPhysical().isInstance(fault)) {
Throwable ex = (Throwable)fault;
DataType<DataType> exType =
@@ -569,9 +585,15 @@ public class MediatorImpl implements Mediator {
faultExceptionMapper.introspectFaultDataType(exType, operation, false);
DataType faultType = exType.getLogical();
Object faultInfo = faultExceptionMapper.getFaultInfo(ex, faultType.getPhysical(), operation);
- faultInfo = copy(faultInfo, faultType);
- fault =
- faultExceptionMapper.wrapFaultInfo(exType, ex.getMessage(), faultInfo, ex.getCause(), operation);
+ DataType targetFaultType;
+ try {
+ targetFaultType = (DataType)faultType.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new IllegalStateException(e);
+ }
+ targetFaultType.setPhysical(targetOperation.getFaultTypes().get(i).getPhysical());
+ faultInfo = copy(faultInfo, faultType, targetFaultType);
+ fault = faultExceptionMapper.wrapFaultInfo(exType, ex.getMessage(), faultInfo, ex.getCause(), operation);
return fault;
}
}
diff --git a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java
index 4981699792..70637b756e 100644
--- a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java
+++ b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java
@@ -59,7 +59,7 @@ public class JavaBeansDataBinding extends BaseDataBinding {
}
@Override
- public Object copy(Object arg, DataType dataType, Operation operation) {
+ public Object copy(Object arg, DataType dataType, Operation operation, DataType targetDataType) {
if (arg == null) {
return null;
}
@@ -82,12 +82,16 @@ public class JavaBeansDataBinding extends BaseDataBinding {
// Work out which ClassLoader to use for deserializing arg
// We want to use:
+ // * The ClassLoader of the targetDataType if it is not the System ClassLoader
// * The ClassLoader of arg if it is not the System ClassLoader
// * The ThreadContext ClassLoader if the ClassLoader of arg is the System ClassLoader
// because Collection classes are loaded by the System ClassLoader but their contents
// may be loaded from another ClassLoader
//
- ClassLoader classLoaderToUse = clazz.getClassLoader();
+ ClassLoader classLoaderToUse = targetDataType.getPhysical().getClassLoader();
+ if (classLoaderToUse == null) {
+ classLoaderToUse = clazz.getClassLoader();
+ }
if (classLoaderToUse == null)
{
// ClassLoader of arg is the System ClassLoader so we will use the ThreadContext ClassLoader