Package org.milyn.javabean

Examples of org.milyn.javabean.Bean


    Properties namespaces = new Properties();
    namespaces.setProperty("e", "http://www.example.net");
    namespaces.setProperty("f", "http://www.blah");
    smooks.setNamespaces(namespaces);
   
    Bean beanConfig = new Bean(HashMap.class, "theBean");
    beanConfig.bindTo("attr1", "test1/@e:attr1");
    beanConfig.bindTo("attr2", "test1/@f:attr2");   
    smooks.addVisitor(beanConfig);
   
    test(smooks);
    }
View Full Code Here


        return strict;
    }

    public void addVisitors(VisitorConfigMap visitorMap) {
        if (bindBeanId != null && bindBeanClass != null) {
            Bean bean;

            if (fieldsInMessage) {
                throw new SmooksConfigurationException("Unsupported reader based bean binding config.  Not supported when fields are defined in message.  See 'fieldsInMessage' attribute.");
            }

            if (vfRecordMetaData.isMultiTypeRecordSet()) {
                throw new SmooksConfigurationException(
                        "Unsupported reader based bean binding config for a multi record type record set.  "
                                + "Only supported for single record type record sets.  Use <jb:bean> configs for multi binding record type record sets.");
            }

            if (bindingType == BindingType.LIST) {
                Bean listBean = new Bean(ArrayList.class, bindBeanId,
                        SmooksResourceConfiguration.DOCUMENT_FRAGMENT_SELECTOR);

                bean = listBean.newBean(bindBeanClass, recordElementName);
                listBean.bindTo(bean);
                addFieldBindings(bean);

                listBean.addVisitors(visitorMap);
            } else if (bindingType == BindingType.MAP) {
                if (bindMapKeyField == null) {
                    throw new SmooksConfigurationException(
                            "'MAP' Binding must specify a 'keyField' property on the binding configuration.");
                }

                vfRecordMetaData.getRecordMetaData().assertValidFieldName(bindMapKeyField);

                Bean mapBean = new Bean(LinkedHashMap.class, bindBeanId,
                        SmooksResourceConfiguration.DOCUMENT_FRAGMENT_SELECTOR);
                Bean recordBean = new Bean(bindBeanClass, RECORD_BEAN, recordElementName);
                MapBindingWiringVisitor wiringVisitor = new MapBindingWiringVisitor(bindMapKeyField, bindBeanId);

                addFieldBindings(recordBean);

                mapBean.addVisitors(visitorMap);
                recordBean.addVisitors(visitorMap);
                visitorMap.addVisitor(wiringVisitor, recordElementName, null, false);
            } else {
                bean = new Bean(bindBeanClass, bindBeanId, recordElementName);
                addFieldBindings(bean);

                bean.addVisitors(visitorMap);
            }
        }
View Full Code Here

    }

    public void test_02_Map_fluid() {
        Smooks smooks = new Smooks();

        Bean orderBean = new Bean(HashMap.class, "order", "/order");

        orderBean.bindTo("header",
                orderBean.newBean(HashMap.class, "/order")
                    .bindTo("customerNumber", "header/customer/@number", new IntegerDecoder())
                    .bindTo("customerName", "header/customer")
                    .bindTo("privatePerson", "header/privatePerson")
                ).bindTo("orderItems",
                orderBean.newBean(ArrayList.class, "/order")
                        .bindTo(orderBean.newBean(HashMap.class, "order-item")
                            .bindTo("productId", "order-item/product")
                            .bindTo("quantity", "order-item/quantity")
                            .bindTo("price", "order-item/price", new DoubleDecoder()))
                );
View Full Code Here

    }

    public void test_02_arrays_programmatic() {
        Smooks smooks = new Smooks();

        Bean orderBean = new Bean(Order.class, "order", "order");
        Bean orderItemArray = new Bean(OrderItem[].class, "orderItemsArray", "order");
        Bean orderItem = new Bean(OrderItem.class, "orderItem", "order-item");

        orderItem.bindTo("productId", "order-item/product");
        orderItemArray.bindTo(orderItem);
        orderBean.bindTo("orderItems", orderItemArray);

        smooks.addVisitor(orderBean);
View Full Code Here

public class FreeMarkerProgramaticConfigTest extends TestCase {

    public void testFreeMarkerTrans_01() throws SAXException, IOException {
        Smooks smooks = new Smooks();

        smooks.addVisitor(new Bean(MyBean.class, "myBeanData", "c").bindTo("x", "c/@x"));
        smooks.addVisitor(new FreeMarkerTemplateProcessor(new TemplatingConfiguration("/org/milyn/templating/freemarker/test-template.ftl")),"c");

        test_ftl(smooks, "<a><b><c x='xvalueonc1' /><c x='xvalueonc2' /></b></a>", "<a><b><mybean>xvalueonc1</mybean><mybean>xvalueonc2</mybean></b></a>");
        // Test transformation via the <context-object /> by transforming the root element using StringTemplate.
        test_ftl(smooks, "<c x='xvalueonc1' />", "<mybean>xvalueonc1</mybean>");
View Full Code Here

        StringReader input;
        ExecutionContext context;

        Smooks smooks = new Smooks();

        smooks.addVisitor(new Bean(MyBean.class, "myBeanData", "c").bindTo("x", "c/@x"));
        smooks.addVisitor(
                new FreeMarkerTemplateProcessor(
                        new TemplatingConfiguration("<mybean>${myBeanData.x}</mybean>").setUsage(BindTo.beanId("mybeanTemplate"))
                ),
                "c"
View Full Code Here

    }

    public void testInsertBefore() throws SAXException, IOException {
        Smooks smooks = new Smooks();

        smooks.addVisitor(new Bean(MyBean.class, "myBeanData", "b").bindTo("x", "b/@x"));
        smooks.addVisitor(
                new FreeMarkerTemplateProcessor(
                        new TemplatingConfiguration("/org/milyn/templating/freemarker/test-template.ftl").setUsage(Inline.INSERT_BEFORE)
                ),
                "c"
View Full Code Here

    }

    public void testInsertAfter() throws SAXException, IOException {
        Smooks smooks = new Smooks();

        smooks.addVisitor(new Bean(MyBean.class, "myBeanData", "b").bindTo("x", "b/@x"));
        smooks.addVisitor(
                new FreeMarkerTemplateProcessor(
                        new TemplatingConfiguration("/org/milyn/templating/freemarker/test-template.ftl").setUsage(Inline.INSERT_AFTER)
                ),
                "c"
View Full Code Here

    }

    public void testAddTo() throws SAXException, IOException {
        Smooks smooks = new Smooks();

        smooks.addVisitor(new Bean(MyBean.class, "myBeanData", "b").bindTo("x", "b/@x"));
        smooks.addVisitor(
                new FreeMarkerTemplateProcessor(
                        new TemplatingConfiguration("/org/milyn/templating/freemarker/test-template.ftl").setUsage(Inline.ADDTO)
                ),
                "c"
View Full Code Here

        test(smooks, FilterSettings.DEFAULT_SAX);
    }

    private void configure(Smooks smooks) {
        // Create a HashMap, name it "object" and then bind the <a> data into it, keyed as "a"...
        smooks.addVisitor(new Bean(HashMap.class, "object").bindTo("a", "a"));

        // On every <a> fragment, apply a simple template and bind the templating result to
        // beanId "orderItem_xml" ...
        smooks.addVisitor(new FreeMarkerTemplateProcessor(new TemplatingConfiguration("${object.a}").setUsage(BindTo.beanId("orderItem_xml"))), "a");
View Full Code Here

TOP

Related Classes of org.milyn.javabean.Bean

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.