KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > pluto > portalImpl > om > portlet > impl > PortletApplicationDefinitionImpl


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

16 /*
17
18  */

19
20 package org.apache.pluto.portalImpl.om.portlet.impl;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.Map JavaDoc;
26 import java.util.Vector JavaDoc;
27
28 import org.apache.pluto.om.common.ObjectID;
29 import org.apache.pluto.om.portlet.PortletApplicationDefinition;
30 import org.apache.pluto.om.portlet.PortletDefinitionList;
31 import org.apache.pluto.om.servlet.WebApplicationDefinition;
32 import org.apache.pluto.portalImpl.om.common.Support;
33 import org.apache.pluto.portalImpl.om.servlet.impl.WebApplicationDefinitionImpl;
34 import org.apache.pluto.util.StringUtils;
35
36 public class PortletApplicationDefinitionImpl
37 implements PortletApplicationDefinition, java.io.Serializable JavaDoc, Support {
38
39     private String JavaDoc GUID = null;
40
41     private String JavaDoc appId = null;
42     private String JavaDoc version = null;
43
44     private ArrayList JavaDoc customPortletMode = new ArrayList JavaDoc();
45     private ArrayList JavaDoc customPortletState = new ArrayList JavaDoc();
46     private ArrayList JavaDoc userAttribute = new ArrayList JavaDoc();
47     private ArrayList JavaDoc securityConstraint = new ArrayList JavaDoc();
48
49     private PortletDefinitionList portlets = new PortletDefinitionListImpl();
50
51     private WebApplicationDefinition webApplication = null;
52
53     private ObjectID objectId = null;
54
55     private String JavaDoc contextPath = null;
56
57     // PortletApplicationDefinition implementation.
58

59     public ObjectID getId()
60     {
61         if (objectId==null) {
62             objectId = org.apache.pluto.portalImpl.util.ObjectID.createFromString(getGUID());
63         }
64         return objectId;
65     }
66
67     public String JavaDoc getVersion()
68     {
69         return version;
70     }
71
72     public PortletDefinitionList getPortletDefinitionList()
73     {
74         return portlets;
75     }
76
77     public WebApplicationDefinition getWebApplicationDefinition()
78     {
79         return webApplication;
80     }
81
82     // Support implementation.
83

84     public void postLoad(Object JavaDoc parameter) throws Exception JavaDoc
85     {
86         ((Support)portlets).postLoad(parameter);
87     }
88
89     public void preBuild(Object JavaDoc parameter) throws Exception JavaDoc
90     {
91         Vector JavaDoc structure = (Vector JavaDoc)parameter;
92         String JavaDoc contextRoot = (String JavaDoc)structure.get(0);
93         WebApplicationDefinition webApplication = (WebApplicationDefinition)structure.get(1);
94         Map JavaDoc servletMap = (Map JavaDoc)structure.get(2);
95
96         setContextRoot(contextRoot);
97
98         setWebApplicationDefinition(webApplication);
99
100         Vector JavaDoc structure2 = new Vector JavaDoc();
101         structure2.add(this);
102         structure2.add(servletMap);
103
104         ((Support)portlets).preBuild(structure2);
105
106     }
107     
108     public void postBuild(Object JavaDoc parameter) throws Exception JavaDoc
109     {
110     }
111
112     public void preStore(Object JavaDoc parameter) throws Exception JavaDoc
113     {
114         ((Support)portlets).preStore(parameter);
115     }
116
117     public void postStore(Object JavaDoc parameter) throws Exception JavaDoc
118     {
119         ((Support)portlets).postStore(parameter);
120     }
121
122     // internal methods.
123

124     private String JavaDoc getGUID()
125     {
126         if (GUID == null) {
127             GUID = "";
128             String JavaDoc id = "";
129
130             if (webApplication != null) {
131                 id = webApplication.getContextRoot();
132             } else {
133                 id = contextPath;
134             }
135
136             if (id!=null) {
137                 if (id.startsWith("/")) {
138                     id = id.substring(id.indexOf("/")+1);
139                 }
140
141                 GUID += id;
142             }
143         }
144
145         return GUID;
146     }
147
148     private void setContextRoot(String JavaDoc contextRoot)
149     {
150         // Test for IBM WebSphere
151
if (contextRoot != null && contextRoot.endsWith(".war"))
152         {
153             contextRoot = contextRoot.substring(0, contextRoot.length()-4);
154         }
155         this.contextPath = contextRoot;
156     }
157
158     // additional methods.
159

160     public String JavaDoc getAppId()
161     {
162         return appId;
163     }
164
165     public void setAppId(String JavaDoc appId)
166     {
167         this.appId = appId;
168     }
169
170     public void setVersion(String JavaDoc version)
171     {
172         this.version = version;
173     }
174
175
176     // not yet fully supported:
177
public Collection JavaDoc getCustomPortletMode()
178     {
179         return customPortletMode;
180     }
181
182     public void setCustomPortletMode(Collection JavaDoc customPortletMode)
183     {
184         this.customPortletMode = (ArrayList JavaDoc)customPortletMode;
185     }
186
187     public Collection JavaDoc getCustomPortletState()
188     {
189         return customPortletState;
190     }
191
192     public void setCustomPortletState(Collection JavaDoc customPortletState)
193     {
194         this.customPortletState = (ArrayList JavaDoc)customPortletState;
195     }
196
197     public Collection JavaDoc getUserAttribute()
198     {
199         return userAttribute;
200     }
201
202     public void setUserAttribute(Collection JavaDoc userAttribute)
203     {
204         this.userAttribute = (ArrayList JavaDoc)userAttribute;
205     }
206
207     public Collection JavaDoc getSecurityConstraint()
208     {
209         return securityConstraint;
210     }
211
212     public void setSecurityConstraint(Collection JavaDoc securityConstraint)
213     {
214         this.securityConstraint = (ArrayList JavaDoc)securityConstraint;
215     }
216
217     // additional internal methods
218

219     public Collection JavaDoc getCastorPortlets()
220     {
221         return(PortletDefinitionListImpl)portlets;
222     }
223
224     protected void setWebApplicationDefinition(WebApplicationDefinition webApplication)
225     {
226         this.webApplication = webApplication;
227     }
228
229     // internal methods used for debugging purposes only
230

231     public String JavaDoc toString()
232     {
233         return toString(0);
234     }
235
236     public String JavaDoc toString(int indent)
237     {
238         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(50);
239         StringUtils.newLine(buffer,indent);
240         buffer.append(getClass().toString()); buffer.append(":");
241         StringUtils.newLine(buffer,indent);
242         buffer.append("{");
243         StringUtils.newLine(buffer,indent);
244         buffer.append("objectID='"); buffer.append(getId().toString()); buffer.append("'");
245         StringUtils.newLine(buffer,indent);
246         buffer.append("GUID='"); buffer.append(GUID); buffer.append("'");
247         StringUtils.newLine(buffer,indent);
248         buffer.append("version='"); buffer.append(version); buffer.append("'");
249
250         Iterator JavaDoc iterator = portlets.iterator();
251         if (iterator.hasNext()) {
252             StringUtils.newLine(buffer,indent);
253             buffer.append("Portlets:");
254         }
255         while (iterator.hasNext()) {
256             buffer.append(((PortletDefinitionImpl)iterator.next()).toString(indent+2));
257         }
258         if (webApplication!=null) {
259             StringUtils.newLine(buffer,indent);
260             buffer.append("webApplication:");
261             buffer.append(((WebApplicationDefinitionImpl)webApplication).toString(indent+2));
262         }
263         StringUtils.newLine(buffer,indent);
264         buffer.append("}");
265         return buffer.toString();
266     }
267
268 }
269
Popular Tags