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.jetspeed.om.servlet.impl;
018:
019: import java.io.Serializable;
020: import java.util.ArrayList;
021: import java.util.Collection;
022: import java.util.Iterator;
023:
024: import org.apache.jetspeed.om.common.servlet.MutableSecurityRoleSet;
025: import org.apache.pluto.om.common.SecurityRole;
026: import org.apache.pluto.om.common.SecurityRoleSet;
027:
028: /**
029: *
030: * SecurityRoleRefSetImpl
031: *
032: * @author <a href="mailto:ate@douma.nu">Ate Douma </a>
033: * @version $Id: SecurityRoleSetImpl.java 517121 2007-03-12 07:45:49Z ate $
034: *
035: */
036: public class SecurityRoleSetImpl implements SecurityRoleSet,
037: MutableSecurityRoleSet, Serializable {
038:
039: protected Collection innerCollection;
040:
041: public SecurityRoleSetImpl() {
042: innerCollection = new ArrayList();
043: }
044:
045: public SecurityRoleSetImpl(Collection collection) {
046: innerCollection = collection;
047: }
048:
049: /**
050: * @see org.apache.pluto.om.common.SecurityRoleSet#get(java.lang.String)
051: */
052: public SecurityRole get(String name) {
053: Iterator itr = innerCollection.iterator();
054: while (itr.hasNext()) {
055: SecurityRole role = (SecurityRole) itr.next();
056: if (role.getRoleName().equals(name)) {
057: return role;
058: }
059: }
060:
061: return null;
062: }
063:
064: /**
065: * @see org.apache.jetspeed.om.common.servlet.MutableSecurityRoleSet#add(org.apache.pluto.om.common.SecurityRole)
066: */
067: public SecurityRole add(SecurityRole securityRole) {
068: if (innerCollection.contains(securityRole)) {
069: throw new IllegalArgumentException("SecurityRole "
070: + securityRole.getRoleName() + " already defined.");
071: }
072: innerCollection.add(securityRole);
073: return securityRole;
074: }
075:
076: /**
077: * @see java.util.Collection#add(java.lang.Object)
078: */
079: public boolean add(Object o) {
080: SecurityRole role = (SecurityRole) o;
081: add(role);
082: return true;
083: }
084:
085: /**
086: * @see java.util.Collection#remove(java.lang.Object)
087: */
088: public boolean remove(Object o) {
089: return innerCollection.remove(o);
090: }
091:
092: /**
093: * @see java.util.Collection#addAll(java.util.Collection)
094: */
095: public boolean addAll(Collection c) {
096: // enforce unique role names in collection by adding them individually
097: Iterator itr = c.iterator();
098: while (itr.hasNext()) {
099: add(itr.next());
100: }
101: return true;
102: }
103:
104: /**
105: * @see java.util.Collection#clear()
106: */
107: public void clear() {
108: innerCollection.clear();
109:
110: }
111:
112: /**
113: * @see java.util.Collection#contains(java.lang.Object)
114: */
115: public boolean contains(Object o) {
116: return innerCollection.contains(o);
117: }
118:
119: /**
120: * @see java.util.Collection#containsAll(java.util.Collection)
121: */
122: public boolean containsAll(Collection c) {
123: return innerCollection.containsAll(c);
124: }
125:
126: /**
127: * @see java.util.Collection#isEmpty()
128: */
129: public boolean isEmpty() {
130: return innerCollection.isEmpty();
131: }
132:
133: /**
134: * @see java.util.Collection#iterator()
135: */
136: public Iterator iterator() {
137: return innerCollection.iterator();
138: }
139:
140: /**
141: * @see java.util.Collection#removeAll(java.util.Collection)
142: */
143: public boolean removeAll(Collection c) {
144: return innerCollection.removeAll(c);
145: }
146:
147: /**
148: * @see java.util.Collection#retainAll(java.util.Collection)
149: */
150: public boolean retainAll(Collection c) {
151: return innerCollection.retainAll(c);
152: }
153:
154: /**
155: * @see java.util.Collection#size()
156: */
157: public int size() {
158: return innerCollection.size();
159: }
160:
161: /**
162: * @see java.util.Collection#toArray()
163: */
164: public Object[] toArray() {
165: return innerCollection.toArray();
166: }
167:
168: /**
169: * @see java.util.Collection#toArray(java.lang.Object[])
170: */
171: public Object[] toArray(Object[] a) {
172: return innerCollection.toArray(a);
173: }
174:
175: /**
176: * @return collection
177: */
178: public Collection getInnerCollection() {
179: return innerCollection;
180: }
181:
182: /**
183: * @param collection
184: */
185: public void setInnerCollection(Collection collection) {
186: innerCollection = collection;
187: }
188:
189: }
|