KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > terracotta > modules > struts_1_1 > StrutsTerracottaConfigurator


1 /*
2  * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
3  * notice. All rights reserved.
4  */

5 package org.terracotta.modules.struts_1_1;
6
7 import org.osgi.framework.BundleActivator;
8 import org.osgi.framework.BundleContext;
9 import org.osgi.framework.BundleException;
10 import org.osgi.framework.ServiceReference;
11
12 import com.tc.object.config.StandardDSOClientConfigHelper;
13 import com.tc.object.config.TransparencyClassSpec;
14
15 public final class StrutsTerracottaConfigurator implements BundleActivator {
16
17   private static final String JavaDoc INCLUDE_TAG_CLASSNAME = "org.apache.struts.taglib.bean.IncludeTag";
18
19   public void start(final BundleContext context) throws Exception JavaDoc {
20     final ServiceReference configHelperRef = context.getServiceReference(StandardDSOClientConfigHelper.class.getName());
21     if (configHelperRef != null) {
22       final StandardDSOClientConfigHelper configHelper = (StandardDSOClientConfigHelper) context
23           .getService(configHelperRef);
24       addStrutsInstrumentation(configHelper);
25       context.ungetService(configHelperRef);
26     } else {
27       throw new BundleException("Expected the " + StandardDSOClientConfigHelper.class.getName()
28           + " service to be registered, was unable to find it");
29     }
30   }
31
32   public void stop(final BundleContext context) throws Exception JavaDoc {
33     // Ignore this, we don't need to stop anything
34
}
35
36   private void addStrutsInstrumentation(final StandardDSOClientConfigHelper configHelper) {
37     // Hack for honoring transient in Struts action classes
38
TransparencyClassSpec spec = configHelper.getOrCreateSpec("org.apache.struts.action.ActionForm");
39     spec.setHonorTransient(true);
40     spec = configHelper.getOrCreateSpec("org.apache.struts.action.ActionMappings");
41     spec.setHonorTransient(true);
42     spec = configHelper.getOrCreateSpec("org.apache.struts.action.ActionServletWrapper");
43     spec.setHonorTransient(true);
44     spec = configHelper.getOrCreateSpec("org.apache.struts.action.DynaActionFormClass");
45     spec.setHonorTransient(true);
46
47     // Hack for Struts <bean:include> tag; when running in tests we need to synchronize as there is a race condition
48
// here. The reason for doing this at all is that you can only ever add one custom class adapter for a given name
49
synchronized (configHelper) {
50       if (!configHelper.hasCustomAdapter(INCLUDE_TAG_CLASSNAME)) {
51         configHelper.addCustomAdapter(INCLUDE_TAG_CLASSNAME, new IncludeTagAdapter());
52       }
53     }
54   }
55
56 }
57
Popular Tags