* @param config the filter configuration
* @throws RuntimeException if an initialization error occurs
*/
public synchronized void init(FilterConfig config) {
HtmlStringBuffer buffer = new HtmlStringBuffer();
buffer.append("DataContextFilter initialized: ");
filterConfig = config;
ServletUtil.initializeSharedConfiguration(config.getServletContext());
dataDomain = Configuration.getSharedConfiguration().getDomain();
String value = null;
value = config.getInitParameter("auto-rollback");
if (StringUtils.isNotBlank(value)) {
autoRollback = "true".equalsIgnoreCase(value);
}
buffer.append(" auto-rollback=" + autoRollback);
value = config.getInitParameter("session-scope");
if (StringUtils.isNotBlank(value)) {
sessionScope = "true".equalsIgnoreCase(value);
}
buffer.append(", session-scope=" + sessionScope);
value = config.getInitParameter("shared-cache");
if (StringUtils.isNotBlank(value)) {
sharedCache = "true".equalsIgnoreCase(value);
}
buffer.append(", shared-cache=");
buffer.append((sharedCache != null) ? sharedCache : "default");
value = config.getInitParameter("oscache-enabled");
boolean oscacheEnabled = "true".equalsIgnoreCase(value);
if (oscacheEnabled) {
dataDomain.setQueryCacheFactory(new OSQueryCacheFactory());
}
buffer.append(", oscache-enabled=" + oscacheEnabled);
String classname = config.getInitParameter("lifecycle-listener");
if (StringUtils.isNotEmpty(classname)) {
try {
@SuppressWarnings("unchecked")
Class listenerClass = ClickUtils.classForName(classname);
LifecycleCallbackRegistry registry =
dataDomain.getEntityResolver().getCallbackRegistry();
LifecycleListener lifecycleListener = (LifecycleListener)
listenerClass.newInstance();
if (registry.isEmpty(LifecycleEvent.POST_LOAD)) {
registry.addDefaultListener(lifecycleListener);
buffer.append(", lifecycle-listener=" + classname);
} else {
String message =
"Could not get LifecycleCallbackRegistry from domain: "
+ dataDomain.getName();
throw new RuntimeException(message);
}
} catch (Exception e) {
String message =
"Could not configure LifecycleCallbackRegistry: " + classname;
throw new RuntimeException(message, e);
}
}
// Log init data, note LogService is not yet initialized
getFilterConfig().getServletContext().log(buffer.toString());
}