1 17 package org.apache.geronimo.jetty6; 18 19 import java.util.Map ; 20 import java.util.Set ; 21 22 import javax.security.auth.Subject ; 23 24 import org.apache.geronimo.gbean.GBeanInfo; 25 import org.apache.geronimo.gbean.GBeanInfoBuilder; 26 import org.apache.geronimo.gbean.GBeanLifecycle; 27 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 28 import org.apache.geronimo.management.Servlet; 29 import org.mortbay.jetty.servlet.ServletHolder; 30 31 32 42 public class JettyServletHolder implements Servlet, GBeanLifecycle { 43 44 45 private final JettyServletRegistration servletRegistration; 46 private final ServletHolder servletHolder; 47 private final String objectName; 48 49 public JettyServletHolder() { 51 servletRegistration = null; 52 servletHolder = null; 53 objectName = null; 54 } 55 56 public JettyServletHolder(String objectName, 57 String servletName, 58 String servletClassName, 59 String jspFile, 60 Map initParams, 61 Integer loadOnStartup, 62 Set servletMappings, 63 Subject runAsSubject, 64 JettyServletRegistration context) throws Exception { 65 servletRegistration = context; 66 servletHolder = new InternalJettyServletHolder(context == null? null: context.getLifecycleChain(), runAsSubject); 67 servletHolder.setName(servletName); 68 servletHolder.setClassName(servletClassName); 69 71 if (context != null) { 72 servletHolder.setInitParameters(initParams); 73 servletHolder.setForcedPath(jspFile); 74 if (loadOnStartup != null) { 75 servletHolder.setInitOrder(loadOnStartup.intValue()); 77 } 78 context.registerServletHolder(servletHolder, servletName, servletMappings, objectName); 80 } 81 this.objectName = objectName; 82 } 83 84 public String getServletName() { 85 return servletHolder.getName(); 86 } 87 88 public String getObjectName() { 89 return objectName; 90 } 91 92 public boolean isStateManageable() { 93 return false; 94 } 95 96 public boolean isStatisticsProvider() { 97 return false; 98 } 99 100 public boolean isEventProvider() { 101 return false; 102 } 103 104 public void doStart() throws Exception { 105 } 108 109 public void doStop() throws Exception { 110 if (servletRegistration != null) { 111 servletRegistration.unregisterServletHolder(servletHolder, servletHolder.getName(), null, objectName); 112 } 113 } 114 115 public void doFail() { 116 try { 117 servletHolder.stop(); 118 } catch (Exception e) { 119 } 121 } 122 123 public static final GBeanInfo GBEAN_INFO; 124 125 static { 126 GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(JettyServletHolder.class, NameFactory.SERVLET); 127 130 infoBuilder.addAttribute("servletName", String .class, true); 131 infoBuilder.addAttribute("servletClass", String .class, true); 132 infoBuilder.addAttribute("jspFile", String .class, true); 133 infoBuilder.addAttribute("initParams", Map .class, true); 134 infoBuilder.addAttribute("loadOnStartup", Integer .class, true); 135 infoBuilder.addAttribute("servletMappings", Set .class, true); 136 infoBuilder.addAttribute("runAsSubject", Subject .class, true); 137 infoBuilder.addAttribute("objectName", String .class, false); 138 infoBuilder.addInterface(Servlet.class); 139 140 infoBuilder.addReference("JettyServletRegistration", JettyServletRegistration.class, NameFactory.WEB_MODULE); 141 142 infoBuilder.setConstructor(new String []{"objectName", 143 "servletName", 144 "servletClass", 145 "jspFile", 146 "initParams", 147 "loadOnStartup", 148 "servletMappings", 149 "runAsSubject", 150 "JettyServletRegistration"}); 151 152 GBEAN_INFO = infoBuilder.getBeanInfo(); 153 } 154 155 public static GBeanInfo getGBeanInfo() { 156 return GBEAN_INFO; 157 } 158 159 } 160 | Popular Tags |