Package org.apache.tuscany.sca.databinding

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


        return context;
    }

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


        Assert.assertEquals(root.getLocalName(), "purchaseOrder");
    }

    @Test
    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 result = source;
        int size = path.size();
        int i = 0;
        while (i < size) {
            Transformer transformer = path.get(i);
            TransformationContext context =
                createTransformationContext(sourceDataType, targetDataType, size, i, transformer, metadata);
            // the source and target type
            if (transformer instanceof PullTransformer) {
                // For intermediate node, set data type to null
                result = ((PullTransformer)transformer).transform(result, context);
View Full Code Here

        if (metadata != null) {
            copy.putAll(metadata);
        }
        copy.put(ExtensionPointRegistry.class.getName(), registry);

        TransformationContext context = new TransformationContextImpl(sourceType, targetType, copy);
        return context;
    }
View Full Code Here

        List<Transformer> path = getTransformerChain(sourceDataType, targetDataType);
        Object result = source;
        int size = path.size();
        for (int i = 0; i < size; i++) {
            Transformer transformer = path.get(i);
            TransformationContext context =
                createTransformationContext(sourceDataType, targetDataType, size, i, transformer, metadata);

            if (transformer instanceof PullTransformer) {
                result = ((PullTransformer)transformer).transform(result, context);
            } else if (transformer instanceof PushTransformer) {
View Full Code Here

        Object result = source;
        int size = path.size();
        int i = 0;
        while (i < size) {
            Transformer transformer = path.get(i);
            TransformationContext context = createTransformationContext(sourceDataType,
                                                                        targetDataType,
                                                                        size,
                                                                        i,
                                                                        transformer,
                                                                        metadata);
View Full Code Here

        DataType sourceType = (index == 0) ? sourceDataType : new DataTypeImpl<Object>(transformer
            .getSourceDataBinding(), Object.class, sourceDataType.getLogical());
        DataType targetType = (index == size - 1) ? targetDataType : new DataTypeImpl<Object>(transformer
            .getTargetDataBinding(), Object.class, targetDataType.getLogical());
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        TransformationContext context = new TransformationContextImpl(sourceType, targetType, classLoader, metadata);
        return context;
    }
View Full Code Here

        List<Transformer> path = getTransformerChain(sourceDataType, targetDataType);
        Object result = source;
        int size = path.size();
        for (int i = 0; i < size; i++) {
            Transformer transformer = path.get(i);
            TransformationContext context = createTransformationContext(sourceDataType,
                                                                        targetDataType,
                                                                        size,
                                                                        i,
                                                                        transformer,
                                                                        metadata);
View Full Code Here

        super.setUp();
    }

    public void testMap() throws Exception {
        SimpleTypeMapperImpl extension = new SimpleTypeMapperImpl();
        TransformationContext context = EasyMock.createMock(TransformationContext.class);
        Map<String, Object> metaData = new HashMap<String, 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.getName(), namespaceContext);
        for (TypeInfo simpleType : SimpleTypeMapperImpl.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

        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.