Package org.apache.tuscany.sca.databinding

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


    }

    private WrapperHandler getWrapperHandler(String dataBindingId, boolean required) {
        WrapperHandler wrapperHandler = null;
        if (dataBindingId != null) {
            DataBinding dataBinding = mediator.getDataBindings().getDataBinding(dataBindingId);
            wrapperHandler = dataBinding == null ? null : dataBinding.getWrapperHandler();
        }
        if (wrapperHandler == null && required) {
            throw new TransformationException("No wrapper handler is provided for databinding: " + dataBindingId);
        }
        return wrapperHandler;
View Full Code Here


    }

    private WrapperHandler getWrapperHandler(String dataBindingId, boolean required) {
        WrapperHandler wrapperHandler = null;
        if (dataBindingId != null) {
            DataBinding dataBinding = mediator.getDataBindings().getDataBinding(dataBindingId);
            wrapperHandler = dataBinding == null ? null : dataBinding.getWrapperHandler();
        }
        if (wrapperHandler == null && required) {
            throw new TransformationException("No wrapper handler is provided for databinding: " + dataBindingId);
        }
        return wrapperHandler;
View Full Code Here

            || QName.class == clazz) {
            // Immutable classes
            return data;
        }

        DataBinding javaBeansDataBinding = dataBindings.getDataBinding(JavaBeansDataBinding.NAME);
        // FIXME: The JAXB databinding is hard-coded here
        DataBinding jaxbDataBinding = dataBindings.getDataBinding("javax.xml.bind.JAXBElement");
        DataBinding dataBinding = dataBindings.getDataBinding(dataType.getDataBinding());
        // If no databinding was specified, introspect the given arg to
        // determine its databinding
        if (dataBinding == null) {
            dataType = dataBindings.introspectType(data, operation);
            if (dataType != null) {
                String db = dataType.getDataBinding();
                dataBinding = dataBindings.getDataBinding(db);
                if (dataBinding == null && db != null) {
                    return data;
                }
            }
            if (dataBinding == null) {

                // Default to the JavaBean databinding
                dataBinding = dataBindings.getDataBinding(JavaBeansDataBinding.NAME);
            }
        }

        // Use the JAXB databinding to copy non-Serializable data
        if (dataBinding == javaBeansDataBinding) {

            // If the input data is an array containing non Serializable elements
            // use JAXB
            clazz = data.getClass();
            if (clazz.isArray()) {
                if (Array.getLength(data) != 0) {
                    Object element = Array.get(data, 0);
                    if (element != null && !(element instanceof Serializable)) {
                        dataBinding = jaxbDataBinding;
                    }
                }
            } else {

                // If the input data is not Serializable use JAXB
                if (!((data instanceof Serializable) || (data instanceof Cloneable))) {
                    dataBinding = jaxbDataBinding;
                }
            }
        }

        if (dataBinding != null) {
            return dataBinding.copy(data, dataType, operation);
        } else {
            return data;
        }
    }
View Full Code Here

        registry = new DefaultDataBindingExtensionPoint();
    }

    @SuppressWarnings("unchecked")
    public void testRegistry() {
        DataBinding db1 = createMock(DataBinding.class);
        expect(db1.getName()).andReturn(ContentHandler.class.getName()).anyTimes();
        DataType<Class> dataType1 = new DataTypeImpl<Class>(ContentHandler.class, ContentHandler.class);
        expect(db1.introspect(dataType1, null)).andReturn(true);
        expect(db1.introspect(EasyMock.not(EasyMock.same(dataType1)), (Operation) EasyMock.isNull()))
            .andReturn(false).anyTimes();
        replay(db1);

        registry.addDataBinding(db1);

        DataBinding db2 = createMock(DataBinding.class);
        expect(db2.getName()).andReturn(XMLStreamReader.class.getName()).anyTimes();
        DataType<Class> dataType2 = new DataTypeImpl<Class>(XMLStreamReader.class, XMLStreamReader.class);
        expect(db2.introspect(dataType2, null)).andReturn(true);
        expect(db2.introspect(EasyMock.not(EasyMock.same(dataType2)), (Operation) EasyMock.isNull()))
            .andReturn(false).anyTimes();
        replay(db2);

        registry.addDataBinding(db2);

        // Lookup by name
        String name = db1.getName();
        DataBinding db3 = registry.getDataBinding(name);
        assertSame(db1, db3);

        DataType dt = new DataTypeImpl<Class>(ContentHandler.class, null);
        registry.introspectType(dt, null);
        assertEquals(dataType1.getLogical(), ContentHandler.class);
        //FIXME does not match with dynamically loaded databindings
        //assertTrue(dt.getDataBinding().equalsIgnoreCase("java.lang.Object"));

        registry.removeDataBinding(name);
        DataBinding db4 = registry.getDataBinding(name);
        assertNull(db4);

        dt = new DataTypeImpl<Class>(null, String.class, null);
        registry.introspectType(dt, null);
        //FIXME does not match with dynamically loaded databindings
View Full Code Here

            result = super.invokeMethod(targetObject, m, msg);

            if (operation.getOutputType() != null) {
                String dataBindingId = operation.getOutputType().getDataBinding();
                DataBinding dataBinding = registry.getDataBinding(dataBindingId);
                result = copy(result, operation.getOutputType(), dataBinding);
            }
        }
        return result;
    }
