KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > pluto > portalImpl > om > entity > impl > PortletEntityImpl


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.entity.impl;
21
22 import java.util.Collection JavaDoc;
23 import java.util.Locale JavaDoc;
24
25 import org.apache.pluto.om.common.Description;
26 import org.apache.pluto.om.common.DescriptionSet;
27 import org.apache.pluto.om.common.ObjectID;
28 import org.apache.pluto.om.common.PreferenceSet;
29 import org.apache.pluto.om.entity.PortletApplicationEntity;
30 import org.apache.pluto.om.entity.PortletEntity;
31 import org.apache.pluto.om.entity.PortletEntityCtrl;
32 import org.apache.pluto.om.portlet.PortletDefinition;
33 import org.apache.pluto.om.window.PortletWindowList;
34 import org.apache.pluto.portalImpl.om.common.impl.DescriptionSetImpl;
35 import org.apache.pluto.portalImpl.services.portletentityregistry.PortletEntityRegistry;
36 import org.apache.pluto.util.StringUtils;
37
38 public class PortletEntityImpl
39 implements PortletEntity, PortletEntityCtrl, java.io.Serializable JavaDoc,
40 org.apache.pluto.portalImpl.om.common.Support {
41
42     private String JavaDoc id;
43     private String JavaDoc definitionId;
44
45     protected PreferenceSet preferences;
46
47     private PreferenceSet origPreferences;
48     private PortletApplicationEntity applicationEntity;
49     private PortletWindowList portletWindows;
50     private ObjectID objectId;
51     private DescriptionSet descriptions;
52
53     public PortletEntityImpl()
54     {
55         id = "";
56         definitionId = "";
57         preferences = new org.apache.pluto.portalImpl.om.common.impl.PreferenceSetImpl();
58         origPreferences = new org.apache.pluto.portalImpl.om.common.impl.PreferenceSetImpl();
59         portletWindows = new org.apache.pluto.portalImpl.om.window.impl.PortletWindowListImpl();
60         descriptions = new org.apache.pluto.portalImpl.om.common.impl.DescriptionSetImpl();
61     }
62
63     // PortletEntity implementation.
64

65     public ObjectID getId()
66     {
67         if (objectId==null && applicationEntity != null) {
68             objectId = org.apache.pluto.portalImpl.util.ObjectID.createFromString(applicationEntity.getId().toString()
69                                                                                   + "." + id);
70         }
71         return objectId;
72     }
73
74     public PreferenceSet getPreferenceSet()
75     {
76         return preferences;
77     }
78
79     public PortletDefinition getPortletDefinition()
80     {
81         return applicationEntity.getPortletApplicationDefinition().getPortletDefinitionList().get(org.apache.pluto.portalImpl.util.ObjectID.createFromString(definitionId));
82     }
83
84     public void setPortletDefinition(PortletDefinition portletDefinition)
85     {
86         this.definitionId = portletDefinition.getId().toString();
87     }
88
89     public PortletApplicationEntity getPortletApplicationEntity()
90     {
91         return applicationEntity;
92     }
93
94     public PortletWindowList getPortletWindowList() {
95         return portletWindows;
96     }
97
98     /* (non-Javadoc)
99      * @see org.apache.pluto.om.entity.PortletEntity#getDescriptionSet()
100      */

101     public Description getDescription(Locale JavaDoc locale) {
102         return descriptions.get(locale);
103     }
104
105     // PortletEntityCtrl implementation.
106

107     public void setId(String JavaDoc id)
108     {
109         this.id = id;
110         objectId = null;
111     }
112
113     public void store() throws java.io.IOException JavaDoc
114     {
115         PortletEntityRegistry.store();
116
117         //save preferences as original preferences
118
origPreferences = new org.apache.pluto.portalImpl.om.common.impl.PreferenceSetImpl();
119         ((org.apache.pluto.portalImpl.om.common.impl.PreferenceSetImpl)origPreferences).addAll((Collection JavaDoc)preferences);
120     }
121
122     public void reset() throws java.io.IOException JavaDoc
123     {
124         //reset by re-activating original preferences
125
preferences = new org.apache.pluto.portalImpl.om.common.impl.PreferenceSetImpl();
126         ((org.apache.pluto.portalImpl.om.common.impl.PreferenceSetImpl)preferences).clear();
127         ((org.apache.pluto.portalImpl.om.common.impl.PreferenceSetImpl)preferences).addAll((Collection JavaDoc)origPreferences);
128     }
129
130     // org.apache.pluto.portalImpl.om.common.Support implementation.
131

132     public void postLoad(Object JavaDoc parameter) throws Exception JavaDoc
133     {
134     }
135
136     public void preBuild(Object JavaDoc parameter) throws Exception JavaDoc
137     {
138         ((org.apache.pluto.portalImpl.om.common.impl.PreferenceSetImpl)origPreferences).addAll((Collection JavaDoc)preferences);
139         setPortletApplicationEntity((PortletApplicationEntity)parameter);
140     }
141
142     public void postBuild(Object JavaDoc parameter) throws Exception JavaDoc
143     {
144     }
145
146     public void preStore(Object JavaDoc parameter) throws Exception JavaDoc
147     {
148     }
149
150     public void postStore(Object JavaDoc parameter) throws Exception JavaDoc
151     {
152     }
153
154     // additional methods.
155

156     // additional internal methods
157

158     public Collection JavaDoc getCastorPreferences()
159     {
160         return(org.apache.pluto.portalImpl.om.common.impl.PreferenceSetImpl)preferences;
161     }
162
163     protected void setPortletApplicationEntity(PortletApplicationEntity applicationEntity)
164     {
165         this.applicationEntity = applicationEntity;
166     }
167
168     protected void setPortletWindowList(PortletWindowList portletWindows)
169     {
170         this.portletWindows = portletWindows;
171     }
172
173     // internal methods used for castor only
174
public String JavaDoc getCastorId() {
175         //ObjectID oid = getId();
176
//if(oid == null)
177
//return null;
178

179         //return oid.toString();
180
return id.length() > 0 ? id : null;
181     }
182
183     public void setCastorId(String JavaDoc id) {
184         setId(id);
185     }
186
187     public String JavaDoc getDefinitionId()
188     {
189         return definitionId;
190     }
191
192     public void setDefinitionId(String JavaDoc definitionId)
193     {
194         this.definitionId = definitionId;
195     }
196
197     // internal methods used for debugging purposes only
198

199     public String JavaDoc toString()
200     {
201         return toString(0);
202     }
203
204     public String JavaDoc toString(int indent)
205     {
206         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(1000);
207         StringUtils.newLine(buffer,indent);
208         buffer.append(getClass().toString()); buffer.append(":");
209         StringUtils.newLine(buffer,indent);
210         buffer.append("{");
211         StringUtils.newLine(buffer,indent);
212         buffer.append("id='");
213         buffer.append(id);
214         buffer.append("'");
215         StringUtils.newLine(buffer,indent);
216         buffer.append("definition-id='");
217         buffer.append(definitionId);
218         buffer.append("'");
219
220         StringUtils.newLine(buffer,indent);
221         buffer.append(((org.apache.pluto.portalImpl.om.common.impl.PreferenceSetImpl)preferences).toString(indent));
222         StringUtils.newLine(buffer,indent);
223         buffer.append(((DescriptionSetImpl) descriptions).toString(indent));
224
225         StringUtils.newLine(buffer,indent);
226         buffer.append("}");
227         return buffer.toString();
228     }
229 }
230
Popular Tags