001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.portal.pluto.om;
018:
019: import java.util.Collection;
020: import java.util.Locale;
021:
022: import javax.servlet.RequestDispatcher;
023: import javax.servlet.ServletContext;
024:
025: import org.apache.pluto.om.common.Description;
026: import org.apache.pluto.om.common.DescriptionSet;
027: import org.apache.pluto.om.common.DisplayName;
028: import org.apache.pluto.om.common.DisplayNameSet;
029: import org.apache.pluto.om.common.ObjectID;
030: import org.apache.pluto.om.common.ParameterSet;
031: import org.apache.pluto.om.common.SecurityRoleRefSet;
032: import org.apache.pluto.om.servlet.ServletDefinition;
033: import org.apache.pluto.om.servlet.ServletDefinitionCtrl;
034: import org.apache.pluto.om.servlet.WebApplicationDefinition;
035: import org.apache.cocoon.portal.pluto.om.common.ParameterSetImpl;
036: import org.apache.cocoon.portal.pluto.om.common.SecurityRoleRefSetImpl;
037: import org.apache.cocoon.portal.pluto.om.common.Support;
038: import org.apache.cocoon.portal.pluto.om.common.DescriptionSetImpl;
039: import org.apache.cocoon.portal.pluto.om.common.DisplayNameSetImpl;
040:
041: /**
042: *
043: *
044: * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
045: *
046: * @version CVS $Id: ServletDefinitionImpl.java 433543 2006-08-22 06:22:54Z crossley $
047: */
048: public class ServletDefinitionImpl implements ServletDefinition,
049: ServletDefinitionCtrl, java.io.Serializable, Support {
050:
051: private DescriptionSet descriptions = new DescriptionSetImpl();
052: private DisplayNameSet displayNames = new DisplayNameSetImpl();
053:
054: // not used variables - only for castor
055: public String icon;
056: private String id = "";
057: private ParameterSet initParams = new ParameterSetImpl();
058: private SecurityRoleRefSet initSecurityRoleRefs = new SecurityRoleRefSetImpl();
059: public String jspFile;
060: public String loadOnStartup;
061: private ObjectID objectId;
062: public String securityRoleRef;
063: private String servletClass;
064: private ServletMapping servletMapping;
065: private String servletName;
066: private long available = 0;
067:
068: private WebApplicationDefinition webApplication;
069:
070: // ServletDefinition implementation.
071:
072: public ObjectID getId() {
073: if (objectId == null) {
074: objectId = org.apache.cocoon.portal.pluto.om.common.ObjectIDImpl
075: .createFromString(id);
076: }
077: return objectId;
078: }
079:
080: public String getServletName() {
081: return servletName;
082: }
083:
084: public DisplayName getDisplayName(Locale locale) {
085: return displayNames.get(locale);
086: }
087:
088: /* (non-Javadoc)
089: * @see org.apache.pluto.om.servlet.ServletDefinition#getDescription(Locale)
090: */
091: public Description getDescription(Locale locale) {
092: return descriptions.get(locale);
093: }
094:
095: public String getServletClass() {
096: return servletClass;
097: }
098:
099: public ParameterSet getInitParameterSet() {
100: return initParams;
101: }
102:
103: public WebApplicationDefinition getWebApplicationDefinition() {
104: return webApplication;
105: }
106:
107: public RequestDispatcher getRequestDispatcher(
108: ServletContext servletContext) {
109: ServletContext newContext = webApplication
110: .getServletContext(servletContext);
111: if (newContext == null) {
112: return null;
113: }
114: return newContext.getRequestDispatcher(servletMapping
115: .getUrlPattern());
116: }
117:
118: public long getAvailable() {
119: return available;
120: }
121:
122: public boolean isUnavailable() {
123: if (available == 0) {
124: return false;
125: } else if (available <= System.currentTimeMillis()) {
126: available = 0;
127: return false;
128: } else {
129: return true;
130: }
131: }
132:
133: // Support implementation.
134:
135: public void postBuild(Object parameter) throws Exception {
136: setServletMapping((ServletMapping) parameter);
137: }
138:
139: public void postLoad(Object parameter) throws Exception {
140: ((Support) descriptions).postLoad(parameter);
141: ((Support) displayNames).postLoad(parameter);
142: }
143:
144: public void postStore(Object parameter) throws Exception {
145: // nothing to do
146: }
147:
148: public void preBuild(Object parameter) throws Exception {
149: setWebApplicationDefinition((WebApplicationDefinition) parameter);
150: }
151:
152: public void preStore(Object parameter) throws Exception {
153: // nothing to do
154: }
155:
156: // additional methods.
157:
158: public String getCastorId() {
159: if (id.length() > 0) {
160: return getId().toString();
161: }
162: return null;
163: }
164:
165: public Collection getCastorInitParams() {
166: return (ParameterSetImpl) initParams;
167: }
168:
169: public SecurityRoleRefSet getCastorInitSecurityRoleRefs() {
170: return initSecurityRoleRefs;
171: }
172:
173: public Collection getCastorDisplayNames() {
174: return (DisplayNameSetImpl) displayNames;
175: }
176:
177: public Collection getCastorDescriptions() {
178: return (DescriptionSetImpl) descriptions;
179: }
180:
181: public Collection getDescriptions() {
182: return (DescriptionSetImpl) descriptions;
183: }
184:
185: public SecurityRoleRefSet getInitSecurityRoleRefSet() {
186: return initSecurityRoleRefs;
187: }
188:
189: public String getJspFile() {
190: return jspFile;
191: }
192:
193: public void setCastorId(String id) {
194: setId(id);
195: }
196:
197: public void setCastorInitSecurityRoleRefs(
198: SecurityRoleRefSet castorInitSecurityRoleRefs) {
199: this .initSecurityRoleRefs = castorInitSecurityRoleRefs;
200: }
201:
202: public void setCastorDisplayNames(DisplayNameSet castorDisplayNames) {
203: this .displayNames = castorDisplayNames;
204: }
205:
206: public void setCastorDescriptions(DescriptionSet castorDescriptions) {
207: this .descriptions = castorDescriptions;
208: }
209:
210: public void setDisplayNames(DisplayNameSet displayNames) {
211: this .displayNames = displayNames;
212: }
213:
214: public void setDescriptions(DescriptionSet descriptions) {
215: this .descriptions = descriptions;
216: }
217:
218: public void setId(String id) {
219: this .id = id;
220: this .objectId = null;
221: }
222:
223: public void setServletClass(String servletClass) {
224: this .servletClass = servletClass;
225: }
226:
227: public void setAvailable(long available) {
228: if (available > System.currentTimeMillis()) {
229: this .available = available;
230: } else {
231: this .available = 0;
232: }
233: }
234:
235: public void setJspFile(String jspFile) {
236: this .jspFile = jspFile;
237: }
238:
239: protected void setServletMapping(ServletMapping servletMapping) {
240: this .servletMapping = servletMapping;
241: }
242:
243: public void setServletName(String servletName) {
244: this .servletName = servletName;
245: }
246:
247: protected void setWebApplicationDefinition(
248: WebApplicationDefinition webApplication) {
249: this.webApplication = webApplication;
250: }
251:
252: }
|