Package org.milyn.javabean

Examples of org.milyn.javabean.Bean


        Smooks smooks = new Smooks();

        try {
            smooks.setFilterSettings(FilterSettings.DEFAULT_SAX);

            smooks.addVisitor(new Bean(HashMap.class, "object").bindTo("a", "a"));
            smooks.addVisitor(new FreeMarkerTemplateProcessor(new TemplatingConfiguration("${object.a}").setUsage(OutputTo.stream("fileOS"))), "a");
            smooks.addVisitor(new FileOutputStreamResource().setFileNamePattern("${object.a}.xml").setDestinationDirectoryPattern("target/config-01-test/${object.a}").setResourceName("fileOS"), "a");

            smooks.filterSource(new StringSource("<root><a>1</a><a>2</a><a>3</a></root>"));
View Full Code Here


        final File destinationDir = new File("target/config-01-test");
      final File outputFile = new File(destinationDir, outputFileName);

        try {
            smooks.setFilterSettings(FilterSettings.DEFAULT_SAX);
            smooks.addVisitor(new Bean(HashMap.class, "object").bindTo("a", "a"));
            smooks.addVisitor(new FreeMarkerTemplateProcessor(new TemplatingConfiguration("${object.a}")
                    .setUsage(OutputTo.stream(outputStreamRef))), "a");
            smooks.addVisitor(new FileOutputStreamResource()
                    .setAppend(true)
                    .setFileNamePattern(outputFileName)
View Full Code Here

    public boolean initialized = false;

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

            if(bindingType == FixedLengthBindingType.LIST) {
                Bean listBean = new Bean(ArrayList.class, bindBeanId, "$document");

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

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

                assertValidFieldName(bindMapKeyField);

                Bean mapBean = new Bean(LinkedHashMap.class, bindBeanId, "$document");
                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

                final SmooksProcessor smooksProcessor = new SmooksProcessor(context);

                // Smooks JavaBean programmatic configuration
                final String beanId = "coordinate";
                final String selector = "coords/coord";
                final Bean beanConfig = new Bean(Coordinate.class, beanId, selector);
                beanConfig.bindTo("x", "coords/coord/@x").bindTo("y", "coords/coord/@y");
                smooksProcessor.addVisitor(beanConfig);

                // Smooks Camel BeanRouter programmatic configuration
                final BeanRouter camelBeanRouter = new BeanRouter(context);
                camelBeanRouter.setBeanId(beanId).setToEndpoint(toEndpoint)
View Full Code Here

    buildFields();
  }

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

            if(bindingType == CSVBindingType.LIST) {
                Bean listBean = new Bean(ArrayList.class, bindBeanId, "$document");

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

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

                assertValidFieldName(bindMapKeyField);

                Bean mapBean = new Bean(LinkedHashMap.class, bindBeanId, "$document");
                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 class ProgrammaticBeanConfigTest extends TestCase {

    public void test_01_fluent() {
        Smooks smooks = new Smooks();
        Bean orderBean = new Bean(Order.class, "order", "/order");

        orderBean.bindTo("header",
            orderBean.newBean(Header.class, "/order")
                .bindTo("order", orderBean)
                .bindTo("customerNumber", "header/customer/@number")
                .bindTo("customerName", "header/customer")
                .bindTo("privatePerson", "header/privatePerson")
            ).bindTo("orderItems",
                orderBean.newBean(ArrayList.class, "/order")
                    .bindTo(orderBean.newBean(OrderItem.class, "order-item")
                        .bindTo("productId", "order-item/product")
                        .bindTo("quantity", "order-item/quantity")
                        .bindTo("price", "order-item/price"))
            ).bindTo("orderItems",
                orderBean.newBean(OrderItem[].class, "/order")
                    .bindTo(orderBean.newBean(OrderItem.class, "order-item")
                        .bindTo("productId", "order-item/product")
                        .bindTo("quantity", "order-item/quantity")
                        .bindTo("price", "order-item/price")));

        smooks.addVisitor(orderBean);
View Full Code Here

        execute_01_test(smooks);
    }

    public void test_01_factory() {
        Smooks smooks = new Smooks();
        Bean orderBean = new Bean(Order.class, "order", "/order", new Factory<Order>() {

      public Order create(ExecutionContext executionContext) {
        return new Order();
      }

        });

        orderBean.bindTo("header",
            orderBean.newBean(Header.class, "/order")
                .bindTo("order", orderBean)
                .bindTo("customerNumber", "header/customer/@number")
                .bindTo("customerName", "header/customer")
                .bindTo("privatePerson", "header/privatePerson")
            ).bindTo("orderItems",
                orderBean.newBean(Collection.class, "/order", new MVELFactory<Collection>("new java.util.ArrayList()"))
                    .bindTo(orderBean.newBean(OrderItem.class, "order-item")
                        .bindTo("productId", "order-item/product")
                        .bindTo("quantity", "order-item/quantity")
                        .bindTo("price", "order-item/price"))
            ).bindTo("orderItems",
                orderBean.newBean(OrderItem[].class, "/order")
                    .bindTo(orderBean.newBean(OrderItem.class, "order-item")
                        .bindTo("productId", "order-item/product")
                        .bindTo("quantity", "order-item/quantity")
                        .bindTo("price", "order-item/price")));

        smooks.addVisitor(orderBean);
View Full Code Here

        execute_01_test(smooks);
    }

    public void test_invalid_bindTo() {
        Smooks smooks = new Smooks();
        Bean orderBean = new Bean(Order.class, "order", "/order");

        smooks.addVisitor(orderBean);

        try {
            // invalid attempt to bindTo after it has been added to the Smooks instance...
            orderBean.bindTo("header",
                orderBean.newBean(Header.class, "/order")
                    .bindTo("privatePerson", "header/privatePerson"));

            fail("Expected IllegalStateException");
        } catch(IllegalStateException e) {
            assertEquals("Unexpected attempt to bindTo Bean instance after the Bean instance has been added to a Smooks instance.", e.getMessage());
View Full Code Here

        }
    }

    public void test_01_flat() {
        Smooks smooks = new Smooks();
        Bean orderBean = new Bean(Order.class, "order", "/order");

        Bean headerBean = new Bean(Header.class, "header", "/order")
                                    .bindTo("order", orderBean)
                                    .bindTo("customerNumber", "header/customer/@number")
                                    .bindTo("customerName", "header/customer")
                                    .bindTo("privatePerson", "header/privatePerson");
View Full Code Here

    context.addRoutes(new RouteBuilder() {
      @Override
      public void configure() throws Exception
      {
                from("direct:c").process(new SmooksProcessor(new Smooks().setExports(new Exports(JavaResult.class)), context).
                addVisitor(new Bean(Coordinate.class, "coordinate").
            bindTo("x", "/coord/@x").
            bindTo("y", "/coord/@y")));
      }
    });
    context.start();
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.