KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tcspring > ApplicationHelper


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

4 package com.tcspring;
5
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8
9 import com.tc.object.bytecode.hook.DSOContext;
10 import com.tc.object.bytecode.hook.impl.ClassProcessorHelper;
11 import com.tc.object.config.DSOSpringConfigHelper;
12 import com.tc.object.loaders.NamedClassLoader;
13
14 import java.util.Iterator JavaDoc;
15
16 /**
17  * ApplicationHelper
18  *
19  * @author Eugene Kuleshov
20  */

21 public class ApplicationHelper {
22   private final transient Log logger = LogFactory.getLog(getClass());
23
24   private static final String JavaDoc STANDALONE_APP = "";
25
26   // Those prefixes defined in com.tc.object.loaders.Namespace which is not visible from this class
27
private static final String JavaDoc TOMCAT_PREFIX = "Tomcat.context:/";
28   private static final String JavaDoc WEBLOGIC_PREFIX = "Weblogic.";
29
30   private String JavaDoc appName;
31   private DSOContext dsoContext;
32
33   public ApplicationHelper(Class JavaDoc c) {
34     ClassLoader JavaDoc cl = c.getClassLoader();
35
36     try {
37       this.dsoContext = ClassProcessorHelper.getContext(cl);
38
39       if (cl instanceof NamedClassLoader) {
40         String JavaDoc name = ((NamedClassLoader) cl).__tc_getClassLoaderName();
41         logger.info("Application name " + name);
42         if (name != null) {
43           if (name.startsWith(TOMCAT_PREFIX)) {
44             name = name.substring(TOMCAT_PREFIX.length());
45           } else if (name.startsWith(WEBLOGIC_PREFIX)) {
46             int n = name.lastIndexOf('@');
47             if (n > -1) {
48               name = name.substring(n + 1);
49             }
50           }
51         }
52         this.appName = name;
53       } else {
54         this.appName = STANDALONE_APP;
55       }
56
57     } catch (Exception JavaDoc e) {
58       // TODO find a better way
59
}
60   }
61
62   public boolean isDSOApplication() {
63     return this.dsoContext != null && this.appName != null;
64   }
65
66   public String JavaDoc getAppName() {
67     return appName;
68   }
69
70   public DSOContext getDsoContext() {
71     return dsoContext;
72   }
73
74   public boolean isFastProxyEnabled() {
75     for (Iterator JavaDoc it = this.dsoContext.getDSOSpringConfigHelpers().iterator(); it.hasNext();) {
76       DSOSpringConfigHelper springConfigHelper = (DSOSpringConfigHelper) it.next();
77       if (springConfigHelper.isMatchingApplication(this.appName)) { return springConfigHelper.isFastProxyEnabled(); }
78     }
79     return false;
80   }
81 }
82
Popular Tags