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.impl;
18  
19  import java.io.Serializable;
20  import java.util.ArrayList;
21  import java.util.Collection;
22  import java.util.Iterator;
23  
24  import org.apache.pluto.om.common.DescriptionSet;
25  import org.apache.pluto.om.common.SecurityRoleRef;
26  import org.apache.pluto.om.common.SecurityRoleRefSet;
27  import org.apache.pluto.om.common.SecurityRoleRefSetCtrl;
28  
29  /***
30   * 
31   * SecurityRoleRefSetImpl
32   * 
33   * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
34   * @version $Id: SecurityRoleRefSetImpl.java 517121 2007-03-12 07:45:49Z ate $
35   *
36   */
37  public class SecurityRoleRefSetImpl implements SecurityRoleRefSet, SecurityRoleRefSetCtrl, Serializable
38  {
39  
40      protected Collection innerCollection;
41  
42      public SecurityRoleRefSetImpl()
43      {
44          innerCollection = new ArrayList();
45      }
46  
47      public SecurityRoleRefSetImpl(Collection collection)
48      {
49          innerCollection = collection;
50      }
51  
52      /***
53       * @see org.apache.pluto.om.common.SecurityRoleRefSet#get(java.lang.String)
54       */
55      public SecurityRoleRef get(String name)
56      {
57          Iterator itr = innerCollection.iterator();
58          while (itr.hasNext())
59          {
60  			SecurityRoleRef roleRef = (SecurityRoleRef) itr.next();
61              if (roleRef.getRoleName().equals(name))
62              {
63                  return roleRef;
64              }
65          }
66  
67          return null;
68      }
69  
70      /***
71       * @see org.apache.pluto.om.common.SecurityRoleRefSetCtrl#add(java.lang.String, java.lang.String, java.lang.String)
72       */
73      public SecurityRoleRef add(String roleName, String roleLink, String description)
74      {
75          // TODO Fix me.  We should try not to directly use implementation classes
76          SecurityRoleRefImpl newRef = new SecurityRoleRefImpl();
77          newRef.setRoleName(roleName);
78          newRef.setRoleLink(roleLink);
79          newRef.setDescription(description);
80          add(newRef);
81          return newRef;
82      }
83  
84      /***
85       * @see org.apache.pluto.om.common.SecurityRoleRefSetCtrl#add(org.apache.pluto.om.common.SecurityRoleRef)
86       */
87      public SecurityRoleRef add(SecurityRoleRef securityRoleRef)
88      {
89          innerCollection.add(securityRoleRef);
90          return securityRoleRef;
91      }
92  
93      /***
94       * @see org.apache.pluto.om.common.SecurityRoleRefSetCtrl#remove(java.lang.String)
95       */
96      public SecurityRoleRef remove(String name)
97      {
98          SecurityRoleRef roleRef = get(name);
99          if(roleRef != null)
100         {
101         	innerCollection.remove(roleRef);
102         }
103         
104         return roleRef;
105     }
106 
107     /***
108      * @see org.apache.pluto.om.common.SecurityRoleRefSetCtrl#remove(org.apache.pluto.om.common.SecurityRoleRef)
109      */
110     public void remove(SecurityRoleRef securityRoleRef)
111     {
112         innerCollection.remove(securityRoleRef);
113 
114     }
115 
116     /***
117      * @see java.util.Collection#add(java.lang.Object)
118      */
119     public boolean add(Object o)
120     {
121         if(innerCollection.contains(o))
122         {
123         	remove(o);
124         }
125         return innerCollection.add(o);
126     }
127 
128     /***
129      * @see java.util.Collection#remove(java.lang.Object)
130      */
131     public boolean remove(Object o)
132     {
133         return innerCollection.remove(o);
134     }
135 
136     /***
137      * @see org.apache.pluto.om.common.SecurityRoleRefSetCtrl#add(java.lang.String, java.lang.String, org.apache.pluto.om.common.DescriptionSet)
138      */
139     public SecurityRoleRef add(String roleName, String roleLink, DescriptionSet descriptions)
140     {
141         SecurityRoleRefImpl newRef = new SecurityRoleRefImpl();
142         newRef.setRoleName(roleName);
143         newRef.setRoleLink(roleLink);
144         newRef.setDescriptionSet(descriptions);
145         add(newRef);
146         return newRef;
147     }
148 
149     /***
150      * @see java.util.Collection#addAll(java.util.Collection)
151      */
152     public boolean addAll(Collection c)
153     {        
154         return innerCollection.addAll(c);
155     }
156 
157     /***
158      * @see java.util.Collection#clear()
159      */
160     public void clear()
161     {
162         innerCollection.clear();
163 
164     }
165 
166     /***
167      * @see java.util.Collection#contains(java.lang.Object)
168      */
169     public boolean contains(Object o)
170     {        
171         return innerCollection.contains(o);
172     }
173 
174     /***
175      * @see java.util.Collection#containsAll(java.util.Collection)
176      */
177     public boolean containsAll(Collection c)
178     {        
179         return innerCollection.containsAll(c);
180     }
181 
182     /***
183      * @see java.util.Collection#isEmpty()
184      */
185     public boolean isEmpty()
186     {        
187         return innerCollection.isEmpty();
188     }
189 
190     /***
191      * @see java.util.Collection#iterator()
192      */
193     public Iterator iterator()
194     {        
195         return innerCollection.iterator();
196     }
197 
198     /***
199      * @see java.util.Collection#removeAll(java.util.Collection)
200      */
201     public boolean removeAll(Collection c)
202     {        
203         return innerCollection.removeAll(c);
204     }
205 
206     /***
207      * @see java.util.Collection#retainAll(java.util.Collection)
208      */
209     public boolean retainAll(Collection c)
210     {        
211         return innerCollection.retainAll(c);
212     }
213 
214     /***
215      * @see java.util.Collection#size()
216      */
217     public int size()
218     {        
219         return innerCollection.size();
220     }
221 
222     /***
223      * @see java.util.Collection#toArray()
224      */
225     public Object[] toArray()
226     {        
227         return innerCollection.toArray();
228     }
229 
230     /***
231      * @see java.util.Collection#toArray(java.lang.Object[])
232      */
233     public Object[] toArray(Object[] a)
234     {        
235         return innerCollection.toArray(a);
236     }
237 
238     /***
239      * @return
240      */
241     public Collection getInnerCollection()
242     {
243         return innerCollection;
244     }
245 
246     /***
247      * @param collection
248      */
249     public void setInnerCollection(Collection collection)
250     {
251         innerCollection = collection;
252     }
253 
254 }