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.jetspeed.om.servlet.impl;
018:
019: import java.io.Serializable;
020: import java.util.ArrayList;
021: import java.util.Collection;
022: import java.util.Locale;
023:
024: import javax.servlet.ServletContext;
025:
026: import org.apache.commons.logging.Log;
027: import org.apache.commons.logging.LogFactory;
028: import org.apache.jetspeed.om.common.MutableDescription;
029: import org.apache.jetspeed.om.common.MutableDisplayName;
030: import org.apache.jetspeed.om.common.servlet.MutableWebApplication;
031: import org.apache.jetspeed.om.impl.DescriptionImpl;
032: import org.apache.jetspeed.om.impl.DescriptionSetImpl;
033: import org.apache.jetspeed.om.impl.DisplayNameSetImpl;
034: import org.apache.jetspeed.om.impl.WebAppDescriptionImpl;
035: import org.apache.jetspeed.om.impl.WebAppDisplayNameImpl;
036: import org.apache.jetspeed.util.JetspeedLocale;
037: import org.apache.jetspeed.util.JetspeedLongObjectID;
038: import org.apache.pluto.om.common.Description;
039: import org.apache.pluto.om.common.DescriptionSet;
040: import org.apache.pluto.om.common.DisplayName;
041: import org.apache.pluto.om.common.DisplayNameSet;
042: import org.apache.pluto.om.common.ObjectID;
043: import org.apache.pluto.om.common.ParameterSet;
044: import org.apache.pluto.om.servlet.ServletDefinitionList;
045: import org.apache.pluto.om.common.SecurityRole;
046: import org.apache.pluto.om.common.SecurityRoleSet;
047:
048: /**
049: *
050: * WebApplicationDefinitionImpl
051: *
052: * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
053: * @version $Id: WebApplicationDefinitionImpl.java 516448 2007-03-09 16:25:47Z ate $
054: *
055: */
056: public class WebApplicationDefinitionImpl implements
057: MutableWebApplication, Serializable {
058: private Long id;
059: private JetspeedLongObjectID oid;
060: private Collection displayNames = new ArrayList();
061: private DisplayNameSetImpl DNCollWrapper = new DisplayNameSetImpl();
062:
063: private Collection descriptions = new ArrayList();
064: private DescriptionSetImpl descCollWrapper = new DescriptionSetImpl(
065: DescriptionImpl.TYPE_WEB_APP);
066: private Collection securityRoles = new ArrayList();
067: private SecurityRoleSetImpl secRolesListWrapper = new SecurityRoleSetImpl();
068:
069: private String contextRoot;
070: private ParameterSet initParameters;
071:
072: private static final Log log = LogFactory
073: .getLog(WebApplicationDefinitionImpl.class);
074:
075: /**
076: * @see org.apache.pluto.om.servlet.WebApplicationDefinition#getId()
077: */
078: public ObjectID getId() {
079: if (oid == null && id != null) {
080: oid = new JetspeedLongObjectID(id);
081: }
082: return oid;
083: }
084:
085: /**
086: * @see org.apache.pluto.om.servlet.WebApplicationDefinition#getDisplayName()
087: */
088: public DisplayName getDisplayName(Locale locale) {
089:
090: if (displayNames != null) {
091: DNCollWrapper.setInnerCollection(displayNames);
092: return DNCollWrapper.get(locale);
093: }
094: return null;
095:
096: }
097:
098: /**
099: * @see org.apache.pluto.om.servlet.WebApplicationDefinition#getDescription()
100: */
101: public Description getDescription(Locale locale) {
102: if (descriptions != null) {
103: descCollWrapper.setInnerCollection(descriptions);
104: return descCollWrapper.get(locale);
105: }
106: return null;
107:
108: }
109:
110: /**
111: * @see org.apache.pluto.om.servlet.WebApplicationDefinition#getInitParameterSet()
112: */
113: public ParameterSet getInitParameterSet() {
114: return initParameters;
115: }
116:
117: /**
118: * @see org.apache.pluto.om.servlet.WebApplicationDefinition#getServletDefinitionList()
119: */
120: public ServletDefinitionList getServletDefinitionList() {
121: // TODO Auto-generated method stub
122: return null;
123: }
124:
125: /**
126: * @see org.apache.pluto.om.servlet.WebApplicationDefinition#getServletContext(javax.servlet.ServletContext)
127: */
128: public ServletContext getServletContext(
129: ServletContext servletContext) {
130: // TODO Auto-generated method stub
131: return null;
132: }
133:
134: /**
135: * @see org.apache.pluto.om.servlet.WebApplicationDefinition#getContextRoot()
136: */
137: public String getContextRoot() {
138: return contextRoot;
139: }
140:
141: /**
142: * @see org.apache.pluto.om.servlet.WebApplicationDefinitionCtrl#setDisplayName(java.lang.String)
143: */
144: public void setDisplayNameSet(DisplayNameSet displayNames) {
145: this .displayNames = ((DisplayNameSetImpl) displayNames)
146: .getInnerCollection();
147: }
148:
149: /**
150: * @see org.apache.jetspeed.om.common.servlet.WebApplicationComposite#setContextRoot(java.lang.String)
151: */
152: public void setContextRoot(String contextRoot) {
153: this .contextRoot = contextRoot;
154: }
155:
156: /**
157: * @see org.apache.jetspeed.om.common.servlet.MutableWebApplication#addDescription(java.util.Locale, java.lang.String)
158: */
159: public void addDescription(Locale locale, String description) {
160: if (descriptions == null) {
161: descriptions = new ArrayList();
162: }
163: descCollWrapper.setInnerCollection(descriptions);
164: try {
165: MutableDescription descObj = new WebAppDescriptionImpl();
166:
167: descObj.setLocale(locale);
168: descObj.setDescription(description);
169: descCollWrapper.addDescription(descObj);
170: } catch (Exception e) {
171: String msg = "Unable to instantiate Description implementor, "
172: + e.toString();
173: log.error(msg, e);
174: throw new IllegalStateException(msg);
175: }
176: }
177:
178: /**
179: * @see org.apache.jetspeed.om.common.servlet.MutableWebApplication#addDisplayName(java.util.Locale, java.lang.String)
180: */
181: public void addDisplayName(Locale locale, String name) {
182: if (displayNames == null) {
183: displayNames = new ArrayList();
184: }
185: DNCollWrapper.setInnerCollection(displayNames);
186: try {
187: MutableDisplayName dn = new WebAppDisplayNameImpl();
188:
189: dn.setLocale(locale);
190: dn.setDisplayName(name);
191: DNCollWrapper.addDisplayName(dn);
192: } catch (Exception e) {
193: String msg = "Unable to instantiate DisplayName implementor, "
194: + e.toString();
195: log.error(msg, e);
196: throw new IllegalStateException(msg);
197: }
198:
199: }
200:
201: /**
202: * @see org.apache.jetspeed.om.common.servlet.MutableWebApplication#setDescriptionSet(org.apache.pluto.om.common.DescriptionSet)
203: */
204: public void setDescriptionSet(DescriptionSet descriptions) {
205: this .descriptions = ((DescriptionSetImpl) descriptions)
206: .getInnerCollection();
207: }
208:
209: /**
210: * Remove when Castor is mapped correctly
211: * @deprecated
212: * @return
213: */
214: public String getDescription() {
215: Description desc = getDescription(JetspeedLocale
216: .getDefaultLocale());
217: if (desc != null) {
218: return desc.getDescription();
219: }
220: return null;
221: }
222:
223: /**
224: * Remove when Castor is mapped correctly
225: * @deprecated
226: * @param desc
227: */
228: public void setDescription(String desc) {
229: addDescription(JetspeedLocale.getDefaultLocale(), desc);
230: }
231:
232: /**
233: * @see org.apache.pluto.om.servlet.WebApplicationDefinition#getSecurityRoles()
234: */
235: public SecurityRoleSet getSecurityRoles() {
236: secRolesListWrapper.setInnerCollection(securityRoles);
237: return secRolesListWrapper;
238: }
239:
240: /**
241: * @see org.apache.jetspeed.om.common.servlet.MutableWebApplication#addSecurityRole(org.apache.pluto.om.common.SecurityRole)
242: */
243: public void addSecurityRole(SecurityRole securityRole) {
244: secRolesListWrapper.setInnerCollection(securityRoles);
245: secRolesListWrapper.add(securityRole);
246: }
247: }
|