Package org.milyn.javabean.context

Examples of org.milyn.javabean.context.BeanContext


    /**
     * Execute the cleanup.
     * @param executionContext The execution context.
     */
    public void executeExecutionLifecycleCleanup(ExecutionContext executionContext) {
        BeanContext beanContext = executionContext.getBeanContext();
        Set<Entry<String, Object>> beanSet = beanContext.getBeanMap().entrySet();

        for(Entry<String, Object> beanEntry : beanSet) {
            String beanID = beanEntry.getKey();
            if(!beanIDSet.contains(beanID)) {
              beanContext.removeBean(beanID, null);
            }
        }
    }
View Full Code Here


                    // Attach the source and results to the context...
                    FilterSource.setSource(executionContext, source);
                    FilterResult.setResults(executionContext, results);

                    // Add pre installed beans + global BeanContext lifecycle observers...
                    BeanContext beanContext = executionContext.getBeanContext();
                    beanContext.addBean(Time.BEAN_ID, new Time());
                    beanContext.addBean(UniqueID.BEAN_ID, new UniqueID());
                    for(BeanContextLifecycleObserver observer : context.getBeanContextLifecycleObservers()) {
                        beanContext.addObserver(observer);
                    }

                    try {
                        deliveryConfig.executeHandlerInit(executionContext);
                      messageFilter.doFilter();
                    } finally {
                        try {
                            // We want to make sure that all the beans from the BeanContext are available in the
                            // JavaResult, if one is supplied by the user...
                            JavaResult javaResult = (JavaResult) FilterResult.getResult(executionContext, JavaResult.class);
                            if(javaResult != null) {
                                javaResult.getResultMap().putAll(executionContext.getBeanContext().getBeanMap());
                            }

                            // Remove the pre-installed beans...
                            beanContext.removeBean(Time.BEAN_ID, null);
                            beanContext.removeBean(UniqueID.BEAN_ID, null);
                        } finally {
                            deliveryConfig.executeHandlerCleanup(executionContext);
                        }
                    }
                } catch(SmooksException e) {
View Full Code Here

    long begin = System.currentTimeMillis();
    for(int l = 0; l < loops; l++) {

      for(BeanId id: beanIds) {
        BeanContext beanContext = executionContext.getBeanContext();
        beanContext.addBean(id, bean, null);
      }
      for(BeanId id: beanIds) {
        BeanContext beanContext = executionContext.getBeanContext();
        beanContext.getBean(id);
      }
    }
    long end  = System.currentTimeMillis();

    if(!warmup) {
View Full Code Here

    count(executionContext, new Fragment(element));
  }

  public void count(ExecutionContext executionContext, Fragment source) {
    BeanContext beanContext = executionContext.getBeanContext();

    Long value = (Long) beanContext.getBean(beanId);

    if(value == null || (resetCondition != null && resetCondition.eval(beanContext.getBeanMap()))) {
      value = getStart(beanContext);
    } else {
      int amount = getAmount(beanContext);

      if(countDirection == CountDirection.INCREMENT) {
        value = value + amount;
      } else {
        value = value - amount;
      }
    }
    beanContext.addBean(beanId, value, source);
  }
View Full Code Here

    }

    @SuppressWarnings("unchecked")
  private void test_appContextTime(Smooks smooks) throws IOException, SAXException, InterruptedException {
        ExecutionContext execContext = smooks.createExecutionContext();
        BeanContext beanContext = execContext.getBeanContext();

        smooks.filterSource(execContext, new StringSource("<doc/>"), null);
        List orders11 = (List) beanContext.getBean("orders1");
        List orders12 = (List) beanContext.getBean("orders2");

        smooks.filterSource(execContext, new StringSource("<doc/>"), null);
        List orders21 = (List) beanContext.getBean("orders1");
        List orders22 = (List) beanContext.getBean("orders2");

        assertTrue(orders11 != orders21);
        assertTrue(orders12 == orders22); // order12 should come from the app context cache

        // timeout the cached resultset...
        Thread.sleep(2050);

        smooks.filterSource(execContext, new StringSource("<doc/>"), null);
        List orders31 = (List) beanContext.getBean("orders1");
        List orders32 = (List) beanContext.getBean("orders2");

        assertTrue(orders11 != orders31);
        assertTrue(orders12 != orders32); // order12 shouldn't come from the app context cache - timed out ala TTL

        smooks.filterSource(execContext, new StringSource("<doc/>"), null);
        List orders41 = (List) beanContext.getBean("orders1");
        List orders42 = (List) beanContext.getBean("orders2");

        assertTrue(orders31 != orders41);
        assertTrue(orders32 == orders42); // order42 should come from the app context cache
    }
