diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-05-01 18:20:45 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-05-01 18:20:45 +0000 |
commit | 7f669616265736234e24b8ffd834d047e9d5e0fa (patch) | |
tree | 453a3554bf59d852b5152a87ebdcc5bafec54221 /java/sca | |
parent | 43308307429f8575e091e6f46b94bdbf6c42055c (diff) |
Merge the Mediator changes from 1.x
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@770781 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca')
17 files changed, 699 insertions, 486 deletions
diff --git a/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java b/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java index de861103c4..782a6fc3d3 100644 --- a/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java +++ b/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java @@ -6,15 +6,15 @@ * 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.core.databinding.module; @@ -22,6 +22,7 @@ package org.apache.tuscany.sca.core.databinding.module; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.core.ModuleActivator; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.core.databinding.processor.DataBindingJavaInterfaceProcessor; import org.apache.tuscany.sca.core.databinding.processor.WrapperJavaInterfaceProcessor; import org.apache.tuscany.sca.core.databinding.transformers.Array2ArrayTransformer; @@ -31,9 +32,9 @@ import org.apache.tuscany.sca.core.databinding.transformers.Input2InputTransform import org.apache.tuscany.sca.core.databinding.transformers.Output2OutputTransformer; import org.apache.tuscany.sca.core.databinding.wire.DataBindingRuntimeWireProcessor; import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.Mediator; import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; import org.apache.tuscany.sca.databinding.impl.Group2GroupTransformer; -import org.apache.tuscany.sca.databinding.impl.MediatorImpl; import org.apache.tuscany.sca.databinding.jaxb.XMLAdapterExtensionPoint; import org.apache.tuscany.sca.interfacedef.FaultExceptionMapper; import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; @@ -55,8 +56,10 @@ public class DataBindingModuleActivator implements ModuleActivator { XMLAdapterExtensionPoint xmlAdapterExtensionPoint = registry.getExtensionPoint(XMLAdapterExtensionPoint.class); xmlAdapterExtensionPoint.addAdapter(CallableReference.class, CallableReferenceXMLAdapter.class); FaultExceptionMapper faultExceptionMapper = new JAXWSFaultExceptionMapper(dataBindings, xmlAdapterExtensionPoint); - - MediatorImpl mediator = new MediatorImpl(dataBindings, transformers); + registry.getExtensionPoint(UtilityExtensionPoint.class).addUtility(faultExceptionMapper); + + Mediator mediator = registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Mediator.class); + Input2InputTransformer input2InputTransformer = new Input2InputTransformer(); input2InputTransformer.setMediator(mediator); transformers.addTransformer(input2InputTransformer, true); @@ -67,7 +70,7 @@ public class DataBindingModuleActivator implements ModuleActivator { Exception2ExceptionTransformer exception2ExceptionTransformer = new Exception2ExceptionTransformer(mediator, faultExceptionMapper); transformers.addTransformer(exception2ExceptionTransformer, false); - + Array2ArrayTransformer array2ArrayTransformer = new Array2ArrayTransformer(); array2ArrayTransformer.setMediator(mediator); transformers.addTransformer(array2ArrayTransformer, true); @@ -75,14 +78,14 @@ public class DataBindingModuleActivator implements ModuleActivator { Group2GroupTransformer group2GroupTransformer = new Group2GroupTransformer(); group2GroupTransformer.setMediator(mediator); transformers.addTransformer(group2GroupTransformer, true); - + // dataBindings.addDataBinding(new CallableReferenceDataBinding()); // transformers.addTransformer(new CallableReference2XMLStreamReader(), true); // transformers.addTransformer(new XMLStreamReader2CallableReference(), false); FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); JavaInterfaceFactory javaFactory = modelFactories.getFactory(JavaInterfaceFactory.class); - // Add the WebServiceInterfaceProcessor to mark the interface remotable + // Add the WebServiceInterfaceProcessor to mark the interface remotable javaFactory.addInterfaceVisitor(new WebServiceInterfaceProcessor()); // Introspect the data types javaFactory.addInterfaceVisitor(new DataBindingJavaInterfaceProcessor(dataBindings)); @@ -93,7 +96,7 @@ public class DataBindingModuleActivator implements ModuleActivator { if (wireProcessorExtensionPoint != null) { wireProcessorExtensionPoint.addWireProcessor(new DataBindingRuntimeWireProcessor(mediator, dataBindings, faultExceptionMapper)); } - + } public void stop(ExtensionPointRegistry registry) { diff --git a/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java b/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java index b41c7fb012..a255763fbf 100644 --- a/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java +++ b/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java @@ -6,15 +6,15 @@ * 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.core.databinding.wire; @@ -37,7 +37,7 @@ import org.apache.tuscany.sca.runtime.RuntimeWireProcessor; /** * This processor is responsible to add an interceptor to invocation chain if * the source and target operations have different databinding requirements - * + * * @version $Rev$ $Date$ */ public class DataBindingRuntimeWireProcessor implements RuntimeWireProcessor { @@ -149,14 +149,13 @@ public class DataBindingRuntimeWireProcessor implements RuntimeWireProcessor { // Add the interceptor to the source side because multiple // references can be wired to the same service interceptor = - new DataTransformationInterceptor(wire, sourceOperation, targetOperation, mediator, - faultExceptionMapper); + new DataTransformationInterceptor(wire, sourceOperation, targetOperation, mediator); } else { // assume pass-by-values copies are required if interfaces are remotable and there is no data binding // transformation, i.e. a transformation will result in a copy so another pass-by-value copy is unnecessary if (!isOnMessage(targetOperation) && isRemotable(chain, sourceOperation, targetOperation)) { interceptor = - new PassByValueInterceptor(dataBindings, faultExceptionMapper, chain, targetOperation); + new PassByValueInterceptor(mediator, chain, targetOperation); } } if (interceptor != null) { @@ -172,7 +171,7 @@ public class DataBindingRuntimeWireProcessor implements RuntimeWireProcessor { /** * FIXME: TUSCANY-2586, temporary work around till the JIRA is fixed to prevent * the PassByValueInterceptor being used for services when the binding protocol - * doesn't need the copies done. + * doesn't need the copies done. */ protected boolean isOnMessage(Operation op) { return "onMessage".equals(op.getName()); diff --git a/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java b/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java index 20dcb1b94a..679897b59b 100644 --- a/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java +++ b/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java @@ -23,12 +23,7 @@ import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.Map; -import javax.xml.namespace.QName; - -import org.apache.tuscany.sca.databinding.DataBinding; import org.apache.tuscany.sca.databinding.Mediator; -import org.apache.tuscany.sca.interfacedef.DataType; -import org.apache.tuscany.sca.interfacedef.FaultExceptionMapper; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; import org.apache.tuscany.sca.interfacedef.util.FaultException; @@ -53,19 +48,16 @@ public class DataTransformationInterceptor implements Interceptor, DataExchangeS private Operation targetOperation; private RuntimeWire wire; private Mediator mediator; - private FaultExceptionMapper faultExceptionMapper; public DataTransformationInterceptor(RuntimeWire wire, Operation sourceOperation, Operation targetOperation, - Mediator mediator, - FaultExceptionMapper faultExceptionMapper) { + Mediator mediator) { super(); this.sourceOperation = sourceOperation; this.targetOperation = targetOperation; this.mediator = mediator; this.wire = wire; - this.faultExceptionMapper = faultExceptionMapper; } public Invoker getNext() { @@ -73,7 +65,9 @@ public class DataTransformationInterceptor implements Interceptor, DataExchangeS } public Message invoke(Message msg) { - Object input = transform(msg.getBody(), sourceOperation.getInputType(), targetOperation.getInputType(), false); + Map<String, Object> metadata = new HashMap<String, Object>(); + metadata.put("wire", wire); + Object input = mediator.mediateInput(msg.getBody(), sourceOperation, targetOperation, metadata); msg.setBody(input); Message resultMsg = next.invoke(msg); Object result = resultMsg.getBody(); @@ -82,177 +76,28 @@ public class DataTransformationInterceptor implements Interceptor, DataExchangeS return resultMsg; } - // FIXME: Should we fix the Operation model so that getOutputType - // returns DataType<DataType<T>>? - DataType<DataType> targetType = - new DataTypeImpl<DataType>(DataBinding.IDL_OUTPUT, Object.class, targetOperation.getOutputType()); - - DataType<DataType> sourceType = - new DataTypeImpl<DataType>(DataBinding.IDL_OUTPUT, Object.class, sourceOperation.getOutputType()); if (resultMsg.isFault()) { - - // FIXME: We need to figure out what fault type it is and then - // transform it - // back the source fault type - // throw new InvocationRuntimeException((Throwable) result); - + Object transformedFault = null; if ((result instanceof Exception) && !(result instanceof RuntimeException)) { - // FIXME: How to match fault data to a fault type for the - // operation? - - // If the result is from an InvocationTargetException look at - // the actual cause. - if (result instanceof InvocationTargetException) { - result = ((InvocationTargetException)result).getCause(); - } - DataType targetDataType = null; - for (DataType exType : targetOperation.getFaultTypes()) { - if (((Class)exType.getPhysical()).isInstance(result)) { - if (result instanceof FaultException) { - DataType faultType = (DataType)exType.getLogical(); - if (((FaultException)result).isMatchingType(faultType.getLogical())) { - targetDataType = exType; - break; - } - } else { - targetDataType = exType; - break; - } - } - } - - /* - if (targetDataType == null) { - // Not a business exception - return resultMsg; - } - */ - - DataType targetFaultType = getFaultType(targetDataType); - if (targetFaultType == null) { - // No matching fault type, it's a system exception - Throwable cause = (Throwable) result; - throw new ServiceRuntimeException(cause); - } - - // FIXME: How to match a source fault type to a target fault - // type? - DataType sourceDataType = null; - DataType sourceFaultType = null; - for (DataType exType : sourceOperation.getFaultTypes()) { - DataType faultType = getFaultType(exType); - // Match by the QName (XSD element) of the fault type - if (faultType != null && typesMatch(targetFaultType.getLogical(), faultType.getLogical())) { - sourceDataType = exType; - sourceFaultType = faultType; - break; - } - } - - if (sourceFaultType == null) { - // No matching fault type, it's a system exception - Throwable cause = (Throwable) result; - throw new ServiceRuntimeException(cause); - } - - Object newResult = - transformException(result, targetDataType, sourceDataType, targetFaultType, sourceFaultType); - if (newResult != result) { - resultMsg.setFaultBody(newResult); + transformedFault = mediator.mediateFault(result, sourceOperation, targetOperation, metadata); + if (transformedFault != result) { + resultMsg.setFaultBody(transformedFault); } } - + // + // Leave it to another layer to actually throw the Exception which constitutes + // the message body. We don't throw it here. + // } else { assert !(result instanceof Throwable) : "Expected messages that are not throwable " + result; - - Object newResult = transform(result, targetType, sourceType, true); - if (newResult != result) { - resultMsg.setBody(newResult); - } + Object newResult = mediator.mediateOutput(result, sourceOperation, targetOperation, metadata); + resultMsg.setBody(newResult); } return resultMsg; } - private Object transform(Object source, DataType sourceType, DataType targetType, boolean isResponse) { - if (sourceType == targetType || (sourceType != null && sourceType.equals(targetType))) { - return source; - } - Map<String, Object> metadata = new HashMap<String, Object>(); - metadata.put("source.operation", isResponse ? targetOperation : sourceOperation); - metadata.put("target.operation", isResponse ? sourceOperation : targetOperation); - metadata.put("wire", wire); - return mediator.mediate(source, sourceType, targetType, metadata); - } - - private DataType getFaultType(DataType exceptionType) { - return exceptionType == null ? null : (DataType)exceptionType.getLogical(); - } - - private boolean typesMatch(Object first, Object second) { - if (first.equals(second)) { - return true; - } - if (first instanceof XMLType && second instanceof XMLType) { - XMLType t1 = (XMLType)first; - XMLType t2 = (XMLType)second; - // TUSCANY-2113, we should compare element names only - return matches(t1.getElementName(), t2.getElementName()); - } - return false; - } - - /** - * @param qn1 - * @param qn2 - */ - private boolean matches(QName qn1, QName qn2) { - if (qn1 == qn2) { - return true; - } - if (qn1 == null || qn2 == null) { - return false; - } - String ns1 = qn1.getNamespaceURI(); - String ns2 = qn2.getNamespaceURI(); - String e1 = qn1.getLocalPart(); - String e2 = qn2.getLocalPart(); - if (e1.equals(e2) && (ns1.equals(ns2) || ns1.equals(ns2 + "/") || ns2.equals(ns1 + "/"))) { - // Tolerating the trailing / which is required by JAX-WS java package --> xml ns mapping - return true; - } - return false; - } - - /** - * @param source The source exception - * @param sourceExType The data type for the source exception - * @param targetExType The data type for the target exception - * @param sourceType The fault type for the source - * @param targetType The fault type for the target - * @return - */ - private Object transformException(Object source, - DataType sourceExType, - DataType targetExType, - DataType sourceType, - DataType targetType) { - if (sourceType == targetType || (sourceType != null && sourceType.equals(targetType))) { - return source; - } - Map<String, Object> metadata = new HashMap<String, Object>(); - metadata.put("source.operation", targetOperation); - metadata.put("target.operation", sourceOperation); - metadata.put("wire", wire); - DataType<DataType> eSourceDataType = - new DataTypeImpl<DataType>("idl:fault", sourceExType.getPhysical(), sourceType); - DataType<DataType> eTargetDataType = - new DataTypeImpl<DataType>("idl:fault", targetExType.getPhysical(), targetType); - - return mediator.mediate(source, eSourceDataType, eTargetDataType, metadata); - } - public void setNext(Invoker next) { this.next = next; } diff --git a/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/PassByValueInterceptor.java b/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/PassByValueInterceptor.java index 1ff8d86f45..a4466bfd1a 100644 --- a/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/PassByValueInterceptor.java +++ b/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/PassByValueInterceptor.java @@ -6,40 +6,21 @@ * 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.core.databinding.wire; -import java.io.Serializable; -import java.lang.reflect.Array; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.URI; -import java.util.IdentityHashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.sca.databinding.DataBinding; -import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; -import org.apache.tuscany.sca.databinding.javabeans.JavaBeansDataBinding; -import org.apache.tuscany.sca.databinding.jaxb.JAXBDataBinding; -import org.apache.tuscany.sca.interfacedef.DataType; -import org.apache.tuscany.sca.interfacedef.FaultExceptionMapper; +import org.apache.tuscany.sca.databinding.Mediator; import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; -import org.apache.tuscany.sca.interfacedef.util.XMLType; import org.apache.tuscany.sca.invocation.Interceptor; import org.apache.tuscany.sca.invocation.InvocationChain; import org.apache.tuscany.sca.invocation.Invoker; @@ -54,13 +35,7 @@ import org.oasisopen.sca.ServiceRuntimeException; */ public class PassByValueInterceptor implements Interceptor { - private DataBindingExtensionPoint dataBindings; - private FaultExceptionMapper faultExceptionMapper; - - private DataBinding[] inputDataBindings; - private DataBinding outputDataBinding; - private DataBinding javaBeanDataBinding; - private DataBinding jaxbDataBinding; + private Mediator mediator; private Operation operation; private Invoker nextInvoker; private InvocationChain chain; @@ -70,36 +45,10 @@ public class PassByValueInterceptor implements Interceptor { * @param dataBindings databinding extension point * @param operation the intercepted operation */ - public PassByValueInterceptor(DataBindingExtensionPoint dataBindings, - FaultExceptionMapper faultExceptionMapper, - InvocationChain chain, - Operation operation) { + public PassByValueInterceptor(Mediator mediator, InvocationChain chain, Operation operation) { + this.mediator = mediator; this.chain = chain; this.operation = operation; - - // Cache data bindings to use - this.dataBindings = dataBindings; - this.faultExceptionMapper = faultExceptionMapper; - - jaxbDataBinding = dataBindings.getDataBinding(JAXBDataBinding.NAME); - javaBeanDataBinding = dataBindings.getDataBinding(JavaBeansDataBinding.NAME); - - // Determine the input databindings - if (operation.getInputType() != null) { - List<DataType> inputTypes = operation.getInputType().getLogical(); - inputDataBindings = new DataBinding[inputTypes.size()]; - int i = 0; - for (DataType inputType : inputTypes) { - String id = inputType.getDataBinding(); - inputDataBindings[i++] = dataBindings.getDataBinding(id); - } - } - - // Determine the output databinding - if (operation.getOutputType() != null) { - String id = operation.getOutputType().getDataBinding(); - outputDataBinding = dataBindings.getDataBinding(id); - } } public Message invoke(Message msg) { @@ -107,156 +56,20 @@ public class PassByValueInterceptor implements Interceptor { return nextInvoker.invoke(msg); } - msg.setBody(copy((Object[])msg.getBody(), inputDataBindings, operation.getInputType().getLogical())); + msg.setBody(mediator.copyInput(msg.getBody(), operation)); Message resultMsg = nextInvoker.invoke(msg); - if (!msg.isFault() && operation.getOutputType() != null) { - resultMsg.setBody(copy(resultMsg.getBody(), outputDataBinding, operation.getOutputType())); + if (!resultMsg.isFault() && operation.getOutputType() != null) { + resultMsg.setBody(mediator.copyOutput(resultMsg.getBody(), operation)); } - if (msg.isFault()) { - msg.setFaultBody(copyFault(msg.getBody())); + if (resultMsg.isFault()) { + resultMsg.setFaultBody(mediator.copyFault(resultMsg.getBody(), operation)); } return resultMsg; } - private Object copyFault(Object fault) { - if (faultExceptionMapper == null) { - return fault; - } - for (DataType et : operation.getFaultTypes()) { - if (et.getPhysical().isInstance(fault)) { - Throwable ex = (Throwable)fault; - DataType<DataType> exType = - new DataTypeImpl<DataType>(ex.getClass(), new DataTypeImpl<XMLType>(ex.getClass(), XMLType.UNKNOWN)); - faultExceptionMapper.introspectFaultDataType(exType, operation, false); - DataType faultType = exType.getLogical(); - Object faultInfo = faultExceptionMapper.getFaultInfo(ex, faultType.getPhysical(), operation); - faultInfo = copy(faultInfo, dataBindings.getDataBinding(faultType.getDataBinding()), faultType); - fault = faultExceptionMapper.wrapFaultInfo(exType, ex.getMessage(), faultInfo, ex.getCause(), operation); - return fault; - } - } - return fault; - } - - /** - * Copy an array of data objects passed to an operation - * @param data array of objects to copy - * @return the copy - */ - private Object[] copy(Object[] data, DataBinding[] dataBindings, List<DataType> dataTypes) { - if (data == null) { - return null; - } - Object[] copy = new Object[data.length]; - Map<Object, Object> map = new IdentityHashMap<Object, Object>(); - for (int i = 0; i < data.length; i++) { - Object arg = data[i]; - if (arg == null) { - copy[i] = null; - } else { - Object copiedArg = map.get(arg); - if (copiedArg != null) { - copy[i] = copiedArg; - } else { - copiedArg = copy(arg, dataBindings[i], dataTypes.get(i)); - map.put(arg, copiedArg); - copy[i] = copiedArg; - } - } - } - return copy; - } - - /** - * Copy data using the specified databinding. - * @param data input data - * @param dataBinding databinding to use - * @param dataType TODO - * @return a copy of the data - */ - private Object copy(Object data, DataBinding dataBinding, DataType dataType) { - if (data == null) { - return null; - } - Class<?> clazz = data.getClass(); - if (String.class == clazz || clazz.isPrimitive() - || Number.class.isAssignableFrom(clazz) - || Boolean.class.isAssignableFrom(clazz) - || Character.class.isAssignableFrom(clazz) - || Byte.class.isAssignableFrom(clazz) - || URI.class == clazz - || UUID.class == clazz - || QName.class == clazz) { - // Immutable classes - return data; - } - // If no databinding was specified, introspect the given arg to - // determine its databinding - if (dataBinding == null) { - dataType = dataBindings.introspectType(data, operation); - if (dataType != null) { - String db = dataType.getDataBinding(); - dataBinding = dataBindings.getDataBinding(db); - if (dataBinding == null && db != null) { - return data; - } - } - if (dataBinding == null) { - - // Default to the JavaBean databinding - dataBinding = javaBeanDataBinding; - } - } - - // Use the JAXB databinding to copy non-Serializable data - if (dataBinding == javaBeanDataBinding) { - - // If the input data is an array containing non Serializable elements - // use JAXB - clazz = data.getClass(); - if (clazz.isArray()) { - if (Array.getLength(data) != 0) { - Object element = Array.get(data, 0); - if (element != null && !(element instanceof Serializable)) { - dataBinding = jaxbDataBinding; - } - } - } else { - - // If the input data is not Serializable use JAXB - if (!(data instanceof Serializable)) { - dataBinding = jaxbDataBinding; - } - - if (data instanceof Cloneable) { - Method clone; - try { - clone = data.getClass().getMethod("clone", (Class[])null); - try { - return clone.invoke(data, (Object[])null); - } catch (InvocationTargetException e) { - if (e.getTargetException() instanceof CloneNotSupportedException) { - // Ignore - } else { - throw new ServiceRuntimeException(e); - } - } catch (Exception e) { - throw new ServiceRuntimeException(e); - } - } catch (NoSuchMethodException e) { - // Ignore it - } - } - } - } - - Object copy = dataBinding.copy(data, dataType, operation); - return copy; - } - public Invoker getNext() { return nextInvoker; } diff --git a/java/sca/modules/databinding/META-INF/MANIFEST.MF b/java/sca/modules/databinding/META-INF/MANIFEST.MF index d3ae3a8018..31aa48462e 100644 --- a/java/sca/modules/databinding/META-INF/MANIFEST.MF +++ b/java/sca/modules/databinding/META-INF/MANIFEST.MF @@ -46,6 +46,7 @@ Import-Package: javax.xml.datatype, javax.xml.transform.sax,
javax.xml.transform.stream,
org.apache.tuscany.sca.contribution.resolver;version="2.0.0",
+ org.apache.tuscany.sca.core;version="2.0.0",
org.apache.tuscany.sca.databinding;version="2.0.0",
org.apache.tuscany.sca.databinding.annotation;version="2.0.0",
org.apache.tuscany.sca.databinding.impl;version="2.0.0",
@@ -58,6 +59,7 @@ Import-Package: javax.xml.datatype, org.apache.tuscany.sca.interfacedef.util;version="2.0.0",
org.apache.tuscany.sca.policy;version="2.0.0",
org.apache.tuscany.sca.xsd;version="2.0.0",
+ org.oasisopen.sca;version="2.0.0",
org.w3c.dom,
org.xml.sax,
org.xml.sax.ext,
diff --git a/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java b/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java index d343fb2d46..6ebfc29121 100644 --- a/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java +++ b/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java @@ -6,15 +6,15 @@ * 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.databinding; @@ -28,6 +28,7 @@ import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.databinding.javabeans.JavaBeansDataBinding; import org.apache.tuscany.sca.databinding.javabeans.JavaExceptionDataBinding; import org.apache.tuscany.sca.extensibility.ServiceDeclaration; @@ -39,10 +40,11 @@ import org.apache.tuscany.sca.interfacedef.util.XMLType; /** * The default implementation of a data binding extension point. - * + * * @version $Rev$ $Date$ */ public class DefaultDataBindingExtensionPoint implements DataBindingExtensionPoint { + private ExtensionPointRegistry registry; private final Map<String, DataBinding> bindings = new HashMap<String, DataBinding>(); private final List<DataBinding> databindings = new ArrayList<DataBinding>(); private static final Logger logger = Logger.getLogger(DefaultDataBindingExtensionPoint.class.getName()); @@ -51,6 +53,10 @@ public class DefaultDataBindingExtensionPoint implements DataBindingExtensionPoi public DefaultDataBindingExtensionPoint() { } + public DefaultDataBindingExtensionPoint(ExtensionPointRegistry registry) { + this.registry = registry; + } + public DataBinding getDataBinding(String id) { if (id == null) { return null; @@ -121,7 +127,7 @@ public class DefaultDataBindingExtensionPoint implements DataBindingExtensionPoi * A data binding facade allowing data bindings to be lazily loaded and * initialized. */ - private static class LazyDataBinding implements DataBinding { + private class LazyDataBinding implements DataBinding { private String name; private ServiceDeclaration dataBindingDeclaration; @@ -134,7 +140,7 @@ public class DefaultDataBindingExtensionPoint implements DataBindingExtensionPoi /** * Load and instantiate the data binding class. - * + * * @return The data binding. */ @SuppressWarnings("unchecked") @@ -142,8 +148,14 @@ public class DefaultDataBindingExtensionPoint implements DataBindingExtensionPoi if (dataBinding == null) { try { Class<DataBinding> dataBindingClass = (Class<DataBinding>)dataBindingDeclaration.loadClass(); - Constructor<DataBinding> constructor = dataBindingClass.getConstructor(); - dataBinding = constructor.newInstance(); + try { + Constructor<DataBinding> constructor = dataBindingClass.getConstructor(); + dataBinding = constructor.newInstance(); + } catch (NoSuchMethodException e) { + Constructor<DataBinding> constructor = + dataBindingClass.getConstructor(ExtensionPointRegistry.class); + dataBinding = constructor.newInstance(DefaultDataBindingExtensionPoint.this.registry); + } } catch (Exception e) { throw new IllegalStateException(e); } diff --git a/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Mediator.java b/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Mediator.java index 6b8acfc7b4..8184d739a8 100644 --- a/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Mediator.java +++ b/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Mediator.java @@ -6,25 +6,26 @@ * 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.databinding; import java.util.Map; import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; /** * This interface will be used as a Tuscany system service to perform data mediations - * + * * Mediate the data from one type to the other one * * @version $Rev$ $Date$ @@ -36,10 +37,11 @@ public interface Mediator { * @param source The data to be mediated * @param sourceDataType Data type for the source data * @param targetDataType Data type for the target data - * @param context + * @param context * @return */ Object mediate(Object source, DataType sourceDataType, DataType targetDataType, Map<String, Object> context); + /** * Mediate the source data into the target which is a sink to receive the data * @param source The data to be mediated @@ -47,22 +49,105 @@ public interface Mediator { * @param sourceDataType Data type for the source data * @param targetDataType Data type for the target data */ - void mediate( - Object source, - Object target, - DataType sourceDataType, - DataType targetDataType, - Map<String, Object> context); - + void mediate(Object source, + Object target, + DataType sourceDataType, + DataType targetDataType, + Map<String, Object> context); + + /** + * Transform the input parameters for the source operation to the expected parameters for + * the target operation + * @param input The input data, typically an array of parameters + * @param sourceOperation The source operation + * @param targetOperation The target operation + * @param metadata Additional metadata + * @return The transformed input data for the target operation + */ + Object mediateInput(Object input, Operation sourceOperation, Operation targetOperation, Map<String, Object> metadata); + + /** + * Transform the return value for the target operation to the expected return value for + * the source operation + * @param output The output data, typically the return value + * @param sourceOperation The source operation + * @param targetOperation The target operation + * @param metadata Additional metadata + * @return The transformed output data for the source operation + */ + Object mediateOutput(Object output, + Operation sourceOperation, + Operation targetOperation, + Map<String, Object> metadata); + + /** + * Transform the fault data for the target operation to the expected fault data for + * the source operation + * @param fault The fault data, such as Java exception or fault message + * @param sourceOperation The source operation + * @param targetOperation The target operation + * @param metadata Additional metadata + * @return The transformed fault data for the source operation + */ + Object mediateFault(Object fault, Operation sourceOperation, Operation targetOperation, Map<String, Object> metadata); + + /** + * Copy the data + * @param data The orginal data + * @param dataType The data type + * @return The copy + */ + Object copy(Object data, DataType dataType); + + /** + * 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); + + /** + * Copy the output data + * @param data The orginal output + * @param operation The operation + * @return The copy + */ + Object copyOutput(Object data, Operation operation); + + /** + * Copy the fault data + * @param fault The orginal fault data + * @param operation The operation + * @return The copy + */ + Object copyFault(Object fault, Operation operation); + /** * Get the DataBindings used by this mediator. * @return */ DataBindingExtensionPoint getDataBindings(); - + /** * Get the Transformers used by this mediator. * @return */ - TransformerExtensionPoint getTransformers(); + TransformerExtensionPoint getTransformers(); + + /** + * Create an instance of TransformationContext + * @return + */ + TransformationContext createTransformationContext(); + + /** + * Create an instance of TransformationContext + * @param sourceDataType + * @param targetDataType + * @param metadata + * @return + */ + TransformationContext createTransformationContext(DataType sourceDataType, + DataType targetDataType, + Map<String, Object> metadata); } diff --git a/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java b/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java index b7ddf87a41..05ab381cc9 100644 --- a/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java +++ b/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java @@ -6,23 +6,38 @@ * 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.databinding.impl; +import static org.apache.tuscany.sca.databinding.DataBinding.IDL_FAULT; +import static org.apache.tuscany.sca.databinding.DataBinding.IDL_OUTPUT; + +import java.io.Serializable; +import java.lang.reflect.Array; +import java.lang.reflect.InvocationTargetException; +import java.net.URI; import java.security.AccessController; import java.security.PrivilegedAction; +import java.util.HashMap; +import java.util.IdentityHashMap; import java.util.List; import java.util.Map; +import java.util.UUID; + +import javax.xml.namespace.QName; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.databinding.DataBinding; import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; import org.apache.tuscany.sca.databinding.DataPipe; import org.apache.tuscany.sca.databinding.DataPipeTransformer; @@ -33,9 +48,15 @@ import org.apache.tuscany.sca.databinding.TransformationContext; import org.apache.tuscany.sca.databinding.TransformationException; import org.apache.tuscany.sca.databinding.Transformer; import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; +import org.apache.tuscany.sca.databinding.javabeans.JavaBeansDataBinding; import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.FaultExceptionMapper; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.FaultException; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.oasisopen.sca.ServiceRuntimeException; + /** * Default Mediator implementation @@ -43,20 +64,32 @@ import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; * @version $Rev$ $Date$ */ public class MediatorImpl implements Mediator { - + private static final String TARGET_OPERATION = "target.operation"; + private static final String SOURCE_OPERATION = "source.operation"; + private ExtensionPointRegistry registry; private DataBindingExtensionPoint dataBindings; private TransformerExtensionPoint transformers; + private FaultExceptionMapper faultExceptionMapper; - public MediatorImpl(DataBindingExtensionPoint dataBindings, TransformerExtensionPoint transformers) { + MediatorImpl(DataBindingExtensionPoint dataBindings, TransformerExtensionPoint transformers) { this.dataBindings = dataBindings; this.transformers = transformers; } + public MediatorImpl(ExtensionPointRegistry registry) { + this.registry = registry; + this.dataBindings = registry.getExtensionPoint(DataBindingExtensionPoint.class); + this.transformers = registry.getExtensionPoint(TransformerExtensionPoint.class); + this.faultExceptionMapper = + registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(FaultExceptionMapper.class); + + } + @SuppressWarnings("unchecked") public Object mediate(Object source, DataType sourceDataType, DataType targetDataType, Map<String, Object> metadata) { if (sourceDataType == null || sourceDataType.getDataBinding() == null) { if (source != null) { - Operation operation = (Operation) metadata.get("source.operation"); + Operation operation = (Operation)metadata.get(SOURCE_OPERATION); sourceDataType = dataBindings.introspectType(source, operation); } } @@ -103,7 +136,7 @@ public class MediatorImpl implements Mediator { DataType targetType = (index == size - 1) ? targetDataType : new DataTypeImpl<Object>(transformer.getTargetDataBinding(), Object.class, targetDataType.getLogical()); - + //FIXME The ClassLoader should be passed in // Allow privileged access to get ClassLoader. Requires RuntimePermission in security // policy. @@ -111,9 +144,15 @@ public class MediatorImpl implements Mediator { public ClassLoader run() { return Thread.currentThread().getContextClassLoader(); } - }); - - TransformationContext context = new TransformationContextImpl(sourceType, targetType, classLoader, metadata); + }); + + Map<String, Object> copy = new HashMap<String, Object>(); + if (metadata != null) { + copy.putAll(metadata); + } + copy.put(ExtensionPointRegistry.class.getName(), registry); + + TransformationContext context = new TransformationContextImpl(sourceType, targetType, classLoader, copy); return context; } @@ -128,7 +167,7 @@ public class MediatorImpl implements Mediator { return; } if (sourceDataType == null || sourceDataType.getDataBinding() == null) { - Operation operation = (Operation) metadata.get("source.operation"); + Operation operation = (Operation)metadata.get(SOURCE_OPERATION); sourceDataType = dataBindings.introspectType(source, operation); } if (sourceDataType == null) { @@ -179,4 +218,348 @@ public class MediatorImpl implements Mediator { return transformers; } + private DataType getFaultType(DataType exceptionType) { + return exceptionType == null ? null : (DataType)exceptionType.getLogical(); + } + + /** + * @param qn1 + * @param qn2 + */ + private boolean matches(QName qn1, QName qn2) { + if (qn1 == qn2) { + return true; + } + if (qn1 == null || qn2 == null) { + return false; + } + String ns1 = qn1.getNamespaceURI(); + String ns2 = qn2.getNamespaceURI(); + String e1 = qn1.getLocalPart(); + String e2 = qn2.getLocalPart(); + if (e1.equals(e2) && (ns1.equals(ns2) || ns1.equals(ns2 + "/") || ns2.equals(ns1 + "/"))) { + // Tolerating the trailing / which is required by JAX-WS java package --> xml ns mapping + return true; + } + return false; + } + + /** + * @param source The source exception + * @param sourceExType The data type for the source exception + * @param targetExType The data type for the target exception + * @param sourceType The fault type for the source + * @param targetType The fault type for the target + * @return + */ + private Object transformException(Object source, + DataType sourceExType, + DataType targetExType, + DataType sourceType, + DataType targetType, + Map<String, Object> metadata) { + + if (sourceType == targetType || (sourceType != null && sourceType.equals(targetType))) { + return source; + } + + DataType<DataType> eSourceDataType = + new DataTypeImpl<DataType>(IDL_FAULT, sourceExType.getPhysical(), sourceType); + DataType<DataType> eTargetDataType = + new DataTypeImpl<DataType>(IDL_FAULT, targetExType.getPhysical(), targetType); + + return mediate(source, eSourceDataType, eTargetDataType, metadata); + } + + // + // Assumes we're going from target->source, knowing that we're throwing BACK an exception, rather than the more + // obvious source->target + // + public Object mediateFault(Object result, + Operation sourceOperation, + Operation targetOperation, + Map<String, Object> metadata) { + + // FIXME: How to match fault data to a fault type for the + // operation? + + // If the result is from an InvocationTargetException look at + // the actual cause. + if (result instanceof InvocationTargetException) { + result = ((InvocationTargetException)result).getCause(); + } + DataType targetDataType = null; + for (DataType exType : targetOperation.getFaultTypes()) { + if (((Class)exType.getPhysical()).isInstance(result)) { + if (result instanceof FaultException) { + DataType faultType = (DataType)exType.getLogical(); + if (((FaultException)result).isMatchingType(faultType.getLogical())) { + targetDataType = exType; + break; + } + } else { + targetDataType = exType; + break; + } + } + } + + /* + if (targetDataType == null) { + // Not a business exception + return resultMsg; + } + */ + + DataType targetFaultType = getFaultType(targetDataType); + if (targetFaultType == null) { + // No matching fault type, it's a system exception + Throwable cause = (Throwable)result; + throw new ServiceRuntimeException(cause); + } + + // FIXME: How to match a source fault type to a target fault + // type? + DataType sourceDataType = null; + DataType sourceFaultType = null; + for (DataType exType : sourceOperation.getFaultTypes()) { + DataType faultType = getFaultType(exType); + // Match by the QName (XSD element) of the fault type + if (faultType != null && typesMatch(targetFaultType.getLogical(), faultType.getLogical())) { + sourceDataType = exType; + sourceFaultType = faultType; + break; + } + } + + if (sourceFaultType == null) { + // No matching fault type, it's a system exception + Throwable cause = (Throwable)result; + throw new ServiceRuntimeException(cause); + } + + Object newResult = + transformException(result, targetDataType, sourceDataType, targetFaultType, sourceFaultType, metadata); + + return newResult; + + } + + private boolean typesMatch(Object first, Object second) { + if (first.equals(second)) { + return true; + } + if (first instanceof XMLType && second instanceof XMLType) { + XMLType t1 = (XMLType)first; + XMLType t2 = (XMLType)second; + // TUSCANY-2113, we should compare element names only + return matches(t1.getElementName(), t2.getElementName()); + } + return false; + } + + /** + * @param output + * @param sourceOperation + * @param targetOperation + * @return + */ + public Object mediateOutput(Object output, + Operation sourceOperation, + Operation targetOperation, + Map<String, Object> metadata) { + // Create a data type to represent the ouput produced by the target operation + DataType<DataType> targetType = + new DataTypeImpl<DataType>(IDL_OUTPUT, Object.class, targetOperation.getOutputType()); + + // Create a data type to represent the ouput expected by the source operation + DataType<DataType> sourceType = + new DataTypeImpl<DataType>(IDL_OUTPUT, Object.class, sourceOperation.getOutputType()); + + if (sourceType == targetType || (sourceType != null && sourceType.equals(targetType))) { + return output; + } + Map<String, Object> context = new HashMap<String, Object>(); + if (metadata != null) { + context.putAll(metadata); + } + if (targetOperation != null) { + context.put(SOURCE_OPERATION, targetOperation); + } + if (sourceOperation != null) { + context.put(TARGET_OPERATION, sourceOperation); + } + return mediate(output, targetType, sourceType, context); + } + + public Object mediateInput(Object input, + Operation sourceOperation, + Operation targetOperation, + Map<String, Object> metadata) { + // Get the data type to represent the input passed in by the source operation + DataType sourceType = sourceOperation.getInputType(); + + // Get the data type to represent the input expected by the target operation + DataType targetType = targetOperation.getInputType(); + + if (sourceType == targetType || (sourceType != null && sourceType.equals(targetType))) { + return input; + } + Map<String, Object> context = new HashMap<String, Object>(); + if (metadata != null) { + context.putAll(metadata); + } + if (sourceOperation != null) { + context.put(SOURCE_OPERATION, sourceOperation); + } + if (targetOperation != null) { + context.put(TARGET_OPERATION, targetOperation); + } + return mediate(input, sourceType, targetType, context); + } + + public TransformationContext createTransformationContext() { + return new TransformationContextImpl(); + } + + public TransformationContext createTransformationContext(DataType sourceDataType, + DataType targetDataType, + Map<String, Object> metadata) { + return new TransformationContextImpl(sourceDataType, targetDataType, metadata); + } + + public Object copy(Object data, DataType dataType) { + return copy(data, dataType, null); + } + + /** + * Copy data using the specified databinding. + * @param data input data + * @param dataType + * @return a copy of the data + */ + private Object copy(Object data, DataType dataType, Operation operation) { + if (data == null) { + return null; + } + Class<?> clazz = data.getClass(); + if (String.class == clazz || clazz.isPrimitive() + || Number.class.isAssignableFrom(clazz) + || Boolean.class.isAssignableFrom(clazz) + || Character.class.isAssignableFrom(clazz) + || Byte.class.isAssignableFrom(clazz) + || URI.class == clazz + || UUID.class == clazz + || QName.class == clazz) { + // Immutable classes + return data; + } + + DataBinding javaBeansDataBinding = dataBindings.getDataBinding(JavaBeansDataBinding.NAME); + // FIXME: The JAXB databinding is hard-coded here + DataBinding jaxbDataBinding = dataBindings.getDataBinding("javax.xml.bind.JAXBElement"); + DataBinding dataBinding = dataBindings.getDataBinding(dataType.getDataBinding()); + // If no databinding was specified, introspect the given arg to + // determine its databinding + if (dataBinding == null) { + dataType = dataBindings.introspectType(data, operation); + if (dataType != null) { + String db = dataType.getDataBinding(); + dataBinding = dataBindings.getDataBinding(db); + if (dataBinding == null && db != null) { + return data; + } + } + if (dataBinding == null) { + + // Default to the JavaBean databinding + dataBinding = dataBindings.getDataBinding(JavaBeansDataBinding.NAME); + } + } + + // Use the JAXB databinding to copy non-Serializable data + if (dataBinding == javaBeansDataBinding) { + + // If the input data is an array containing non Serializable elements + // use JAXB + clazz = data.getClass(); + if (clazz.isArray()) { + if (Array.getLength(data) != 0) { + Object element = Array.get(data, 0); + if (element != null && !(element instanceof Serializable)) { + dataBinding = jaxbDataBinding; + } + } + } else { + + // If the input data is not Serializable use JAXB + if (!((data instanceof Serializable) || (data instanceof Cloneable))) { + dataBinding = jaxbDataBinding; + } + } + } + + if (dataBinding != null) { + return dataBinding.copy(data, dataType, operation); + } else { + return data; + } + } + + /** + * 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) { + if (input == null) { + return null; + } + Object[] data = (input instanceof Object[]) ? (Object[])input : new Object[] {input}; + List<DataType> inputTypes = operation.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++) { + Object arg = data[i]; + if (arg == null) { + copy[i] = null; + } else { + Object copiedArg = map.get(arg); + if (copiedArg != null) { + copy[i] = copiedArg; + } else { + copiedArg = copy(arg, inputTypes.get(i)); + map.put(arg, copiedArg); + copy[i] = copiedArg; + } + } + } + return copy; + } + + public Object copyOutput(Object data, Operation operation) { + return copy(data, operation.getOutputType(), operation); + } + + public Object copyFault(Object fault, Operation operation) { + if (faultExceptionMapper == null) { + return fault; + } + for (DataType et : operation.getFaultTypes()) { + if (et.getPhysical().isInstance(fault)) { + Throwable ex = (Throwable)fault; + DataType<DataType> exType = + new DataTypeImpl<DataType>(ex.getClass(), new DataTypeImpl<XMLType>(ex.getClass(), XMLType.UNKNOWN)); + 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); + return fault; + } + } + return fault; + } + } diff --git a/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/TransformationContextImpl.java b/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/TransformationContextImpl.java index a6c0639411..a5b8e0a0bd 100644 --- a/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/TransformationContextImpl.java +++ b/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/TransformationContextImpl.java @@ -6,15 +6,15 @@ * 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.databinding.impl; @@ -27,6 +27,10 @@ import org.apache.tuscany.sca.interfacedef.DataType; import org.apache.tuscany.sca.interfacedef.Operation; public class TransformationContextImpl implements TransformationContext { + private static final String SOURCE_OPERATION = "source.operation"; + + private static final String TARGET_OPERATION = "target.operation"; + private DataType sourceDataType; private DataType targetDataType; @@ -54,6 +58,18 @@ public class TransformationContextImpl implements TransformationContext { } } + public TransformationContextImpl(DataType sourceDataType, + DataType targetDataType, + Map<String, Object> metadata) { + super(); + this.sourceDataType = sourceDataType; + this.targetDataType = targetDataType; + setClassLoader(Thread.currentThread().getContextClassLoader()); + if (metadata != null) { + this.metadata.putAll(metadata); + } + } + public DataType getSourceDataType() { return sourceDataType; } @@ -86,28 +102,28 @@ public class TransformationContextImpl implements TransformationContext { * @return the sourceOperation */ public Operation getSourceOperation() { - return (Operation) metadata.get("source.operation"); + return (Operation) metadata.get(SOURCE_OPERATION); } /** * @param sourceOperation the sourceOperation to set */ public void setSourceOperation(Operation sourceOperation) { - this.metadata.put("source.operation", sourceOperation); + this.metadata.put(SOURCE_OPERATION, sourceOperation); } /** * @return the targetOperation */ public Operation getTargetOperation() { - return (Operation) metadata.get("target.operation"); + return (Operation) metadata.get(TARGET_OPERATION); } /** * @param targetOperation the targetOperation to set */ public void setTargetOperation(Operation targetOperation) { - this.metadata.put("target.operation", targetOperation); + this.metadata.put(TARGET_OPERATION, targetOperation); } } diff --git a/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java b/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java index c7d21ebc66..2234aa07c2 100644 --- a/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java +++ b/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java @@ -6,15 +6,15 @@ * 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.databinding.javabeans;
@@ -28,6 +28,9 @@ import java.io.ObjectOutputStream; import java.io.ObjectStreamClass;
import java.io.OutputStream;
import java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.logging.Logger;
import org.apache.tuscany.sca.databinding.impl.BaseDataBinding;
import org.apache.tuscany.sca.interfacedef.DataType;
@@ -39,6 +42,7 @@ import org.apache.tuscany.sca.interfacedef.Operation; * @version $Rev$ $Date$
*/
public class JavaBeansDataBinding extends BaseDataBinding {
+ private final static Logger logger = Logger.getLogger(JavaBeansDataBinding.class.getName());
/**
* Defining a weight to a very high number so that the transformer won't be picked
* up by other paths unless it's the only available path
@@ -53,7 +57,7 @@ public class JavaBeansDataBinding extends BaseDataBinding { protected JavaBeansDataBinding(String name, Class<?> baseType) {
super(name, baseType);
}
-
+
@Override
public Object copy(Object arg, DataType dataType, Operation operation) {
if (arg == null) {
@@ -82,7 +86,7 @@ public class JavaBeansDataBinding extends BaseDataBinding { // * 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();
if (classLoaderToUse == null)
{
@@ -90,20 +94,39 @@ public class JavaBeansDataBinding extends BaseDataBinding { // instead
classLoaderToUse = Thread.currentThread().getContextClassLoader();
}
-
+
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
ObjectInputStream ois = getObjectInputStream(bis, classLoaderToUse);
Object objectCopy = ois.readObject();
ois.close();
bis.close();
return objectCopy;
- } else {
- // return arg;
- throw new IllegalArgumentException("Argument type '" + arg.getClass().getCanonicalName() + "' is not Serializable. " +
- " Pass-by-value cannot be performed on this argument");
+ } else if (arg instanceof Cloneable) {
+ Method clone;
+ try {
+ clone = arg.getClass().getMethod("clone");
+ try {
+ return clone.invoke(arg, (Object[])null);
+ } catch (InvocationTargetException e) {
+ if (e.getTargetException() instanceof CloneNotSupportedException) {
+ // Ignore
+ } else {
+ throw new IllegalArgumentException(e);
+ }
+ } catch (Exception e) {
+ throw new IllegalArgumentException(e);
+ }
+ } catch (NoSuchMethodException e) {
+ // Ignore it
+ }
}
- } catch (Exception e) {
- throw new IllegalArgumentException("Pass-by-value is not supported for the given object", e);
+ // return arg;
+ logger.warning("Argument type '" + arg.getClass().getName()
+ + "' is not Serializable or Cloneable. Pass-by-value is skipped.");
+ return arg;
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Pass-by-value is not supported for the given object: " + arg.getClass()
+ .getName(), e);
}
}
@@ -135,5 +158,5 @@ public class JavaBeansDataBinding extends BaseDataBinding { };
return ois;
}
-
+
}
diff --git a/java/sca/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.Mediator b/java/sca/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.Mediator new file mode 100644 index 0000000000..e01e121aa5 --- /dev/null +++ b/java/sca/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.Mediator @@ -0,0 +1,17 @@ +# 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.
+org.apache.tuscany.sca.databinding.impl.MediatorImpl
\ No newline at end of file diff --git a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java b/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java index 885004b09b..57d6d199ea 100644 --- a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java +++ b/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java @@ -6,15 +6,15 @@ * 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.injection;
@@ -260,7 +260,7 @@ public class JavaPropertyValueObjectFactory implements PropertyValueFactory { */
/**
- *
+ *
* @param property
* @return
*/
diff --git a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java b/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java index 0044c0f196..141d991d27 100644 --- a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java +++ b/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java @@ -6,15 +6,15 @@ * 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; @@ -37,6 +37,7 @@ import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.assembly.Multiplicity; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.context.ComponentContextFactory; +import org.apache.tuscany.sca.context.PropertyValueFactory; import org.apache.tuscany.sca.context.RequestContextFactory; import org.apache.tuscany.sca.core.factory.InstanceWrapper; import org.apache.tuscany.sca.core.factory.ObjectCreationException; @@ -67,7 +68,7 @@ import org.oasisopen.sca.annotation.ConversationID; /** * The runtime instantiation of Java component implementations - * + * * @version $Rev$ $Date$ */ public class JavaComponentContextProvider { @@ -79,7 +80,7 @@ public class JavaComponentContextProvider { public JavaComponentContextProvider(RuntimeComponent component, JavaInstanceFactoryProvider configuration, DataBindingExtensionPoint dataBindingExtensionPoint, - JavaPropertyValueObjectFactory propertyValueObjectFactory, + PropertyValueFactory propertyValueObjectFactory, ComponentContextFactory componentContextFactory, RequestContextFactory requestContextFactory) { super(); @@ -91,7 +92,7 @@ public class JavaComponentContextProvider { // this.componentContext = new ComponentContextImpl(this, requestContextFactory, this.proxyService); // } this.component = component; - this.propertyValueFactory = propertyValueObjectFactory; + this.propertyValueFactory = (JavaPropertyValueObjectFactory) propertyValueObjectFactory; } InstanceWrapper<?> createInstanceWrapper() throws ObjectCreationException { @@ -129,7 +130,7 @@ public class JavaComponentContextProvider { ObjectFactory<?> propertyObjectFactory = createPropertyValueFactory(configuredProperty, configuredProperty.getValue(), element); instanceFactoryProvider.setObjectFactory(element, propertyObjectFactory); - + JavaConstructorImpl<?> constructor = instanceFactoryProvider.getImplementation().getConstructor(); for(JavaElementImpl p: constructor.getParameters()){ if(element.getName().equals(p.getName())) { diff --git a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProvider.java b/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProvider.java index 0b560e8c88..9f716c8059 100644 --- a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProvider.java +++ b/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProvider.java @@ -6,15 +6,15 @@ * 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; @@ -23,6 +23,7 @@ import java.lang.reflect.Method; import org.apache.tuscany.sca.assembly.Service; import org.apache.tuscany.sca.context.ComponentContextFactory; +import org.apache.tuscany.sca.context.PropertyValueFactory; import org.apache.tuscany.sca.context.RequestContextFactory; import org.apache.tuscany.sca.core.factory.InstanceWrapper; import org.apache.tuscany.sca.core.factory.ObjectFactory; @@ -32,7 +33,6 @@ import org.apache.tuscany.sca.core.scope.ScopedImplementationProvider; import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; import org.apache.tuscany.sca.implementation.java.JavaImplementation; import org.apache.tuscany.sca.implementation.java.JavaResourceImpl; -import org.apache.tuscany.sca.implementation.java.injection.JavaPropertyValueObjectFactory; import org.apache.tuscany.sca.implementation.java.injection.RequestContextObjectFactory; import org.apache.tuscany.sca.implementation.java.injection.ResourceHost; import org.apache.tuscany.sca.implementation.java.injection.ResourceObjectFactory; @@ -53,27 +53,27 @@ public class JavaImplementationProvider implements ScopedImplementationProvider private JavaImplementation implementation; private JavaComponentContextProvider componentContextProvider; private RequestContextFactory requestContextFactory; - + public JavaImplementationProvider(RuntimeComponent component, JavaImplementation implementation, ProxyFactory proxyService, DataBindingExtensionPoint dataBindingRegistry, - JavaPropertyValueObjectFactory propertyValueObjectFactory, + PropertyValueFactory propertyValueObjectFactory, ComponentContextFactory componentContextFactory, RequestContextFactory requestContextFactory) { super(); this.implementation = implementation; this.requestContextFactory = requestContextFactory; - + try { JavaInstanceFactoryProvider configuration = new JavaInstanceFactoryProvider(implementation); configuration.setProxyFactory(proxyService); componentContextProvider = - new JavaComponentContextProvider(component, - configuration, + new JavaComponentContextProvider(component, + configuration, dataBindingRegistry, propertyValueObjectFactory, - componentContextFactory, + componentContextFactory, requestContextFactory); Scope scope = getScope(); @@ -106,9 +106,9 @@ public class JavaImplementationProvider implements ScopedImplementationProvider } catch (Exception e) { throw new IllegalStateException(e); } - + } - + private void handleResources(JavaImplementation componentType, ProxyFactory proxyService) { for (JavaResourceImpl resource : componentType.getResources().values()) { String name = resource.getName(); @@ -165,7 +165,7 @@ public class JavaImplementationProvider implements ScopedImplementationProvider } } } - + public boolean supportsOneWayInvocation() { return false; } diff --git a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProviderFactory.java b/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProviderFactory.java index 77e0e44065..326ab28bc9 100644 --- a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProviderFactory.java +++ b/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProviderFactory.java @@ -6,25 +6,25 @@ * 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 org.apache.tuscany.sca.context.ComponentContextFactory; +import org.apache.tuscany.sca.context.PropertyValueFactory; import org.apache.tuscany.sca.context.RequestContextFactory; import org.apache.tuscany.sca.core.invocation.ProxyFactory; import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; import org.apache.tuscany.sca.implementation.java.JavaImplementation; -import org.apache.tuscany.sca.implementation.java.injection.JavaPropertyValueObjectFactory; import org.apache.tuscany.sca.provider.ImplementationProvider; import org.apache.tuscany.sca.provider.ImplementationProviderFactory; import org.apache.tuscany.sca.runtime.RuntimeComponent; @@ -33,7 +33,7 @@ import org.apache.tuscany.sca.runtime.RuntimeComponent; * @version $Rev$ $Date$ */ public class JavaImplementationProviderFactory implements ImplementationProviderFactory<JavaImplementation> { - private JavaPropertyValueObjectFactory propertyValueObjectFactory; + private PropertyValueFactory propertyValueObjectFactory; private DataBindingExtensionPoint dataBindingRegistry; private ProxyFactory proxyService; private ComponentContextFactory componentContextFactory; @@ -41,7 +41,7 @@ public class JavaImplementationProviderFactory implements ImplementationProvider public JavaImplementationProviderFactory(ProxyFactory proxyService, DataBindingExtensionPoint dataBindingRegistry, - JavaPropertyValueObjectFactory propertyValueObjectFactory, + PropertyValueFactory propertyValueObjectFactory, ComponentContextFactory componentContextFactory, RequestContextFactory requestContextFactory) { super(); @@ -54,12 +54,12 @@ public class JavaImplementationProviderFactory implements ImplementationProvider public ImplementationProvider createImplementationProvider(RuntimeComponent component, JavaImplementation implementation) { - return new JavaImplementationProvider(component, - implementation, - proxyService, + return new JavaImplementationProvider(component, + implementation, + proxyService, dataBindingRegistry, - propertyValueObjectFactory, - componentContextFactory, + propertyValueObjectFactory, + componentContextFactory, requestContextFactory); } diff --git a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/module/JavaRuntimeModuleActivator.java b/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/module/JavaRuntimeModuleActivator.java index b3a3210285..e1e8b05ab8 100644 --- a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/module/JavaRuntimeModuleActivator.java +++ b/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/module/JavaRuntimeModuleActivator.java @@ -6,15 +6,15 @@ * 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.module; @@ -23,6 +23,7 @@ import java.util.logging.Logger; import org.apache.tuscany.sca.context.ComponentContextFactory; import org.apache.tuscany.sca.context.ContextFactoryExtensionPoint; +import org.apache.tuscany.sca.context.PropertyValueFactory; import org.apache.tuscany.sca.context.RequestContextFactory; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; @@ -33,9 +34,7 @@ import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory; import org.apache.tuscany.sca.core.invocation.ProxyFactory; import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint; import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; -import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; -import org.apache.tuscany.sca.databinding.impl.MediatorImpl; -import org.apache.tuscany.sca.implementation.java.injection.JavaPropertyValueObjectFactory; +import org.apache.tuscany.sca.databinding.Mediator; 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; @@ -58,7 +57,7 @@ public class JavaRuntimeModuleActivator implements ModuleActivator { FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class); MessageFactory messageFactory = factories.getFactory(MessageFactory.class); - + UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); InterfaceContractMapper interfaceContractMapper = utilities.getUtility(InterfaceContractMapper.class); @@ -72,10 +71,8 @@ public class JavaRuntimeModuleActivator implements ModuleActivator { JavaInterfaceFactory javaFactory = factories.getFactory(JavaInterfaceFactory.class); DataBindingExtensionPoint dataBindings = registry.getExtensionPoint(DataBindingExtensionPoint.class); - TransformerExtensionPoint transformers = registry.getExtensionPoint(TransformerExtensionPoint.class); - MediatorImpl mediator = new MediatorImpl(dataBindings, transformers); - utilities.addUtility(mediator); - JavaPropertyValueObjectFactory factory = new JavaPropertyValueObjectFactory(mediator); + Mediator mediator = utilities.getUtility(Mediator.class); + PropertyValueFactory factory = utilities.getUtility(PropertyValueFactory.class); factories.addFactory(factory); ContextFactoryExtensionPoint contextFactories = registry.getExtensionPoint(ContextFactoryExtensionPoint.class); @@ -83,7 +80,7 @@ public class JavaRuntimeModuleActivator implements ModuleActivator { RequestContextFactory requestContextFactory = contextFactories.getFactory(RequestContextFactory.class); ProxyFactory proxyFactory = new ExtensibleProxyFactory(proxyFactories); - + JavaImplementationProviderFactory javaImplementationProviderFactory = new JavaImplementationProviderFactory(proxyFactory, dataBindings, factory, componentContextFactory, requestContextFactory); diff --git a/java/sca/modules/implementation-java-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.context.PropertyValueFactory b/java/sca/modules/implementation-java-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.context.PropertyValueFactory new file mode 100644 index 0000000000..f2feb6156a --- /dev/null +++ b/java/sca/modules/implementation-java-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.context.PropertyValueFactory @@ -0,0 +1,17 @@ +# 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.
+org.apache.tuscany.sca.implementation.java.injection.JavaPropertyValueObjectFactory
\ No newline at end of file |