Package org.apache.tuscany.spi.databinding

Examples of org.apache.tuscany.spi.databinding.WrapperHandler


    private WrapperHandler getWapperHandler(Operation<?> operation) {
        String dataBindingId;
        dataBindingId = operation.getDataBinding();
        DataBinding dataBinding = dataBindingRegistry.getDataBinding(dataBindingId);
        WrapperHandler wrapperHandler = dataBinding == null ? null : dataBinding.getWrapperHandler();
        if (wrapperHandler == null) {
            throw new TransformationException(
                                              "No wrapper handler is provided for databinding: " + dataBindingId);
        }
        return wrapperHandler;
View Full Code Here


    public Object transform(Object response, TransformationContext context) {
        try {
            DataType<DataType> sourceType = context.getSourceDataType();
            Operation<?> sourceOp = (Operation<?>)sourceType.getMetadata(Operation.class.getName());
            boolean sourceWrapped = sourceOp != null && sourceOp.isWrapperStyle();
            WrapperHandler sourceWrapperHandler = null;
            if (sourceWrapped) {
                sourceWrapperHandler = getWapperHandler(sourceOp);
            }

            DataType<DataType> targetType = context.getTargetDataType();
            Operation<?> targetOp = (Operation<?>)targetType.getMetadata(Operation.class.getName());
            boolean targetWrapped = targetOp != null && targetOp.isWrapperStyle();
            WrapperHandler targetWrapperHandler = null;
            if (targetWrapped) {
                targetWrapperHandler = getWapperHandler(targetOp);
            }

            if ((!sourceWrapped) && targetWrapped) {
                // Unwrapped --> Wrapped
                WrapperInfo wrapper = targetOp.getWrapper();
                Object targetWrapper =
                    targetWrapperHandler.create(wrapper.getOutputWrapperElement(), context);
                if (response == null) {
                    return targetWrapper;
                }

                ElementInfo argElement = wrapper.getOutputChildElements().get(0);
                DataType<QName> 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<ElementInfo> childElements = sourceOp.getWrapper().getOutputChildElements();
                ElementInfo childElement = childElements.get(0);

                targetWrapperHandler = getWapperHandler(targetType.getLogical().getDataBinding());
                if (targetWrapperHandler != null) {
                    ElementInfo wrapperElement = sourceOp.getWrapper().getInputWrapperElement();
                    // Object targetWrapper =
                    // targetWrapperHandler.create(wrapperElement, context);
                    DataType<QName> targetWrapperType =
                        new DataType<QName>(targetType.getLogical().getDataBinding(), Object.class,
                                            wrapperElement.getQName());
                    Object targetWrapper =
                        mediator.mediate(sourceWrapper, sourceType.getLogical(), targetWrapperType, context
                            .getMetadata());
                    return targetWrapperHandler.getChild(targetWrapper, 0, childElement);
                } else {
                    Object child = sourceWrapperHandler.getChild(sourceWrapper, 0, childElement);
                    DataType<?> childType = sourceOp.getWrapper().getUnwrappedOutputType();
                    return mediator.mediate(child, childType, targetType.getLogical(), context.getMetadata());
                }
View Full Code Here

    public Object[] transform(Object[] source, TransformationContext context) {
        DataType<List<DataType<?>>> sourceType = context.getSourceDataType();
        Operation<?> sourceOp = (Operation<?>)sourceType.getMetadata(Operation.class.getName());
        boolean sourceWrapped = sourceOp != null && sourceOp.isWrapperStyle();

        WrapperHandler sourceWrapperHandler = null;
        if (sourceWrapped) {
            sourceWrapperHandler = getWapperHandler(sourceType.getLogical().get(0).getDataBinding(), true);
        }

        DataType<List<DataType<QName>>> targetType = context.getTargetDataType();
        Operation<?> targetOp = (Operation<?>)targetType.getMetadata(Operation.class.getName());
        boolean targetWrapped = targetOp != null && targetOp.isWrapperStyle();
        WrapperHandler targetWrapperHandler = null;
        if (targetWrapped) {
            targetWrapperHandler = getWapperHandler(targetType.getLogical().get(0).getDataBinding(), true);
        }

        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) {
                Object sourceWrapper = sourceWrapperHandler.create(wrapperElement, context);
                for (int i = 0; i < source.length; i++) {
                    ElementInfo argElement = wrapper.getInputChildElements().get(i);
                    sourceWrapperHandler.setChild(sourceWrapper, i, argElement, source[0]);
                }
            }
            Object targetWrapper = targetWrapperHandler.create(wrapperElement, context);
            if (source == null) {
                return new Object[] {targetWrapper};
            }
            List<DataType<QName>> argTypes = wrapper.getUnwrappedInputType().getLogical();

            for (int i = 0; i < source.length; i++) {
                ElementInfo argElement = wrapper.getInputChildElements().get(i);
                DataType<QName> 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];
            List<ElementInfo> childElements = sourceOp.getWrapper().getInputChildElements();
            Object[] target = new Object[childElements.size()];

            targetWrapperHandler = getWapperHandler(targetType.getLogical().get(0).getDataBinding(), false);
            if (targetWrapperHandler != null) {
                ElementInfo wrapperElement = sourceOp.getWrapper().getInputWrapperElement();
                // Object targetWrapper =
                // targetWrapperHandler.create(wrapperElement, context);
                DataType<QName> targetWrapperType =
                    new DataType<QName>(targetType.getLogical().get(0).getDataBinding(), Object.class,
                                        wrapperElement.getQName());
                Object targetWrapper =
                    mediator.mediate(sourceWrapper,
                                     sourceType.getLogical().get(0),
                                     targetWrapperType,
                                     context.getMetadata());
                for (int i = 0; i < childElements.size(); i++) {
                    ElementInfo childElement = childElements.get(i);
                    target[i] = targetWrapperHandler.getChild(targetWrapper, i, childElement);
                }
            } else {
                for (int i = 0; i < childElements.size(); i++) {
                    ElementInfo childElement = childElements.get(i);
                    Object child = sourceWrapperHandler.getChild(sourceWrapper, i, childElement);
View Full Code Here

        }
    }

    private WrapperHandler getWapperHandler(String dataBindingId, boolean required) {
        DataBinding dataBinding = dataBindingRegistry.getDataBinding(dataBindingId);
        WrapperHandler wrapperHandler = dataBinding == null ? null : dataBinding.getWrapperHandler();
        if (wrapperHandler == null && required) {
            throw new TransformationException(
                                              "No wrapper handler is provided for databinding: " + dataBindingId);
        }
        return wrapperHandler;
View Full Code Here

TOP

Related Classes of org.apache.tuscany.spi.databinding.WrapperHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.