package jfun.yan.xml.nuts.spring;
import java.util.Properties;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.context.ApplicationContext;
import org.springframework.transaction.PlatformTransactionManager;
import jfun.yan.Component;
import jfun.yan.spring.SpringAdapter;
import jfun.yan.spring.SpringContext;
import jfun.yan.xml.SingletonMode;
import jfun.yan.xml.nuts.ConstructorNut;
/**
* A spring-aware ctor tag.
* <p>
* @author Ben Yu
* Nov 17, 2005 12:07:08 AM
*/
public class SpringCtorNut extends ConstructorNut
implements SpringContext{
private final SpringService spring;
private Component tx;
private Component transaction_attrs;
private String[] interfaces;
public void setInit_method(String name){
setInitializer(name);
}
public void setDestroy_method(String name){
setDisposer(name);
}
public void setStart_method(String name){
setStarter(name);
}
public void setStop_method(String name){
setStopper(name);
}
public String[] getInterfaces() {
return interfaces;
}
public void setInterfaces(String[] interfaces) {
this.interfaces = interfaces;
}
public Component getTransactionAttributes() {
return transaction_attrs;
}
public void setTransactionAttributes(Component transaction_attrs) {
this.transaction_attrs =
cast(Properties.class, transaction_attrs);
}
public Component getTransactionManager() {
return tx;
}
public void setTransactionManager(Component tx) {
this.tx = cast(PlatformTransactionManager.class, tx);
}
public SpringCtorNut(SpringService service) {
this.spring = service;
}
public void manageDisposableBean(DisposableBean instance){
spring.manageDisposableBean(instance);
}
public ApplicationContext getApplicationContext() {
return spring.getApplicationContext();
}
public Component eval(){
final Component r = super.eval();
return SpringAdapter.adapt(r, this, tx, transaction_attrs, interfaces);
}
public void addBeanPostProcessor(String key, Component bpp) {
spring.addBeanPostProcessor(key, bpp.getType(), bpp);
}
private boolean singleton_attribute_set = false;
private SingletonMode singleton;
public SingletonMode getSingleton() {
return singleton;
}
public void setSingleton(SingletonMode singleton) {
singleton_attribute_set = true;
this.singleton = singleton;
}
public boolean isSingletonAttributeSet() {
return singleton_attribute_set;
}
}