Package org.apache.tuscany.spi.databinding

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


        Assert.assertEquals(root.getNamespaceURI(), "http://www.example.com/IPO");
        Assert.assertEquals(root.getLocalName(), "purchaseOrder");
    }

    public void testTransform2() {
        TransformationContext context = createTransformationContext(String.class, Writer.class);
        Writer writer = new StringWriter();
        mediator.mediate(IPO_XML, writer, context.getSourceDataType(), context.getTargetDataType(), null);
        String str = writer.toString();
        Assert.assertTrue(str != null && str.indexOf("<shipDate>1999-12-05</shipDate>") != -1);
    }
View Full Code Here


        Object[] source = new Object[] {"cust001", IPO_XML, Integer.valueOf(1)};
        Input2InputTransformer t = new Input2InputTransformer();
        t.setDataBindingRegistry(dataBindingRegistry);
        t.setMediator(m);

        TransformationContext context = new TransformationContextImpl();
        List<DataType<Class>> types = new ArrayList<DataType<Class>>();
        types.add(new DataType<Class>(Object.class.getName(), String.class, String.class));
        types.add(new DataType<Class>("java.lang.String", String.class, String.class));
        types.add(new DataType<Class>(Object.class.getName(), int.class, int.class));
        DataType<List<DataType<Class>>> inputType1 =
            new DataType<List<DataType<Class>>>("idl:input", Object[].class, types);
        context.setSourceDataType(inputType1);
        context.setTargetDataType(op.getInputType());
        Object[] results = t.transform(source, context);
        assertEquals(1, results.length);
        assertTrue(results[0] instanceof Element);
        Element element = (Element)results[0];
        assertEquals("http://example.com/order.xsd", element.getNamespaceURI());
        assertEquals("checkOrderStatus", element.getLocalName());

        TransformationContext context1 = new TransformationContextImpl();
        DataType<DataType> sourceType =
            new DataType<DataType>("idl:output", Object.class, op.getOutputType());
        sourceType.setMetadata(OPERATION_KEY, op.getOutputType().getMetadata(OPERATION_KEY));

        context1.setSourceDataType(sourceType);
        DataType<DataType> targetType =
            new DataType<DataType>("idl:output", Object.class,
                                   new DataType<Class>("java.lang.Object", String.class, String.class));
        context1.setTargetDataType(targetType);

        Document factory = DOMHelper.newDocument();
        Element responseElement =
            factory.createElementNS("http://example.com/order.wsdl", "p:checkOrderStatusResponse");
        Element status = factory.createElement("status");
View Full Code Here

        DataBindingRegistry dataBindingRegistry = new DataBindingRegistryImpl();
        mediator.setDataBindingRegistry(dataBindingRegistry);
    }

    private TransformationContext createTransformationContext(Class sourceType, Class targetType) {
        TransformationContext context = new TransformationContextImpl();
        DataType sourceDataType = new DataType<Class>(sourceType, sourceType);
        DataType targetDataType = new DataType<Class>(targetType, targetType);
        context.setSourceDataType(sourceDataType);
        context.setTargetDataType(targetDataType);
        return context;
    }
View Full Code Here

        context.setTargetDataType(targetDataType);
        return context;
    }

    public void testTransform1() {
        TransformationContext context = createTransformationContext(String.class, Node.class);
        Object node =
            mediator.mediate(IPO_XML, context.getSourceDataType(), context.getTargetDataType(), null);
        Assert.assertTrue(node instanceof Document);
        Element root = ((Document)node).getDocumentElement();
        Assert.assertEquals(root.getNamespaceURI(), "http://www.example.com/IPO");
        Assert.assertEquals(root.getLocalName(), "purchaseOrder");
    }
View Full Code Here

        super.setUp();
    }

    public void testMap() throws Exception {
        SimpleTypeMapperExtension extension = new SimpleTypeMapperExtension();
        TransformationContext context = EasyMock.createMock(TransformationContext.class);
        Map<Class<?>, Object> metaData = new HashMap<Class<?>, Object>();
        EasyMock.expect(context.getMetadata()).andReturn(metaData).anyTimes();
        EasyMock.replay(context);

        NamespaceContext namespaceContext = EasyMock.createMock(NamespaceContext.class);
        EasyMock.expect(namespaceContext.getNamespaceURI(EasyMock.eq("f"))).andReturn("http://foo")
            .anyTimes();
        EasyMock.expect(namespaceContext.getPrefix(EasyMock.eq("http://foo"))).andReturn("f").anyTimes();
        EasyMock.replay(namespaceContext);
        context.getMetadata().put(NamespaceContext.class, namespaceContext);
        for (TypeInfo simpleType : SimpleTypeMapperExtension.XSD_SIMPLE_TYPES.values()) {
            String name = simpleType.getQName().getLocalPart();
            Object value = SAMPLE_VALUES.get(name);
            if (value instanceof String[]) {
                for (String s : (String[])value) {
View Full Code Here

            InputStream in = getNodeStream(input);
            XMLInputFactory staxFactory = XMLInputFactory.newInstance();
            XMLStreamReader reader = staxFactory.createXMLStreamReader(in);

            XMLStreamReader2XMLDocument transformer = new XMLStreamReader2XMLDocument();
            TransformationContext context = new TransformationContextImpl();
            DataType<QName> binding = new DataType<QName>(DataObject.class, null);
            binding.setMetadata(TypeHelper.class.getName(), callback.getTypeHelper());
            context.setTargetDataType(binding);
            XMLDocument document = transformer.transform(reader, context);

            boolean isWrapped = false;
            return toObjects(document, isWrapped);
        } catch (Exception e) {
View Full Code Here

            XMLInputFactory staxFactory = XMLInputFactory.newInstance(
                "javax.xml.stream.XMLInputFactory", getClass().getClassLoader());
            XMLStreamReader reader = staxFactory.createXMLStreamReader(in);

            XMLStreamReader2XMLDocument transformer = new XMLStreamReader2XMLDocument();
            TransformationContext context = new TransformationContextImpl();
            DataType<QName> binding = new DataType<QName>(DataObject.class, null);
            binding.setMetadata(TypeHelper.class.getName(), callback.getTypeHelper());
            context.setTargetDataType(binding);
            XMLDocument document = transformer.transform(reader, context);

            //boolean isWrapped = true;
            Object[] objects = toObjects(document, true);
View Full Code Here

TOP

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

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.