KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > pluto > om > PortletApplicationDefinitionImpl


1 /*
2  * Copyright 2004,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 package org.apache.cocoon.portal.pluto.om;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.Collection JavaDoc;
20 import java.util.Map JavaDoc;
21 import java.util.Vector JavaDoc;
22
23 import org.apache.pluto.om.common.ObjectID;
24 import org.apache.pluto.om.portlet.PortletApplicationDefinition;
25 import org.apache.pluto.om.portlet.PortletDefinitionList;
26 import org.apache.pluto.om.servlet.WebApplicationDefinition;
27 import org.apache.cocoon.portal.pluto.om.common.AbstractSupportSet;
28 import org.apache.cocoon.portal.pluto.om.common.Support;
29
30 /**
31  *
32  *
33  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
34  *
35  * @version CVS $Id: PortletApplicationDefinitionImpl.java 123407 2004-12-27 13:51:59Z cziegeler $
36  */

37 public class PortletApplicationDefinitionImpl
38 extends AbstractSupportSet
39 implements PortletApplicationDefinition {
40
41     protected String JavaDoc GUID;
42
43     protected String JavaDoc appId;
44     protected String JavaDoc version;
45     protected PortletDefinitionRegistryImpl registry;
46
47
48     private ArrayList JavaDoc customPortletMode = new ArrayList JavaDoc();
49     private ArrayList JavaDoc customPortletState = new ArrayList JavaDoc();
50     private ArrayList JavaDoc userAttribute = new ArrayList JavaDoc();
51     private ArrayList JavaDoc securityConstraint = new ArrayList JavaDoc();
52
53     private PortletDefinitionListImpl portlets = new PortletDefinitionListImpl();
54
55     private WebApplicationDefinition webApplication;
56
57     private ObjectID objectId;
58
59     private String JavaDoc contextPath;
60
61     /*
62      * (non-Javadoc)
63      * @return The PortletDefinitionRegistryImpl.
64      */

65     public PortletDefinitionRegistryImpl getRegistry() {
66         return this.registry;
67     }
68
69     /*
70      * (non-Javadoc)
71      * @param service The PortletDefnitionRegistryImpl.
72      */

73     public void setRegistry(PortletDefinitionRegistryImpl registry) {
74         this.registry = registry;
75     }
76
77     /* (non-Javadoc)
78      * @see org.apache.pluto.om.portlet.PortletApplicationDefinition#getId()
79      */

80     public ObjectID getId() {
81         if ( this.objectId == null ) {
82             this.objectId = org.apache.cocoon.portal.pluto.om.common.ObjectIDImpl.createFromString(getGUID());
83         }
84         return this.objectId;
85     }
86
87     /* (non-Javadoc)
88      * @see org.apache.pluto.om.portlet.PortletApplicationDefinition#getVersion()
89      */

90     public String JavaDoc getVersion() {
91         return this.version;
92     }
93
94     /* (non-Javadoc)
95      * @see org.apache.pluto.om.portlet.PortletApplicationDefinition#getPortletDefinitionList()
96      */

97     public PortletDefinitionList getPortletDefinitionList() {
98         return this.portlets;
99     }
100
101     /* (non-Javadoc)
102      * @see org.apache.pluto.om.portlet.PortletApplicationDefinition#getWebApplicationDefinition()
103      */

104     public WebApplicationDefinition getWebApplicationDefinition() {
105         return this.webApplication;
106     }
107
108     /* (non-Javadoc)
109      * @see org.apache.cocoon.portal.pluto.om.common.Support#postLoad(java.lang.Object)
110      */

111     public void postLoad(Object JavaDoc parameter) throws Exception JavaDoc {
112         ((Support)portlets).postLoad(parameter);
113     }
114
115     /* (non-Javadoc)
116      * @see org.apache.cocoon.portal.pluto.om.common.Support#preBuild(java.lang.Object)
117      */

118     public void preBuild(Object JavaDoc parameter)
119     throws Exception JavaDoc {
120         Vector JavaDoc structure = (Vector JavaDoc)parameter;
121         String JavaDoc contextRoot = (String JavaDoc)structure.get(0);
122         WebApplicationDefinition webApplication = (WebApplicationDefinition)structure.get(1);
123         Map JavaDoc servletMap = (Map JavaDoc)structure.get(2);
124
125         this.setContextRoot(contextRoot);
126
127         setWebApplicationDefinition(webApplication);
128
129         Vector JavaDoc structure2 = new Vector JavaDoc();
130         structure2.add(this);
131         structure2.add(servletMap);
132
133         ((Support)portlets).preBuild(structure2);
134
135     }
136     
137     /* (non-Javadoc)
138      * @see org.apache.cocoon.portal.pluto.om.common.Support#postBuild(java.lang.Object)
139      */

140     public void postBuild(Object JavaDoc parameter) throws Exception JavaDoc {
141         // nothing to do
142
}
143
144     /* (non-Javadoc)
145      * @see org.apache.cocoon.portal.pluto.om.common.Support#preStore(java.lang.Object)
146      */

147     public void preStore(Object JavaDoc parameter) throws Exception JavaDoc {
148         ((Support)portlets).preStore(parameter);
149     }
150
151     /* (non-Javadoc)
152      * @see org.apache.cocoon.portal.pluto.om.common.Support#postStore(java.lang.Object)
153      */

154     public void postStore(Object JavaDoc parameter) throws Exception JavaDoc {
155         ((Support)portlets).postStore(parameter);
156     }
157
158     // internal methods.
159

160     protected String JavaDoc getGUID() {
161         if (GUID == null) {
162             GUID = "";
163             String JavaDoc id = "";
164
165             if (webApplication != null) {
166                 id = webApplication.getContextRoot();
167             } else {
168                 id = contextPath;
169             }
170
171             if (id!=null) {
172                 if (id.startsWith("/")) {
173                     id = id.substring(id.indexOf("/")+1);
174                 }
175
176                 GUID += id;
177             }
178         }
179
180         return GUID;
181     }
182
183     private void setContextRoot(String JavaDoc contextRoot) {
184         // PATCH for IBM WebSphere
185
if (contextRoot != null && contextRoot.endsWith(".war") ) {
186             this.contextPath = contextRoot.substring(0, contextRoot.length()-4);
187         } else {
188         this.contextPath = contextRoot;
189     }
190     }
191
192     // additional methods.
193

194     public String JavaDoc getAppId() {
195         return appId;
196     }
197
198     public void setAppId(String JavaDoc appId) {
199         this.appId = appId;
200     }
201
202     public void setVersion(String JavaDoc version) {
203         this.version = version;
204     }
205
206
207     // not yet fully supported:
208
public Collection JavaDoc getCustomPortletMode() {
209         return customPortletMode;
210     }
211
212     public void setCustomPortletMode(Collection JavaDoc customPortletMode) {
213         this.customPortletMode = (ArrayList JavaDoc)customPortletMode;
214     }
215
216     public Collection JavaDoc getCustomPortletState() {
217         return customPortletState;
218     }
219
220     public void setCustomPortletState(Collection JavaDoc customPortletState) {
221         this.customPortletState = (ArrayList JavaDoc)customPortletState;
222     }
223
224     public Collection JavaDoc getUserAttribute() {
225         return userAttribute;
226     }
227
228     public void setUserAttribute(Collection JavaDoc userAttribute) {
229         this.userAttribute = (ArrayList JavaDoc)userAttribute;
230     }
231
232     public Collection JavaDoc getSecurityConstraint() {
233         return securityConstraint;
234     }
235
236     public void setSecurityConstraint(Collection JavaDoc securityConstraint) {
237         this.securityConstraint = (ArrayList JavaDoc)securityConstraint;
238     }
239
240     // additional internal methods
241

242     public Collection JavaDoc getCastorPortlets() {
243         return portlets;
244     }
245
246     protected void setWebApplicationDefinition(WebApplicationDefinition webApplication) {
247         this.webApplication = webApplication;
248     }
249
250 }
251
Popular Tags