KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > pluto > om > common > SecurityRoleSetImpl


1 /*
2  * Copyright 2004,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 package org.apache.cocoon.portal.pluto.om.common;
17
18 import java.util.HashSet JavaDoc;
19 import java.util.Iterator JavaDoc;
20
21 import org.apache.pluto.om.common.SecurityRole;
22 import org.apache.pluto.om.common.SecurityRoleSet;
23 import org.apache.pluto.util.StringUtils;
24
25 /**
26  *
27  *
28  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
29  *
30  * @version CVS $Id: SecurityRoleSetImpl.java 123407 2004-12-27 13:51:59Z cziegeler $
31  */

32 public class SecurityRoleSetImpl extends HashSet JavaDoc implements SecurityRoleSet, java.io.Serializable JavaDoc {
33
34
35     // unmodifiable part
36

37     public static class Unmodifiable
38         extends UnmodifiableSet
39         implements SecurityRoleSet {
40
41         public Unmodifiable(SecurityRoleSet c) {
42             super(c);
43         }
44
45         public SecurityRole get(String JavaDoc roleName) {
46             return ((SecurityRoleSet)c).get(roleName);
47         }
48
49     }
50
51     public SecurityRoleSetImpl() {
52         // nothing to do
53
}
54
55     // SecurityRoleSet implementation.
56

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

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