1 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 ; 15 16 21 public class ApplicationHelper { 22 private final transient Log logger = LogFactory.getLog(getClass()); 23 24 private static final String STANDALONE_APP = ""; 25 26 private static final String TOMCAT_PREFIX = "Tomcat.context:/"; 28 private static final String WEBLOGIC_PREFIX = "Weblogic."; 29 30 private String appName; 31 private DSOContext dsoContext; 32 33 public ApplicationHelper(Class c) { 34 ClassLoader cl = c.getClassLoader(); 35 36 try { 37 this.dsoContext = ClassProcessorHelper.getContext(cl); 38 39 if (cl instanceof NamedClassLoader) { 40 String 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 e) { 58 } 60 } 61 62 public boolean isDSOApplication() { 63 return this.dsoContext != null && this.appName != null; 64 } 65 66 public String getAppName() { 67 return appName; 68 } 69 70 public DSOContext getDsoContext() { 71 return dsoContext; 72 } 73 74 public boolean isFastProxyEnabled() { 75 for (Iterator 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 |