001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.portal.pluto.om.common;
018:
019: import java.util.HashSet;
020: import java.util.Iterator;
021:
022: import org.apache.pluto.om.common.SecurityRole;
023: import org.apache.pluto.om.common.SecurityRoleSet;
024: import org.apache.pluto.util.StringUtils;
025:
026: /**
027: *
028: *
029: * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
030: *
031: * @version CVS $Id: SecurityRoleSetImpl.java 433543 2006-08-22 06:22:54Z crossley $
032: */
033: public class SecurityRoleSetImpl extends HashSet implements
034: SecurityRoleSet, java.io.Serializable {
035:
036: // unmodifiable part
037:
038: public static class Unmodifiable extends UnmodifiableSet implements
039: SecurityRoleSet {
040:
041: public Unmodifiable(SecurityRoleSet c) {
042: super (c);
043: }
044:
045: public SecurityRole get(String roleName) {
046: return ((SecurityRoleSet) c).get(roleName);
047: }
048:
049: }
050:
051: public SecurityRoleSetImpl() {
052: // nothing to do
053: }
054:
055: // SecurityRoleSet implementation.
056:
057: public SecurityRole get(String roleName) {
058: Iterator iterator = this .iterator();
059: while (iterator.hasNext()) {
060: SecurityRole securityRole = (SecurityRole) iterator.next();
061: if (securityRole.getRoleName().equals(roleName)) {
062: return securityRole;
063: }
064: }
065: return null;
066: }
067:
068: // additional methods.
069:
070: public SecurityRole add(SecurityRole securityRole) {
071: SecurityRoleImpl newSecurityRole = new SecurityRoleImpl();
072: newSecurityRole.setRoleName(securityRole.getRoleName());
073: newSecurityRole.setDescription(securityRole.getDescription());
074:
075: super .add(newSecurityRole);
076:
077: return newSecurityRole;
078: }
079:
080: public SecurityRole add(String roleName, String description) {
081: SecurityRoleImpl securityRole = new SecurityRoleImpl();
082: securityRole.setRoleName(roleName);
083: securityRole.setDescription(description);
084:
085: super .add(securityRole);
086:
087: return securityRole;
088: }
089:
090: public void remove(SecurityRole securityRole) {
091: super .remove(securityRole);
092: }
093:
094: public SecurityRole remove(String roleName) {
095: Iterator iterator = this .iterator();
096: while (iterator.hasNext()) {
097: SecurityRole securityRole = (SecurityRole) iterator.next();
098: if (securityRole.getRoleName().equals(roleName)) {
099: super .remove(securityRole);
100: return securityRole;
101: }
102: }
103: return null;
104: }
105:
106: public String toString() {
107: return toString(0);
108: }
109:
110: public String toString(int indent) {
111: StringBuffer buffer = new StringBuffer(50);
112: StringUtils.newLine(buffer, indent);
113: buffer.append(getClass().toString());
114: buffer.append(": ");
115: Iterator iterator = this .iterator();
116: while (iterator.hasNext()) {
117: buffer.append(((SecurityRoleImpl) iterator.next())
118: .toString(indent + 2));
119: }
120: return buffer.toString();
121: }
122:
123: }
|