From 6fadbc9cd1fcf03d0b3630f772d91df149b70428 Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 11 Nov 2009 23:07:19 +0000 Subject: Moving 1.x branches git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835123 13f79535-47bb-0310-9956-ffa450edef68 --- .../module/DataBindingModuleActivator.java | 76 ------ .../DataBindingJavaInterfaceProcessor.java | 185 --------------- .../Exception2ExceptionTransformer.java | 127 ---------- .../transformers/Input2InputTransformer.java | 214 ----------------- .../transformers/Output2OutputTransformer.java | 206 ----------------- .../wire/DataBindingRuntimeWireProcessor.java | 220 ------------------ .../wire/DataTransformationInterceptor.java | 255 --------------------- .../databinding/wire/PassByValueInterceptor.java | 113 --------- 8 files changed, 1396 deletions(-) delete mode 100644 branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java delete mode 100644 branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java delete mode 100644 branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Exception2ExceptionTransformer.java delete mode 100644 branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Input2InputTransformer.java delete mode 100644 branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java delete mode 100644 branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java delete mode 100644 branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java delete mode 100644 branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/PassByValueInterceptor.java (limited to 'branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany') diff --git a/branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java b/branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java deleted file mode 100644 index aaa333c336..0000000000 --- a/branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.core.databinding.module; - -import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.ModuleActivator; -import org.apache.tuscany.sca.core.databinding.processor.DataBindingJavaInterfaceProcessor; -import org.apache.tuscany.sca.core.databinding.transformers.Exception2ExceptionTransformer; -import org.apache.tuscany.sca.core.databinding.transformers.Input2InputTransformer; -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.TransformerExtensionPoint; -import org.apache.tuscany.sca.databinding.impl.Group2GroupTransformer; -import org.apache.tuscany.sca.databinding.impl.MediatorImpl; -import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; -import org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint; - -/** - * @version $Rev$ $Date$ - */ -public class DataBindingModuleActivator implements ModuleActivator { - - public void start(ExtensionPointRegistry registry) { - DataBindingExtensionPoint dataBindings = registry.getExtensionPoint(DataBindingExtensionPoint.class); - TransformerExtensionPoint transformers = registry.getExtensionPoint(TransformerExtensionPoint.class); - - MediatorImpl mediator = new MediatorImpl(dataBindings, transformers); - Input2InputTransformer input2InputTransformer = new Input2InputTransformer(); - input2InputTransformer.setMediator(mediator); - transformers.addTransformer(input2InputTransformer); - - Output2OutputTransformer output2OutputTransformer = new Output2OutputTransformer(); - output2OutputTransformer.setMediator(mediator); - transformers.addTransformer(output2OutputTransformer); - - Exception2ExceptionTransformer exception2ExceptionTransformer = new Exception2ExceptionTransformer(); - exception2ExceptionTransformer.setMediator(mediator); - transformers.addTransformer(exception2ExceptionTransformer); - - Group2GroupTransformer group2GroupTransformer = new Group2GroupTransformer(); - group2GroupTransformer.setMediator(mediator); - transformers.addTransformer(group2GroupTransformer); - - ModelFactoryExtensionPoint modelFactories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class); - JavaInterfaceFactory javaFactory = modelFactories.getFactory(JavaInterfaceFactory.class); - javaFactory.addInterfaceVisitor(new DataBindingJavaInterfaceProcessor(dataBindings)); - - RuntimeWireProcessorExtensionPoint wireProcessorExtensionPoint = registry.getExtensionPoint(RuntimeWireProcessorExtensionPoint.class); - if (wireProcessorExtensionPoint != null) { - wireProcessorExtensionPoint.addWireProcessor(new DataBindingRuntimeWireProcessor(mediator, dataBindings)); - } - - } - - public void stop(ExtensionPointRegistry registry) { - } -} diff --git a/branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java b/branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java deleted file mode 100644 index d7f489ee75..0000000000 --- a/branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.core.databinding.processor; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; -import org.apache.tuscany.sca.databinding.annotation.DataBinding; -import org.apache.tuscany.sca.databinding.javabeans.JavaBeansDataBinding; -import org.apache.tuscany.sca.databinding.javabeans.SimpleJavaDataBinding; -import org.apache.tuscany.sca.interfacedef.DataType; -import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; -import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.interfacedef.java.JavaInterface; -import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor; -import org.osoa.sca.annotations.Reference; - -/** - * The databinding annotation processor for java interfaces - * - * @version $Rev$ $Date$ - */ -public class DataBindingJavaInterfaceProcessor implements JavaInterfaceVisitor { - private DataBindingExtensionPoint dataBindingRegistry; - - public DataBindingJavaInterfaceProcessor(@Reference - DataBindingExtensionPoint dataBindingRegistry) { - super(); - this.dataBindingRegistry = dataBindingRegistry; - } - - public void visitInterface(JavaInterface javaInterface) throws InvalidInterfaceException { - if (!javaInterface.isRemotable()) { - return; - } - List operations = javaInterface.getOperations(); - processInterface(javaInterface, operations); - } - - private void processInterface(JavaInterface javaInterface, List operations) { - Class clazz = javaInterface.getJavaClass(); - DataBinding dataBinding = clazz.getAnnotation(DataBinding.class); - String dataBindingId = null; - boolean wrapperStyle = false; - if (dataBinding != null) { - dataBindingId = dataBinding.value(); - wrapperStyle = dataBinding.wrapped(); - } - - Map opMap = new HashMap(); - for (Operation op : javaInterface.getOperations()) { - opMap.put(op.getName(), op); - if (dataBindingId != null) { - op.setDataBinding(dataBindingId); - op.setWrapperStyle(wrapperStyle); - } - } - for (Method method : clazz.getMethods()) { - Operation operation = opMap.get(method.getName()); - DataBinding methodDataBinding = clazz.getAnnotation(DataBinding.class); - if (methodDataBinding == null) { - methodDataBinding = dataBinding; - } - dataBindingId = null; - wrapperStyle = false; - if (dataBinding != null) { - dataBindingId = dataBinding.value(); - wrapperStyle = dataBinding.wrapped(); - operation.setDataBinding(dataBindingId); - operation.setWrapperStyle(wrapperStyle); - } - - // FIXME: We need a better way to identify simple java types - int i = 0; - for (org.apache.tuscany.sca.interfacedef.DataType d : operation.getInputType().getLogical()) { - if (d.getDataBinding() == null) { - d.setDataBinding(dataBindingId); - } - for (Annotation a : method.getParameterAnnotations()[i]) { - if (a.annotationType() == org.apache.tuscany.sca.databinding.annotation.DataType.class) { - String value = ((org.apache.tuscany.sca.databinding.annotation.DataType)a).value(); - d.setDataBinding(value); - } - } - dataBindingRegistry.introspectType(d, method.getParameterAnnotations()[i]); - i++; - } - if (operation.getOutputType() != null) { - DataType d = operation.getOutputType(); - if (d.getDataBinding() == null) { - d.setDataBinding(dataBindingId); - } - org.apache.tuscany.sca.databinding.annotation.DataType dt = - method.getAnnotation(org.apache.tuscany.sca.databinding.annotation.DataType.class); - if (dt != null) { - d.setDataBinding(dt.value()); - } - dataBindingRegistry.introspectType(d, method.getAnnotations()); - } - for (org.apache.tuscany.sca.interfacedef.DataType d : operation.getFaultTypes()) { - if (d.getDataBinding() == null) { - d.setDataBinding(dataBindingId); - } - // TODO: Handle exceptions - dataBindingRegistry.introspectType(d, method.getAnnotations(), true); - } - - // JIRA: TUSCANY-842 - if (operation.getDataBinding() == null) { - assignOperationDataBinding(operation); - } - - // FIXME: Do we want to heuristically check the wrapper style? - // introspectWrapperStyle(operation); - } - } - - /* - * Assigns an operation DB if one of the input types, output type, fault types has a non-default DB. - * However, if two of the input types, output type, fault types have two different non-default DBs - * ( e.g. SDO and JAXB), then we do nothing to the operation DB. - * - * The method logic assumes the JavaBeans DataBinding is the default - */ - private void assignOperationDataBinding(Operation operation) { - - String nonDefaultDataBindingName = null; - - // Can't use DataType since operation.getInputType() returns: DataType> - List opDataTypes = new LinkedList(); - - opDataTypes.addAll(operation.getInputType().getLogical()); - opDataTypes.add(operation.getOutputType()); - opDataTypes.addAll(operation.getFaultTypes()); - - for (DataType d : opDataTypes) { - if (d != null) { - String dataBinding = d.getDataBinding(); - // Assumes JavaBeans DB is default - if (dataBinding != null && !dataBinding.equals(JavaBeansDataBinding.NAME) - && !dataBinding.equals(SimpleJavaDataBinding.NAME)) { - if (nonDefaultDataBindingName != null) { - if (!nonDefaultDataBindingName.equals(dataBinding)) { - // We've seen two different non-default DBs, e.g. SDO and JAXB - // so unset the string and break out of the loop - nonDefaultDataBindingName = null; - break; - } else { - continue; - } - } else { - nonDefaultDataBindingName = dataBinding; - } - } - } - } - - // We have a DB worthy of promoting to operation level. - if (nonDefaultDataBindingName != null) { - operation.setDataBinding(nonDefaultDataBindingName); - } - } -} diff --git a/branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Exception2ExceptionTransformer.java b/branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Exception2ExceptionTransformer.java deleted file mode 100644 index cd71869154..0000000000 --- a/branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Exception2ExceptionTransformer.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.core.databinding.transformers; - -import org.apache.tuscany.sca.databinding.DataBinding; -import org.apache.tuscany.sca.databinding.ExceptionHandler; -import org.apache.tuscany.sca.databinding.Mediator; -import org.apache.tuscany.sca.databinding.PullTransformer; -import org.apache.tuscany.sca.databinding.TransformationContext; -import org.apache.tuscany.sca.databinding.Transformer; -import org.apache.tuscany.sca.databinding.impl.BaseTransformer; -import org.apache.tuscany.sca.interfacedef.DataType; -import org.osoa.sca.annotations.Reference; -import org.osoa.sca.annotations.Service; - -/** - * This is a special transformer to transform the exception from one IDL to the - * other one - */ -@Service(Transformer.class) -public class Exception2ExceptionTransformer extends BaseTransformer implements - PullTransformer { - - protected Mediator mediator; - - public Exception2ExceptionTransformer() { - super(); - } - - @Override - public String getSourceDataBinding() { - return DataBinding.IDL_FAULT; - } - - @Override - public String getTargetDataBinding() { - return DataBinding.IDL_FAULT; - } - - /** - * @param mediator the mediator to set - */ - @Reference - public void setMediator(Mediator mediator) { - this.mediator = mediator; - } - - /** - * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getSourceType() - */ - @Override - protected Class getSourceType() { - return Exception.class; - } - - /** - * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getTargetType() - */ - @Override - protected Class getTargetType() { - return Exception.class; - } - - /** - * @see org.apache.tuscany.sca.databinding.Transformer#getWeight() - */ - @Override - public int getWeight() { - return 10000; - } - - @SuppressWarnings("unchecked") - public Exception transform(Exception source, TransformationContext context) { - DataType sourceType = context.getSourceDataType(); - - DataType targetType = context.getTargetDataType(); - - ExceptionHandler exceptionHandler = getExceptionHandler(sourceType); - if (exceptionHandler == null) { - return source; - } - - Object sourceFaultInfo = exceptionHandler.getFaultInfo(source); - Object targetFaultInfo = - mediator.mediate(sourceFaultInfo, sourceType.getLogical(), targetType.getLogical(), context.getMetadata()); - - ExceptionHandler targetHandler = getExceptionHandler(targetType); - - if (targetHandler != null) { - Exception targetException = - targetHandler.createException(targetType, source.getMessage(), targetFaultInfo, source.getCause()); - return targetException; - } - - // FIXME - return source; - - } - - private ExceptionHandler getExceptionHandler(DataType targetType) { - DataType targetFaultType = (DataType)targetType.getLogical(); - DataBinding targetDataBinding = - mediator.getDataBindings().getDataBinding(targetFaultType.getDataBinding()); - if (targetDataBinding == null) { - return null; - } - ExceptionHandler targetHandler = targetDataBinding.getExceptionHandler(); - return targetHandler; - } -} diff --git a/branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Input2InputTransformer.java b/branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Input2InputTransformer.java deleted file mode 100644 index e71c504ff5..0000000000 --- a/branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Input2InputTransformer.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.core.databinding.transformers; - -import java.util.List; -import java.util.logging.Logger; - -import org.apache.tuscany.sca.databinding.DataBinding; -import org.apache.tuscany.sca.databinding.Mediator; -import org.apache.tuscany.sca.databinding.PullTransformer; -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.WrapperHandler; -import org.apache.tuscany.sca.databinding.impl.BaseTransformer; -import org.apache.tuscany.sca.interfacedef.DataType; -import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.interfacedef.util.ElementInfo; -import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; -import org.apache.tuscany.sca.interfacedef.util.XMLType; -import org.osoa.sca.annotations.Reference; -import org.osoa.sca.annotations.Service; - -/** - * This is a special transformer to transform the input from one IDL to the - * other one - */ -@Service(Transformer.class) -public class Input2InputTransformer extends BaseTransformer implements - PullTransformer { - private static final Logger logger = Logger.getLogger(Input2InputTransformer.class.getName()); - - protected Mediator mediator; - - public Input2InputTransformer() { - super(); - } - - @Override - public String getSourceDataBinding() { - return DataBinding.IDL_INPUT; - } - - @Override - public String getTargetDataBinding() { - return DataBinding.IDL_INPUT; - } - - /** - * @param mediator the mediator to set - */ - @Reference - public void setMediator(Mediator mediator) { - this.mediator = mediator; - } - - /** - * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getSourceType() - */ - @Override - protected Class getSourceType() { - return Object[].class; - } - - /** - * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getTargetType() - */ - @Override - protected Class getTargetType() { - return Object[].class; - } - - /** - * @see org.apache.tuscany.sca.databinding.Transformer#getWeight() - */ - @Override - public int getWeight() { - return 10000; - } - - @SuppressWarnings("unchecked") - public Object[] transform(Object[] source, TransformationContext context) { - DataType> sourceType = context.getSourceDataType(); - Operation sourceOp = context.getSourceOperation(); - boolean sourceWrapped = sourceOp != null && sourceOp.isWrapperStyle(); - - WrapperHandler sourceWrapperHandler = null; - String sourceDataBinding = getDataBinding(sourceOp); - sourceWrapperHandler = getWrapperHandler(sourceDataBinding, sourceWrapped); - - DataType> targetType = context.getTargetDataType(); - Operation targetOp = (Operation)context.getTargetOperation(); - boolean targetWrapped = targetOp != null && targetOp.isWrapperStyle(); - WrapperHandler targetWrapperHandler = null; - String targetDataBinding = getDataBinding(targetOp); - targetWrapperHandler = getWrapperHandler(targetDataBinding, targetWrapped); - - if ((!sourceWrapped) && targetWrapped) { - // Unwrapped --> Wrapped - WrapperInfo wrapper = targetOp.getWrapper(); - ElementInfo wrapperElement = wrapper.getInputWrapperElement(); - - // If the source can be wrapped, wrapped it first - if (sourceWrapperHandler != null) { - DataType sourceWrapperType = - sourceWrapperHandler.getWrapperType(wrapperElement, wrapper.getInputChildElements(), context); - if (sourceWrapperType != null) { - Object sourceWrapper = sourceWrapperHandler.create(wrapperElement, context); - if (sourceWrapper != null) { - for (int i = 0; i < source.length; i++) { - ElementInfo argElement = wrapper.getInputChildElements().get(i); - sourceWrapperHandler.setChild(sourceWrapper, i, argElement, source[i]); - } - Object targetWrapper = - mediator.mediate(sourceWrapper, sourceWrapperType, targetType.getLogical().get(0), context - .getMetadata()); - return new Object[] {targetWrapper}; - } - } - } - // Fall back to child by child transformation - Object targetWrapper = targetWrapperHandler.create(wrapperElement, context); - if (source == null) { - return new Object[] {targetWrapper}; - } - List argTypes = wrapper.getUnwrappedInputType().getLogical(); - - for (int i = 0; i < source.length; i++) { - ElementInfo argElement = wrapper.getInputChildElements().get(i); - DataType argType = argTypes.get(i); - Object child = source[i]; - child = mediator.mediate(source[i], sourceType.getLogical().get(i), argType, context.getMetadata()); - targetWrapperHandler.setChild(targetWrapper, i, argElement, child); - } - return new Object[] {targetWrapper}; - - } else if (sourceWrapped && (!targetWrapped)) { - // Wrapped to Unwrapped - Object sourceWrapper = source[0]; - Object[] target = null; - - List childElements = sourceOp.getWrapper().getInputChildElements(); - if (targetWrapperHandler != null) { - ElementInfo wrapperElement = sourceOp.getWrapper().getInputWrapperElement(); - // FIXME: This is a workaround for the wsdless support as it passes in child elements - // under the wrapper that only matches by position - if (sourceWrapperHandler.isInstance(sourceWrapper, wrapperElement, childElements, context)) { - DataType targetWrapperType = - targetWrapperHandler.getWrapperType(wrapperElement, childElements, context); - if (targetWrapperType != null) { - Object targetWrapper = - mediator.mediate(sourceWrapper, sourceType.getLogical().get(0), targetWrapperType, context - .getMetadata()); - target = targetWrapperHandler.getChildren(targetWrapper, childElements, context).toArray(); - return target; - } - } - } - Object[] sourceChildren = sourceWrapperHandler.getChildren(sourceWrapper, childElements, context).toArray(); - target = new Object[sourceChildren.length]; - for (int i = 0; i < sourceChildren.length; i++) { - DataType childType = sourceOp.getWrapper().getUnwrappedInputType().getLogical().get(i); - target[i] = - mediator.mediate(sourceChildren[i], childType, targetType.getLogical().get(i), context - .getMetadata()); - } - return target; - } else { - // Assuming wrapper to wrapper conversion can be handled here as well - Object[] newArgs = new Object[source.length]; - for (int i = 0; i < source.length; i++) { - Object child = - mediator.mediate(source[i], sourceType.getLogical().get(i), targetType.getLogical().get(i), context - .getMetadata()); - newArgs[i] = child; - } - return newArgs; - } - } - - private WrapperHandler getWrapperHandler(String dataBindingId, boolean required) { - WrapperHandler wrapperHandler = null; - if (dataBindingId != null) { - DataBinding dataBinding = mediator.getDataBindings().getDataBinding(dataBindingId); - wrapperHandler = dataBinding == null ? null : dataBinding.getWrapperHandler(); - } - if (wrapperHandler == null && required) { - throw new TransformationException("No wrapper handler is provided for databinding: " + dataBindingId); - } - return wrapperHandler; - } - - private String getDataBinding(Operation operation) { - return operation.getDataBinding(); - } - -} diff --git a/branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java b/branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java deleted file mode 100644 index 43439b1385..0000000000 --- a/branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.core.databinding.transformers; - -import java.util.List; - -import org.apache.tuscany.sca.databinding.DataBinding; -import org.apache.tuscany.sca.databinding.Mediator; -import org.apache.tuscany.sca.databinding.PullTransformer; -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.WrapperHandler; -import org.apache.tuscany.sca.databinding.impl.BaseTransformer; -import org.apache.tuscany.sca.interfacedef.DataType; -import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.interfacedef.util.ElementInfo; -import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; -import org.apache.tuscany.sca.interfacedef.util.XMLType; -import org.osoa.sca.annotations.Reference; -import org.osoa.sca.annotations.Service; - -/** - * This is a special transformer to transform the output from one IDL to the - * other one - */ -@Service(Transformer.class) -public class Output2OutputTransformer extends BaseTransformer implements - PullTransformer { - - protected Mediator mediator; - - /** - * @param wrapperHandler - */ - public Output2OutputTransformer() { - super(); - } - - /** - * @param mediator the mediator to set - */ - @Reference - public void setMediator(Mediator mediator) { - this.mediator = mediator; - } - - @Override - public String getSourceDataBinding() { - return DataBinding.IDL_OUTPUT; - } - - @Override - public String getTargetDataBinding() { - return DataBinding.IDL_OUTPUT; - } - - /** - * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getSourceType() - */ - @Override - protected Class getSourceType() { - return Object.class; - } - - /** - * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getTargetType() - */ - @Override - protected Class getTargetType() { - return Object.class; - } - - /** - * @see org.apache.tuscany.sca.databinding.Transformer#getWeight() - */ - @Override - public int getWeight() { - return 10; - } - - private String getDataBinding(Operation operation) { - return operation.getDataBinding(); - } - - private WrapperHandler getWrapperHandler(String dataBindingId, boolean required) { - WrapperHandler wrapperHandler = null; - if (dataBindingId != null) { - DataBinding dataBinding = mediator.getDataBindings().getDataBinding(dataBindingId); - wrapperHandler = dataBinding == null ? null : dataBinding.getWrapperHandler(); - } - if (wrapperHandler == null && required) { - throw new TransformationException("No wrapper handler is provided for databinding: " + dataBindingId); - } - return wrapperHandler; - } - - @SuppressWarnings("unchecked") - public Object transform(Object response, TransformationContext context) { - try { - DataType sourceType = context.getSourceDataType(); - Operation sourceOp = context.getSourceOperation(); - boolean sourceWrapped = sourceOp != null && sourceOp.isWrapperStyle(); - - WrapperHandler sourceWrapperHandler = null; - String sourceDataBinding = getDataBinding(sourceOp); - sourceWrapperHandler = getWrapperHandler(sourceDataBinding, sourceWrapped); - - DataType targetType = context.getTargetDataType(); - Operation targetOp = (Operation)context.getTargetOperation(); - boolean targetWrapped = targetOp != null && targetOp.isWrapperStyle(); - WrapperHandler targetWrapperHandler = null; - String targetDataBinding = getDataBinding(targetOp); - targetWrapperHandler = getWrapperHandler(targetDataBinding, targetWrapped); - - if ((!sourceWrapped) && targetWrapped) { - // Unwrapped --> Wrapped - WrapperInfo wrapper = targetOp.getWrapper(); - ElementInfo wrapperElement = wrapper.getOutputWrapperElement(); - List childElements = wrapper.getOutputChildElements(); - - // If the source can be wrapped, wrapped it first - if (sourceWrapperHandler != null) { - DataType sourceWrapperType = - sourceWrapperHandler.getWrapperType(wrapperElement, childElements, context); - if (sourceWrapperType != null) { - Object sourceWrapper = sourceWrapperHandler.create(wrapperElement, context); - if (sourceWrapper != null) { - if (!childElements.isEmpty()) { - // Set the return value - ElementInfo returnElement = wrapper.getOutputChildElements().get(0); - sourceWrapperHandler.setChild(sourceWrapper, 0, returnElement, response); - } - Object targetWrapper = - mediator.mediate(sourceWrapper, sourceWrapperType, targetType.getLogical(), context - .getMetadata()); - return targetWrapper; - } - } - } - Object targetWrapper = targetWrapperHandler.create(wrapper.getOutputWrapperElement(), context); - - if (childElements.isEmpty()) { - // void output - return targetWrapper; - } - ElementInfo argElement = childElements.get(0); - DataType argType = wrapper.getUnwrappedOutputType(); - Object child = response; - child = mediator.mediate(response, sourceType.getLogical(), argType, context.getMetadata()); - targetWrapperHandler.setChild(targetWrapper, 0, argElement, child); - return targetWrapper; - } else if (sourceWrapped && (!targetWrapped)) { - // Wrapped to Unwrapped - Object sourceWrapper = response; - List childElements = sourceOp.getWrapper().getOutputChildElements(); - if (childElements.isEmpty()) { - // The void output - return null; - } - if (targetWrapperHandler != null) { - ElementInfo wrapperElement = sourceOp.getWrapper().getOutputWrapperElement(); - - // FIXME: This is a workaround for the wsdless support as it passes in child elements - // under the wrapper that only matches by position - if (sourceWrapperHandler.isInstance(sourceWrapper, wrapperElement, childElements, context)) { - DataType targetWrapperType = - targetWrapperHandler.getWrapperType(wrapperElement, childElements, context); - if (targetWrapperType != null) { - Object targetWrapper = - mediator.mediate(sourceWrapper, sourceType.getLogical(), targetWrapperType, context - .getMetadata()); - return targetWrapperHandler.getChildren(targetWrapper, childElements, context).get(0); - } - } - } - Object child = sourceWrapperHandler.getChildren(sourceWrapper, childElements, context).get(0); - DataType childType = sourceOp.getWrapper().getUnwrappedOutputType(); - return mediator.mediate(child, childType, targetType.getLogical(), context.getMetadata()); - } else { - // FIXME: Do we want to handle wrapped to wrapped? - return mediator.mediate(response, sourceType.getLogical(), targetType.getLogical(), context - .getMetadata()); - } - } catch (Exception e) { - throw new TransformationException(e); - } - } - -} diff --git a/branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java b/branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java deleted file mode 100644 index d0a2dbc003..0000000000 --- a/branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.core.databinding.wire; - -import java.lang.reflect.Method; -import java.util.List; - -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; -import org.apache.tuscany.sca.databinding.Mediator; -import org.apache.tuscany.sca.interfacedef.DataType; -import org.apache.tuscany.sca.interfacedef.InterfaceContract; -import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.invocation.Interceptor; -import org.apache.tuscany.sca.invocation.InvocationChain; -import org.apache.tuscany.sca.runtime.RuntimeComponent; -import org.apache.tuscany.sca.runtime.RuntimeWire; -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 { - private Mediator mediator; - private DataBindingExtensionPoint dataBindings; - - public DataBindingRuntimeWireProcessor(Mediator mediator, DataBindingExtensionPoint dataBindings) { - super(); - this.mediator = mediator; - this.dataBindings = dataBindings; - } - - public boolean isTransformationRequired(DataType source, DataType target) { - if (source == null || target == null) { // void return type - return false; - } - if (source == target) { - return false; - } - - // Output type can be null - if (source == null && target == null) { - return false; - } else if (source == null || target == null) { - return true; - } - String sourceDataBinding = source.getDataBinding(); - String targetDataBinding = target.getDataBinding(); - if (sourceDataBinding == targetDataBinding) { - return false; - } - if (sourceDataBinding == null || targetDataBinding == null) { - // TODO: If any of the databinding is null, then no transformation - return false; - } - return !sourceDataBinding.equals(targetDataBinding); - } - - public boolean isTransformationRequired(Operation source, Operation target) { - if (source == target) { - return false; - } - - if (source.isWrapperStyle() != target.isWrapperStyle()) { - return true; - } - - // Check output type - DataType sourceOutputType = source.getOutputType(); - DataType targetOutputType = target.getOutputType(); - - // Note the target output type is now the source for checking - // compatibility - if (isTransformationRequired(targetOutputType, sourceOutputType)) { - return true; - } - - List sourceInputType = source.getInputType().getLogical(); - List targetInputType = target.getInputType().getLogical(); - - int size = sourceInputType.size(); - if (size != targetInputType.size()) { - // TUSCANY-1682: The wrapper style may have different arguments - return true; - } - for (int i = 0; i < size; i++) { - if (isTransformationRequired(sourceInputType.get(i), targetInputType.get(i))) { - return true; - } - } - - return false; - } - - private boolean isTransformationRequired(InterfaceContract sourceContract, - Operation sourceOperation, - InterfaceContract targetContract, - Operation targetOperation) { - if (targetContract == null) { - targetContract = sourceContract; - } - if (sourceContract == targetContract) { - return false; - } - return isTransformationRequired(sourceOperation, targetOperation); - } - - public void process(RuntimeWire wire) { - InterfaceContract sourceContract = wire.getSource().getInterfaceContract(); - InterfaceContract targetContract = wire.getTarget().getInterfaceContract(); - if (targetContract == null) { - targetContract = sourceContract; - } - - if (!sourceContract.getInterface().isRemotable()) { - return; - } - List chains = wire.getInvocationChains(); - for (InvocationChain chain : chains) { - Operation sourceOperation = chain.getSourceOperation(); - Operation targetOperation = chain.getTargetOperation(); - - Interceptor interceptor = null; - if (isTransformationRequired(sourceContract, sourceOperation, targetContract, targetOperation)) { - // Add the interceptor to the source side because multiple - // references can be wired to the same service - interceptor = 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 (requiresCopy(wire, sourceOperation, targetOperation)) { - interceptor = new PassByValueInterceptor(dataBindings, targetOperation); - } - } - if (interceptor != null) { - chain.addInterceptor(0, interceptor); - } - } - - } - - /** - * Pass-by-value copies are required if the interfaces are remotable unless the - * implementation uses the @AllowsPassByReference annotation. - */ - protected boolean requiresCopy(RuntimeWire wire, Operation sourceOperation, Operation targetOperation) { - if (!sourceOperation.getInterface().isRemotable()) { - return false; - } - if (!targetOperation.getInterface().isRemotable()) { - return false; - } - - if (allowsPassByReference(wire.getSource().getComponent(), sourceOperation)) { - return false; - } - - if (allowsPassByReference(wire.getTarget().getComponent(), sourceOperation)) { - return false; - } - - return true; - } - - /** - * Does the implementation use the @AllowsPassByReference annotation for the operation. - * Uses reflection to avoid a dependency on JavaImplementation because the isAllowsPassByReference - * and getAllowsPassByReference methods are not on the Implementation interface. - * TODO: move isAllowsPassByReference/getAllowsPassByReference to Implementation interface - */ - protected boolean allowsPassByReference(RuntimeComponent component, Operation operation) { - if (component == null || component.getImplementation() == null) { - return true; // err on the side of no copies - } - Implementation impl = component.getImplementation(); - try { - - Method m = impl.getClass().getMethod("isAllowsPassByReference", new Class[] {}); - if ((Boolean)m.invoke(impl, new Object[]{})) { - return true; - } - - m = impl.getClass().getMethod("getAllowsPassByReferenceMethods", new Class[] {}); - List ms = (List)m.invoke(impl, new Object[]{}); - if (ms != null) { - for (Method m2 : ms) { - // simple name matching is ok as its a remote operation so no overloading - if (operation.getName().equals(m2.getName())) - return true; - } - } - - } catch (Exception e) { - // ignore, assume the impl has no isAllowsPassByReference method - } - - return false; - } - -} diff --git a/branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java b/branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java deleted file mode 100644 index 6751fe0f37..0000000000 --- a/branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java +++ /dev/null @@ -1,255 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.core.databinding.wire; - -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.ExceptionHandler; -import org.apache.tuscany.sca.databinding.Mediator; -import org.apache.tuscany.sca.databinding.TransformationException; -import org.apache.tuscany.sca.interfacedef.DataType; -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.apache.tuscany.sca.invocation.Interceptor; -import org.apache.tuscany.sca.invocation.Invoker; -import org.apache.tuscany.sca.invocation.Message; -import org.apache.tuscany.sca.runtime.RuntimeWire; - -/** - * An interceptor to transform data accross databindings on the wire - * - * @version $Rev$ $Date$ - */ -public class DataTransformationInterceptor implements Interceptor { - private Invoker next; - - private Operation sourceOperation; - - private Operation targetOperation; - - private Mediator mediator; - - public DataTransformationInterceptor(RuntimeWire wire, - Operation sourceOperation, - Operation targetOperation, - Mediator mediator) { - super(); - this.sourceOperation = sourceOperation; - this.targetOperation = targetOperation; - this.mediator = mediator; - } - - public Invoker getNext() { - return next; - } - - public Message invoke(Message msg) { - Object input = transform(msg.getBody(), sourceOperation.getInputType(), targetOperation.getInputType(), false); - msg.setBody(input); - Message resultMsg = next.invoke(msg); - Object result = resultMsg.getBody(); - if (sourceOperation.isNonBlocking()) { - // Not to reset the message body - return resultMsg; - } - - // FIXME: Should we fix the Operation model so that getOutputType - // returns DataType>? - DataType targetType = - new DataTypeImpl(DataBinding.IDL_OUTPUT, Object.class, targetOperation.getOutputType()); - - DataType sourceType = - new DataTypeImpl(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); - - 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) { - if (((FaultException)result).isMatchingType(exType.getLogical())) { - targetDataType = exType; - break; - } - } else { - targetDataType = exType; - break; - } - } - } - - if (targetDataType == null) { - // Not a business exception - return resultMsg; - } - - DataType targetFaultType = getFaultType(targetDataType); - if (targetFaultType == null) { - throw new TransformationException("Target fault type cannot be resolved: " + targetDataType); - } - - // 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) { - throw new TransformationException("No matching source fault type is found: " + targetFaultType); - } - - Object newResult = - transformException(result, targetDataType, sourceDataType, targetFaultType, sourceFaultType); - if (newResult != result) { - resultMsg.setFaultBody(newResult); - } - } - - } 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); - } - } - - return resultMsg; - } - - private Object transform(Object source, DataType sourceType, DataType targetType, boolean isResponse) { - if (sourceType == targetType || (sourceType != null && sourceType.equals(targetType))) { - return source; - } - Map metadata = new HashMap(); - metadata.put("source.operation", isResponse ? targetOperation : sourceOperation); - metadata.put("target.operation", isResponse ? sourceOperation : targetOperation); - return mediator.mediate(source, sourceType, targetType, metadata); - } - - private DataType getFaultType(DataType exceptionType) { - // FIXME: We cannot assume the exception will have a databinding set - DataBinding targetDataBinding = mediator.getDataBindings().getDataBinding(exceptionType.getDataBinding()); - if (targetDataBinding == null) { - return null; - } - ExceptionHandler targetHandler = targetDataBinding.getExceptionHandler(); - if (targetHandler == null) { - return null; - } - return targetHandler.getFaultType(exceptionType); - } - - 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; - return matches(t1.getElementName(), t2.getElementName()) && matches(t1.getTypeName(), t2.getTypeName()); - } - 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 metadata = new HashMap(); - metadata.put("source.operation", targetOperation); - metadata.put("target.operation", sourceOperation); - - DataType eSourceDataType = - new DataTypeImpl("idl:fault", sourceExType.getPhysical(), sourceType); - DataType eTargetDataType = - new DataTypeImpl("idl:fault", targetExType.getPhysical(), targetType); - - return mediator.mediate(source, eSourceDataType, eTargetDataType, metadata); - } - - public void setNext(Invoker next) { - this.next = next; - } - -} diff --git a/branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/PassByValueInterceptor.java b/branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/PassByValueInterceptor.java deleted file mode 100644 index 6ecfe4e2ef..0000000000 --- a/branches/sca-java-1.0.1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/PassByValueInterceptor.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.core.databinding.wire; - -import java.util.IdentityHashMap; -import java.util.Map; - -import org.apache.tuscany.sca.databinding.DataBinding; -import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; -import org.apache.tuscany.sca.interfacedef.DataType; -import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.invocation.Interceptor; -import org.apache.tuscany.sca.invocation.Invoker; -import org.apache.tuscany.sca.invocation.Message; - -public class PassByValueInterceptor implements Interceptor { - - private DataBindingExtensionPoint dataBindings; - private Operation operation; - - private Invoker nextInvoker; - - public PassByValueInterceptor(DataBindingExtensionPoint dataBindings, Operation operation) { - this.dataBindings = dataBindings; - this.operation = operation; - } - - public Message invoke(Message msg) { - Object obj = msg.getBody(); - msg.setBody(copy((Object[])obj)); - - Message resultMsg = nextInvoker.invoke(msg); - - if (!msg.isFault() && operation.getOutputType() != null) { - String dataBindingId = operation.getOutputType().getDataBinding(); - DataBinding dataBinding = dataBindings.getDataBinding(dataBindingId); - resultMsg.setBody(copy(resultMsg.getBody(), dataBinding)); - } - return resultMsg; - } - - public Object[] copy(Object[] args) { - if (args == null) { - return null; - } - Object[] copiedArgs = new Object[args.length]; - Map map = new IdentityHashMap(); - for (int i = 0; i < args.length; i++) { - if (args[i] == null) { - copiedArgs[i] = null; - } else { - Object copiedArg = map.get(args[i]); - if (copiedArg != null) { - copiedArgs[i] = copiedArg; - } else { - String dataBindingId = operation.getInputType().getLogical().get(i).getDataBinding(); - DataBinding dataBinding = dataBindings.getDataBinding(dataBindingId); - copiedArg = copy(args[i], dataBinding); - map.put(args[i], copiedArg); - copiedArgs[i] = copiedArg; - } - } - } - return copiedArgs; - } - - public Object copy(Object arg, DataBinding argDataBinding) { - if (arg == null) { - return null; - } - Object copiedArg; - if (argDataBinding != null) { - copiedArg = argDataBinding.copy(arg); - } else { - copiedArg = arg; - DataType dataType = dataBindings.introspectType(arg); - if (dataType != null) { - DataBinding binding = dataBindings.getDataBinding(dataType.getDataBinding()); - if (binding != null) { - copiedArg = binding.copy(arg); - } - } - // FIXME: What to do if it's not recognized? - } - return copiedArg; - } - - public Invoker getNext() { - return nextInvoker; - } - - public void setNext(Invoker next) { - this.nextInvoker = next; - } - -} -- cgit v1.2.3