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.portlet.impl;
21  
22  import java.util.Iterator;
23  import java.util.Map;
24  import java.util.Vector;
25  
26  import org.apache.pluto.om.common.ObjectID;
27  import org.apache.pluto.om.portlet.PortletApplicationDefinition;
28  import org.apache.pluto.om.portlet.PortletDefinition;
29  import org.apache.pluto.om.portlet.PortletDefinitionList;
30  import org.apache.pluto.om.servlet.ServletDefinition;
31  import org.apache.pluto.portalImpl.om.common.AbstractSupportSet;
32  import org.apache.pluto.portalImpl.om.common.Support;
33  import org.apache.pluto.util.StringUtils;
34  
35  public class PortletDefinitionListImpl extends AbstractSupportSet
36  implements PortletDefinitionList, java.io.Serializable, Support {
37  
38      // PortletDefinitionList implementation.
39  
40      public PortletDefinition get(ObjectID objectId)
41      {
42          Iterator iterator = this.iterator();
43          while (iterator.hasNext()) {
44              PortletDefinition portletDefinition = (PortletDefinition)iterator.next();
45              if (portletDefinition.getId().equals(objectId)) {
46                  return portletDefinition;
47              }
48          }
49          return null;
50      }
51  
52      // Support implementation.
53      
54      /* (non-Javadoc)
55       * @see org.apache.pluto.portalImpl.om.common.Support#preBuild(Object)
56       */
57      public void preBuild(Object parameter) throws Exception
58      {
59          Vector structure = (Vector)parameter;
60          PortletApplicationDefinition portletApplication = (PortletApplicationDefinition)structure.get(0);
61          Map servletMap = (Map)structure.get(1);
62  
63          Iterator iterator = this.iterator();
64          while (iterator.hasNext()) {
65              PortletDefinition portlet = (PortletDefinition)iterator.next();
66  
67              ((Support)portlet).preBuild(portletApplication);
68  
69              ServletDefinition servlet = null;
70              if (servletMap != null) {
71                  servlet = (ServletDefinition)servletMap.get(portlet.getId().toString());
72              }
73  
74              ((Support)portlet).postBuild(servlet);
75  
76          }
77      }
78      
79  
80      /* (non-Javadoc)
81       * @see org.apache.pluto.portalImpl.om.common.Support#postBuild(Object)
82       */
83      public void postBuild(Object parameter) throws Exception {
84      }
85  
86      /* (non-Javadoc)
87       * @see org.apache.pluto.portalImpl.om.common.Support#postLoad(Object)
88       */
89      public void postLoad(Object parameter) throws Exception {
90          Iterator iterator = this.iterator();
91          while (iterator.hasNext()) {
92              ((PortletDefinitionImpl)iterator.next()).postLoad(parameter);
93          }
94      }
95  
96      /* (non-Javadoc)
97       * @see org.apache.pluto.portalImpl.om.common.Support#postStore(Object)
98       */
99      public void postStore(Object parameter) throws Exception {
100     }
101 
102     /* (non-Javadoc)
103      * @see org.apache.pluto.portalImpl.om.common.Support#preStore(Object)
104      */
105     public void preStore(Object parameter) throws Exception {
106     }
107 
108     // additional methods.
109 
110     public PortletDefinition get(String objectId)
111     {
112         Iterator iterator = this.iterator();
113         while (iterator.hasNext()) {
114             PortletDefinition portletDefinition = (PortletDefinition)iterator.next();
115             if (portletDefinition.getId().toString().equals(objectId)) {
116                 return portletDefinition;
117             }
118         }
119         return null;
120     }
121 
122     public String toString()
123     {
124         return toString(0);
125     }
126 
127     public String toString(int indent)
128     {
129         StringBuffer buffer = new StringBuffer(50);
130         StringUtils.newLine(buffer,indent);
131         buffer.append(getClass().toString());
132         buffer.append(": ");
133         Iterator iterator = this.iterator();
134         while (iterator.hasNext()) {
135             buffer.append(((PortletDefinitionImpl)iterator.next()).toString(indent+2));
136         }
137         return buffer.toString();
138     }
139 }