diff options
Diffstat (limited to 'sandbox/ant/sca/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers')
9 files changed, 0 insertions, 1103 deletions
diff --git a/sandbox/ant/sca/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Array2ArrayTransformer.java b/sandbox/ant/sca/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Array2ArrayTransformer.java deleted file mode 100644 index 427e0b254a..0000000000 --- a/sandbox/ant/sca/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Array2ArrayTransformer.java +++ /dev/null @@ -1,110 +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.lang.reflect.Array; - -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.impl.BaseTransformer; -import org.apache.tuscany.sca.interfacedef.DataType; -import org.oasisopen.sca.annotation.Reference; - -/** - * This is a special transformer to transform the output from one IDL to the - * other one - * - * @version $Rev$ $Date$ - */ -public class Array2ArrayTransformer extends BaseTransformer<Object, Object> implements PullTransformer<Object, Object> { - - protected Mediator mediator; - - public Array2ArrayTransformer() { - super(); - } - - /** - * @param mediator the mediator to set - */ - @Reference - public void setMediator(Mediator mediator) { - this.mediator = mediator; - } - - @Override - public String getSourceDataBinding() { - return "java:array"; - } - - @Override - public String getTargetDataBinding() { - return "java:array"; - } - - /** - * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getSourceType() - */ - @Override - protected Class<Object> getSourceType() { - return Object.class; - } - - /** - * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getTargetType() - */ - @Override - protected Class<Object> getTargetType() { - return Object.class; - } - - /** - * @see org.apache.tuscany.sca.databinding.Transformer#getWeight() - */ - @Override - public int getWeight() { - return 10; - } - - @SuppressWarnings("unchecked") - public Object transform(Object array, TransformationContext context) { - try { - if (array == null) { - return null; - } - DataType<DataType> sourceType = context.getSourceDataType(); - DataType<DataType> targetType = context.getTargetDataType(); - int length = Array.getLength(array); - Object targetArray = Array.newInstance(targetType.getPhysical().getComponentType(), length); - for (int i = 0; i < length; i++) { - Object sourceItem = Array.get(array, i); - Object targetItem = - mediator.mediate(sourceItem, sourceType.getLogical(), targetType.getLogical(), context - .getMetadata()); - Array.set(targetArray, i, targetItem); - } - return targetArray; - } catch (Exception e) { - throw new TransformationException(e); - } - } - -} diff --git a/sandbox/ant/sca/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReference2XMLStreamReader.java b/sandbox/ant/sca/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReference2XMLStreamReader.java deleted file mode 100644 index 4267b1e347..0000000000 --- a/sandbox/ant/sca/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReference2XMLStreamReader.java +++ /dev/null @@ -1,75 +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 javax.xml.stream.XMLStreamReader;
-
-import org.apache.tuscany.sca.core.context.CallableReferenceExt;
-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.impl.BaseTransformer;
-import org.apache.tuscany.sca.databinding.xml.StAXHelper;
-import org.oasisopen.sca.CallableReference;
-
-public class CallableReference2XMLStreamReader extends BaseTransformer<CallableReference, XMLStreamReader> implements
- PullTransformer<CallableReference, XMLStreamReader> {
-
- @Override
- protected Class<CallableReference> getSourceType() {
- return CallableReference.class;
- }
-
- @Override
- protected Class<XMLStreamReader> getTargetType() {
- return XMLStreamReader.class;
- }
-
- public XMLStreamReader transform(CallableReference source, TransformationContext context) {
- try {
- if (source != null) {
- if (source instanceof CallableReferenceExt) {
- XMLStreamReader xmlReader = ((CallableReferenceExt)source).getXMLReader();
- if (xmlReader != null) {
- return xmlReader;
- } else {
- String xmlString = ((CallableReferenceExt)source).toXMLString();
-
- // remove "<?xml...?>" processing instruction and wrap with a top-level element
- return StAXHelper.createXMLStreamReader("<reference xmlns=\"http://callable\">"
- + xmlString.substring(xmlString.indexOf("?>") + 2)
- + "</reference>");
- }
- } else {
- throw new TransformationException("Unrecognized transformation source object");
- }
- } else {
- return null;
- }
- } catch (Exception e) {
- throw new TransformationException(e);
- }
- }
-
- @Override
- public int getWeight() {
- return 10;
- }
-
-}
diff --git a/sandbox/ant/sca/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceDataBinding.java b/sandbox/ant/sca/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceDataBinding.java deleted file mode 100644 index 97e16da273..0000000000 --- a/sandbox/ant/sca/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceDataBinding.java +++ /dev/null @@ -1,42 +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.XMLTypeHelper;
-import org.apache.tuscany.sca.databinding.impl.BaseDataBinding;
-import org.oasisopen.sca.CallableReference;
-
-public class CallableReferenceDataBinding extends BaseDataBinding {
-
- public static final String NAME = CallableReference.class.getName();
-
- private CallableReferenceTypeHelper xmlTypeHelper;
-
- public CallableReferenceDataBinding() {
- super(NAME, CallableReference.class);
- this.xmlTypeHelper = new CallableReferenceTypeHelper();
- }
-
- @Override
- public XMLTypeHelper getXMLTypeHelper() {
- return xmlTypeHelper;
- }
-
-}
diff --git a/sandbox/ant/sca/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceTypeHelper.java b/sandbox/ant/sca/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceTypeHelper.java deleted file mode 100644 index 97629ea7b5..0000000000 --- a/sandbox/ant/sca/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceTypeHelper.java +++ /dev/null @@ -1,75 +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.beans.Introspector; -import java.util.ArrayList; -import java.util.List; -import javax.xml.namespace.QName; - -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.databinding.XMLTypeHelper; -import org.apache.tuscany.sca.interfacedef.DataType; -import org.apache.tuscany.sca.interfacedef.Interface; -import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper; -import org.apache.tuscany.sca.interfacedef.util.TypeInfo; -import org.apache.tuscany.sca.interfacedef.util.XMLType; -import org.apache.tuscany.sca.xsd.XSDFactory; -import org.apache.tuscany.sca.xsd.XSDefinition; - -/** - * - * @version $Rev$ $Date$ - */ -public class CallableReferenceTypeHelper implements XMLTypeHelper { - private static final String SCHEMA_NS = "http://www.w3.org/2001/XMLSchema"; - private static final String ANYTYPE_NAME = "anyType"; - private static final QName ANYTYPE_QNAME = new QName(SCHEMA_NS, ANYTYPE_NAME); - - public CallableReferenceTypeHelper() { - super(); - } - - public TypeInfo getTypeInfo(Class javaType, Object logical) { - QName xmlType = JavaXMLMapper.getXMLType(javaType); - if (xmlType != null) { - return new TypeInfo(xmlType, true, null); - } else if (javaType.isInterface()) { - return new TypeInfo(ANYTYPE_QNAME, true, null); - } else { - if (logical instanceof XMLType) { - xmlType = ((XMLType)logical).getTypeName(); - } - if (xmlType == null) { - xmlType = new QName(Introspector.decapitalize(javaType.getSimpleName())); - } - return new TypeInfo(xmlType, false, null); - } - } - - public List<XSDefinition> getSchemaDefinitions(XSDFactory factory, ModelResolver resolver, Interface intf) { - return new ArrayList<XSDefinition>(); - } - - public List<XSDefinition> getSchemaDefinitions(XSDFactory factory, ModelResolver resolver, List<DataType> dataTypes) { - return new ArrayList<XSDefinition>(); - } - -} diff --git a/sandbox/ant/sca/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceXMLAdapter.java b/sandbox/ant/sca/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceXMLAdapter.java deleted file mode 100644 index 82853599b5..0000000000 --- a/sandbox/ant/sca/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceXMLAdapter.java +++ /dev/null @@ -1,50 +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 javax.xml.bind.annotation.adapters.XmlAdapter; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.sca.databinding.xml.Node2XMLStreamReader; -import org.apache.tuscany.sca.databinding.xml.XMLStreamReader2Node; -import org.oasisopen.sca.CallableReference; -import org.w3c.dom.Element; - -/** - * @version $Rev$ $Date$ - */ -public class CallableReferenceXMLAdapter extends XmlAdapter<Element, CallableReference> { - - @Override - public CallableReference unmarshal(Element v) throws Exception { - Node2XMLStreamReader tf = new Node2XMLStreamReader(); - XMLStreamReader reader = tf.transform(v, null); - XMLStreamReader2CallableReference t2 = new XMLStreamReader2CallableReference(); - return t2.transform(reader, null); - } - - @Override - public Element marshal(CallableReference v) throws Exception { - CallableReference2XMLStreamReader t = new CallableReference2XMLStreamReader(); - XMLStreamReader reader = t.transform(v, null); - XMLStreamReader2Node t2 = new XMLStreamReader2Node(); - return (Element) t2.transform(reader, null); - } -} diff --git a/sandbox/ant/sca/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Exception2ExceptionTransformer.java b/sandbox/ant/sca/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Exception2ExceptionTransformer.java deleted file mode 100644 index 6e2e714bdb..0000000000 --- a/sandbox/ant/sca/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Exception2ExceptionTransformer.java +++ /dev/null @@ -1,114 +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.Mediator; -import org.apache.tuscany.sca.databinding.PullTransformer; -import org.apache.tuscany.sca.databinding.TransformationContext; -import org.apache.tuscany.sca.databinding.impl.BaseTransformer; -import org.apache.tuscany.sca.interfacedef.DataType; -import org.apache.tuscany.sca.interfacedef.FaultExceptionMapper; - -/** - * This is a special transformer to transform the exception from one IDL to the - * other one - * - * @version $Rev$ $Date$ - */ -public class Exception2ExceptionTransformer extends BaseTransformer<Throwable, Throwable> implements - PullTransformer<Throwable, Throwable> { - - protected Mediator mediator; - protected FaultExceptionMapper faultExceptionMapper; - - public Exception2ExceptionTransformer(Mediator mediator, FaultExceptionMapper faultExceptionMapper) { - super(); - this.mediator = mediator; - this.faultExceptionMapper = faultExceptionMapper; - } - - 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 - */ - public void setMediator(Mediator mediator) { - this.mediator = mediator; - } - - /** - * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getSourceType() - */ - @Override - protected Class<Throwable> getSourceType() { - return Throwable.class; - } - - /** - * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getTargetType() - */ - @Override - protected Class<Throwable> getTargetType() { - return Throwable.class; - } - - /** - * @see org.apache.tuscany.sca.databinding.Transformer#getWeight() - */ - @Override - public int getWeight() { - return 10000; - } - - @SuppressWarnings("unchecked") - public Throwable transform(Throwable source, TransformationContext context) { - DataType<DataType> sourceType = context.getSourceDataType(); - - DataType<DataType> targetType = context.getTargetDataType(); - - Object sourceFaultInfo = faultExceptionMapper.getFaultInfo(source, sourceType.getLogical().getPhysical(), context.getSourceOperation()); - Object targetFaultInfo = - mediator.mediate(sourceFaultInfo, sourceType.getLogical(), targetType.getLogical(), context.getMetadata()); - - Throwable targetException = - faultExceptionMapper.wrapFaultInfo(targetType, source.getMessage(), targetFaultInfo, source.getCause(), context.getTargetOperation()); - - // FIXME - return targetException == null ? source : targetException; - - } - - public void setFaultExceptionMapper(FaultExceptionMapper faultExceptionMapper) { - this.faultExceptionMapper = faultExceptionMapper; - } -} diff --git a/sandbox/ant/sca/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Input2InputTransformer.java b/sandbox/ant/sca/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Input2InputTransformer.java deleted file mode 100644 index b05f0cc238..0000000000 --- a/sandbox/ant/sca/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Input2InputTransformer.java +++ /dev/null @@ -1,279 +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.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.oasisopen.sca.annotation.Reference; - -/** - * This is a special transformer to transform the input from one IDL to the - * other one - * - * @version $Rev$ $Date$ - */ -public class Input2InputTransformer extends BaseTransformer<Object[], Object[]> implements - PullTransformer<Object[], Object[]> { - 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<Object[]> getSourceType() { - return Object[].class; - } - - /** - * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getTargetType() - */ - @Override - protected Class<Object[]> getTargetType() { - return Object[].class; - } - - /** - * @see org.apache.tuscany.sca.databinding.Transformer#getWeight() - */ - @Override - public int getWeight() { - return 10000; - } - - /** - * Match the structure of the wrapper element. If it matches, then we can do - * wrapper to wrapper transformation. Otherwise, we do child to child. - * @param w1 - * @param w2 - * @return - */ - private boolean matches(WrapperInfo w1, WrapperInfo w2) { - if (w1 == null || w2 == null) { - return false; - } - if (!w1.getInputWrapperElement().equals(w2.getInputWrapperElement())) { - return false; - } - - // Compare the child elements - List<ElementInfo> list1 = w1.getInputChildElements(); - List<ElementInfo> list2 = w2.getInputChildElements(); - if (list1.size() != list2.size()) { - return false; - } - // FXIME: [rfeng] At this point, the J2W generates local elments under the namespace - // of the interface instead of "". We only compare the local parts only to work around - // the namespace mismatch - for (int i = 0; i < list1.size(); i++) { - String n1 = list1.get(i).getQName().getLocalPart(); - String n2 = list2.get(i).getQName().getLocalPart(); - if (!n1.equals(n2)) { - return false; - } - } - return true; - } - - @SuppressWarnings("unchecked") - public Object[] transform(Object[] source, TransformationContext context) { - // Check if the source operation is wrapped - DataType<List<DataType>> sourceType = context.getSourceDataType(); - Operation sourceOp = context.getSourceOperation(); - boolean sourceWrapped = sourceOp != null && sourceOp.isWrapperStyle() && sourceOp.getWrapper() != null; - boolean sourceBare = sourceOp != null && !sourceOp.isWrapperStyle() && sourceOp.getWrapper() == null; - - // Find the wrapper handler for source data - WrapperHandler sourceWrapperHandler = null; - String sourceDataBinding = getDataBinding(sourceOp); - sourceWrapperHandler = getWrapperHandler(sourceDataBinding, sourceWrapped); - - // Check if the target operation is wrapped - DataType<List<DataType>> targetType = context.getTargetDataType(); - Operation targetOp = (Operation)context.getTargetOperation(); - boolean targetWrapped = targetOp != null && targetOp.isWrapperStyle() && targetOp.getWrapper() != null; - boolean targetBare = targetOp != null && !targetOp.isWrapperStyle() && targetOp.getWrapper() == null; - - // Find the wrapper handler for target data - WrapperHandler targetWrapperHandler = null; - String targetDataBinding = getDataBinding(targetOp); - targetWrapperHandler = getWrapperHandler(targetDataBinding, targetWrapped); - - if ((!sourceWrapped && !sourceBare) && targetWrapped) { - // Unwrapped --> Wrapped - WrapperInfo wrapper = targetOp.getWrapper(); - // ElementInfo wrapperElement = wrapper.getInputWrapperElement(); - - // Class<?> targetWrapperClass = wrapper != null ? wrapper.getInputWrapperClass() : null; - - if (source == null) { - // Empty child elements - Object targetWrapper = targetWrapperHandler.create(targetOp, true); - return new Object[] {targetWrapper}; - } - - // If the source can be wrapped, wrapped it first - if (sourceWrapperHandler != null) { - WrapperInfo sourceWrapperInfo = sourceOp.getWrapper(); - DataType sourceWrapperType = sourceWrapperInfo != null ? sourceWrapperInfo.getInputWrapperType() : null; - - // We only do wrapper to wrapper transformation if the source has a wrapper and both sides - // match by XML structure - if (sourceWrapperType != null && matches(sourceOp.getWrapper(), targetOp.getWrapper())) { - Class<?> sourceWrapperClass = sourceWrapperType.getPhysical(); - - // Create the source wrapper - Object sourceWrapper = sourceWrapperHandler.create(sourceOp, true); - - // Populate the source wrapper - if (sourceWrapper != null) { - sourceWrapperHandler.setChildren(sourceWrapper, - source, - sourceOp, - true); - - // Transform the data from source wrapper to target wrapper - 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(targetOp, true); - List<DataType> argTypes = wrapper.getUnwrappedInputType().getLogical(); - Object[] targetChildren = new Object[source.length]; - for (int i = 0; i < source.length; i++) { - // ElementInfo argElement = wrapper.getInputChildElements().get(i); - DataType<XMLType> argType = argTypes.get(i); - targetChildren[i] = - mediator.mediate(source[i], sourceType.getLogical().get(i), argType, context.getMetadata()); - } - targetWrapperHandler.setChildren(targetWrapper, - targetChildren, - targetOp, - true); - return new Object[] {targetWrapper}; - - } else if (sourceWrapped && (!targetWrapped && !targetBare)) { - // Wrapped to Unwrapped - Object sourceWrapper = source[0]; - Object[] target = null; - - // List<ElementInfo> 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, sourceOp, true)) { - - WrapperInfo targetWrapperInfo = targetOp.getWrapper(); - DataType targetWrapperType = - targetWrapperInfo != null ? targetWrapperInfo.getInputWrapperType() : null; - if (targetWrapperType != null && matches(sourceOp.getWrapper(), targetOp.getWrapper())) { - Object targetWrapper = - mediator.mediate(sourceWrapper, sourceType.getLogical().get(0), targetWrapperType, context - .getMetadata()); - target = targetWrapperHandler.getChildren(targetWrapper, targetOp, true).toArray(); - return target; - } - } - } - Object[] sourceChildren = sourceWrapperHandler.getChildren(sourceWrapper, sourceOp, true).toArray(); - target = new Object[sourceChildren.length]; - for (int i = 0; i < sourceChildren.length; i++) { - DataType<XMLType> 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) { - WrapperInfo wrapper = operation.getWrapper(); - if (wrapper != null) { - return wrapper.getDataBinding(); - } else { - return null; - } - } - -} diff --git a/sandbox/ant/sca/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java b/sandbox/ant/sca/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java deleted file mode 100644 index d5ba528475..0000000000 --- a/sandbox/ant/sca/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java +++ /dev/null @@ -1,257 +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.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.oasisopen.sca.annotation.Reference; - -/** - * This is a special transformer to transform the output from one IDL to the - * other one - * - * @version $Rev$ $Date$ - */ -public class Output2OutputTransformer extends BaseTransformer<Object, Object> implements - PullTransformer<Object, Object> { - - 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<Object> getSourceType() { - return Object.class; - } - - /** - * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getTargetType() - */ - @Override - protected Class<Object> getTargetType() { - return Object.class; - } - - /** - * @see org.apache.tuscany.sca.databinding.Transformer#getWeight() - */ - @Override - public int getWeight() { - return 10; - } - - private String getDataBinding(Operation operation) { - WrapperInfo wrapper = operation.getWrapper(); - if (wrapper != null) { - return wrapper.getDataBinding(); - } else { - return null; - } - } - - 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; - } - - /** - * Match the structure of the wrapper element. If it matches, then we can do - * wrapper to wrapper transformation. Otherwise, we do child to child. - * @param w1 - * @param w2 - * @return - */ - private boolean matches(WrapperInfo w1, WrapperInfo w2) { - if (w1 == null || w2 == null) { - return false; - } - if (!w1.getOutputWrapperElement().equals(w2.getOutputWrapperElement())) { - return false; - } - - // Compare the child elements - List<ElementInfo> list1 = w1.getOutputChildElements(); - List<ElementInfo> list2 = w2.getOutputChildElements(); - if (list1.size() != list2.size()) { - return false; - } - // FXIME: [rfeng] At this point, the J2W generates local elments under the namespace - // of the interface instead of "". We only compare the local parts only to work around - // the namespace mismatch - for (int i = 0; i < list1.size(); i++) { - String n1 = list1.get(i).getQName().getLocalPart(); - String n2 = list2.get(i).getQName().getLocalPart(); - if (!n1.equals(n2)) { - return false; - } - } - return true; - } - - @SuppressWarnings("unchecked") - public Object transform(Object response, TransformationContext context) { - try { - DataType<DataType> sourceType = context.getSourceDataType(); - Operation sourceOp = context.getSourceOperation(); - boolean sourceWrapped = sourceOp != null && sourceOp.isWrapperStyle() && sourceOp.getWrapper() != null; - boolean sourceBare = sourceOp != null && !sourceOp.isWrapperStyle() && sourceOp.getWrapper() == null; - - WrapperHandler sourceWrapperHandler = null; - String sourceDataBinding = getDataBinding(sourceOp); - sourceWrapperHandler = getWrapperHandler(sourceDataBinding, sourceWrapped); - - DataType<DataType> targetType = context.getTargetDataType(); - Operation targetOp = (Operation)context.getTargetOperation(); - boolean targetWrapped = targetOp != null && targetOp.isWrapperStyle() && targetOp.getWrapper() != null; - boolean targetBare = targetOp != null && !targetOp.isWrapperStyle() && targetOp.getWrapper() == null; - - WrapperHandler targetWrapperHandler = null; - String targetDataBinding = getDataBinding(targetOp); - targetWrapperHandler = getWrapperHandler(targetDataBinding, targetWrapped); - - if ((!sourceWrapped &&!sourceBare) && targetWrapped) { - // Unwrapped --> Wrapped - WrapperInfo wrapper = targetOp.getWrapper(); - ElementInfo wrapperElement = wrapper.getOutputWrapperElement(); - List<ElementInfo> childElements = wrapper.getOutputChildElements(); - Class<?> targetWrapperClass = wrapper != null ? wrapper.getOutputWrapperClass() : null; - - // If the source can be wrapped, wrapped it first - if (sourceWrapperHandler != null) { - WrapperInfo sourceWrapperInfo = sourceOp.getWrapper(); - DataType sourceWrapperType = - sourceWrapperInfo != null ? sourceWrapperInfo.getOutputWrapperType() : null; - - if (sourceWrapperType != null && matches(sourceOp.getWrapper(), targetOp.getWrapper())) { - Class<?> sourceWrapperClass = sourceWrapperType.getPhysical(); - - Object sourceWrapper = sourceWrapperHandler.create(sourceOp, false); - if (sourceWrapper != null) { - if (!childElements.isEmpty()) { - // Set the return value - sourceWrapperHandler.setChildren(sourceWrapper, - new Object[] {response}, - sourceOp, - false); - } - Object targetWrapper = - mediator.mediate(sourceWrapper, sourceWrapperType, targetType.getLogical(), context - .getMetadata()); - return targetWrapper; - } - } - } - Object targetWrapper = targetWrapperHandler.create(targetOp, false); - - if (childElements.isEmpty()) { - // void output - return targetWrapper; - } - - DataType<XMLType> argType = wrapper.getUnwrappedOutputType(); - Object child = response; - child = mediator.mediate(response, sourceType.getLogical(), argType, context.getMetadata()); - targetWrapperHandler.setChildren(targetWrapper, new Object[] {child}, targetOp, false); - return targetWrapper; - } else if (sourceWrapped && (!targetWrapped && !targetBare)) { - // Wrapped to Unwrapped - Object sourceWrapper = response; - List<ElementInfo> 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, sourceOp, false)) { - - WrapperInfo targetWrapperInfo = targetOp.getWrapper(); - DataType targetWrapperType = - targetWrapperInfo != null ? targetWrapperInfo.getOutputWrapperType() : null; - - if (targetWrapperType != null && matches(sourceOp.getWrapper(), targetOp.getWrapper())) { - Object targetWrapper = - mediator.mediate(sourceWrapper, sourceType.getLogical(), targetWrapperType, context - .getMetadata()); - return targetWrapperHandler.getChildren(targetWrapper, targetOp, false).get(0); - } - } - } - Object child = sourceWrapperHandler.getChildren(sourceWrapper, sourceOp, false).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/sandbox/ant/sca/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/XMLStreamReader2CallableReference.java b/sandbox/ant/sca/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/XMLStreamReader2CallableReference.java deleted file mode 100644 index 9633262116..0000000000 --- a/sandbox/ant/sca/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/XMLStreamReader2CallableReference.java +++ /dev/null @@ -1,101 +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 static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
-
-import java.lang.reflect.Constructor;
-
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
-import org.apache.tuscany.sca.core.context.CallableReferenceExt;
-import org.apache.tuscany.sca.core.context.ServiceReferenceExt;
-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.impl.BaseTransformer;
-import org.oasisopen.sca.CallableReference;
-
-@SuppressWarnings("unchecked")
-public class XMLStreamReader2CallableReference extends BaseTransformer<XMLStreamReader, CallableReference>
- implements PullTransformer<XMLStreamReader, CallableReference> {
-
- private static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200903";
- private static final String COMPOSITE = "composite";
- private static final QName COMPOSITE_QNAME = new QName(SCA11_NS, COMPOSITE);
-
- public CallableReference transform(XMLStreamReader source, TransformationContext context) {
- try {
- if (source != null) {
- skipTopLevelElement(source);
- Class refType =
- context == null ? CallableReferenceExt.class : context.getTargetDataType().getPhysical();
- Class implType;
- if (refType.isAssignableFrom(CallableReferenceExt.class)) {
- implType = CallableReferenceExt.class;
- } else if (refType.isAssignableFrom(ServiceReferenceExt.class)) {
- implType = ServiceReferenceExt.class;
- } else {
- throw new TransformationException("Unrecognized transformation target type");
- }
- Constructor constructor = implType.getConstructor(new Class[] {XMLStreamReader.class});
- return (CallableReference)constructor.newInstance(new Object[] {source});
- } else {
- return null;
- }
- } catch (Exception e) {
- throw new TransformationException(e);
- }
- }
-
- /*
- * Step over top-level element added by CallableReference2XMLStreamReader
- */
- private void skipTopLevelElement(XMLStreamReader source) throws XMLStreamException {
- while (source.hasNext()) {
- int event = source.getEventType();
- if (event == START_ELEMENT) {
- QName name = source.getName();
- if (COMPOSITE_QNAME.equals(name)) {
- return;
- }
- }
- source.next();
- }
- throw new TransformationException("<composite> element not found");
- }
-
- @Override
- protected Class<XMLStreamReader> getSourceType() {
- return XMLStreamReader.class;
- }
-
- @Override
- protected Class<CallableReference> getTargetType() {
- return CallableReference.class;
- }
-
- @Override
- public int getWeight() {
- return 10;
- }
-
-}
|