Example usage for org.springframework.beans.factory.config RuntimeBeanReference RuntimeBeanReference

List of usage examples for org.springframework.beans.factory.config RuntimeBeanReference RuntimeBeanReference

Introduction

In this page you can find the example usage for org.springframework.beans.factory.config RuntimeBeanReference RuntimeBeanReference.

Prototype

public RuntimeBeanReference(Class<?> beanType) 

Source Link

Document

Create a new RuntimeBeanReference to a bean of the given type.

Usage

From source file:com.clican.pluto.dataprocess.spring.parser.IBatisExecProcessorParser.java

public void customiseBeanDefinition(BeanDefinition beanDef, Element element, ParserContext parserContext) {
    String sqlMapClient = element.getAttribute("sqlMapClient");
    beanDef.getPropertyValues().addPropertyValue("sqlMapClient", new RuntimeBeanReference(sqlMapClient));

    List<IBatisExecBean> ibatisExecBeanList = new ArrayList<IBatisExecBean>();
    NodeList nodeList = element.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            String localName = node.getLocalName();
            if ("exec".equals(localName)) {
                IBatisExecBean bean = new IBatisExecBean();
                Element ibatisExecElement = (Element) node;
                String batch = ibatisExecElement.getAttribute("batch");
                String statement = ibatisExecElement.getAttribute("statement");
                String insertStatement = ibatisExecElement.getAttribute("insertStatement");
                String updateStatement = ibatisExecElement.getAttribute("updateStatement");
                String ibatisExecType = ibatisExecElement.getAttribute("ibatisExecType");
                String paramName = ibatisExecElement.getAttribute("paramName");
                String keyProp = ibatisExecElement.getAttribute("keyProp");
                String valueProp = ibatisExecElement.getAttribute("valueProp");
                String resultName = ibatisExecElement.getAttribute("resultName");
                String paramNameMap = ibatisExecElement.getAttribute("paramNameMap");
                if (StringUtils.isNotEmpty(paramNameMap)) {
                    Map<String, String> map = new HashMap<String, String>();
                    for (String pnm : paramNameMap.split(";")) {
                        String contextName = pnm.split("=>")[0].trim();
                        String ibatisName = pnm.split("=>")[1].trim();
                        map.put(contextName, ibatisName);
                    }//from   w w  w  .  j a v  a  2 s . c  o  m
                    bean.setParamNameMap(map);
                }
                if (StringUtils.isNotEmpty(batch)) {
                    bean.setBatch(Boolean.parseBoolean(batch));
                }

                bean.setStatement(statement);
                bean.setInsertStatement(insertStatement);
                bean.setUpdateStatement(updateStatement);
                bean.setIbatisExecType(IBatisExecType.convert(ibatisExecType));
                bean.setKeyProp(keyProp);
                bean.setValueProp(valueProp);
                bean.setParamName(paramName);
                bean.setResultName(resultName);
                ibatisExecBeanList.add(bean);
            }
        }
    }
    beanDef.getPropertyValues().addPropertyValue("ibatisExecBeanList", ibatisExecBeanList);
}

From source file:com.clican.pluto.dataprocess.spring.parser.JdbcExecProcessorParser.java

@SuppressWarnings("unchecked")

public void customiseBeanDefinition(BeanDefinition beanDef, Element element, ParserContext parserContext) {
    String jdbcTemplate = element.getAttribute("jdbcTemplate");
    beanDef.getPropertyValues().addPropertyValue("jdbcTemplate", new RuntimeBeanReference(jdbcTemplate));
    List jdbcExecBeanList = new ManagedList();
    NodeList nodeList = element.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            String localName = node.getLocalName();
            if ("exec".equals(localName)) {
                RootBeanDefinition bean = new RootBeanDefinition();
                bean.setAbstract(false);
                bean.setBeanClass(JdbcExecBean.class);
                bean.setLazyInit(false);
                bean.setAutowireMode(Autowire.BY_NAME.value());

                Element jdbcExecElement = (Element) node;
                String batch = jdbcExecElement.getAttribute("batch");
                String paramName = jdbcExecElement.getAttribute("paramName");
                String resultName = jdbcExecElement.getAttribute("resultName");
                String paramNameMap = jdbcExecElement.getAttribute("paramNameMap");
                String singleRow = jdbcExecElement.getAttribute("singleRow");
                String clazz = jdbcExecElement.getAttribute("clazz");
                String sql = jdbcExecElement.getTextContent();
                if (StringUtils.isNotEmpty(paramNameMap)) {
                    Map<String, String> map = new HashMap<String, String>();
                    for (String pnm : paramNameMap.split(";")) {
                        String contextName = pnm.split("=>")[0].trim();
                        String ibatisName = pnm.split("=>")[1].trim();
                        map.put(contextName, ibatisName);
                    }// www  .j  a  v  a  2  s . c  om
                    bean.getPropertyValues().addPropertyValue("paramNameMap", map);
                }
                if (StringUtils.isNotEmpty(batch)) {
                    bean.getPropertyValues().addPropertyValue("batch", Boolean.parseBoolean(batch));
                }
                if (StringUtils.isNotEmpty(singleRow)) {
                    bean.getPropertyValues().addPropertyValue("singleRow", Boolean.parseBoolean(singleRow));
                }
                if (StringUtils.isNotEmpty(clazz)) {
                    try {
                        bean.getPropertyValues().addPropertyValue("clazz", Class.forName(clazz));
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }
                bean.getPropertyValues().addPropertyValue("paramName", paramName);
                bean.getPropertyValues().addPropertyValue("resultName", resultName);
                bean.getPropertyValues().addPropertyValue("sql", sql);
                jdbcExecBeanList.add(bean);
            }
        }
    }
    beanDef.getPropertyValues().addPropertyValue("jdbcExecBeanList", jdbcExecBeanList);
}

