Package org.milyn.javabean.context

Examples of org.milyn.javabean.context.BeanContext


  }

  private void bindValue(String dataString, ExecutionContext executionContext, Fragment source) {
    Object valueObj = decodeDataString(dataString, executionContext);

    BeanContext beanContext = executionContext.getBeanContext();

    if(valueObj == null) {
      beanContext.removeBean(beanId, source);
    } else {
      beanContext.addBean(beanId, valueObj, source);
    }
  }
View Full Code Here


public class MILYN_451_Test extends TestCase {

  public void test() throws IOException, SAXException {
    Smooks smooks = new Smooks(getClass().getResourceAsStream("smooks-config.xml"));
    ExecutionContext execCtx = smooks.createExecutionContext();
    BeanContext beanContext = execCtx.getBeanContext();
    JavaResult jResult = new JavaResult();
   
    smooks.filterSource(execCtx, new StreamSource(getClass().getResourceAsStream("message.xml")), jResult);
    assertEquals(3, jResult.getResultMap().size());
  }
View Full Code Here

                IOException {
            wireObject(executionContext);
        }

        private void wireObject(ExecutionContext executionContext) {
            BeanContext beanContext = executionContext.getBeanContext();
            Map<String, Object> beanMap = beanContext.getBeanMap();
            Object key = keyExtractor.getValue(beanMap);

            @SuppressWarnings("unchecked")
            // TODO: Optimize to use the BeanId object
            Map<Object, Object> map = (Map<Object, Object>) beanContext.getBean(mapBindingKey);
            Object record = beanContext.getBean(RECORD_BEAN);

            map.put(key, record);
        }
View Full Code Here

    if(logger.isDebugEnabled()) {
      logger.debug("Inserting bean under BeanId '" + beanIdName + "' with DAO '" + daoName + "'.");
    }

    BeanContext beanRepository = executionContext.getBeanContext();

    Object bean = beanRepository.getBean(beanId);

    final DaoRegister emr = PersistenceUtil.getDAORegister(executionContext);

    Object dao = null;
    try {
      if(daoName == null) {
        dao = emr.getDefaultDao();
      } else {
        dao = emr.getDao(daoName);
      }

      if(dao == null) {
        throw new IllegalStateException("The DAO register returned null while getting the DAO '" + daoName + "'");
      }

      final DaoInvoker daoInvoker = DaoInvokerFactory.getInstance().create(dao, objectStore);

      Object result = name == null ? daoInvoker.insert(bean) : daoInvoker.insert(name, bean) ;

      if(insertedBeanId != null) {
        if(result == null) {
          result = bean;
        }
        beanRepository.addBean(insertedBeanId, result, source);
      } else if(result != null && bean != result) {
        beanRepository.changeBean(beanId, bean, source);
      }
    } finally {
      if(dao != null) {
        emr.returnDao(dao);
      }
View Full Code Here

    if(logger.isDebugEnabled()) {
      logger.debug("Updating bean under BeanId '" + beanIdName + "' with DAO '" + daoName + "'.");
    }

    BeanContext beanContext = executionContext.getBeanContext();

    Object bean = beanContext.getBean(beanId);

    final DaoRegister emr = PersistenceUtil.getDAORegister(executionContext);

    Object dao = null;
    try {
      if(daoName == null) {
        dao = emr.getDefaultDao();
      } else {
        dao = emr.getDao(daoName);
      }

      if(dao == null) {
        throw new IllegalStateException("The DAO register returned null while getting the DAO '" + daoName + "'");
      }

      final DaoInvoker daoInvoker = DaoInvokerFactory.getInstance().create(dao, objectStore);

      Object result = name == null ? daoInvoker.update(bean) : daoInvoker.update(name, bean) ;

      if(updatedBeanId != null) {
        if(result == null) {
          result = bean;
        }
        beanContext.addBean(updatedBeanId, result, source);
      } else if(result != null && bean != result) {
        beanContext.changeBean(beanId, bean, source);
      }
    } finally {
      if(dao != null) {
        emr.returnDao(dao);
      }
View Full Code Here

            logger.info("attributes.getQName(" + n + ") == " + attributes.getQName(n));
            logger.info("attributes.getType(" + n + ") == " + attributes.getType(n));
            logger.info("attributes.getValue(" + n + ") == " + attributes.getValue(n));
          }

          BeanContext beans = execution.getBeanContext();
          assertNotNull(beans);

          Data data = (Data) beans.getBean("Data");
          assertNotNull(data);

          logger.info("data.getNumber() == " + data.getNumber());
          logger.info("data.getTruncated() == " + data.getTruncated());
View Full Code Here

            populateAndSetPropertyValue(dataString, executionContext);
        }
    }

    private void bindBeanValue(final ExecutionContext executionContext) {
      final BeanContext beanContext = executionContext.getBeanContext();

      Object bean = beanContext.getBean(wireBeanId);
        if(bean == null) {

            // Register the observer which looks for the creation of the selected bean via its beanIdName. When this observer is triggered then
            // we look if we got something we can set immediately or that we got an array collection. For an array collection we need the array representation
            // and not the list representation. So we register and observer who looks for the change from the list to the array
          BeanRuntimeInfo wiredBeanRI = getWiredBeanRuntimeInfo();
          beanContext.addObserver(new BeanCreateLifecycleObserver(wireBeanId, this, wiredBeanRI));
        } else {
            populateAndSetPropertyValue(bean, executionContext);
        }
  }
View Full Code Here

  public void visitAfter(ExecutionContext executionContext, Fragment source) {
        Classification thisBeanType = beanRuntimeInfo.getClassification();
        boolean isBeanTypeArray = (thisBeanType == Classification.ARRAY_COLLECTION);

        BeanContext beanContext = executionContext.getBeanContext();
        beanContext.setBeanInContext(beanId, false);

        if(isBeanTypeArray) {
            Object bean  = beanContext.getBean(beanId);

            if(logger.isDebugEnabled()) {
                logger.debug("Converting bean [" + beanIdName + "] to an array and rebinding to context.");
            }
            bean = convert(executionContext, bean, source);
View Full Code Here

      return bean;
    }

  private void createAndSetBean(ExecutionContext executionContext, Fragment source) {
        Object bean;
        BeanContext beanContext = executionContext.getBeanContext();

        bean = createBeanInstance(executionContext);

        executionContext.getBeanContext().notifyObservers(new BeanContextLifecycleEvent(executionContext,
                source, BeanLifecycle.START_FRAGMENT, beanId, bean));

        if(initValsExpression != null) {
          initValsExpression.exec(bean);
        }

        beanContext.setBeanInContext(beanId, false);
        beanContext.addBean(beanId, bean, source);
        beanContext.setBeanInContext(beanId, true);

        if (logger.isDebugEnabled()) {
            logger.debug("Bean [" + beanIdName + "] instance created.");
        }
    }
View Full Code Here

        throw new SmooksConfigurationException("Invalid Smooks bean configuration.  Bean class " + beanRuntimeInfo.getPopulateType().getName() + " doesn't have a public default constructor.");
    }
  }

  public void executeVisitLifecycleCleanup(Fragment fragment, ExecutionContext executionContext) {
        BeanContext beanContext = executionContext.getBeanContext();
        Object bean = beanContext.getBean(beanId);

        beanContext.notifyObservers(new BeanContextLifecycleEvent(executionContext,
                fragment, BeanLifecycle.END_FRAGMENT, beanId, bean));

        if(!retain) {
            beanContext.removeBean(beanId, null);
        }
    }
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.