Package org.apache.tuscany.sca.databinding.impl

Examples of org.apache.tuscany.sca.databinding.impl.TransformationContextImpl


    private static final QName XSI_NIL = new QName("http://www.w3.org/2001/XMLSchema-instance", "nil", "xsi");

    public final void testNil() {
        Object2OMElement t1 = new Object2OMElement();
        TransformationContext context = new TransformationContextImpl();
        DataType<XMLType> dataType =
            new DataTypeImpl<XMLType>(int.class, new XMLType(new QName("http://ns1", "nilElement"),
                                                             SimpleTypeMapperImpl.XSD_INT));
        context.setTargetDataType(dataType);
        OMElement element = t1.transform(null, context);
        OMAttribute attribute = element.getAttribute(XSI_NIL);
        Assert.assertNotNull(attribute);
        Assert.assertEquals("true", attribute.getAttributeValue());
    }
View Full Code Here


    @Test
    public void testTransform() throws Exception {
        DataType<?> sourceDataType = new DataTypeImpl<XMLType>(PurchaseOrderType.class, XMLType.UNKNOWN);
        QName qname = new QName("http://www.example.com/IPO", "purchaseOrder");
        DataType<?> targetDataType = new DataTypeImpl<XMLType>(PurchaseOrderType.class, new XMLType(qname, null));
        TransformationContext tContext = new TransformationContextImpl();
        tContext.setSourceDataType(sourceDataType);
        tContext.setTargetDataType(targetDataType);

        StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(XML.getBytes("UTF-8")));
        OMElement root = builder.getDocumentElement();
        OMElement next = (OMElement)root.getChildElements().next();
        OMElement po = (OMElement)next.getChildElements().next();
View Full Code Here

    @Test
    public void testTransformElement() throws Exception {
        JAXBElement<PurchaseOrderType> po = createPO();
        DataType<?> sourceDataType = new DataTypeImpl<XMLType>(PurchaseOrderType.class, XMLType.UNKNOWN);
        DataType<?> targetDataType = new DataTypeImpl<XMLType>(PurchaseOrderType.class, new XMLType(po.getName(), null));
        TransformationContext tContext = new TransformationContextImpl();
        tContext.setSourceDataType(sourceDataType);
        tContext.setTargetDataType(targetDataType);

        // Force the JAXBContext to be cached
        JAXBContextHelper.createJAXBContext(tContext, true);

        long start = System.currentTimeMillis();
View Full Code Here

    @Test
    public void testTransformType() throws Exception {
        JAXBElement<PurchaseOrderType> po = createPO();
        DataType<?> sourceDataType = new DataTypeImpl<XMLType>(PurchaseOrderType.class, XMLType.UNKNOWN);
        DataType<?> targetDataType = new DataTypeImpl<XMLType>(PurchaseOrderType.class, new XMLType(po.getName(), null));
        TransformationContext tContext = new TransformationContextImpl();
        tContext.setSourceDataType(sourceDataType);
        tContext.setTargetDataType(targetDataType);
        OMElement om = new JAXB2OMElement().transform(po.getValue(), tContext);
        StringWriter sw = new StringWriter();
        om.serializeAndConsume(sw);
        System.out.println(sw.toString());
    }
View Full Code Here

            .contains("<xsl:root xmlns:xsl=\"http://foo.com\"><data>my json string</data></xsl:root>"));
    }

    public void testJSON2OMElement() throws Exception {
        JSON2OMElement t1 = new JSON2OMElement();
        TransformationContext context = new TransformationContextImpl();
        DataType dt = new DataTypeImpl(Object.class, new XMLType(new QName("http://foo.com", "root"), null));
        context.setTargetDataType(dt);
        OMElement element = t1.transform(new JSONObject(JSON_STR), context);
        StringWriter writer = new StringWriter();
        element.serialize(writer);
        // System.out.println(writer.toString());
    }
