Package org.apache.tuscany.sca.interfacedef

Examples of org.apache.tuscany.sca.interfacedef.DataType


        // wireService.checkCompatibility(source, target, false);
    }

    public void testIncompatibleOutputTypes() throws Exception {
        InterfaceContract source = new MockContract("FooContract");
        DataType sourceOutputType = new DataTypeImpl<Type>(String.class, String.class);
        Operation opSource1 = newOperation("op1");
        opSource1.setOutputType(sourceOutputType);
        Map<String, Operation> sourceOperations = new HashMap<String, Operation>();
        sourceOperations.put("op1", opSource1);
        source.getInterface().getOperations().addAll(sourceOperations.values());

        InterfaceContract target = new MockContract("FooContract");
        DataType targetOutputType = new DataTypeImpl<Type>(Integer.class, Integer.class);
        Operation opTarget = newOperation("op1");
        opTarget.setOutputType(targetOutputType);
        Map<String, Operation> targetOperations = new HashMap<String, Operation>();
        targetOperations.put("op1", opTarget);
        target.getInterface().getOperations().addAll(targetOperations.values());
View Full Code Here


        }
    }

    public void testFaultTypes() throws Exception {
        InterfaceContract source = new MockContract("FooContract");
        DataType sourceFaultType = new DataTypeImpl<Type>(String.class, String.class);
        List<DataType> sourceFaultTypes = new ArrayList<DataType>();
        sourceFaultTypes.add(0, sourceFaultType);
        Operation opSource1 = newOperation("op1");
        opSource1.setFaultTypes(sourceFaultTypes);
        Map<String, Operation> sourceOperations = new HashMap<String, Operation>();
        sourceOperations.put("op1", opSource1);
        source.getInterface().getOperations().addAll(sourceOperations.values());

        InterfaceContract target = new MockContract("FooContract");
        DataType targetFaultType = new DataTypeImpl<Type>(String.class, String.class);
        List<DataType> targetFaultTypes = new ArrayList<DataType>();
        targetFaultTypes.add(0, targetFaultType);

        Operation opTarget = newOperation("op1");
        opTarget.setFaultTypes(targetFaultTypes);
View Full Code Here

        mapper.checkCompatibility(source, target, false, false);
    }

    public void testSourceFaultTargetNoFaultCompatibility() throws Exception {
        InterfaceContract source = new MockContract("FooContract");
        DataType sourceFaultType = new DataTypeImpl<Type>(String.class, String.class);
        List<DataType> sourceFaultTypes = new ArrayList<DataType>();
        sourceFaultTypes.add(0, sourceFaultType);
        Operation opSource1 = newOperation("op1");
        opSource1.setFaultTypes(sourceFaultTypes);
        Map<String, Operation> sourceOperations = new HashMap<String, Operation>();
View Full Code Here

                return new Object[] {targetWrapper};
            }

            // 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);
            List<DataType> argTypes = wrapper.getUnwrappedInputType().getLogical();

            for (int i = 0; i < source.length; i++) {
                ElementInfo argElement = wrapper.getInputChildElements().get(i);
                DataType<XMLType> 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<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, 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());
