Package org.milyn.javabean.context

Examples of org.milyn.javabean.context.BeanContext


            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


        executionContext.getBeanContext().addBean(bindTo, serializedFragment, new Fragment(element));
  }

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

        beanContext.notifyObservers(new BeanContextLifecycleEvent(executionContext,
                source, BeanLifecycle.START_FRAGMENT, beanContext.getBeanId(bindTo), ""));
    }
View Full Code Here



  private void executeSQL(ExecutionContext executionContext, Fragment source) throws SmooksException {
        Connection connection = AbstractDataSource.getConnection(datasource, executionContext);
        BeanContext beanContext = executionContext.getBeanContext();

        Map<String, Object> beanMap = beanContext.getBeanMap();

        try {
            if(!statementExec.isJoin()) {
                if(statementExec.getStatementType() == StatementType.QUERY) {
                    if(resultSetScope == ResultSetScope.EXECUTION) {
                        beanContext.addBean(resultSetBeanId, statementExec.executeUnjoinedQuery(connection), source);
                    } else {
                        List<Map<String, Object>> resultMap;
                        // Cached in the application context...
                        ApplicationContext appContext = executionContext.getContext();
                        ResultSetContextObject rsContextObj = ResultSetContextObject.getInstance(rsAppContextKey, appContext);

                        if(rsContextObj.hasExpired()) {
                            synchronized (rsContextObj) {
                                if(rsContextObj.hasExpired()) {
                                    rsContextObj.resultSet = statementExec.executeUnjoinedQuery(connection);
                                    rsContextObj.expiresAt = System.currentTimeMillis() + resultSetTTL;
                                }
                            }
                        }
                        resultMap = rsContextObj.resultSet;
                        beanContext.addBean(resultSetBeanId, resultMap, source);
                    }
                } else {
                    statementExec.executeUnjoinedUpdate(connection);
                }
            } else {
                if(statementExec.getStatementType() == StatementType.QUERY) {
                    List<Map<String, Object>> resultMap = new ArrayList<Map<String, Object>>();
                    statementExec.executeJoinedQuery(connection, beanMap, resultMap);
                    beanContext.addBean(resultSetBeanId, resultMap, source);
                } else {
                    if(resultSetBeanId == null) {
                        statementExec.executeJoinedUpdate(connection, beanMap);
                    } else {
                        Object resultSetObj = beanContext.getBean(resultSetBeanId);
                        if(resultSetObj != null) {
                            try {
                              @SuppressWarnings("unchecked")
                                List<Map<String, Object>> resultSet = (List<Map<String, Object>>) resultSetObj;
                                statementExec.executeJoinedStatement(connection, resultSet);
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

          exception += "query '" + query + "'";
        }
        throw new NoLookupResultException(exception);
      }

      BeanContext beanContext = executionContext.getBeanContext();

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

            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

      throws SmooksException {
    selectRow(executionContext, new Fragment(element));
  }

    private void selectRow(ExecutionContext executionContext, Fragment source) throws SmooksException {
      BeanContext beanRepository = executionContext.getBeanContext();

      Map<String, Object> beanMapClone = new HashMap<String, Object>(beanRepository.getBeanMap());

        // Lookup the new current value for the bean...
        try {
          @SuppressWarnings("unchecked")
            List<Map<String, Object>> resultSet = (List<Map<String, Object>>) beanRepository.getBean(resultSetBeanId);

            if(resultSet == null) {
                throw new SmooksException("Resultset '" + resultSetName + "' not found in bean context.  Make sure an appropriate SQLExecutor resource config wraps this selector config.");
            }

            try {
              Object selectedRow = null;

              Iterator<Map<String, Object>> resultIter = resultSet.iterator();
                while (selectedRow == null && resultIter.hasNext()) {
                  Map<String, Object> row = resultIter.next();

                  beanMapClone.put("row", row);

                    if(whereEvaluator.eval(beanMapClone)) {
                      selectedRow = row;
                      beanRepository.addBean(beanIdObj, selectedRow, source);
                    }
                }

                if(selectedRow == null && failedSelectError != null) {
                    throw new DataSelectionException(failedSelectError.apply(beanRepository.getBeanMap()));
                }

                if(logger.isDebugEnabled()) {
                    logger.debug("Selected resultset where '" + whereEvaluator.getExpression() + "': [" + selectedRow + "].");
                }
            } catch(ClassCastException e) {
                throw new SmooksException("Bean '" + resultSetName + "' cannot be used as a Reference Data resultset.  The resultset List must contain entries of type Map<String, Object>.");
            }
        } catch(ClassCastException e) {
            throw new SmooksException("Bean '" + resultSetName + "' cannot be used as a Reference Data resultset.  A resultset must be of type List<Map<String, Object>>. '" + resultSetName + "' is of type '" + beanRepository.getBean(resultSetBeanId).getClass().getName() + "'.");
        }
    }
View Full Code Here

    if(logger.isDebugEnabled()) {
      logger.debug("Deleting 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) {
        String msg = "The DAO register returned null while getting the ";

        if(daoName == null) {
          msg += "default DAO";
        } else {
          msg += "DAO '" + daoName + "'";
        }

        throw new NullPointerException(msg);
      }

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

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

      if(deletedBeanId != null) {
        if(result == null) {
          result = bean;
        }
        beanContext.addBean(deletedBeanId, result, source);
      } else if(result != null && bean != result) {
        beanContext.changeBean(beanId, bean, source);
      }


    } finally {
      if(dao != null) {
View Full Code Here

        beanContext.notifyObservers(new BeanContextLifecycleEvent(executionContext,
                source, BeanLifecycle.START_FRAGMENT, beanContext.getBeanId(bindTo), ""));
    }

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

        beanContext.notifyObservers(new BeanContextLifecycleEvent(executionContext, fragment, BeanLifecycle.END_FRAGMENT, beanId, bean));
        if(!retain) {
            executionContext.getBeanContext().removeBean(beanId, null);
        }
    }
View Full Code Here

      }
     
      ExecutionContext executionContext = event.getExecutionContext();
      populator.populateAndSetPropertyValue(bean, executionContext.getBeanContext(), watchingBeanId, executionContext, event.getSource());
    } else if(beanId == watchingBeanId && lifecycle == BeanLifecycle.REMOVE) {
      BeanContext beanContext = event.getExecutionContext().getBeanContext();
     
      beanContext.removeObserver(this);
      // Need to remove the watched bean from the bean context too because it's lifecycle is associated
      // with the lifecycle of the watching bean, which has been removed...
      if(watchedBeanId != null) {
        beanContext.removeBean(watchedBeanId, event.getSource());
      }
    }
  }
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.