View Full Code Here

    public void testTransform() throws Exception {
        Reader2JAXB t0 = new Reader2JAXB();

        DataType targetDataType = new DataTypeImpl<Class>(PurchaseOrderType.class, null);

        TransformationContext tContext = new TransformationContextImpl();
        tContext.setTargetDataType(targetDataType);

        Object object1 = t0.transform(new StringReader(IPO_XML), tContext);

        DataType sourceDataType = new DataTypeImpl<Class>(PurchaseOrderType.class, null);

        TransformationContext tContext1 = new TransformationContextImpl();
        tContext1.setSourceDataType(sourceDataType);

        JAXB2Node t1 = new JAXB2Node();
        Node node = t1.transform(object1, tContext1);

        Assert.assertNotNull(node);
View Full Code Here

        QName root = new QName("http://www.example.com/IPO", "purchaseOrder");
        DataType targetDataType = new DataTypeImpl<XMLType>(PurchaseOrderType.class, new XMLType(root, null));
        // targetDataType.setMetadata(JAXBContextHelper.JAXB_CONTEXT_PATH, contextPath);

        TransformationContext tContext = new TransformationContextImpl();
        tContext.setTargetDataType(targetDataType);
        Object object1 = t0.transform(new StringReader(IPO_XML), tContext);

        DataType sourceDataType = new DataTypeImpl<XMLType>(PurchaseOrderType.class, new XMLType(root, null));
        // sourceDataType.setMetadata(JAXBContextHelper.JAXB_CONTEXT_PATH, contextPath);

        TransformationContext tContext1 = new TransformationContextImpl();
        tContext1.setSourceDataType(sourceDataType);

        JAXB2Node t1 = new JAXB2Node();
        Node node = t1.transform(object1, tContext1);

        Assert.assertNotNull(node);
View Full Code Here

    @Test
    public void testTransform3() throws Exception {

        DataType sourceDataType = new DataTypeImpl<Class>(PurchaseOrderType.class, null);

        TransformationContext tContext1 = new TransformationContextImpl();
        tContext1.setSourceDataType(sourceDataType);


        JAXB2Node t1 = new JAXB2Node();
        PurchaseOrderType po = new ObjectFactory().createPurchaseOrderType();
        Node node = t1.transform(po, tContext1);
View Full Code Here

    private static final QName XSI_NIL = new QName("http://www.w3.org/2001/XMLSchema-instance", "nil", "xsi");

    public final void testNil() {
        Object2OMElement t1 = new Object2OMElement();
        TransformationContext context = new TransformationContextImpl();
        DataType<XMLType> dataType =
            new DataTypeImpl<XMLType>(int.class, new XMLType(new QName("http://ns1", "nilElement"),
                                                             SimpleTypeMapperImpl.XSD_INT));
        context.setTargetDataType(dataType);
        OMElement element = t1.transform(null, context);
        OMAttribute attribute = element.getAttribute(XSI_NIL);
        Assert.assertNotNull(attribute);
        Assert.assertEquals("true", attribute.getAttributeValue());
    }
View Full Code Here

    @Test
    public void testTransform() throws Exception {
        DataType<?> sourceDataType = new DataTypeImpl<XMLType>(PurchaseOrderType.class, XMLType.UNKNOWN);
        QName qname = new QName("http://www.example.com/IPO", "purchaseOrder");
        DataType<?> targetDataType = new DataTypeImpl<XMLType>(PurchaseOrderType.class, new XMLType(qname, null));
        TransformationContext tContext = new TransformationContextImpl();
        tContext.setSourceDataType(sourceDataType);
        tContext.setTargetDataType(targetDataType);

        StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(XML.getBytes("UTF-8")));
        OMElement root = builder.getDocumentElement();
        OMElement next = (OMElement)root.getChildElements().next();
        OMElement po = (OMElement)next.getChildElements().next();
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.databinding.impl.TransformationContextImpl

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.