Package org.apache.tuscany.sca.databinding

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


    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);

        ExtensionPointRegistry registry = new DefaultExtensionPointRegistry();
        JAXBContextHelper contextHelper = JAXBContextHelper.getInstance(registry);
        // Force the JAXBContext to be cached
        contextHelper.createJAXBContext(tContext, true);
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(new DefaultExtensionPointRegistry()).transform(po.getValue(), tContext);
        StringWriter sw = new StringWriter();
        om.serializeAndConsume(sw);
        System.out.println(sw.toString());
    }
View Full Code Here

    }

    @Test
    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

        Object json = t1.transform(bean, null);
        System.out.println(json);
        JSON2Object t2 = new JSON2Object();

        TransformationContext context = new TransformationContextImpl();
        context.setTargetDataType(new DataTypeImpl(bean == null ? Object.class : bean.getClass(), null));
        Object newBean = t2.transform(json, context);

        if (newBean != null && newBean.getClass().isArray()) {
            int len = Array.getLength(newBean);
            Assert.assertEquals(Array.getLength(bean), len);
View Full Code Here

        me.setYou(you);
        Object2JSON t1 = new Object2JSON();
        Object result = t1.transform(me, null);
        System.out.println(result);
        JSON2Object t2 = new JSON2Object();
        TransformationContext context = new TransformationContextImpl();
        context.setTargetDataType(new DataTypeImpl(MyBean.class, null));
        Object v = t2.transform(result.toString(), context);
        Assert.assertTrue(v instanceof MyBean);
        //        String json =
        //            "{\"age\":30,\"books\":[],\"friends\":[\"John\",\"Mike\"],\"name\":\"Me\",\"vip\":true,\"you\":{\"id\":123,\"name\":null}}";
        //        Assert.assertEquals(json, result.toString());
View Full Code Here

    public void testString2JSON() throws Exception {
        Object2JSON t1 = new Object2JSON();
        Object result = t1.transform("ABC", null);
        System.out.println(result);
        JSON2Object t2 = new JSON2Object();
        TransformationContext context = new TransformationContextImpl();
        context.setTargetDataType(new DataTypeImpl(String.class, null));
        Object v = t2.transform(result, context);
        Assert.assertTrue(v instanceof String);
        Assert.assertEquals("ABC", v);
    }
View Full Code Here

    public void testStringArray2JSON() throws Exception {
        Object2JSON t1 = new Object2JSON();
        Object result = t1.transform(new String[] {"ABC", "DF"}, null);
        System.out.println(result);
        JSON2Object t2 = new JSON2Object();
        TransformationContext context = new TransformationContextImpl();
        context.setTargetDataType(new DataTypeImpl(String[].class, null));
        Object v = t2.transform(result, context);
        Assert.assertTrue(v instanceof String[]);
        String[] strs = (String[])v;
        Assert.assertEquals("ABC", strs[0]);
        Assert.assertEquals("DF", strs[1]);
View Full Code Here

        mediator = new MediatorImpl(dataBindingRegistry, registry);
    }

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

TOP

Related Classes of org.apache.tuscany.sca.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.