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