Package org.milyn.javabean.binding.xml

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


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

        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

        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

    }

    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

        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

    /**
     * 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

    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

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

    public static String orderV2XMLMessage = readInputMessage("v2-message.xml");

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

        // Create and initilise the XMLBinding instances for v1 and v2 of the XMLs...
        XMLBinding xmlBindingV1 = new XMLBinding().add("v1-binding-config.xml");
        XMLBinding xmlBindingV2 = new XMLBinding().add("v2-binding-config.xml");
        xmlBindingV1.intiailize();
        xmlBindingV2.intiailize();

        // Read the v1 order XML into the Order Object model...
        Order order = xmlBindingV1.fromXML(new StringSource(orderV1XMLMessage), Order.class);

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

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

TOP

Related Classes of org.milyn.javabean.binding.xml.XMLBinding

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.