From source file:net.sourceforge.jabm.spring.PropertyOverrideWithReferencesConfigurer.java

@Override
protected void applyPropertyValue(ConfigurableListableBeanFactory factory, String beanName, String property,
        String value) {/*w w w .j  av a 2  s.c o m*/
    if (value != null && value.length() > 0 && !(value.charAt(0) == '&')) {
        super.applyPropertyValue(factory, beanName, property, value);
    } else {
        BeanDefinition bd = factory.getBeanDefinition(beanName);
        while (bd.getOriginatingBeanDefinition() != null) {
            bd = bd.getOriginatingBeanDefinition();
        }
        Object referencedValue = new RuntimeBeanReference(value.substring(1));
        PropertyValue pv = new PropertyValue(property, referencedValue);
        pv.setOptional(false);
        bd.getPropertyValues().addPropertyValue(pv);
    }
}

From source file:com.clican.pluto.dataprocess.spring.parser.CollectionIteratorProcessorParser.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public void customiseBeanDefinition(BeanDefinition beanDef, Element element, ParserContext parserContext) {
    this.setBeanDefinitionStringProperty("elementName", beanDef, element);
    this.setBeanDefinitionStringProperty("collectionName", beanDef, element);
    String commit = element.getAttribute("stepCommit");
    if (StringUtils.isNotEmpty(commit)) {
        beanDef.getPropertyValues().addPropertyValue("stepCommit", Boolean.parseBoolean(commit));
    }/*from   ww w.  j  av  a  2s  . co  m*/
    String iteratorProcessors = element.getAttribute("iteratorProcessors");
    List iteratorProcessorList = new ManagedList();
    for (String nextDataProcess : iteratorProcessors.split(",")) {
        nextDataProcess = nextDataProcess.trim();
        iteratorProcessorList.add(new RuntimeBeanReference(nextDataProcess));
    }
    beanDef.getPropertyValues().addPropertyValue("iteratorProcessors", iteratorProcessorList);
}

From source file:com.clican.pluto.dataprocess.spring.parser.ForProcessorParser.java

@SuppressWarnings("unchecked")

public void customiseBeanDefinition(BeanDefinition beanDef, Element element, ParserContext parserContext) {
    this.setBeanDefinitionStringProperty("elementName", beanDef, element);
    this.setBeanDefinitionStringProperty("step", beanDef, element);
    this.setBeanDefinitionStringProperty("start", beanDef, element);
    this.setBeanDefinitionStringProperty("end", beanDef, element);
    String commit = element.getAttribute("stepCommit");
    if (StringUtils.isNotEmpty(commit)) {
        beanDef.getPropertyValues().addPropertyValue("stepCommit", Boolean.parseBoolean(commit));
    }//  w ww  .  j a v a  2  s  . co m
    String iteratorProcessors = element.getAttribute("iteratorProcessors");
    List iteratorProcessorList = new ManagedList();
    for (String nextDataProcess : iteratorProcessors.split(",")) {
        nextDataProcess = nextDataProcess.trim();
        iteratorProcessorList.add(new RuntimeBeanReference(nextDataProcess));
    }
    beanDef.getPropertyValues().addPropertyValue("iteratorProcessors", iteratorProcessorList);
}

From source file:org.springmodules.cache.config.AbstractCacheSetupStrategyParserImplTestCase.java

protected final void onSetUp() throws Exception {
    propertySource = new CacheSetupStrategyPropertySource(new RuntimeBeanReference("cacheKeyGenerator"),
            new RuntimeBeanReference("cacheProvider"), new ArrayList(), new HashMap(), new HashMap());

    afterSetUp();/*from   w ww. j a v a  2 s  .c  om*/
}

From source file:com.clican.pluto.dataprocess.spring.parser.TimerProcessorParser.java

@SuppressWarnings("unchecked")