View Full Code Here

  public void test_ResultsetRowSelector_01() throws IOException, SAXException, InterruptedException {
        Smooks smooks = new Smooks(getClass().getResourceAsStream("smooks-config.xml"));

        try {
            ExecutionContext execContext = smooks.createExecutionContext();
            BeanContext beanContext = execContext.getBeanContext();

            smooks.filterSource(execContext, new StringSource("<doc/>"), null);
            Map<String, Object> myOrder = (Map<String, Object>) beanContext.getBean("myOrder");

            assertEquals("{ORDERNUMBER=2, CUSTOMERNUMBER=2, PRODUCTCODE=456}", myOrder.toString());
        } finally {
            smooks.close();
        }
View Full Code Here

  public void test_ResultsetRowSelector_02() throws IOException, SAXException, InterruptedException {
        Smooks smooks = new Smooks(getClass().getResourceAsStream("smooks-config-failed-select-01.xml"));

        try {
            ExecutionContext execContext = smooks.createExecutionContext();
            BeanContext beanContext = execContext.getBeanContext();

            smooks.filterSource(execContext, new StringSource("<doc/>"), null);
            Map<String, Object> myOrder = (Map<String, Object>) beanContext.getBean("myOrder");

            assertEquals(null, myOrder);
        } finally {
            smooks.close();
        }
View Full Code Here

    public void test_ResultsetRowSelector_03() throws IOException, SAXException, InterruptedException {
        Smooks smooks = new Smooks(getClass().getResourceAsStream("smooks-config-failed-select-02.xml"));

        try {
            ExecutionContext execContext = smooks.createExecutionContext();
            BeanContext beanContext = execContext.getBeanContext();
            BeanIdStore beanIdStore =  execContext.getContext().getBeanIdStore();

            BeanId requiredOrderNumId = beanIdStore.register("requiredOrderNum");

            beanContext.addBean(requiredOrderNumId, 9999, null);
            try {
                smooks.filterSource(execContext, new StringSource("<doc/>"), null);
                fail("Expected DataSelectionException");
            } catch(SmooksException e) {
                assertEquals("Order with ORDERNUMBER=9999 not found in Database", e.getCause().getMessage());
View Full Code Here

    @Before
  public void setupSmooksExeceutionContext() throws Exception
  {
    endpoint = createAndConfigureMockEndpoint(END_POINT_URI);
    Exchange exchange = createExchangeAndSetFromEndpoint(endpoint);
    BeanContext beanContext = createBeanContextAndSetBeanInContext(BEAN_ID, myBean);
   
    smooksExecutionContext = createStandaloneExecutionContext();
    setExchangeAsAttributeInExecutionContext(exchange);
    makeExecutionContextReturnBeanContext(beanContext);
  }
View Full Code Here

            decodeAndSetPropertyValue(propertyName, dataString, executionContext, new Fragment(element));
        }
    }

    private void bindBeanValue(final ExecutionContext executionContext, Fragment source) {
      final BeanContext beanContext = executionContext.getBeanContext();
      Object bean = null;
     
      if(wireBeanId != null) {
        bean = beanContext.getBean(wireBeanId);
      }

        if(bean != null) {
      if(!BeanWiringObserver.isMatchingBean(bean, wireBeanType, wireBeanAnnotation)) {
        bean = null;
      }
        }
     
        if(bean == null) {

            if(logger.isDebugEnabled()) {
                logger.debug("Registering bean ADD wiring observer for wiring bean '" + wireBeanId + "' onto target bean '" + beanId.getName() + "'.");
            }

            // Register the observer which looks for the creation of the selected bean via its beanIdName...
            beanContext.addObserver(wireByBeanIdObserver);
        } else {
            populateAndSetPropertyValue(bean, beanContext, wireBeanId, executionContext, source);
        }
  }
View Full Code Here

TOP

Related Classes of org.milyn.javabean.context.BeanContext

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.