1 22 23 package org.jboss.web.php; 24 25 import java.lang.reflect.Method ; 26 import org.apache.catalina.Lifecycle; 27 import org.apache.catalina.LifecycleEvent; 28 import org.apache.catalina.util.StringManager; 29 import org.apache.commons.logging.Log; 30 import org.apache.commons.logging.LogFactory; 31 32 40 41 public class LifecycleListener 42 implements org.apache.catalina.LifecycleListener { 43 44 private static Log log = LogFactory.getLog(LifecycleListener.class); 45 46 49 protected StringManager sm = 50 StringManager.getManager(Constants.Package); 51 52 54 55 protected static final int REQUIRED_MAJOR = 5; 56 protected static final int REQUIRED_MINOR = 1; 57 protected static final int REQUIRED_PATCH = 0; 58 59 60 62 63 68 public void lifecycleEvent(LifecycleEvent event) { 69 70 if (Lifecycle.INIT_EVENT.equals(event.getType())) { 71 int major = 0; 72 int minor = 0; 73 int patch = 0; 74 try { 75 String methodName = "initialize"; 76 Class paramTypes[] = new Class [1]; 77 paramTypes[0] = String .class; 78 Object paramValues[] = new Object [1]; 79 paramValues[0] = null; 80 Class clazz = Class.forName("org.apache.catalina.servlets.php.Library"); 81 Method method = clazz.getMethod(methodName, paramTypes); 82 method.invoke(null, paramValues); 84 major = clazz.getField("PHP_MAJOR_VERSION").getInt(null); 85 minor = clazz.getField("PHP_MINOR_VERSION").getInt(null); 86 patch = clazz.getField("PHP_PATCH_VERSION").getInt(null); 87 } catch (Throwable t) { 88 if (!log.isDebugEnabled()) { 89 log.info(sm.getString("listener.initialize", 90 System.getProperty("java.library.path"))); 91 } 92 else { 93 log.debug(sm.getString("listener.initialize", 94 System.getProperty("java.library.path")), t); 95 } 96 return; 97 } 98 if ((major != REQUIRED_MAJOR) || 100 (minor != REQUIRED_MINOR) || 101 (patch < REQUIRED_PATCH)) { 102 log.error(sm.getString("listener.invalid", major + "." 103 + minor + "." + patch, REQUIRED_MAJOR + "." 104 + REQUIRED_MINOR + "." 105 + REQUIRED_PATCH)); 106 } 107 } 108 else if (Lifecycle.AFTER_STOP_EVENT.equals(event.getType())) { 109 try { 110 String methodName = "terminate"; 111 Method method = Class.forName("org.apache.catalina.servlets.php.Library") 112 .getMethod(methodName, (Class [])null); 113 method.invoke(null, (Object []) null); 114 } 115 catch (Throwable t) { 116 if (!log.isDebugEnabled()) { 117 log.info(sm.getString("listener.terminate")); 118 } 119 else { 120 log.debug(sm.getString("listener.terminate"), t); 121 } 122 } 123 } 124 } 125 } 126 | Popular Tags |