1 17 package org.apache.geronimo.tomcat; 18 19 import java.util.Map ; 20 21 import org.apache.catalina.Valve; 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 import org.apache.geronimo.gbean.GBeanInfo; 25 import org.apache.geronimo.gbean.GBeanInfoBuilder; 26 import org.apache.geronimo.gbean.GBeanLifecycle; 27 28 31 public class ValveGBean extends BaseGBean implements GBeanLifecycle, ObjectRetriever { 32 33 private static final Log log = LogFactory.getLog(ValveGBean.class); 34 35 public static final String J2EE_TYPE = "TomcatValve"; 36 37 private final Valve valve; 38 private final ValveGBean nextValve; 39 private final String className; 40 41 42 public ValveGBean(){ 43 valve = null; 44 nextValve = null; 45 className = null; 46 } 47 48 public ValveGBean(String className, Map initParams, ValveGBean nextValve) throws Exception { 49 50 if (className == null){ 52 throw new IllegalArgumentException ("className cannot be null."); 53 } 54 55 if (nextValve != null){ 56 if (!(nextValve.getInternalObject() instanceof Valve)){ 57 throw new IllegalArgumentException ("The class given as the NextValve attribute does not wrap an object of org.apache.catalina.Valve type."); 58 } 59 this.nextValve = nextValve; 60 } else { 61 this.nextValve = null; 62 } 63 64 this.className = className; 65 66 valve = (Valve)Class.forName(className).newInstance(); 68 69 setParameters(valve, initParams); 71 72 } 73 74 public void doStart() throws Exception { 75 log.debug(className + " started."); 76 } 77 78 public void doStop() throws Exception { 79 log.debug(className + " stopped."); 80 } 81 82 public void doFail() { 83 log.warn(className + " failed."); 84 } 85 86 public Object getInternalObject() { 87 return valve; 88 } 89 90 public ValveGBean getNextValve() { 91 return nextValve; 92 } 93 94 public static final GBeanInfo GBEAN_INFO; 95 96 static { 97 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(ValveGBean.class, J2EE_TYPE); 98 infoFactory.addAttribute("className", String .class, true); 99 infoFactory.addAttribute("initParams", Map .class, true); 100 infoFactory.addReference("NextValve", ValveGBean.class, J2EE_TYPE); 101 infoFactory.addOperation("getInternalObject"); 102 infoFactory.addOperation("getNextValve"); 103 infoFactory.setConstructor(new String [] { "className", "initParams", "NextValve" }); 104 GBEAN_INFO = infoFactory.getBeanInfo(); 105 } 106 107 public static GBeanInfo getGBeanInfo() { 108 return GBEAN_INFO; 109 } 110 111 } 112 | Popular Tags |