List of usage examples for org.springframework.beans.factory.support RootBeanDefinition setAbstract
public void setAbstract(boolean abstractFlag)
From source file:com.clican.pluto.dataprocess.spring.parser.DeployParser.java
public BeanDefinition parse(Element element, ParserContext parserContext) { BeanDefinitionRegistry bdr = parserContext.getRegistry(); RootBeanDefinition beanDef = new RootBeanDefinition(); beanDef.setAbstract(false); beanDef.setBeanClass(Deploy.class); beanDef.setLazyInit(false);// ww w . j a v a 2 s . c o m beanDef.setAutowireMode(Autowire.BY_NAME.value()); String id = element.getAttribute("id"); if (StringUtils.isEmpty(id)) { id = "dplDeploy#" + element.hashCode(); } bdr.registerBeanDefinition(id, beanDef); this.setBeanDefinitionStringProperty("name", beanDef, element); this.setBeanDefinitionStringProperty("url", beanDef, element); this.setBeanDefinitionStringProperty("propertyResources", beanDef, element); return beanDef; }
From source file:com.clican.pluto.dataprocess.spring.parser.ParamProcessorParser.java
@SuppressWarnings("unchecked") public void customiseBeanDefinition(BeanDefinition beanDef, Element element, ParserContext parserContext) { List paramBeanList = 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 ("param".equals(localName)) { RootBeanDefinition bean = new RootBeanDefinition(); bean.setAbstract(false); bean.setBeanClass(ParamBean.class); bean.setLazyInit(false); bean.setAutowireMode(Autowire.BY_NAME.value()); Element paramElement = (Element) node; String paramName = paramElement.getAttribute("paramName"); String paramValue = paramElement.getAttribute("paramValue"); String type = paramElement.getAttribute("type"); String override = paramElement.getAttribute("override"); String pattern = paramElement.getAttribute("pattern"); bean.getPropertyValues().addPropertyValue("paramName", paramName); bean.getPropertyValues().addPropertyValue("paramValue", paramValue); bean.getPropertyValues().addPropertyValue("type", type); bean.getPropertyValues().addPropertyValue("pattern", pattern); if (StringUtils.isNotEmpty(override)) { RootBeanDefinition over = new RootBeanDefinition(); over.setAbstract(false); over.setBeanClass(Boolean.class); over.setLazyInit(false); over.getConstructorArgumentValues().addIndexedArgumentValue(0, override); bean.getPropertyValues().addPropertyValue("override", over); }/* w w w .j av a 2 s. c om*/ paramBeanList.add(bean); } } } beanDef.getPropertyValues().addPropertyValue("paramBeanList", paramBeanList); }
From source file:com.clican.pluto.dataprocess.spring.parser.ExcelProcessorParser.java
@SuppressWarnings("unchecked") public void customiseBeanDefinition(BeanDefinition beanDef, Element element, ParserContext parserContext) { List excelBeanList = 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 ("write".equals(localName) || "read".equals(localName)) { RootBeanDefinition bean = new RootBeanDefinition(); bean.setAbstract(false); bean.setBeanClass(ExcelExecBean.class); bean.setLazyInit(false); bean.setAutowireMode(Autowire.BY_NAME.value()); Element paramElement = (Element) node; String paramName = paramElement.getAttribute("paramName"); String resultName = paramElement.getAttribute("resultName"); String resource = paramElement.getAttribute("resource"); String sheetName = paramElement.getAttribute("sheetName"); String columns = paramElement.getAttribute("columns"); String columnsVarName = paramElement.getAttribute("columnsVarName"); String sheetVarName = paramElement.getAttribute("sheetVarName"); String typeMapStr = paramElement.getAttribute("typeMap"); String resourceVarName = paramElement.getAttribute("resourceVarName"); Map<String, String> typeMap = new HashMap<String, String>(); if ("read".equals(localName)) { for (String type : typeMapStr.split(";")) { typeMap.put(type.split("=>")[0], type.split("=>")[1]); }/*from ww w. j a v a 2 s. com*/ } bean.getPropertyValues().addPropertyValue("paramName", paramName); bean.getPropertyValues().addPropertyValue("resultName", resultName); bean.getPropertyValues().addPropertyValue("sheetName", sheetName); if (StringUtils.isNotEmpty(columns)) { bean.getPropertyValues().addPropertyValue("columns", columns.split(",")); } bean.getPropertyValues().addPropertyValue("resource", resource); bean.getPropertyValues().addPropertyValue("typeMap", typeMap); bean.getPropertyValues().addPropertyValue("columnsVarName", columnsVarName); bean.getPropertyValues().addPropertyValue("sheetVarName", sheetVarName); bean.getPropertyValues().addPropertyValue("resourceVarName", resourceVarName); if ("write".equals(localName)) { bean.getPropertyValues().addPropertyValue("read", false); } excelBeanList.add(bean); } } } beanDef.getPropertyValues().addPropertyValue("excelExecBeanList", excelBeanList); }
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 a2 s. c o m 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:com.clican.pluto.dataprocess.spring.parser.AbstractProcessorParser.java
@SuppressWarnings({ "unchecked", "rawtypes" })
public BeanDefinition parse(Element element, ParserContext parserContext) {
BeanDefinitionRegistry bdr = parserContext.getRegistry();
RootBeanDefinition beanDef = new RootBeanDefinition();
beanDef.setDestroyMethodName("destroy");
beanDef.setAbstract(false);
beanDef.setBeanClass(getDataProcessorClass());
beanDef.setLazyInit(false);/*from w w w . ja v a 2 s. co m*/
beanDef.setAutowireMode(Autowire.BY_NAME.value());
String id = element.getAttribute("id");
if (bdr.containsBeanDefinition(id)) {
throw new RuntimeException("id[" + id + "]??");
}
bdr.registerBeanDefinition(id, beanDef);
beanDef.getPropertyValues().addPropertyValue("id", id);
String startProcessor = element.getAttribute("startProcessor");
boolean sp = false;
if (StringUtils.isNotEmpty(startProcessor)) {
sp = Boolean.parseBoolean(startProcessor);
}
beanDef.getPropertyValues().addPropertyValue("startProcessor", sp);
String transaction = element.getAttribute("transaction");
if (StringUtils.isNotEmpty(transaction)) {
beanDef.getPropertyValues().addPropertyValue("transaction", transaction);
} else if (sp) {
beanDef.getPropertyValues().addPropertyValue("transaction", TransactionMode.BEGIN.getMode());
}
String cloneContext = element.getAttribute("cloneContext");
if (StringUtils.isNotEmpty(cloneContext)) {
beanDef.getPropertyValues().addPropertyValue("cloneContext", Boolean.parseBoolean(cloneContext));
}
String propagations = element.getAttribute("propagations");
if (StringUtils.isNotEmpty(propagations)) {
List<String> propataionList = new ArrayList<String>();
for (String propagation : propagations.split(",")) {
propataionList.add(propagation);
}
beanDef.getPropertyValues().addPropertyValue("propagations", propataionList);
}
String nextDataProcessors = element.getAttribute("nextDataProcessors");
if (StringUtils.isNotEmpty(nextDataProcessors)) {
List nextDataProcessList = new ManagedList();
for (String nextDataProcess : nextDataProcessors.split(",")) {
nextDataProcess = nextDataProcess.trim();
nextDataProcessList.add(new RuntimeBeanReference(nextDataProcess));
}
beanDef.getPropertyValues().addPropertyValue("nextDataProcessors", nextDataProcessList);
}
customiseBeanDefinition(beanDef, element, parserContext);
return beanDef;
}
From source file:com.clican.pluto.fsm.spring.parser.AbstractStateParser.java
@SuppressWarnings({ "rawtypes", "unchecked" })
public BeanDefinition parse(Element element, ParserContext parserContext) {
BeanDefinitionRegistry bdr = parserContext.getRegistry();
RootBeanDefinition beanDef = new RootBeanDefinition();
beanDef.setDestroyMethodName("destroy");
beanDef.setAbstract(false);
beanDef.setBeanClass(getStateClass(element));
beanDef.setLazyInit(false);/*w w w. java2 s. c o m*/
beanDef.setAutowireMode(Autowire.BY_NAME.value());
String name = element.getAttribute("name");
if (bdr.containsBeanDefinition(name)) {
throw new RuntimeException("name[" + name + "]is defined duplicated");
}
bdr.registerBeanDefinition(name, beanDef);
beanDef.getPropertyValues().addPropertyValue("name", name);
String value = element.getAttribute("value");
beanDef.getPropertyValues().addPropertyValue("value", value);
String propagation = element.getAttribute("propagation");
beanDef.getPropertyValues().addPropertyValue("propagation", propagation);
String nextStates = element.getAttribute("nextStates");
if (StringUtils.isNotEmpty(nextStates)) {
List nextStateList = new ManagedList();
for (String nextState : nextStates.split(",")) {
nextStateList.add(new RuntimeBeanReference(nextState.trim()));
}
beanDef.getPropertyValues().addPropertyValue("nextStates", nextStateList);
}
String previousStates = element.getAttribute("previousStates");
if (StringUtils.isNotEmpty(previousStates)) {
List previousStateList = new ManagedList();
for (String previousState : previousStates.split(",")) {
previousStateList.add(new RuntimeBeanReference(previousState.trim()));
}
beanDef.getPropertyValues().addPropertyValue("previousStates", previousStateList);
}
NodeList nodeList = element.getChildNodes();
Map nextCondStates = new ManagedMap();
Map params = new ManagedMap();
List stateListeners = new ManagedList();
List taskListeners = new ManagedList();
Map timeoutListeners = new ManagedMap();
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
String localName = node.getLocalName();
Element e = (Element) node;
if ("nextCondStates".equals(localName)) {
String expr = e.getAttribute("expr");
nextStates = e.getAttribute("nextStates");
List nextStateList = new ManagedList();
if (StringUtils.isNotEmpty(nextStates)) {
for (String nextState : nextStates.split(",")) {
nextStateList.add(new RuntimeBeanReference(nextState.trim()));
}
}
nextCondStates.put(expr, nextStateList);
} else if ("param".equals(localName)) {
String paramName = e.getAttribute("name");
String paramValue = e.getAttribute("value");
params.put(paramName, paramValue);
} else if ("stateListener".equals(localName) || "timeoutListener".equals(localName)
|| "taskListener".equals(localName)) {
String clazz = e.getAttribute("clazz");
String listener = e.getAttribute("listener");
Object obj;
if (StringUtils.isNotEmpty(clazz)) {
try {
RootBeanDefinition bean = new RootBeanDefinition();
bean.setAbstract(false);
bean.setBeanClass(Class.forName(clazz));
bean.setLazyInit(false);
bean.setAutowireMode(Autowire.BY_NAME.value());
if ("timeoutListener".equals(localName)) {
String timeoutName = e.getAttribute("name");
String startTime = e.getAttribute("startTime");
String dueTime = e.getAttribute("dueTime");
String repeatTime = e.getAttribute("repeatTime");
String repeatDuration = e.getAttribute("repeatDuration");
String businessCalendarName = e.getAttribute("businessCalendarName");
bean.getPropertyValues().addPropertyValue("name", timeoutName);
bean.getPropertyValues().addPropertyValue("startTime", startTime);
bean.getPropertyValues().addPropertyValue("dueTime", dueTime);
bean.getPropertyValues().addPropertyValue("repeatTime", repeatTime);
bean.getPropertyValues().addPropertyValue("repeatDuration", repeatDuration);
bean.getPropertyValues().addPropertyValue("businessCalendarName",
businessCalendarName);
}
NodeList nodeList2 = element.getChildNodes();
Map params2 = new ManagedMap();
for (int j = 0; j < nodeList2.getLength(); j++) {
Node node2 = nodeList2.item(j);
if (node2.getNodeType() == Node.ELEMENT_NODE) {
String localName2 = node2.getLocalName();
if ("param".equals(localName2)) {
String paramName = ((Element) node2).getAttribute("name");
String paramValue = ((Element) node2).getAttribute("value");
params2.put(paramName, paramValue);
}
}
}
obj = bean;
} catch (Exception ex) {
throw new RuntimeException(ex);
}
} else if (StringUtils.isNotEmpty(listener)) {
obj = new RuntimeBeanReference(listener.trim());
} else {
throw new RuntimeException("There must be clazz or listener parameter setting");
}
if ("stateListener".equals(localName)) {
stateListeners.add(obj);
} else if ("taskListeners".equals(localName)) {
taskListeners.add(obj);
} else {
String timeoutName = e.getAttribute("name");
timeoutListeners.put(timeoutName, obj);
}
}
}
}
beanDef.getPropertyValues().addPropertyValue("nextCondStates", nextCondStates);
beanDef.getPropertyValues().addPropertyValue("params", params);
beanDef.getPropertyValues().addPropertyValue("stateListeners", stateListeners);
if (element.getNodeName().equals("task")) {
beanDef.getPropertyValues().addPropertyValue("taskListeners", taskListeners);
}
beanDef.getPropertyValues().addPropertyValue("timeoutListeners", timeoutListeners);
customiseBeanDefinition(beanDef, element, parserContext);
return beanDef;
}
From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java
@Test public void testCanReferenceParentBeanFromChildViaAlias() { final String EXPECTED_NAME = "Juergen"; final int EXPECTED_AGE = 41; RootBeanDefinition parentDefinition = new RootBeanDefinition(TestBean.class); parentDefinition.setAbstract(true); parentDefinition.getPropertyValues().add("name", EXPECTED_NAME); parentDefinition.getPropertyValues().add("age", EXPECTED_AGE); ChildBeanDefinition childDefinition = new ChildBeanDefinition("alias"); DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); factory.registerBeanDefinition("parent", parentDefinition); factory.registerBeanDefinition("child", childDefinition); factory.registerAlias("parent", "alias"); TestBean child = (TestBean) factory.getBean("child"); assertEquals(EXPECTED_NAME, child.getName()); assertEquals(EXPECTED_AGE, child.getAge()); assertEquals("Use cached merged bean definition", factory.getMergedBeanDefinition("child"), factory.getMergedBeanDefinition("child")); }
From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java
@Test public void testGetTypeForAbstractFactoryBean() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); RootBeanDefinition bd = new RootBeanDefinition(FactoryBeanThatShouldntBeCalled.class); bd.setAbstract(true); lbf.registerBeanDefinition("factoryBean", bd); assertNull(lbf.getType("factoryBean")); }