① WebWork2.2.1とSeasarをつなげてみる。
1. ObjectFactoryを継承したクラスを作る
com.opensymphony.xwork.ObjectFactoryを継承したクラスを作る。その際com.opensymphony.webwork.util.ObjectFactoryInitializableをimplementsする
public class S2ObjectFactory extends ObjectFactory implements ObjectFactoryInitializable { private S2Container container = null; /** * @see com.opensymphony.webwork.util.ObjectFactoryInitializable#init(javax.servlet.ServletContext) */ public void init(ServletContext servletContext) { this.container = SingletonS2ContainerFactory.getContainer(); } /** * @see com.opensymphony.xwork.ObjectFactory#buildAction(java.lang.String, java.lang.String, * com.opensymphony.xwork.config.entities.ActionConfig, java.util.Map) */ public Object buildAction(String actionName, String namespace, ActionConfig config, Map extraContext) throws Exception { return buildBean(config.getClassName(), extraContext); } /** * @see com.opensymphony.xwork.ObjectFactory#buildBean(java.lang.Class, java.util.Map) */ public Object buildBean(Class clazz, Map extraContext) throws Exception { return getComponent(clazz); } /** * @see com.opensymphony.xwork.ObjectFactory#buildBean(java.lang.String, java.util.Map) */ public Object buildBean(String className, Map extraContext) throws Exception { return getComponent(className); } private Object getComponent(Object targetClass) throws InstantiationException, IllegalAccessException, ClassNotFoundException { if (this.container.hasComponentDef(targetClass)) { return this.container.getComponent(targetClass); } // 指定されたクラスがない場合 // 実際はgetClassInstanceメソッドでContinuation対応がなれているがとりあえず未対応 Class clazz = null; if (targetClass instanceof Class) { clazz = (Class) targetClass; } else if (targetClass instanceof String) { clazz = Class.forName((String) targetClass); } if (clazz == null) { throw new ClassNotFoundException(targetClass.toString()); } return clazz.newInstance(); } }
2. webwork.properties
webwork.propertiesに上記で作ったObjectFactoryを設定する
webwork.objectFactory = jp.co.ysd.webwork.seaser.S2ObjectFactory