1 9 package org.jboss.portal.server.deployment; 10 11 import java.lang.reflect.Method ; 12 13 import javax.management.MBeanServer ; 14 15 import org.apache.log4j.Logger; 16 import org.jboss.web.WebApplication; 17 18 24 public class PortalWebAppFactory 25 { 26 27 private static Logger log = Logger.getLogger(PortalWebAppFactory.class); 28 29 private static final Class [] EMPTY_CLASS_ARRAY = new Class [0]; 30 private static final Object [] EMPTY_OBJECT_ARRAY = new Object [0]; 31 32 private static final int UNKNOWN = 0; 33 private static final int TOMCAT4 = 1; 34 private static final int TOMCAT5 = 2; 35 36 private final MBeanServer server; 37 38 public PortalWebAppFactory(MBeanServer server) 39 { 40 this.server = server; 41 } 42 43 48 public PortalWebApp create(WebApplication webApp) throws CannotCreatePortletWebAppException 49 { 50 switch (getVersion()) 51 { 52 case TOMCAT4: 53 return new PortalWebTomcat4App(webApp); 54 case TOMCAT5: 55 return new PortalWebTomcat5App(webApp, server); 56 default: 57 throw new CannotCreatePortletWebAppException("JBossWeb cannot handle it"); 58 } 59 } 60 61 64 private static int getVersion() 65 { 66 try 67 { 68 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 70 Class serverInfoClass = cl.loadClass("org.apache.catalina.util.ServerInfo"); 71 Method getServerInfoMethod = serverInfoClass.getMethod("getServerInfo", EMPTY_CLASS_ARRAY); 72 String result = (String )getServerInfoMethod.invoke(null, EMPTY_OBJECT_ARRAY); 73 if (result != null) 74 { 75 if (result.startsWith("Apache Tomcat/5")) 76 { 77 return TOMCAT5; 78 } 79 else if (result.startsWith("Apache Tomcat/4")) 80 { 81 return TOMCAT4; 82 } 83 } 84 } 85 catch (ClassNotFoundException e) 86 { 87 log.error("Cannot getPortalObjectContext catalina ServerInfo class"); 88 } 89 catch (NoSuchMethodException e) 90 { 91 log.error("Cannot invoke ServerInfo.getServerInfo()", e); 92 } 93 catch (Exception e) 94 { 95 log.error("Unexpected error", e); 96 } 97 return UNKNOWN; 98 } 99 } 100 | Popular Tags |