List of usage examples for org.springframework.beans.factory.support RootBeanDefinition setDestroyMethodName
@Override public void setDestroyMethodName(@Nullable String destroyMethodName)
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);//from w w w . j a v a 2 s. c o m
beanDef.setBeanClass(getDataProcessorClass());
beanDef.setLazyInit(false);
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);//from ww w .j a v a 2 s . com
beanDef.setBeanClass(getStateClass(element));
beanDef.setLazyInit(false);
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 testBeanPostProcessorWithWrappedObjectAndDestroyMethod() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); RootBeanDefinition bd = new RootBeanDefinition(BeanWithDestroyMethod.class); bd.setDestroyMethodName("close"); lbf.registerBeanDefinition("test", bd); lbf.addBeanPostProcessor(new BeanPostProcessor() { @Override// w w w.ja v a 2 s . co m public Object postProcessBeforeInitialization(Object bean, String beanName) { return new TestBean(); } @Override public Object postProcessAfterInitialization(Object bean, String beanName) { return bean; } }); BeanWithDestroyMethod.closeCount = 0; lbf.preInstantiateSingletons(); lbf.destroySingletons(); assertEquals("Destroy methods invoked", 1, BeanWithDestroyMethod.closeCount); }
From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java
@Test public void testDestroyMethodOnInnerBean() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); RootBeanDefinition innerBd = new RootBeanDefinition(BeanWithDestroyMethod.class); innerBd.setDestroyMethodName("close"); RootBeanDefinition bd = new RootBeanDefinition(BeanWithDestroyMethod.class); bd.setDestroyMethodName("close"); bd.getPropertyValues().add("inner", innerBd); lbf.registerBeanDefinition("test", bd); BeanWithDestroyMethod.closeCount = 0; lbf.preInstantiateSingletons();/*from w w w . j av a2s. co m*/ lbf.destroySingletons(); assertEquals("Destroy methods invoked", 2, BeanWithDestroyMethod.closeCount); }
From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java
@Test public void testDestroyMethodOnInnerBeanAsPrototype() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); RootBeanDefinition innerBd = new RootBeanDefinition(BeanWithDestroyMethod.class); innerBd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); innerBd.setDestroyMethodName("close"); RootBeanDefinition bd = new RootBeanDefinition(BeanWithDestroyMethod.class); bd.setDestroyMethodName("close"); bd.getPropertyValues().add("inner", innerBd); lbf.registerBeanDefinition("test", bd); BeanWithDestroyMethod.closeCount = 0; lbf.preInstantiateSingletons();// w ww. j a v a 2 s .com lbf.destroySingletons(); assertEquals("Destroy methods invoked", 1, BeanWithDestroyMethod.closeCount); }
From source file:org.springframework.context.annotation.Spr3775InitDestroyLifecycleTests.java
private DefaultListableBeanFactory createBeanFactoryAndRegisterBean(final Class<?> beanClass, final String initMethodName, final String destroyMethodName) { DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); RootBeanDefinition beanDefinition = new RootBeanDefinition(beanClass); beanDefinition.setInitMethodName(initMethodName); beanDefinition.setDestroyMethodName(destroyMethodName); beanFactory.addBeanPostProcessor(new CommonAnnotationBeanPostProcessor()); beanFactory.registerBeanDefinition(LIFECYCLE_TEST_BEAN, beanDefinition); return beanFactory; }