public void customiseBeanDefinition(BeanDefinition beanDef, Element element, ParserContext parserContext) {
    String cronExpression = element.getAttribute("cronExpression");
    String startTime = element.getAttribute("startTime");
    String endTime = element.getAttribute("endTime");
    String taskScheduler = element.getAttribute("taskScheduler");
    String concurrent = element.getAttribute("concurrent");
    if (StringUtils.isEmpty(taskScheduler)) {
        taskScheduler = "taskScheduler";
    }/*w  w w.ja  v a  2s . co  m*/
    String stepCommit = element.getAttribute("stepCommit");
    if (StringUtils.isNotEmpty(stepCommit)) {
        beanDef.getPropertyValues().addPropertyValue("stepCommit", Boolean.parseBoolean(stepCommit));
    }
    beanDef.getPropertyValues().addPropertyValue("cronExpression", cronExpression);
    beanDef.getPropertyValues().addPropertyValue("startTime", startTime);
    beanDef.getPropertyValues().addPropertyValue("endTime", endTime);
    beanDef.getPropertyValues().addPropertyValue("taskScheduler", new RuntimeBeanReference(taskScheduler));
    if (StringUtils.isNotEmpty(concurrent)) {
        beanDef.getPropertyValues().addPropertyValue("concurrent", Boolean.parseBoolean(concurrent));
    }
    String[] timerProcessors = element.getAttribute("timerProcessors").split(",");
    List partitionProcessorList = new ManagedList();
    for (String timerProcessor : timerProcessors) {
        partitionProcessorList.add(new RuntimeBeanReference(timerProcessor.trim()));
    }
    beanDef.getPropertyValues().addPropertyValue("timerProcessors", partitionProcessorList);

}

From source file:org.devefx.httpmapper.spring.config.ListenersBeanDefinitionParser.java

public BeanDefinition parse(Element element, ParserContext parserContext) {
    CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(),
            parserContext.extractSource(element));
    parserContext.pushContainingComponent(compDefinition);

    RuntimeBeanReference pathMatcherRef = null;
    if (element.hasAttribute("path-matcher")) {
        pathMatcherRef = new RuntimeBeanReference(element.getAttribute("path-matcher"));
    }/*from  w w  w. j a  v a2s .  co  m*/

    List<Element> listeners = DomUtils.getChildElementsByTagName(element, "bean", "ref", "listener");
    for (Element listener : listeners) {
        RootBeanDefinition mappedListenerDef = new RootBeanDefinition(MappedListener.class);
        mappedListenerDef.setSource(parserContext.extractSource(listener));
        mappedListenerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);

        ManagedList<String> includePatterns = null;
        ManagedList<String> excludePatterns = null;
        Object listenerBean;
        if ("listener".equals(listener.getLocalName())) {
            includePatterns = getIncludePatterns(listener, "mapping");
            excludePatterns = getIncludePatterns(listener, "exclude-mapping");
            Element beanElem = DomUtils.getChildElementsByTagName(listener, "bean", "ref").get(0);
            listenerBean = parserContext.getDelegate().parsePropertySubElement(beanElem, null);
        } else {
            listenerBean = parserContext.getDelegate().parsePropertySubElement(listener, null);
        }
        mappedListenerDef.getConstructorArgumentValues().addIndexedArgumentValue(0, includePatterns);
        mappedListenerDef.getConstructorArgumentValues().addIndexedArgumentValue(1, excludePatterns);
        mappedListenerDef.getConstructorArgumentValues().addIndexedArgumentValue(2, listenerBean);

        if (pathMatcherRef != null) {
            mappedListenerDef.getPropertyValues().add("pathMatcher", pathMatcherRef);
        }

        String beanName = parserContext.getReaderContext().registerWithGeneratedName(mappedListenerDef);
        parserContext.registerComponent(new BeanComponentDefinition(mappedListenerDef, beanName));
    }

    parserContext.popAndRegisterContainingComponent();
    return null;
}

From source file:com.jaspersoft.jasperserver.api.common.util.spring.BeanPropertyOverrider.java

protected Object getOverrideValue() {
    Object value;//from  w w w  . java2 s.  com
    if (overrideReference == null) {
        value = override;
    } else {
        value = new RuntimeBeanReference(overrideReference);
    }
    return value;
}

From source file:org.springmodules.cache.config.BeanReferenceParserImpl.java

/**
 * @see BeanReferenceParser#parse(Element,ParserContext,boolean)
 *//* w ww.ja v a2s  . c  o  m*/
public Object parse(Element element, ParserContext parserContext, boolean registerInnerBean) {

    String refId = element.getAttribute("refId");
    if (StringUtils.hasText(refId)) {
        return new RuntimeBeanReference(refId);
    }

    Element beanElement = null;
    List beanElements = DomUtils.getChildElementsByTagName(element, "bean");
    if (!CollectionUtils.isEmpty(beanElements)) {
        beanElement = (Element) beanElements.get(0);
    }
    if (beanElement == null) {
        throw new IllegalStateException("The XML element " + StringUtils.quote(element.getNodeName())
                + " should either have a " + "reference to an already registered bean definition or contain a "
                + "bean definition");
    }

    BeanDefinitionHolder holder = parserContext.getDelegate().parseBeanDefinitionElement(beanElement);

    String beanName = holder.getBeanName();

    if (registerInnerBean && StringUtils.hasText(beanName)) {
        BeanDefinitionRegistry registry = parserContext.getRegistry();
        BeanDefinition beanDefinition = holder.getBeanDefinition();
        registry.registerBeanDefinition(beanName, beanDefinition);

        return new RuntimeBeanReference(beanName);
    }

    return holder;
}