KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > pluto > portalImpl > om > common > impl > SecurityRoleSetImpl


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 JavaDoc;
23 import java.util.Iterator JavaDoc;
24
25 import org.apache.pluto.om.common.SecurityRole;
26 import org.apache.pluto.om.common.SecurityRoleSet;
27 import org.apache.pluto.util.StringUtils;
28
29 public class SecurityRoleSetImpl extends HashSet JavaDoc implements SecurityRoleSet, java.io.Serializable JavaDoc {
30
31
32     // unmodifiable part
33

34     public static class Unmodifiable
35         extends org.apache.pluto.portalImpl.om.common.impl.UnmodifiableSet
36         implements SecurityRoleSet
37     {
38
39         public Unmodifiable(SecurityRoleSet c)
40         {
41             super(c);
42         }
43
44         public SecurityRole get(String JavaDoc roleName)
45         {
46             return ((SecurityRoleSet)c).get(roleName);
47         }
48
49     }
50
51     public SecurityRoleSetImpl()
52     {
53     }
54
55     // SecurityRoleSet implementation.
56

57     public SecurityRole get(String JavaDoc roleName)
58     {
59         Iterator JavaDoc iterator = this.iterator();
60         while (iterator.hasNext()) {
61             SecurityRole securityRole = (SecurityRole)iterator.next();
62             if (securityRole.getRoleName().equals(roleName)) {
63                 return securityRole;
64             }
65         }
66         return null;
67     }
68
69     // additional methods.
70

71     public SecurityRole add(SecurityRole securityRole)
72     {
73         SecurityRoleImpl newSecurityRole = new SecurityRoleImpl();
74         newSecurityRole.setRoleName(securityRole.getRoleName());
75         newSecurityRole.setDescription(securityRole.getDescription());
76
77         super.add(newSecurityRole);
78
79         return newSecurityRole;
80     }
81
82     public SecurityRole add(String JavaDoc roleName, String JavaDoc description)
83     {
84         SecurityRoleImpl securityRole = new SecurityRoleImpl();
85         securityRole.setRoleName(roleName);
86         securityRole.setDescription(description);
87
88         super.add(securityRole);
89
90         return securityRole;
91     }
92
93     public void remove(SecurityRole securityRole)
94     {
95         super.remove(securityRole);
96     }
97
98     public SecurityRole remove(String JavaDoc roleName)
99     {
100         Iterator JavaDoc iterator = this.iterator();
101         while (iterator.hasNext())
102         {
103             SecurityRole securityRole = (SecurityRole)iterator.next();
104             if (securityRole.getRoleName().equals(roleName))
105             {
106                 super.remove(securityRole);
107                 return securityRole;
108             }
109         }
110         return null;
111     }
112
113     public String JavaDoc toString()
114     {
115         return toString(0);
116     }
117
118     public String JavaDoc toString(int indent)
119     {
120         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(50);
121         StringUtils.newLine(buffer,indent);
122         buffer.append(getClass().toString());
123         buffer.append(": ");
124         Iterator JavaDoc iterator = this.iterator();
125         while (iterator.hasNext()) {
126             buffer.append(((SecurityRoleImpl)iterator.next()).toString(indent+2));
127         }
128         return buffer.toString();
129     }
130
131 }
132
Popular Tags