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.Iterator;
24  
25  import org.apache.pluto.om.common.ObjectID;
26  import org.apache.pluto.om.entity.PortletApplicationEntity;
27  import org.apache.pluto.om.entity.PortletEntityList;
28  import org.apache.pluto.om.portlet.PortletApplicationDefinition;
29  import org.apache.pluto.portalImpl.services.portletdefinitionregistry.PortletDefinitionRegistry;
30  import org.apache.pluto.portalImpl.services.ConfigurationException;
31  import org.apache.pluto.util.StringUtils;
32  
33  public class PortletApplicationEntityImpl 
34  implements PortletApplicationEntity, java.io.Serializable,
35  org.apache.pluto.portalImpl.om.common.Support {
36  
37      private String id = "";
38      private String definitionId = ""; 
39      private PortletEntityList portlets = new PortletEntityListImpl();
40  
41      private ObjectID objectId = null;    
42  
43      // PortletApplicationEntity implementation.
44  
45      public ObjectID getId()
46      {
47          if (objectId==null) {
48              objectId = org.apache.pluto.portalImpl.util.ObjectID.createFromString(id);
49          }
50          return objectId;
51      }    
52  
53      public PortletEntityList getPortletEntityList()
54      {
55          return portlets;
56      }
57  
58      public PortletApplicationDefinition getPortletApplicationDefinition()
59      {
60          PortletApplicationDefinition definition =
61              PortletDefinitionRegistry.getPortletApplicationDefinitionList()
62                  .get(org.apache.pluto.portalImpl.util.ObjectID.createFromString(definitionId));
63          if(definition == null) {
64              throw new ConfigurationException("Unable to find portlet application definition. "+
65                      "Ensure that all portlets definied within the portlet registry are correct" +
66                      "and have been deployed.");
67          }
68          return definition;
69      }
70  
71      // additional methods.
72      
73      // additional internal methods
74  
75      public void setId(String id)
76      {
77          this.id = id;
78          objectId= null;
79      }
80  
81      public Collection getCastorPortlets()
82      { 
83          return(PortletEntityListImpl)portlets;
84      }
85  
86      public void postLoad(Object parameter) throws Exception
87      {
88      }
89  
90      public void preBuild(Object parameter) throws Exception
91      {
92          Iterator iterator = portlets.iterator();
93          while (iterator.hasNext()) {
94              ((PortletEntityImpl)iterator.next()).preBuild(this);
95          }
96      }
97  
98      public void postBuild(Object parameter) throws Exception
99      {
100     }
101 
102     public void preStore(Object parameter) throws Exception
103     {
104     }
105 
106     public void postStore(Object parameter) throws Exception
107     {
108     }
109 
110     // internal methods used for castor only
111     public String getCastorId() {                
112         return getId().toString();        
113     }
114 
115     public void setCastorId(String id) {        
116         setId(id);
117     }   
118 
119     public String getDefinitionId()
120     {
121         return definitionId;
122     }
123 
124     public void setDefinitionId(String definitionId)
125     {
126         this.definitionId = definitionId;
127     }
128 
129     // internal methods used for debugging purposes only
130 
131     public String toString()
132     {
133         return toString(0);
134     }
135 
136     public String toString(int indent)
137     {
138         StringBuffer buffer = new StringBuffer(1000);
139         StringUtils.newLine(buffer,indent);
140         buffer.append(getClass().toString()); buffer.append(":");
141         StringUtils.newLine(buffer,indent);
142         buffer.append("{");
143         StringUtils.newLine(buffer,indent);
144         buffer.append("id='");
145         buffer.append(id);
146         buffer.append("'");
147         StringUtils.newLine(buffer,indent);
148         buffer.append("definition-id='");
149         buffer.append(definitionId);
150         buffer.append("'");
151 
152         StringUtils.newLine(buffer,indent);
153         buffer.append(((org.apache.pluto.portalImpl.om.entity.impl.PortletEntityListImpl)portlets).toString(indent));
154 
155         StringUtils.newLine(buffer,indent);
156         buffer.append("}");
157         return buffer.toString();
158     }
159 
160 }