View Full Code Here

                if (copiedArg != null) {
                    copiedArgs[i] = copiedArg;
                } else {
                    DataType dt = operation.getInputType().getLogical().get(i);
                    String dataBindingId = dt.getDataBinding();
                    DataBinding dataBinding = registry.getDataBinding(dataBindingId);
                    copiedArg = copy(args[i], dt, dataBinding);
                    map.put(args[i], copiedArg);
                    copiedArgs[i] = copiedArg;
                }
            }
View Full Code Here

            copiedArg = argDataBinding.copy(arg, dataType, operation);
        } else {
            copiedArg = arg;
            dataType = registry.introspectType(arg, operation);
            if (dataType != null) {
                DataBinding binding = registry.getDataBinding(dataType.getDataBinding());
                if (binding != null) {
                    copiedArg = binding.copy(arg, dataType, operation);
                }
            }
            // FIXME: What to do if it's not recognized?
        }
        return copiedArg;
View Full Code Here

            dataType = (DataType)dataType.getLogical();
            db = dataType.getDataBinding();
        }
        XMLTypeHelper helper = helpers.get(db);
        if (helper == null) {
            DataBinding dataBinding = dataBindings.getDataBinding(db);
            if (dataBinding == null) {
                QName element = name;
                if (element == null || dataType.getLogical() instanceof XMLType) {
                    XMLType xmlType = (XMLType)dataType.getLogical();
                    if (xmlType.getElementName() != null) {
                        element = xmlType.getElementName();
                    }
                }
                return new ElementInfo(element, new TypeInfo(ANYTYPE_QNAME, false, null));
                // throw new ServiceRuntimeException("No data binding for " + db);
            }

            helper = dataBinding.getXMLTypeHelper();
            if (helper == null) {
                // Default to JAXB
                helper = helpers.get(JAXBDataBinding.NAME);
                if (helper == null) {
                    helper = dataBindings.getDataBinding(JAXBDataBinding.NAME).getXMLTypeHelper();
View Full Code Here

    }

    private WrapperHandler getWrapperHandler(String dataBindingId, boolean required) {
        WrapperHandler wrapperHandler = null;
        if (dataBindingId != null) {
            DataBinding dataBinding = mediator.getDataBindings().getDataBinding(dataBindingId);
            wrapperHandler = dataBinding == null ? null : dataBinding.getWrapperHandler();
        }
        if (wrapperHandler == null && required) {
            throw new TransformationException("No wrapper handler is provided for databinding: " + dataBindingId);
        }
        return wrapperHandler;
View Full Code Here

    }

    private WrapperHandler getWrapperHandler(String dataBindingId, boolean required) {
        WrapperHandler wrapperHandler = null;
        if (dataBindingId != null) {
            DataBinding dataBinding = mediator.getDataBindings().getDataBinding(dataBindingId);
            wrapperHandler = dataBinding == null ? null : dataBinding.getWrapperHandler();
        }
        if (wrapperHandler == null && required) {
            throw new TransformationException("No wrapper handler is provided for databinding: " + dataBindingId);
        }
        return wrapperHandler;
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.databinding.DataBinding

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.