001: /* JFox, the OpenSource J2EE Application Server
002: *
003: * Copyright (C) 2002 huihoo.org
004: * Distributable under GNU LGPL license
005: * See the GNU Lesser General Public License for more details.
006: */
007:
008: package javax.management.relation;
009:
010: import java.util.ArrayList;
011: import java.util.List;
012:
013: /**
014: * A RoleList represents a list of roles (Role objects). It is used as
015: * parameter when creating a relation, and when trying to set several roles in
016: * a relation (via 'setRoles()' method). It is returned as part of a
017: * RoleResult, to provide roles successfully retrieved.
018: *
019: * @author <a href="mailto:young_yy@hotmail.org">Young Yang</a>
020: */
021:
022: public class RoleList extends ArrayList {
023:
024: public RoleList() {
025: super ();
026: }
027:
028: /**
029: * Constructs an empty RoleList with the initial capacity
030: * specified.
031: *
032: * @param initialCapacity initial capacity
033: */
034: public RoleList(int initialCapacity) {
035: super (initialCapacity);
036: }
037:
038: /**
039: * Constructs a RoleList containing the elements of the
040: * ArrayList specified, in the order in which they are returned
041: * by the ArrayList's iterator. The RoleList instance has
042: * an initial capacity of 110% of the size of the ArrayList
043: * specified.
044: *
045: * @param roleList list of Role objects
046: *
047: * @exception IllegalArgumentException if:
048: * <P>- null parameter
049: * <P>or
050: * <P>- an element in the ArrayList is not a Role
051: */
052: public RoleList(List roleList) throws IllegalArgumentException {
053:
054: if (roleList == null)
055: throw new IllegalArgumentException(
056: "Invalid parameter: roleList can not be null");
057:
058: for (int i = 0; i < roleList.size(); i++) {
059: Object obj = roleList.get(i);
060: if (!(obj instanceof Role)) {
061: throw new IllegalArgumentException(
062: "The element at index " + i + "is not a Role, "
063: + obj.toString());
064: }
065: }
066: super .addAll(roleList);
067: }
068:
069: /**
070: * Adds the Role specified as the last element of the list.
071: *
072: * @param theRole the role to be added.
073: *
074: * @exception IllegalArgumentException if the role is null.
075: */
076: public void add(Role theRole) throws IllegalArgumentException {
077: if (theRole == null)
078: throw new IllegalArgumentException(
079: "Invalid parameter: theRole can not be null");
080: super .add(theRole);
081: }
082:
083: /**
084: * Inserts the role specified as an element at the position specified.
085: * Elements with an index greater than or equal to the current position are
086: * shifted up.
087: *
088: * @param theIndex The position in the list where the new Role
089: * object is to be inserted.
090: * @param theRole The Role object to be inserted.
091: *
092: * @exception IllegalArgumentException if the role is null.
093: * @exception IndexOutOfBoundsException if accessing with an index
094: * outside of the list.
095: */
096: public void add(int theIndex, Role theRole)
097: throws IllegalArgumentException, IndexOutOfBoundsException {
098: if (theRole == null)
099: throw new IllegalArgumentException(
100: "Invalid parameter: theRole can not be null");
101: super .add(theIndex, theRole);
102: }
103:
104: /**
105: * Sets the element at the position specified to be the role
106: * specified.
107: * The previous element at that position is discarded.
108: *
109: * @param theIndex The position specified.
110: * @param theRole The value to which the role element should be set.
111: *
112: * @exception IllegalArgumentException if the role is null.
113: * @exception IndexOutOfBoundsException if accessing with an index
114: * outside of the list.
115: */
116: public void set(int theIndex, Role theRole)
117: throws IllegalArgumentException, IndexOutOfBoundsException {
118: if (theRole == null)
119: throw new IllegalArgumentException(
120: "Invalid parameter: theRole can not be null");
121: super .set(theIndex, theRole);
122: }
123:
124: /**
125: * Appends all the elements in the RoleList specified to the end
126: * of the list, in the order in which they are returned by the Iterator of
127: * the RoleList specified.
128: *
129: * @param _roleList Elements to be inserted into the list (can be null)
130: *
131: * @exception IndexOutOfBoundsException if accessing with an index
132: * outside of the list.
133: */
134: public boolean addAll(RoleList _roleList)
135: throws IndexOutOfBoundsException {
136: if (_roleList == null) {
137: return true;
138: }
139: return (super .addAll(_roleList));
140: }
141:
142: /**
143: * Inserts all of the elements in the RoleList specified into this
144: * list, starting at the specified position, in the order in which they are
145: * returned by the Iterator of the RoleList specified.
146: *
147: * @param theIndex Position at which to insert the first element from the
148: * RoleList specified.
149: * @param _roleList Elements to be inserted into the list.
150: *
151: * @exception IllegalArgumentException if the role is null.
152: * @exception IndexOutOfBoundsException if accessing with an index
153: * outside of the list.
154: */
155: public boolean addAll(int theIndex, RoleList _roleList)
156: throws IllegalArgumentException, IndexOutOfBoundsException {
157: if (_roleList == null)
158: throw new IllegalArgumentException(
159: "Invalid parameter: roleList can not be null");
160: return (super .addAll(theIndex, _roleList));
161: }
162:
163: /**
164: * Cloning
165: * <P>Returns a new RoleList, but no copy of the included elements.
166: */
167: public Object clone() {
168: ArrayList array = (ArrayList) (super .clone());
169: return new RoleList(array);
170: }
171: }
|