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.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.pluto.om.common.DescriptionSet;
025: import org.apache.pluto.om.common.SecurityRoleRef;
026: import org.apache.pluto.om.common.SecurityRoleRefSet;
027: import org.apache.pluto.om.common.SecurityRoleRefSetCtrl;
028:
029: /**
030: *
031: * SecurityRoleRefSetImpl
032: *
033: * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
034: * @version $Id: SecurityRoleRefSetImpl.java 517121 2007-03-12 07:45:49Z ate $
035: *
036: */
037: public class SecurityRoleRefSetImpl implements SecurityRoleRefSet,
038: SecurityRoleRefSetCtrl, Serializable {
039:
040: protected Collection innerCollection;
041:
042: public SecurityRoleRefSetImpl() {
043: innerCollection = new ArrayList();
044: }
045:
046: public SecurityRoleRefSetImpl(Collection collection) {
047: innerCollection = collection;
048: }
049:
050: /**
051: * @see org.apache.pluto.om.common.SecurityRoleRefSet#get(java.lang.String)
052: */
053: public SecurityRoleRef get(String name) {
054: Iterator itr = innerCollection.iterator();
055: while (itr.hasNext()) {
056: SecurityRoleRef roleRef = (SecurityRoleRef) itr.next();
057: if (roleRef.getRoleName().equals(name)) {
058: return roleRef;
059: }
060: }
061:
062: return null;
063: }
064:
065: /**
066: * @see org.apache.pluto.om.common.SecurityRoleRefSetCtrl#add(java.lang.String, java.lang.String, java.lang.String)
067: */
068: public SecurityRoleRef add(String roleName, String roleLink,
069: String description) {
070: // TODO Fix me. We should try not to directly use implementation classes
071: SecurityRoleRefImpl newRef = new SecurityRoleRefImpl();
072: newRef.setRoleName(roleName);
073: newRef.setRoleLink(roleLink);
074: newRef.setDescription(description);
075: add(newRef);
076: return newRef;
077: }
078:
079: /**
080: * @see org.apache.pluto.om.common.SecurityRoleRefSetCtrl#add(org.apache.pluto.om.common.SecurityRoleRef)
081: */
082: public SecurityRoleRef add(SecurityRoleRef securityRoleRef) {
083: innerCollection.add(securityRoleRef);
084: return securityRoleRef;
085: }
086:
087: /**
088: * @see org.apache.pluto.om.common.SecurityRoleRefSetCtrl#remove(java.lang.String)
089: */
090: public SecurityRoleRef remove(String name) {
091: SecurityRoleRef roleRef = get(name);
092: if (roleRef != null) {
093: innerCollection.remove(roleRef);
094: }
095:
096: return roleRef;
097: }
098:
099: /**
100: * @see org.apache.pluto.om.common.SecurityRoleRefSetCtrl#remove(org.apache.pluto.om.common.SecurityRoleRef)
101: */
102: public void remove(SecurityRoleRef securityRoleRef) {
103: innerCollection.remove(securityRoleRef);
104:
105: }
106:
107: /**
108: * @see java.util.Collection#add(java.lang.Object)
109: */
110: public boolean add(Object o) {
111: if (innerCollection.contains(o)) {
112: remove(o);
113: }
114: return innerCollection.add(o);
115: }
116:
117: /**
118: * @see java.util.Collection#remove(java.lang.Object)
119: */
120: public boolean remove(Object o) {
121: return innerCollection.remove(o);
122: }
123:
124: /**
125: * @see org.apache.pluto.om.common.SecurityRoleRefSetCtrl#add(java.lang.String, java.lang.String, org.apache.pluto.om.common.DescriptionSet)
126: */
127: public SecurityRoleRef add(String roleName, String roleLink,
128: DescriptionSet descriptions) {
129: SecurityRoleRefImpl newRef = new SecurityRoleRefImpl();
130: newRef.setRoleName(roleName);
131: newRef.setRoleLink(roleLink);
132: newRef.setDescriptionSet(descriptions);
133: add(newRef);
134: return newRef;
135: }
136:
137: /**
138: * @see java.util.Collection#addAll(java.util.Collection)
139: */
140: public boolean addAll(Collection c) {
141: return innerCollection.addAll(c);
142: }
143:
144: /**
145: * @see java.util.Collection#clear()
146: */
147: public void clear() {
148: innerCollection.clear();
149:
150: }
151:
152: /**
153: * @see java.util.Collection#contains(java.lang.Object)
154: */
155: public boolean contains(Object o) {
156: return innerCollection.contains(o);
157: }
158:
159: /**
160: * @see java.util.Collection#containsAll(java.util.Collection)
161: */
162: public boolean containsAll(Collection c) {
163: return innerCollection.containsAll(c);
164: }
165:
166: /**
167: * @see java.util.Collection#isEmpty()
168: */
169: public boolean isEmpty() {
170: return innerCollection.isEmpty();
171: }
172:
173: /**
174: * @see java.util.Collection#iterator()
175: */
176: public Iterator iterator() {
177: return innerCollection.iterator();
178: }
179:
180: /**
181: * @see java.util.Collection#removeAll(java.util.Collection)
182: */
183: public boolean removeAll(Collection c) {
184: return innerCollection.removeAll(c);
185: }
186:
187: /**
188: * @see java.util.Collection#retainAll(java.util.Collection)
189: */
190: public boolean retainAll(Collection c) {
191: return innerCollection.retainAll(c);
192: }
193:
194: /**
195: * @see java.util.Collection#size()
196: */
197: public int size() {
198: return innerCollection.size();
199: }
200:
201: /**
202: * @see java.util.Collection#toArray()
203: */
204: public Object[] toArray() {
205: return innerCollection.toArray();
206: }
207:
208: /**
209: * @see java.util.Collection#toArray(java.lang.Object[])
210: */
211: public Object[] toArray(Object[] a) {
212: return innerCollection.toArray(a);
213: }
214:
215: /**
216: * @return
217: */
218: public Collection getInnerCollection() {
219: return innerCollection;
220: }
221:
222: /**
223: * @param collection
224: */
225: public void setInnerCollection(Collection collection) {
226: innerCollection = collection;
227: }
228:
229: }
|