S2Tapestry
次の3つのクラスで構成されます。
以前のまさたかさんのコードを最新のS2に対応させてます。
public class GlobalProxy {private Object global_;
public GlobalProxy(Object global) {
global_ = global;
}
public Object getGlobal() {
return global_;
}
}
public class GlobalProxyPropertyAccessor extends
ObjectPropertyAccessor {public Object getProperty(Map cx, Object target, Object name)
throws OgnlException {GlobalProxy proxy = (GlobalProxy) target;
S2Container container =
SingletonS2ContainerFactory.getContainer();
String componentName = name.toString();
if (container.hasComponentDef(componentName)) {
return container.getComponent(componentName);
} else {
return super.getProperty(cx, proxy.getGlobal(), name);
}
}
}
public class S2Engine extends BaseEngine {static {
OgnlRuntime.setPropertyAccessor(
GlobalProxy.class,
new GlobalProxyPropertyAccessor());
}protected Object createGlobal(RequestContext context) {
Object global = super.createGlobal(context);
return new GlobalProxy(global);
}
}