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.common.impl;
21  
22  import java.util.HashSet;
23  import java.util.Iterator;
24  
25  import org.apache.pluto.om.common.DescriptionSet;
26  import org.apache.pluto.om.common.SecurityRoleRef;
27  import org.apache.pluto.om.common.SecurityRoleRefSet;
28  import org.apache.pluto.om.common.SecurityRoleRefSetCtrl;
29  import org.apache.pluto.util.StringUtils;
30  
31  public class SecurityRoleRefSetImpl extends HashSet implements SecurityRoleRefSet, SecurityRoleRefSetCtrl, java.io.Serializable {
32  
33      public SecurityRoleRefSetImpl()
34      {
35      }
36  
37      // SecurityRoleRefSet implementation.
38  
39      public SecurityRoleRef get(String roleName)
40      {
41          Iterator iterator = this.iterator();
42          while (iterator.hasNext()) {
43              SecurityRoleRef securityRoleRef = (SecurityRoleRef)iterator.next();
44              if (securityRoleRef.getRoleName().equals(roleName)) {
45                  return securityRoleRef;
46              }
47          }
48          return null;
49      }
50  
51      // SecurityRoleRefSetCtrl implementation.
52  
53      public SecurityRoleRef add(SecurityRoleRef securityRoleRef)
54      {
55          SecurityRoleRefImpl newSecurityRoleRef = new SecurityRoleRefImpl();
56          newSecurityRoleRef.setRoleName(securityRoleRef.getRoleName());
57          newSecurityRoleRef.setRoleLink(securityRoleRef.getRoleLink());
58          newSecurityRoleRef.setDescriptionSet(((SecurityRoleRefImpl)securityRoleRef).getDescriptionSet());
59  
60          super.add(newSecurityRoleRef);
61  
62          return newSecurityRoleRef;
63      }
64  
65      public SecurityRoleRef remove(String roleName)
66      {
67          Iterator iterator = this.iterator();
68          while (iterator.hasNext()) {
69              SecurityRoleRef securityRoleRef = (SecurityRoleRef)iterator.next();
70              if (securityRoleRef.getRoleName().equals(roleName)) {
71                  super.remove(securityRoleRef);
72                  return securityRoleRef;
73              }
74          }
75          return null;
76      }
77  
78      public void remove(SecurityRoleRef securityRoleRef)
79      {
80          super.remove(securityRoleRef);
81      }
82  
83      // additional methods.
84      
85      public SecurityRoleRef add(String roleName, String roleLink, DescriptionSet descriptions)
86      {
87          SecurityRoleRefImpl securityRoleRef = new SecurityRoleRefImpl();
88          securityRoleRef.setRoleName(roleName);
89          securityRoleRef.setRoleLink(roleLink);
90          securityRoleRef.setDescriptionSet(descriptions);
91  
92          super.add(securityRoleRef);
93  
94          return securityRoleRef;
95      }
96  
97      public String toString()
98      {
99          return toString(0);
100     }
101 
102     public String toString(int indent)
103     {
104         StringBuffer buffer = new StringBuffer(50);
105         StringUtils.newLine(buffer,indent);
106         buffer.append(getClass().toString());
107         buffer.append(": ");
108         Iterator iterator = this.iterator();
109         while (iterator.hasNext()) {
110             buffer.append(((SecurityRoleRefImpl)iterator.next()).toString(indent+2));
111         }
112         return buffer.toString();
113     }
114 
115     // unmodifiable part
116 
117     public static class Unmodifiable extends org.apache.pluto.portalImpl.om.common.impl.UnmodifiableSet
118             implements SecurityRoleRefSet {
119 
120         public Unmodifiable(SecurityRoleRefSet c)
121         {
122             super(c);
123         }
124 
125         // additional methods.
126 
127         public SecurityRoleRef get(String roleName)
128         {
129             return((SecurityRoleRefSet)c).get(roleName);
130         }
131 
132     }
133 
134 }