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.Iterator;
23  
24  import org.apache.pluto.om.common.ObjectID;
25  import org.apache.pluto.om.entity.PortletApplicationEntity;
26  import org.apache.pluto.om.entity.PortletEntity;
27  import org.apache.pluto.om.entity.PortletEntityList;
28  import org.apache.pluto.om.entity.PortletEntityListCtrl;
29  import org.apache.pluto.portalImpl.om.common.AbstractSupportSet;
30  import org.apache.pluto.util.StringUtils;
31  
32  public class PortletEntityListImpl extends AbstractSupportSet
33      implements PortletEntityList, PortletEntityListCtrl, java.io.Serializable {
34  
35      // PortletEntityList implementation.
36  
37      public PortletEntity get(ObjectID objectId)
38      {
39          Iterator iterator = this.iterator();
40          while (iterator.hasNext()) {
41              PortletEntity portletEntity = (PortletEntity)iterator.next();
42              if (portletEntity.getId().equals(objectId)) {
43                  return portletEntity;
44              }
45          }
46          return null;
47      }
48  
49  
50      // PortletEntityListCtrl implementation.
51  
52      public PortletEntity add(PortletApplicationEntity appEntity, String definitionId) {
53          PortletEntityImpl entity = new PortletEntityImpl();
54  
55          int id = -1;
56          for (Iterator iter = iterator(); iter.hasNext();) {
57              PortletEntityImpl ent = (PortletEntityImpl)iter.next();
58              try {
59                  id = Math.max(id, Integer.parseInt(ent.getCastorId()));
60              } catch (NumberFormatException e) {
61                  //don't care
62              }
63          }
64          entity.setId(Integer.toString(++id));
65          entity.setDefinitionId(definitionId);
66          entity.setPortletApplicationEntity(appEntity);
67  
68          add(entity);
69  
70          return entity;
71      }
72  
73      // additional methods.
74      
75      public PortletEntity get(String objectId)
76      {
77          Iterator iterator = this.iterator();
78          while (iterator.hasNext()) {
79              PortletEntity portletEntity = (PortletEntity)iterator.next();
80              if (portletEntity.getId().equals(objectId)) {
81                  return portletEntity;
82              }
83          }
84          return null;
85      }
86  
87      public String toString()
88      {
89          return toString(0);
90      }
91  
92      public String toString(int indent)
93      {
94          StringBuffer buffer = new StringBuffer(50);
95          StringUtils.newLine(buffer,indent);
96          buffer.append(getClass().toString());
97          buffer.append(": ");
98          Iterator iterator = this.iterator();
99          while (iterator.hasNext()) {
100             buffer.append(((PortletEntityImpl)iterator.next()).toString(indent+2));
101         }
102         return buffer.toString();
103     }
104 }