View Javadoc

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;
23  import java.util.Locale;
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.portlet.PortletDefinitionList;
34  import org.apache.pluto.om.window.PortletWindowList;
35  import org.apache.pluto.portalImpl.om.common.impl.DescriptionSetImpl;
36  import org.apache.pluto.portalImpl.services.portletentityregistry.PortletEntityRegistry;
37  import org.apache.pluto.portalImpl.services.ConfigurationException;
38  import org.apache.pluto.util.StringUtils;
39  
40  public class PortletEntityImpl
41  implements PortletEntity, PortletEntityCtrl, java.io.Serializable,
42  org.apache.pluto.portalImpl.om.common.Support {
43  
44      private String id;
45      private String definitionId;
46  
47      protected PreferenceSet preferences;
48  
49      private PreferenceSet origPreferences;
50      private PortletApplicationEntity applicationEntity;
51      private PortletWindowList portletWindows;
52      private ObjectID objectId;
53      private DescriptionSet descriptions;
54  
55      public PortletEntityImpl()
56      {
57          id              = "";
58          definitionId    = "";
59          preferences     = new org.apache.pluto.portalImpl.om.common.impl.PreferenceSetImpl();
60          origPreferences = new org.apache.pluto.portalImpl.om.common.impl.PreferenceSetImpl();
61          portletWindows  = new org.apache.pluto.portalImpl.om.window.impl.PortletWindowListImpl();
62          descriptions    = new org.apache.pluto.portalImpl.om.common.impl.DescriptionSetImpl();
63      }
64  
65      // PortletEntity implementation.
66  
67      public ObjectID getId()
68      {
69          if (objectId==null && applicationEntity != null) {
70              objectId = org.apache.pluto.portalImpl.util.ObjectID.createFromString(applicationEntity.getId().toString()
71                                                                                    + "." + id);
72          }
73          return objectId;
74      }    
75  
76      public PreferenceSet getPreferenceSet()
77      {
78          return preferences;
79      }
80  
81      public PortletDefinition getPortletDefinition()
82      {
83          PortletDefinition def =
84              applicationEntity.getPortletApplicationDefinition()
85                  .getPortletDefinitionList()
86                  .get(org.apache.pluto.portalImpl.util.ObjectID.createFromString(definitionId));
87          if(def == null) {
88              throw new ConfigurationException("Unable to obtain portlet definition for :"+definitionId+
89                      " Perhaps a portlet has been defined incorrectly in the portlet registry.");
90          }
91          return def;
92      }
93  
94      public void setPortletDefinition(PortletDefinition portletDefinition)
95      {
96          this.definitionId = portletDefinition.getId().toString();
97      }
98  
99      public PortletApplicationEntity getPortletApplicationEntity()
100     {
101         return applicationEntity;
102     }
103 
104     public PortletWindowList getPortletWindowList() {
105         return portletWindows;
106     }
107 
108     /* (non-Javadoc)
109      * @see org.apache.pluto.om.entity.PortletEntity#getDescriptionSet()
110      */
111     public Description getDescription(Locale locale) {
112         return descriptions.get(locale);
113     }
114 
115     // PortletEntityCtrl implementation.
116 
117     public void setId(String id)
118     {
119         this.id = id;
120         objectId = null;
121     }
122 
123     public void store() throws java.io.IOException
124     {
125         PortletEntityRegistry.store();
126 
127         //save preferences as original preferences
128         origPreferences = new org.apache.pluto.portalImpl.om.common.impl.PreferenceSetImpl();
129         ((org.apache.pluto.portalImpl.om.common.impl.PreferenceSetImpl)origPreferences).addAll((Collection)preferences);
130     }
131 
132     public void reset() throws java.io.IOException
133     {
134         //reset by re-activating original preferences
135         preferences = new org.apache.pluto.portalImpl.om.common.impl.PreferenceSetImpl();
136         ((org.apache.pluto.portalImpl.om.common.impl.PreferenceSetImpl)preferences).clear();
137         ((org.apache.pluto.portalImpl.om.common.impl.PreferenceSetImpl)preferences).addAll((Collection)origPreferences);
138     }
139 
140     // org.apache.pluto.portalImpl.om.common.Support implementation.
141 
142     public void postLoad(Object parameter) throws Exception
143     {        
144     }
145 
146     public void preBuild(Object parameter) throws Exception
147     {        
148         ((org.apache.pluto.portalImpl.om.common.impl.PreferenceSetImpl)origPreferences).addAll((Collection)preferences);
149         setPortletApplicationEntity((PortletApplicationEntity)parameter);
150     }
151 
152     public void postBuild(Object parameter) throws Exception
153     {
154     }
155 
156     public void preStore(Object parameter) throws Exception
157     {
158     }
159 
160     public void postStore(Object parameter) throws Exception
161     {
162     }
163 
164     // additional methods.
165     
166     // additional internal methods
167 
168     public Collection getCastorPreferences()
169     {
170         return(org.apache.pluto.portalImpl.om.common.impl.PreferenceSetImpl)preferences;
171     }
172 
173     protected void setPortletApplicationEntity(PortletApplicationEntity applicationEntity)
174     {
175         this.applicationEntity = applicationEntity;
176     }
177 
178     protected void setPortletWindowList(PortletWindowList portletWindows)
179     {
180         this.portletWindows = portletWindows;
181     }
182 
183     // internal methods used for castor only 
184     public String getCastorId() {                
185         //ObjectID oid = getId();        
186         //if(oid == null) 
187         //return null;
188 
189         //return  oid.toString();
190         return id.length() > 0 ? id : null;
191     }
192 
193     public void setCastorId(String id) {        
194         setId(id);
195     }
196 
197     public String getDefinitionId()
198     {
199         return definitionId;
200     }
201 
202     public void setDefinitionId(String definitionId)
203     {
204         this.definitionId = definitionId;
205     }
206 
207     // internal methods used for debugging purposes only
208 
209     public String toString()
210     {
211         return toString(0);
212     }
213 
214     public String toString(int indent)
215     {
216         StringBuffer buffer = new StringBuffer(1000);
217         StringUtils.newLine(buffer,indent);
218         buffer.append(getClass().toString()); buffer.append(":");
219         StringUtils.newLine(buffer,indent);
220         buffer.append("{");
221         StringUtils.newLine(buffer,indent);
222         buffer.append("id='");
223         buffer.append(id);
224         buffer.append("'");
225         StringUtils.newLine(buffer,indent);
226         buffer.append("definition-id='");
227         buffer.append(definitionId);
228         buffer.append("'");
229 
230         StringUtils.newLine(buffer,indent);
231         buffer.append(((org.apache.pluto.portalImpl.om.common.impl.PreferenceSetImpl)preferences).toString(indent));
232         StringUtils.newLine(buffer,indent);
233         buffer.append(((DescriptionSetImpl) descriptions).toString(indent));
234 
235         StringUtils.newLine(buffer,indent);
236         buffer.append("}");
237         return buffer.toString();
238     }
239 }