Examples of XMLBinding

More advanced bindings can also be created through sub-classing.[code] // XML binding using reflection. public ReflectionBinding extends XMLBinding { protected XMLFormat getFormat(Class forClass) { Field[] fields = forClass.getDeclaredFields(); return new XMLReflectionFormat(fields); } } // XML binding read from DTD input source. public DTDBinding extends XMLBinding { public DTDBinding(InputStream dtd) { ... } } // XML binding overriding default formats. public MyBinding extends XMLBinding { // Non-static formats use unmapped XMLFormat instances. XMLFormat myStringFormat = new XMLFormat(null) {...} XMLFormat myCollectionFormat = new XMLFormat(null) {...} protected XMLFormat getFormat(Class forClass) throws XMLStreamException { if (String.class.equals(forClass)) return myStringFormat; if (Collection.class.isAssignableFrom(forClass)) return myCollectionFormat; return super.getFormat(cls); } } [/code]

The default XML binding implementation supports all static XML formats (static members of the classes being mapped) as well as the following types:

@author Jean-Marie Dautelle @version 5.4, December 1, 2009
  • org.apache.cxf.binding.xml.XMLBinding
  • org.eclipse.sapphire.modeling.xml.annotations.XmlBinding
  • org.milyn.javabean.binding.xml.XMLBinding
    XML Binding class.

    This class is designed specifically for reading and writing XML data (does not work for other data formats) to and from Java Object models using nothing more than standard <jb:bean> configurations i.e. no need to write a template for serializing the Java Objects to an output character based format, as with Smooks v1.4 and before. @author tom.fennelly@gmail.com @since 1.5


  • Examples of org.eclipse.sapphire.modeling.xml.annotations.XmlBinding

        {
            final Value<?> property = (Value<?>) property();
            final ValueProperty pdef = property.definition();
            final XmlNamespaceResolver xmlNamespaceResolver = resource().getXmlNamespaceResolver();
           
            final XmlBinding genericBindingAnnotation = pdef.getAnnotation( XmlBinding.class );
           
            if( genericBindingAnnotation != null )
            {
                this.path = new XmlPath( genericBindingAnnotation.path(), xmlNamespaceResolver );
                this.removeNodeOnSetIfNull = true;
            }
            else
            {
                final XmlValueBinding bindingAnnotation = pdef.getAnnotation( XmlValueBinding.class );
    View Full Code Here

    Examples of org.milyn.javabean.binding.xml.XMLBinding

         * @param beanModel Bean model.
         * @param direction Binding direction.
         */
        protected XMLBindingTransformer(final QName from, final QName to, Smooks smooks, ModelSet beanModel, BindingDirection direction) {
            super(from, to);
            _xmlBinding = new XMLBinding(smooks);
            _xmlBinding.setOmitXMLDeclaration(true); // XML decl causes problems for StAX code used by SOAP handler
            _xmlBinding.intiailize();
            _bean = beanModel.getModels().values().iterator().next();
            _direction = direction;
        }
    View Full Code Here

    Examples of org.milyn.javabean.binding.xml.XMLBinding

    * @author <a href="mailto:tom.fennelly@gmail.com">tom.fennelly@gmail.com</a>
    */
    public class POTypeTest extends TestCase {

        public void test() throws IOException, SAXException {
            XMLBinding xmlBinding =
                    new XMLBinding().add(getClass().getResourceAsStream("POType-binding.xml")).intiailize();

            String poXML = StreamUtils.readStreamAsString(getClass().getResourceAsStream("po.xml"));
            POType po = xmlBinding.fromXML(new StringSource(poXML), POType.class);

            StringWriter writer = new StringWriter();
            xmlBinding.toXML(po, writer);

            XMLUnit.setIgnoreWhitespace(true);
            XMLUnit.compareXML(poXML, writer.toString());
        }
    View Full Code Here

    Examples of org.milyn.javabean.binding.xml.XMLBinding

            test_pre_created_Smooks("config4");
            test_post_created_Smooks("config4");
        }

        public void test_Person_binding() throws IOException, SAXException {
            XMLBinding xmlBinding = new XMLBinding().add(getClass().getResourceAsStream("config5/person-binding-config.xml"));
            xmlBinding.intiailize();

            Person person = xmlBinding.fromXML("<person name='Max' age='50' />", Person.class);
            String xml = xmlBinding.toXML(person);
            XMLUnit.setIgnoreWhitespace(true);
            XMLAssert.assertXMLEqual("<person name='Max' age='50' />", xml);

        }
    View Full Code Here

    Examples of org.milyn.javabean.binding.xml.XMLBinding

            test_post_created_Smooks("config6");
        }

        public void test_add_fails_after_smooks_constructed() throws IOException, SAXException {
            Smooks smooks = new Smooks(getClass().getResourceAsStream("config1/order-binding-config.xml"));
            XMLBinding xmlBinding = new XMLBinding(smooks);

            try {
                xmlBinding.add("blah");
            } catch (IllegalStateException e) {
                assertEquals("Illegal call to method after all configurations have been added.", e.getMessage());
            }
        }
    View Full Code Here

    Examples of org.milyn.javabean.binding.xml.XMLBinding

        }

        private void test_pre_created_Smooks(String config) throws IOException, SAXException {
            String inputXML = StreamUtils.readStreamAsString(getClass().getResourceAsStream(config + "/order.xml"));
            Smooks smooks = new Smooks(getClass().getResourceAsStream(config + "/order-binding-config.xml"));
            XMLBinding xmlBinding = new XMLBinding(smooks);
            xmlBinding.intiailize();

            assertTrue("Should be a binding only config.", ModelSet.get(smooks.getApplicationContext()).isBindingOnlyConfig());

            test(inputXML, xmlBinding);
        }
    View Full Code Here

    Examples of org.milyn.javabean.binding.xml.XMLBinding

            test(inputXML, xmlBinding);
        }

        private void test_post_created_Smooks(String config) throws IOException, SAXException {
            String inputXML = StreamUtils.readStreamAsString(getClass().getResourceAsStream(config + "/order.xml"));
            XMLBinding xmlBinding = new XMLBinding().add(getClass().getResourceAsStream(config + "/order-binding-config.xml"));
            xmlBinding.intiailize();

            test(inputXML, xmlBinding);
        }
    View Full Code Here

    Examples of org.milyn.javabean.binding.xml.XMLBinding

        /**
         * Read using v1 binding config and write back out using v2 binding config... i.e. transform from v1 to v2...
         */
        @Test
        public void test() throws IOException, SAXException {
            XMLBinding xmlV1Binding = new XMLBinding().add("v1-binding-config.xml");
            XMLBinding xmlV2Binding = new XMLBinding().add("v2-binding-config.xml");

            xmlV1Binding.intiailize();
            xmlV2Binding.intiailize();

            Order order = xmlV1Binding.fromXML(new StringSource(Main.orderV1XMLMessage), Order.class);

            StringWriter orderWriter = new StringWriter();
            xmlV2Binding.toXML(order, orderWriter);

            XMLUnit.setIgnoreWhitespace(true);
            XMLAssert.assertXMLEqual(Main.orderV2XMLMessage, orderWriter.toString());
        }
    View Full Code Here

    Examples of org.milyn.javabean.binding.xml.XMLBinding

        public static String orderXMLMessage = readInputMessage();

        public static void main(String[] args) throws IOException, SAXException, SmooksException {

            // Create and initilise the XMLBinding instance...
            XMLBinding xmlBinding = new XMLBinding().add("smooks-config.xml");
            xmlBinding.intiailize();

            // Read the order XML into the Order Object model...
            Order order = xmlBinding.fromXML(new StringSource(orderXMLMessage), Order.class);

            // Do something with the order....

            // Write the Order object model instance back out to XML...
            String outXML = xmlBinding.toXML(order)// (Note: There's also a version of toXML() that takes a Writer)

            // Display read/write info to the example user...
            displayInputMessage(orderXMLMessage);
            displayReadJavaObjects(order);
            displayWriteXML(outXML);
    View Full Code Here

    Examples of org.milyn.javabean.binding.xml.XMLBinding

    * @author <a href="mailto:tom.fennelly@gmail.com">tom.fennelly@gmail.com</a>
    */
    public class XMLReadWriteTest extends TestCase {

        public void test() throws IOException, SAXException {
            XMLBinding xmlBinding = new XMLBinding().add("smooks-config.xml");
            xmlBinding.intiailize();

            Order order = xmlBinding.fromXML(new StringSource(Main.orderXMLMessage), Order.class);

            assertNotNull(order);
            assertNotNull(order.getHeader());
            assertNotNull(order.getOrderItems());
            assertEquals(2, order.getOrderItems().size());

            assertEquals(1163616328000L, order.getHeader().getDate().getTime());
            assertEquals("Joe", order.getHeader().getCustomerName());
            assertEquals(new Long(123123), order.getHeader().getCustomerNumber());

            OrderItem orderItem = order.getOrderItems().get(0);
            assertEquals(8.90d, orderItem.getPrice());
            assertEquals(111, orderItem.getProductId());
            assertEquals(new Integer(2), orderItem.getQuantity());

            orderItem = order.getOrderItems().get(1);
            assertEquals(5.20d, orderItem.getPrice());
            assertEquals(222, orderItem.getProductId());
            assertEquals(new Integer(7), orderItem.getQuantity());

            StringWriter orderWriter = new StringWriter();
            xmlBinding.toXML(order, orderWriter);

            XMLUnit.setIgnoreWhitespace(true);
            XMLAssert.assertXMLEqual(Main.orderXMLMessage, orderWriter.toString());
        }
    View Full Code Here
    TOP
    Copyright © 2018 www.massapi.com. 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.