1 9 10 package com.opensymphony.module.sitemesh.util; 11 12 import java.util.HashMap ; 13 import java.util.Iterator ; 14 import java.util.Map ; 15 16 28 public final class Container { 29 public static final int UNKNOWN = 0; 30 public static final int TOMCAT = 1; 31 public static final int RESIN = 2; 32 public static final int ORION = 3; public static final int WEBLOGIC = 4; 34 public static final int HPAS = 5; 35 public static final int JRUN = 6; 36 public static final int WEBSPHERE = 7; 37 38 private static int result = -1; 39 40 44 private static Map classMappings = null; 45 46 static { 47 classMappings = new HashMap (6); 49 classMappings.put("org.apache.jasper.runtime.JspFactoryImpl", new Integer (TOMCAT)); 50 classMappings.put("com.caucho.jsp.JspServlet", new Integer (RESIN)); 51 classMappings.put("com.evermind.server.http.JSPServlet", new Integer (ORION)); 52 classMappings.put("weblogic.servlet.JSPServlet", new Integer (WEBLOGIC)); 53 classMappings.put("com.hp.mwlabs.j2ee.containers.servlet.jsp.JspServlet", new Integer (HPAS)); 54 classMappings.put("jrun.servlet.WebApplicationService", new Integer (JRUN)); 55 classMappings.put("com.ibm.ws.webcontainer.jsp.servlet.JspServlet", new Integer (WEBSPHERE)); 56 } 57 58 59 public static int get() { 60 if (result == -1) { 61 final String classMatch = searchForClosestClass(classMappings); 62 63 if (classMatch == null) { 64 result = UNKNOWN; 65 } 66 else { 67 result = ((Integer ) classMappings.get(classMatch)).intValue(); 68 } 69 } 70 return result; 71 } 72 73 79 private static String searchForClosestClass(Map classMappings) { 80 ClassLoader loader = Container.class.getClassLoader(); 82 83 while (loader != null) { 85 86 for (Iterator iterator = classMappings.keySet().iterator(); iterator.hasNext();) { 87 String className = (String ) iterator.next(); 88 89 try { 90 loader.loadClass(className); 92 return className; 94 } 95 catch (ClassNotFoundException e) { 96 } 98 } 99 loader = loader.getParent(); 100 } 101 102 return null; 104 } 105 } 106 | Popular Tags |