View Full Code Here

                    // Default to <operationName>Response for doc-bare
                    String name = getValue(result.name(), documentStyle ? operationName + "Response" : "return");
                    QName element = new QName(ns, name);
                    if (!operation.hasReturnTypeVoid()) {
                        List<DataType> outputDataTypes = operation.getOutputType().getLogical();                   
                        DataType returnDataType = outputDataTypes.get(0);
                        if (returnDataType instanceof XMLType) {
                            ((XMLType)returnDataType).setElementName(element);
                        }
                    }
                }
                // Rather than relying on null wrapper, we use a flag with a clearer meaning.
                operation.setNotSubjectToWrapping(true);
            } else {

                RequestWrapper requestWrapper = method.getAnnotation(RequestWrapper.class);
                String ns = requestWrapper == null ? tns : getValue(requestWrapper.targetNamespace(), tns);
                String name =
                    requestWrapper == null ? operationName : getValue(requestWrapper.localName(), operationName);
                String wrapperBeanName = requestWrapper == null ? "" : requestWrapper.className();
                if ("".equals(wrapperBeanName)) {
                    wrapperBeanName = CodeGenerationHelper.getPackagePrefix(clazz) + capitalize(method.getName());
                }

                DataType<XMLType> inputWrapperDT = null;

                final String inputWrapperClassName = wrapperBeanName;
                final String inputNS = ns;
                final String inputName = name;
                inputWrapperDT = AccessController.doPrivileged(new PrivilegedAction<DataType<XMLType>>() {
                    public DataType<XMLType> run() {
                        try {
                            Class<?> wrapperClass = Class.forName(inputWrapperClassName, false, clazz.getClassLoader());
                            QName qname = new QName(inputNS, inputName);
                            DataType dt = new DataTypeImpl<XMLType>(wrapperClass, new XMLType(qname, qname));
                            dataBindingExtensionPoint.introspectType(dt, operation);
                            // TUSCANY-2505
                            if (dt.getLogical() instanceof XMLType) {
                                XMLType xmlType = (XMLType)dt.getLogical();
                                xmlType.setElementName(qname);
                            }
                            return dt;
                        } catch (ClassNotFoundException e) {
                            GeneratedClassLoader cl = new GeneratedClassLoader(clazz.getClassLoader());
                            return new GeneratedDataTypeImpl(xmlAdapterExtensionPoint, method, inputWrapperClassName, inputNS, inputName, true,
                                                             cl);
                        }
                    }
                });

                QName inputWrapper = inputWrapperDT.getLogical().getElementName();

                ResponseWrapper responseWrapper = method.getAnnotation(ResponseWrapper.class);
                ns = responseWrapper == null ? tns : getValue(responseWrapper.targetNamespace(), tns);
                name =
                    responseWrapper == null ? operationName + "Response" : getValue(responseWrapper.localName(),
                                                                                    operationName + "Response");
                wrapperBeanName = responseWrapper == null ? "" : responseWrapper.className();
                if ("".equals(wrapperBeanName)) {
                    wrapperBeanName =
                        CodeGenerationHelper.getPackagePrefix(clazz) + capitalize(method.getName()) + "Response";
                }

                DataType<XMLType> outputWrapperDT = null;
                final String outputWrapperClassName = wrapperBeanName;
                final String outputNS = ns;
                final String outputName = name;

                outputWrapperDT = AccessController.doPrivileged(new PrivilegedAction<DataType<XMLType>>() {
                    public DataType<XMLType> run() {
                        try {
                            Class<?> wrapperClass =
                                Class.forName(outputWrapperClassName, false, clazz.getClassLoader());
                            QName qname = new QName(outputNS, outputName);
                            DataType dt = new DataTypeImpl<XMLType>(wrapperClass, new XMLType(qname, qname));
                            dataBindingExtensionPoint.introspectType(dt, operation);
                            // TUSCANY-2505
                            if (dt.getLogical() instanceof XMLType) {
                                XMLType xmlType = (XMLType)dt.getLogical();
                                xmlType.setElementName(qname);
                            }
                            return dt;
                        } catch (ClassNotFoundException e) {
                            GeneratedClassLoader cl = new GeneratedClassLoader(clazz.getClassLoader());
View Full Code Here

    @SuppressWarnings("unchecked")
    private void introspectFaultTypes(Operation operation) {
        if (operation != null && operation.getFaultTypes() != null) {
            for (DataType exceptionType : operation.getFaultTypes()) {
                faultExceptionMapper.introspectFaultDataType(exceptionType, operation, true);
                DataType faultType = (DataType)exceptionType.getLogical();
                if (JavaExceptionDataBinding.NAME.equals(faultType.getDataBinding())) {
                    // The exception class doesn't have an associated bean class, so
                    // synthesize a virtual bean by introspecting the exception class.
                    createSyntheticBean(operation, exceptionType);
                }
            }
View Full Code Here

            }
        }
    }

    private void createSyntheticBean(Operation operation, DataType exceptionType) {
        DataType faultType = (DataType)exceptionType.getLogical();
        QName faultBeanName = ((XMLType)faultType.getLogical()).getElementName();
        List<DataType<XMLType>> beanDataTypes = new ArrayList<DataType<XMLType>>();
        for (Method aMethod : exceptionType.getPhysical().getMethods()) {
            if (Modifier.isPublic(aMethod.getModifiers()) && aMethod.getName().startsWith(GET)
                && aMethod.getParameterTypes().length == 0
                && JAXWSFaultExceptionMapper.isMappedGetter(aMethod.getName())) {
View Full Code Here

             * whether we can assume JAXWSJavaInterfaceProcessor was already used to process
             */
            if (input) {
                List<DataType> inputDTs = operation.getInputType().getLogical();
                for (int i = 0; i < inputDTs.size(); i++) {
                    DataType nextInput = inputDTs.get(i);
                    elements.set(i, getElementInfo(nextInput.getPhysical(), nextInput, elements.get(i).getQName(), helpers));
                }

            } else {
                List<DataType> outputDTs = operation.getOutputType().getLogical();
                for (int i = 0; i < outputDTs.size(); i++) {
                    DataType nextOutput = outputDTs.get(i);
                    elements.set(i, getElementInfo(nextOutput.getPhysical(), nextOutput, elements.get(i).getQName(), helpers));
                }
            }
        }
        return part;
    }
View Full Code Here

    }

    private static void getDataTypes(List<DataType> dataTypes, Operation op, boolean useWrapper) {
        WrapperInfo wrapper = op.getWrapper();
        if (useWrapper && wrapper != null) {
            DataType dt1 = wrapper.getInputWrapperType();
            if (dt1 != null) {
                dataTypes.add(dt1);
            }
            DataType dt2 = wrapper.getOutputWrapperType();
            if (dt2 != null) {
                dataTypes.add(dt2);
            }
        }
        // FIXME: [rfeng] We may need to find the referenced classes in the child types
        // else
        {
            for (DataType dt1 : op.getInputType().getLogical()) {
                dataTypes.add(dt1);
            }           
            for (DataType dt2 : op.getOutputType().getLogical()) {
                dataTypes.add(dt2);
            }
        }
        for (DataType<DataType> dt3 : op.getFaultTypes()) {
            DataType dt4 = dt3.getLogical();
            if (dt4 != null) {
                dataTypes.add(dt4);
            }
        }
    }
View Full Code Here

    public Message invokeResponse(Message msg) {
        if (msg.getBody() != null) {
            javax.jms.Message jmsMsg = (javax.jms.Message) msg.getBody();

            Operation op = msg.getOperation();
            DataType outputDataType = op.getOutputType();

            Class<?> outputType = null;
            if (outputDataType != null) {
                outputType = outputDataType.getPhysical();
            }

            if (outputType != null && javax.jms.Message.class.isAssignableFrom(outputType)) {
                msg.setBody(jmsMsg);
            } else {
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.interfacedef.DataType

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.