1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.om.servlet.impl;
18
19 import java.io.Serializable;
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.Locale;
23
24 import javax.servlet.ServletContext;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.apache.jetspeed.om.common.MutableDescription;
29 import org.apache.jetspeed.om.common.MutableDisplayName;
30 import org.apache.jetspeed.om.common.servlet.MutableWebApplication;
31 import org.apache.jetspeed.om.impl.DescriptionImpl;
32 import org.apache.jetspeed.om.impl.DescriptionSetImpl;
33 import org.apache.jetspeed.om.impl.DisplayNameSetImpl;
34 import org.apache.jetspeed.om.impl.WebAppDescriptionImpl;
35 import org.apache.jetspeed.om.impl.WebAppDisplayNameImpl;
36 import org.apache.jetspeed.util.JetspeedLocale;
37 import org.apache.jetspeed.util.JetspeedLongObjectID;
38 import org.apache.pluto.om.common.Description;
39 import org.apache.pluto.om.common.DescriptionSet;
40 import org.apache.pluto.om.common.DisplayName;
41 import org.apache.pluto.om.common.DisplayNameSet;
42 import org.apache.pluto.om.common.ObjectID;
43 import org.apache.pluto.om.common.ParameterSet;
44 import org.apache.pluto.om.servlet.ServletDefinitionList;
45 import org.apache.pluto.om.common.SecurityRole;
46 import org.apache.pluto.om.common.SecurityRoleSet;
47
48 /***
49 *
50 * WebApplicationDefinitionImpl
51 *
52 * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
53 * @version $Id: WebApplicationDefinitionImpl.java 516448 2007-03-09 16:25:47Z ate $
54 *
55 */
56 public class WebApplicationDefinitionImpl implements MutableWebApplication, Serializable
57 {
58 private Long id;
59 private JetspeedLongObjectID oid;
60 private Collection displayNames = new ArrayList();
61 private DisplayNameSetImpl DNCollWrapper = new DisplayNameSetImpl();
62
63 private Collection descriptions = new ArrayList();
64 private DescriptionSetImpl descCollWrapper = new DescriptionSetImpl(DescriptionImpl.TYPE_WEB_APP);
65 private Collection securityRoles = new ArrayList();
66 private SecurityRoleSetImpl secRolesListWrapper = new SecurityRoleSetImpl();
67
68 private String contextRoot;
69 private ParameterSet initParameters;
70
71 private static final Log log = LogFactory.getLog(WebApplicationDefinitionImpl.class);
72
73 /***
74 * @see org.apache.pluto.om.servlet.WebApplicationDefinition#getId()
75 */
76 public ObjectID getId()
77 {
78 if ( oid == null && id != null )
79 {
80 oid = new JetspeedLongObjectID(id);
81 }
82 return oid;
83 }
84
85 /***
86 * @see org.apache.pluto.om.servlet.WebApplicationDefinition#getDisplayName()
87 */
88 public DisplayName getDisplayName(Locale locale)
89 {
90
91 if (displayNames != null)
92 {
93 DNCollWrapper.setInnerCollection(displayNames);
94 return DNCollWrapper.get(locale);
95 }
96 return null;
97
98 }
99
100 /***
101 * @see org.apache.pluto.om.servlet.WebApplicationDefinition#getDescription()
102 */
103 public Description getDescription(Locale locale)
104 {
105 if (descriptions != null)
106 {
107 descCollWrapper.setInnerCollection(descriptions);
108 return descCollWrapper.get(locale);
109 }
110 return null;
111
112 }
113
114 /***
115 * @see org.apache.pluto.om.servlet.WebApplicationDefinition#getInitParameterSet()
116 */
117 public ParameterSet getInitParameterSet()
118 {
119 return initParameters;
120 }
121
122 /***
123 * @see org.apache.pluto.om.servlet.WebApplicationDefinition#getServletDefinitionList()
124 */
125 public ServletDefinitionList getServletDefinitionList()
126 {
127
128 return null;
129 }
130
131 /***
132 * @see org.apache.pluto.om.servlet.WebApplicationDefinition#getServletContext(javax.servlet.ServletContext)
133 */
134 public ServletContext getServletContext(ServletContext servletContext)
135 {
136
137 return null;
138 }
139
140 /***
141 * @see org.apache.pluto.om.servlet.WebApplicationDefinition#getContextRoot()
142 */
143 public String getContextRoot()
144 {
145 return contextRoot;
146 }
147
148 /***
149 * @see org.apache.pluto.om.servlet.WebApplicationDefinitionCtrl#setDisplayName(java.lang.String)
150 */
151 public void setDisplayNameSet(DisplayNameSet displayNames)
152 {
153 this.displayNames = ((DisplayNameSetImpl) displayNames).getInnerCollection();
154 }
155
156 /***
157 * @see org.apache.jetspeed.om.common.servlet.WebApplicationComposite#setContextRoot(java.lang.String)
158 */
159 public void setContextRoot(String contextRoot)
160 {
161 this.contextRoot = contextRoot;
162 }
163
164 /***
165 * @see org.apache.jetspeed.om.common.servlet.MutableWebApplication#addDescription(java.util.Locale, java.lang.String)
166 */
167 public void addDescription(Locale locale, String description)
168 {
169 if (descriptions == null)
170 {
171 descriptions = new ArrayList();
172 }
173 descCollWrapper.setInnerCollection(descriptions);
174 try
175 {
176 MutableDescription descObj = new WebAppDescriptionImpl();
177
178 descObj.setLocale(locale);
179 descObj.setDescription(description);
180 descCollWrapper.addDescription(descObj);
181 }
182 catch (Exception e)
183 {
184 String msg = "Unable to instantiate Description implementor, " + e.toString();
185 log.error(msg, e);
186 throw new IllegalStateException(msg);
187 }
188 }
189
190 /***
191 * @see org.apache.jetspeed.om.common.servlet.MutableWebApplication#addDisplayName(java.util.Locale, java.lang.String)
192 */
193 public void addDisplayName(Locale locale, String name)
194 {
195 if (displayNames == null)
196 {
197 displayNames = new ArrayList();
198 }
199 DNCollWrapper.setInnerCollection(displayNames);
200 try
201 {
202 MutableDisplayName dn = new WebAppDisplayNameImpl();
203
204 dn.setLocale(locale);
205 dn.setDisplayName(name);
206 DNCollWrapper.addDisplayName(dn);
207 }
208 catch (Exception e)
209 {
210 String msg = "Unable to instantiate DisplayName implementor, " + e.toString();
211 log.error(msg, e);
212 throw new IllegalStateException(msg);
213 }
214
215 }
216
217 /***
218 * @see org.apache.jetspeed.om.common.servlet.MutableWebApplication#setDescriptionSet(org.apache.pluto.om.common.DescriptionSet)
219 */
220 public void setDescriptionSet(DescriptionSet descriptions)
221 {
222 this.descriptions = ((DescriptionSetImpl) descriptions).getInnerCollection();
223 }
224
225 /***
226 * Remove when Castor is mapped correctly
227 * @deprecated
228 * @return
229 */
230 public String getDescription()
231 {
232 Description desc = getDescription(JetspeedLocale.getDefaultLocale());
233 if (desc != null)
234 {
235 return desc.getDescription();
236 }
237 return null;
238 }
239
240 /***
241 * Remove when Castor is mapped correctly
242 * @deprecated
243 * @param desc
244 */
245 public void setDescription(String desc)
246 {
247 addDescription(JetspeedLocale.getDefaultLocale(), desc);
248 }
249
250 /***
251 * @see org.apache.pluto.om.servlet.WebApplicationDefinition#getSecurityRoles()
252 */
253 public SecurityRoleSet getSecurityRoles()
254 {
255 secRolesListWrapper.setInnerCollection(securityRoles);
256 return secRolesListWrapper;
257 }
258
259 /***
260 * @see org.apache.jetspeed.om.common.servlet.MutableWebApplication#addSecurityRole(org.apache.pluto.om.common.SecurityRole)
261 */
262 public void addSecurityRole(SecurityRole securityRole)
263 {
264 secRolesListWrapper.setInnerCollection(securityRoles);
265 secRolesListWrapper.add(securityRole);
266 }
267 }