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.ArrayList;
23  import java.util.Collection;
24  import java.util.Iterator;
25  
26  import org.apache.pluto.om.common.ObjectID;
27  import org.apache.pluto.om.entity.PortletApplicationEntity;
28  import org.apache.pluto.om.entity.PortletApplicationEntityList;
29  import org.apache.pluto.om.entity.PortletApplicationEntityListCtrl;
30  import org.apache.pluto.portalImpl.om.common.AbstractSupportSet;
31  import org.apache.pluto.util.StringUtils;
32  
33  public class PortletApplicationEntityListImpl extends AbstractSupportSet
34  implements PortletApplicationEntityList, PortletApplicationEntityListCtrl, java.io.Serializable,
35  org.apache.pluto.portalImpl.om.common.Support {
36  
37      // PortletApplicationEntityList implementation.
38  
39      public PortletApplicationEntity get(ObjectID objectId)
40      {
41          Iterator iterator = this.iterator();
42          while (iterator.hasNext()) {
43              PortletApplicationEntity portletApplicationEntity = (PortletApplicationEntity)iterator.next();
44              if (portletApplicationEntity.getId().equals(objectId)) {
45                  return portletApplicationEntity;
46              }
47          }
48          return null;
49      }
50  
51      // PortletApplicationEntityListCtrl implementation.
52  
53      public PortletApplicationEntity add(String definitionId) {
54          PortletApplicationEntityImpl entity = new PortletApplicationEntityImpl();
55  
56          int id = -1;
57          for (Iterator iter = iterator(); iter.hasNext();) {
58              PortletApplicationEntityImpl ent = (PortletApplicationEntityImpl)iter.next();
59              try {
60                  id = Math.max(id, Integer.parseInt(ent.getCastorId()));
61              } catch (NumberFormatException e) {
62                  //don't care
63              }
64          }
65          entity.setId(Integer.toString(++id)); 
66          entity.setDefinitionId(definitionId);
67  
68          add(entity);
69  
70          return entity;
71      }
72  
73      // org.apache.pluto.portalImpl.om.common.Support implemenatation.
74  
75      public void postLoad(Object parameter) throws Exception
76      {
77          this.clear();
78          this.addAll(castorApplications);
79      }
80  
81      public void preBuild(Object parameter) throws Exception
82      {
83          Iterator iterator = this.iterator();
84          while (iterator.hasNext()) {
85              ((PortletApplicationEntityImpl)iterator.next()).preBuild(this);
86          }
87      }
88  
89      public void postBuild(Object parameter) throws Exception
90      {
91      }
92  
93      public void preStore(Object parameter) throws Exception
94      {
95          castorApplications.clear();
96          castorApplications.addAll(this);
97      }
98  
99      public void postStore(Object parameter) throws Exception
100     {
101     }
102 
103     // additional methods.
104 
105     // additional internal methods
106 
107     public PortletApplicationEntity get(String objectId)
108     {
109         Iterator iterator = this.iterator();
110         while (iterator.hasNext()) {
111             PortletApplicationEntity portletApplicationEntity = (PortletApplicationEntity)iterator.next();
112             if (portletApplicationEntity.getId().toString().equals(objectId)) {
113                 return portletApplicationEntity;
114             }
115         }
116         return null;
117     }
118 
119     // internal methods used for debugging purposes only
120 
121     public String toString()
122     {
123         return toString(0);
124     }
125 
126     public String toString(int indent)
127     {
128         StringBuffer buffer = new StringBuffer(1000);
129         StringUtils.newLine(buffer,indent);
130         buffer.append(getClass().toString()); buffer.append(":");
131         StringUtils.newLine(buffer,indent);
132         buffer.append("{");
133         Iterator iterator = this.iterator();
134         if (iterator.hasNext()) {
135             StringUtils.newLine(buffer,indent);
136             buffer.append("Portlet Application Entities:");
137         }
138         while (iterator.hasNext()) {
139             buffer.append(((PortletApplicationEntityImpl)iterator.next()).toString(indent+2));
140         }
141         StringUtils.newLine(buffer,indent);
142         buffer.append("}");
143         return buffer.toString();
144     }
145 
146     // Castor related methods and attributes
147 
148     private Collection castorApplications = new ArrayList();
149 
150     public Collection getCastorApplications()
151     {        
152         return castorApplications;
153     }
154 }