View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.jetspeed.om.portlet.impl;
18  
19  import java.io.Serializable;
20  import java.util.ArrayList;
21  import java.util.Collection;
22  import java.util.Iterator;
23  
24  
25  
26  import org.apache.pluto.om.common.ObjectID;
27  import org.apache.pluto.om.portlet.PortletDefinition;
28  import org.apache.pluto.om.portlet.PortletDefinitionList;
29  
30  /***
31   * 
32   * PortletDefinitionListImpl
33   * 
34   * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
35   * @version $Id: PortletDefinitionListImpl.java 516448 2007-03-09 16:25:47Z ate $
36   *
37   */
38  public class PortletDefinitionListImpl implements PortletDefinitionList, Serializable
39  {
40  
41      protected Collection innerCollection;
42  
43      /***
44       * 
45       */
46      public PortletDefinitionListImpl()
47      {
48          super();
49          innerCollection = new ArrayList();
50      }
51  
52      public PortletDefinitionListImpl(Collection collection)
53      {
54          super();
55          innerCollection = collection;
56      }
57  
58      /***
59       * @see org.apache.pluto.om.portlet.PortletDefinitionList#iterator()
60       */
61      public Iterator iterator()
62      {
63          return innerCollection.iterator();
64      }
65  
66      /***
67       * @see org.apache.pluto.om.portlet.PortletDefinitionList#get(org.apache.pluto.om.common.ObjectID)
68       */
69      public PortletDefinition get(ObjectID id)
70      {
71          Iterator itr = innerCollection.iterator();
72          while (itr.hasNext())
73          {
74              PortletDefinition pd = (PortletDefinition) itr.next();
75              if (pd.getId().equals(id))
76              {
77                  return pd;
78              }
79          }
80  
81          return null;
82      }
83  
84      /***
85       * Retrieves a <code>PortletDefinition</code> from this 
86       * collection by the PortletDefinitions proper name
87       * @param name Proper name of PortletDefinition to locate.
88       * @return PortletDefinition matching <code>name</code> or <code>null</code>
89       * if no PortletDefinition within this PortletApplication has that name.
90       */
91      public PortletDefinition get(String name)
92      {
93          Iterator itr = innerCollection.iterator();
94          while (itr.hasNext())
95          {
96              PortletDefinition pd = (PortletDefinition) itr.next();
97              if (pd.getName().equals(name))
98              {
99                  return pd;
100             }
101         }
102 
103         return null;
104     }
105 
106     /***
107      * @see java.util.Collection#add(java.lang.Object)
108      */
109     public boolean add(Object o)
110     {
111         PortletDefinition pd = (PortletDefinition) o;        
112         return innerCollection.add(pd);
113     }
114 
115     /***
116      * @see java.util.Collection#remove(java.lang.Object)
117      */
118     public boolean remove(Object o)
119     {
120         PortletDefinition pd = (PortletDefinition) o;        
121         return innerCollection.remove(pd);
122     }
123 
124     /***
125      * @return
126      */
127     public Collection getInnerCollection()
128     {
129         return innerCollection;
130     }
131 
132     /***
133      * @param collection
134      */
135     public void setInnerCollection(Collection collection)
136     {
137         innerCollection = collection;
138     }
139 
140 }