001: /*
002: * Copyright (C) The MX4J Contributors.
003: * All rights reserved.
004: *
005: * This software is distributed under the terms of the MX4J License version 1.0.
006: * See the terms of the MX4J License in the documentation provided with this software.
007: */
008:
009: package javax.management;
010:
011: import java.util.ArrayList;
012: import java.util.Collection;
013:
014: /**
015: * @version $Revision: 1.8 $
016: */
017: public class AttributeList extends ArrayList {
018: private static final long serialVersionUID = -4077085769279709076L;
019:
020: public AttributeList() {
021: }
022:
023: public AttributeList(int initialCapacity) {
024: super (initialCapacity);
025: }
026:
027: public AttributeList(AttributeList list) {
028: super (list);
029: }
030:
031: public boolean add(Object o) {
032: if (o instanceof Attribute)
033: return super .add(o);
034: else
035: throw new RuntimeOperationsException(
036: new IllegalArgumentException(
037: "Elements of AttributeList can only be Attribute objects"));
038: }
039:
040: public void add(Attribute a) {
041: add((Object) a);
042: }
043:
044: public void add(int index, Object element) {
045: if (element instanceof Attribute) {
046: try {
047: super .add(index, element);
048: } catch (IndexOutOfBoundsException x) {
049: throw new RuntimeOperationsException(x);
050: }
051: } else {
052: throw new RuntimeOperationsException(
053: new IllegalArgumentException(
054: "Elements of AttributeList can only be Attribute objects"));
055: }
056: }
057:
058: public void add(int index, Attribute element) {
059: add(index, (Object) element);
060: }
061:
062: public boolean addAll(Collection c) {
063: if (c instanceof AttributeList) {
064: return super .addAll(c);
065: } else {
066: throw new RuntimeOperationsException(
067: new IllegalArgumentException(
068: "Only AttributeList objects can be added to other AttributeList"));
069: }
070: }
071:
072: public boolean addAll(AttributeList c) {
073: return addAll((Collection) c);
074: }
075:
076: public boolean addAll(int index, Collection c) {
077: if (c instanceof AttributeList) {
078: try {
079: return super .addAll(index, c);
080: } catch (IndexOutOfBoundsException x) {
081: throw new RuntimeOperationsException(x);
082: }
083: } else {
084: throw new RuntimeOperationsException(
085: new IllegalArgumentException(
086: "Only AttributeList objects can be added to other AttributeList"));
087: }
088: }
089:
090: public boolean addAll(int index, AttributeList c) {
091: return addAll(index, (Collection) c);
092: }
093:
094: public Object set(int index, Object element) {
095: if (element instanceof Attribute) {
096: try {
097: return super .set(index, element);
098: } catch (IndexOutOfBoundsException x) {
099: throw new RuntimeOperationsException(x);
100: }
101: } else {
102: throw new RuntimeOperationsException(
103: new IllegalArgumentException(
104: "Elements of AttributeList can only be Attribute objects"));
105: }
106: }
107:
108: public void set(int index, Attribute element) {
109: set(index, (Object) element);
110: }
111: }
|