KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > jetty6 > JettyServletHolder


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.jetty6;
18
19 import java.util.Map JavaDoc;
20 import java.util.Set JavaDoc;
21
22 import javax.security.auth.Subject JavaDoc;
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 /**
33  * This ServletHolder's sole purpose is to provide the thread's current
34  * ServletHolder for realms that are interested in the current servlet, e.g.
35  * current servlet name.
36  * <p/>
37  * It is also being our servlet gbean for now. We could gbean-ize the superclass to avoid the thread local access.
38  *
39  * @version $Rev: 482336 $ $Date: 2006-12-04 15:12:19 -0500 (Mon, 04 Dec 2006) $
40  * @see JAASJettyRealm#isUserInRole(java.security.Principal, String)
41  */

42 public class JettyServletHolder implements Servlet, GBeanLifecycle {
43
44
45     private final JettyServletRegistration servletRegistration;
46     private final ServletHolder servletHolder;
47     private final String JavaDoc objectName;
48
49     //todo consider interface instead of this constructor for endpoint use.
50
public JettyServletHolder() {
51         servletRegistration = null;
52         servletHolder = null;
53         objectName = null;
54     }
55
56     public JettyServletHolder(String JavaDoc objectName,
57             String JavaDoc servletName,
58             String JavaDoc servletClassName,
59             String JavaDoc jspFile,
60             Map JavaDoc initParams,
61             Integer JavaDoc loadOnStartup,
62             Set JavaDoc servletMappings,
63             Subject JavaDoc runAsSubject,
64             JettyServletRegistration context) throws Exception JavaDoc {
65         servletRegistration = context;
66         servletHolder = new InternalJettyServletHolder(context == null? null: context.getLifecycleChain(), runAsSubject);
67         servletHolder.setName(servletName);
68         servletHolder.setClassName(servletClassName);
69         //context will be null only for use as "default servlet info holder" in deployer.
70

71         if (context != null) {
72             servletHolder.setInitParameters(initParams);
73             servletHolder.setForcedPath(jspFile);
74             if (loadOnStartup != null) {
75                 //This has no effect on the actual start order, the gbean references "previous" control that.
76
servletHolder.setInitOrder(loadOnStartup.intValue());
77             }
78             //this now starts the servlet in the appropriate context
79
context.registerServletHolder(servletHolder, servletName, servletMappings, objectName);
80         }
81         this.objectName = objectName;
82     }
83
84     public String JavaDoc getServletName() {
85         return servletHolder.getName();
86     }
87
88     public String JavaDoc 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 JavaDoc {
105         //start actually handled in constructor
106
// servletHolder.start();
107
}
108
109     public void doStop() throws Exception JavaDoc {
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 JavaDoc e) {
119             //?? ignore
120
}
121     }
122
123     public static final GBeanInfo GBEAN_INFO;
124
125     static {
126         GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(JettyServletHolder.class, NameFactory.SERVLET);
127         //todo replace with interface
128
// infoBuilder.addInterface(ServletHolder.class);
129

130         infoBuilder.addAttribute("servletName", String JavaDoc.class, true);
131         infoBuilder.addAttribute("servletClass", String JavaDoc.class, true);
132         infoBuilder.addAttribute("jspFile", String JavaDoc.class, true);
133         infoBuilder.addAttribute("initParams", Map JavaDoc.class, true);
134         infoBuilder.addAttribute("loadOnStartup", Integer JavaDoc.class, true);
135         infoBuilder.addAttribute("servletMappings", Set JavaDoc.class, true);
136         infoBuilder.addAttribute("runAsSubject", Subject JavaDoc.class, true);
137         infoBuilder.addAttribute("objectName", String JavaDoc.class, false);
138         infoBuilder.addInterface(Servlet.class);
139
140         infoBuilder.addReference("JettyServletRegistration", JettyServletRegistration.class, NameFactory.WEB_MODULE);
141
142         infoBuilder.setConstructor(new String JavaDoc[]{"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