01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tcspring;
06:
07: import org.apache.commons.logging.Log;
08: import org.apache.commons.logging.LogFactory;
09:
10: import com.tc.object.bytecode.hook.DSOContext;
11: import com.tc.object.bytecode.hook.impl.ClassProcessorHelper;
12: import com.tc.object.config.DSOSpringConfigHelper;
13: import com.tc.object.loaders.NamedClassLoader;
14:
15: import java.util.Iterator;
16:
17: /**
18: * ApplicationHelper
19: *
20: * @author Eugene Kuleshov
21: */
22: public class ApplicationHelper {
23: private final transient Log logger = LogFactory.getLog(getClass());
24:
25: private static final String STANDALONE_APP = "";
26:
27: // Those prefixes defined in com.tc.object.loaders.Namespace which is not visible from this class
28: private static final String TOMCAT_PREFIX = "Tomcat.";
29: private static final String WEBLOGIC_PREFIX = "Weblogic.";
30:
31: private String appName;
32: private DSOContext dsoContext;
33:
34: public ApplicationHelper(Class c) {
35: ClassLoader cl = c.getClassLoader();
36:
37: try {
38: this .dsoContext = ClassProcessorHelper.getContext(cl);
39:
40: if (cl instanceof NamedClassLoader) {
41: String name = ((NamedClassLoader) cl)
42: .__tc_getClassLoaderName();
43: logger.info("Application name " + name);
44: if (name != null) {
45: if (name.startsWith(TOMCAT_PREFIX)) {
46: name = name
47: .substring(name.lastIndexOf('/') + 1);
48: } else if (name.startsWith(WEBLOGIC_PREFIX)) {
49: int n = name.lastIndexOf('@');
50: if (n > -1) {
51: name = name.substring(n + 1);
52: }
53:
54: // for weblogic 9.2
55: if (name.endsWith(".war")) {
56: name = name.substring(0, name.length() - 4);
57: }
58: }
59: }
60: this .appName = name;
61: } else {
62: this .appName = STANDALONE_APP;
63: }
64:
65: } catch (Exception e) {
66: // TODO find a better way
67: }
68: }
69:
70: public boolean isDSOApplication() {
71: return this .dsoContext != null && this .appName != null;
72: }
73:
74: public String getAppName() {
75: return appName;
76: }
77:
78: public DSOContext getDsoContext() {
79: return dsoContext;
80: }
81:
82: public boolean isFastProxyEnabled() {
83: for (Iterator it = this .dsoContext.getDSOSpringConfigHelpers()
84: .iterator(); it.hasNext();) {
85: DSOSpringConfigHelper springConfigHelper = (DSOSpringConfigHelper) it
86: .next();
87: if (springConfigHelper.isMatchingApplication(this .appName)) {
88: return springConfigHelper.isFastProxyEnabled();
89: }
90: }
91: return false;
92: }
93: }
|