001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package javax.management.relation;
023:
024: import java.util.ArrayList;
025: import java.util.Iterator;
026: import java.util.List;
027:
028: /**
029: * A list of roles.<p>
030: *
031: * I think the idea is supposed to be that only roles should be in the
032: * list. But this isn't true.
033: *
034: * <p><b>Revisions:</b>
035: * <p><b>20020313 Adrian Brock:</b>
036: * <ul>
037: * <li>Fix the cloning
038: * </ul>
039: *
040: * @author <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>
041: * @version $Revision: 57200 $
042: */
043: public class RoleList extends ArrayList {
044: // Constants -----------------------------------------------------
045:
046: private static final long serialVersionUID = 5568344346499649313L;
047:
048: // Attributes ----------------------------------------------------
049:
050: // Static --------------------------------------------------------
051:
052: // Constructors --------------------------------------------------
053:
054: /**
055: * Construct an empty RoleList.
056: */
057: public RoleList() {
058: super ();
059: }
060:
061: /**
062: * Construct a RoleList with an initial capacity.
063: *
064: * @param initialCapacity the initial capacity.
065: */
066: public RoleList(int initialCapacity) {
067: super (initialCapacity);
068: }
069:
070: /**
071: * Construct a RoleList from a list. It must be an ArrayList.
072: * The order of the list is maintained.
073: *
074: * @param list the list to copy from.
075: * @exception IllegalArgumentException for a null list or
076: * an list element that is not a role.
077: */
078: public RoleList(List list) throws IllegalArgumentException {
079: super ();
080: if (list == null)
081: throw new IllegalArgumentException("Null list");
082: Iterator iterator = new ArrayList(list).iterator();
083: while (iterator.hasNext()) {
084: try {
085: add((Role) iterator.next());
086: } catch (ClassCastException cce) {
087: throw new IllegalArgumentException(
088: "List element is not a role.");
089: }
090: }
091: }
092:
093: // Public ---------------------------------------------------------
094:
095: /**
096: * Appends a role to the end of the list.
097: *
098: * @param role the new role.
099: * @exception IllegalArgumentException if the role is null
100: */
101: public void add(Role role) throws IllegalArgumentException {
102: if (role == null)
103: throw new IllegalArgumentException("Null role");
104: super .add(role);
105: }
106:
107: /**
108: * Adds a role at the specified location in the list.
109: *
110: * @param index the location at which to insert the role.
111: * @param role the new role.
112: * @exception IllegalArgumentException if the role is null
113: * @exception IndexOutOfBoundsException if there is no such index
114: * in the list
115: */
116: public void add(int index, Role role)
117: throws IllegalArgumentException, IndexOutOfBoundsException {
118: if (role == null)
119: throw new IllegalArgumentException("Null role");
120: super .add(index, role);
121: }
122:
123: /**
124: * Appends a role list to the end of the list.
125: *
126: * @param roleList the role list to insert, can be null
127: * @return true if the list changes, false otherwise
128: * @exception IndexOutOfBoundsException if there is no such index
129: * in the list (this is part of ArrayList for some reason?)
130: */
131: public boolean addAll(RoleList roleList)
132: throws IndexOutOfBoundsException {
133: if (roleList == null)
134: return false;
135: return super .addAll(roleList);
136: }
137:
138: /**
139: * Inserts a role list at the specified location in the list.
140: *
141: * @param index the location at which to insert the role list.
142: * @param roleList the role list to insert.
143: * @return true if the list changes, false otherwise
144: * @exception IllegalArgumentException if the role list is null
145: * @exception IndexOutOfBoundsException if there is no such index
146: * in the list
147: */
148: public boolean addAll(int index, RoleList roleList)
149: throws IllegalArgumentException, IndexOutOfBoundsException {
150: if (roleList == null)
151: throw new IllegalArgumentException("null roleList");
152: return super .addAll(index, roleList);
153: }
154:
155: /**
156: * Sets a role at the specified location in the list.
157: *
158: * @param index the location of the role to replace.
159: * @param role the new role.
160: * @exception IllegalArgumentException if the role is null
161: * @exception IndexOutOfBoundsException if there is no such index
162: * in the list
163: */
164: public void set(int index, Role role)
165: throws IllegalArgumentException, IndexOutOfBoundsException {
166: if (role == null)
167: throw new IllegalArgumentException("Null role");
168: super .set(index, role);
169: }
170:
171: // Array List Overrides -------------------------------------------
172:
173: // NONE! I think there was supposed to be?
174:
175: // Object Overrides -----------------------------------------------
176:
177: /**
178: * Cloning, creates a new RoleList with the same elements.
179: * The roles in the list are not cloned.
180: *
181: * @return the new empty role list.
182: */
183: public Object clone() {
184: return super.clone();
185: }
186: }
|