1 17 package org.apache.geronimo.tomcat; 18 19 import java.util.ArrayList ; 20 import java.util.Iterator ; 21 import java.util.Map ; 22 import org.apache.catalina.Host; 23 import org.apache.catalina.Manager; 24 import org.apache.catalina.Realm; 25 import org.apache.catalina.Valve; 26 import org.apache.catalina.core.StandardHost; 27 import org.apache.commons.logging.Log; 28 import org.apache.commons.logging.LogFactory; 29 import org.apache.geronimo.gbean.GBeanInfo; 30 import org.apache.geronimo.gbean.GBeanInfoBuilder; 31 import org.apache.geronimo.gbean.GBeanLifecycle; 32 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 33 34 37 public class HostGBean extends BaseGBean implements GBeanLifecycle, ObjectRetriever { 38 39 private static final Log log = LogFactory.getLog(HostGBean.class); 40 41 public static final String J2EE_TYPE = "Host"; 42 private static final String WORKDIR = "workDir"; 43 private static final String NAME = "name"; 44 45 private final Host host; 46 47 public HostGBean(){ 48 host = null; 49 } 50 51 public HostGBean(String className, 52 Map initParams, 53 ArrayList aliases, 54 ObjectRetriever realmGBean, 55 ValveGBean tomcatValveChain, 56 ManagerGBean manager) throws Exception { 58 super(); 60 if (className == null){ 62 className = "org.apache.catalina.core.StandardHost"; 63 } 64 65 if (initParams == null){ 66 throw new IllegalArgumentException ("Must have a 'name' value in initParams."); 67 } 68 69 if (!initParams.containsKey(NAME)){ 71 throw new IllegalArgumentException ("Must have a 'name' value initParams."); 72 } 73 74 if (!initParams.containsKey(WORKDIR)){ 76 initParams.put(WORKDIR, "work"); 77 } 78 79 host = (Host)Class.forName(className).newInstance(); 81 82 setParameters(host, initParams); 84 85 if (aliases != null){ 87 for (Iterator iter = aliases.iterator(); iter.hasNext();) { 88 String alias = (String ) iter.next(); 89 host.addAlias(alias); 90 } 91 } 92 93 if (realmGBean != null) 94 host.setRealm((Realm)realmGBean.getInternalObject()); 95 96 if (host instanceof StandardHost){ 98 if (tomcatValveChain != null){ 99 ValveGBean valveGBean = tomcatValveChain; 100 while(valveGBean != null){ 101 ((StandardHost)host).addValve((Valve)valveGBean.getInternalObject()); 102 valveGBean = valveGBean.getNextValve(); 103 } 104 } 105 } 106 107 112 if (manager != null) 114 host.setManager((Manager)manager.getInternalObject()); 115 } 116 117 public Object getInternalObject() { 118 return host; 119 } 120 121 public void doFail() { 122 log.warn("Failed"); 123 } 124 125 public void doStart() throws Exception { 126 log.debug("Started host name '" + host.getName() + "'"); 127 } 128 129 public void doStop() throws Exception { 130 log.debug("Stopped host '" + host.getName() + "'"); 131 } 132 133 public static final GBeanInfo GBEAN_INFO; 134 135 static { 136 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic("TomcatHost", HostGBean.class, J2EE_TYPE); 137 infoFactory.addAttribute("className", String .class, true); 138 infoFactory.addAttribute("initParams", Map .class, true); 139 infoFactory.addAttribute("aliases", ArrayList .class, true); 140 infoFactory.addReference("RealmGBean", ObjectRetriever.class, NameFactory.GERONIMO_SERVICE); 141 infoFactory.addReference("TomcatValveChain", ValveGBean.class, ValveGBean.J2EE_TYPE); 142 infoFactory.addReference("Manager", ManagerGBean.class, ManagerGBean.J2EE_TYPE); 144 infoFactory.addOperation("getInternalObject"); 145 infoFactory.setConstructor(new String [] { 146 "className", 147 "initParams", 148 "aliases", 149 "RealmGBean", 150 "TomcatValveChain", 151 "Manager"}); 153 GBEAN_INFO = infoFactory.getBeanInfo(); 154 } 155 156 public static GBeanInfo getGBeanInfo() { 157 return GBEAN_INFO; 158 } 159 } 160 | Popular Tags |