Source for javax.management.AttributeList

   1: /* AttributeList.java -- A list of MBean attributes.
   2:    Copyright (C) 2006 Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: package javax.management;
  39: 
  40: import java.util.ArrayList;
  41: 
  42: /**
  43:  * Represents a list of MBean {@link Attribute}s, with their
  44:  * names and values.  This is implemented as an
  45:  * {@link java.util.ArrayList} extension, with additional
  46:  * methods typed to only allow the addition of {@link Attribute}s.
  47:  *
  48:  * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
  49:  * @since 1.5
  50:  */
  51: public class AttributeList
  52:   extends ArrayList<Object>
  53: {
  54: 
  55:   /**
  56:    * Compatible with JDK 1.5
  57:    */
  58:   private static final long serialVersionUID = -4077085769279709076L;
  59: 
  60:   /**
  61:    * Constructs an empty list with an initial capacity of ten.
  62:    *
  63:    * @see java.util.ArrayList#ArrayList()
  64:    */
  65:   public AttributeList()
  66:   {
  67:     super();
  68:   }
  69: 
  70:   /**
  71:    * Constructs an {@link AttributeList} using the contents
  72:    * of an existing list.  The initial capacity is 110% of the
  73:    * size of the specified list.
  74:    *
  75:    * @param list the list to use to fill this list.
  76:    * @see java.util.ArrayList#ArrayList(java.util.Collection)
  77:    */
  78:   public AttributeList(AttributeList list)
  79:   {
  80:     super(list);
  81:   }
  82: 
  83:   /**
  84:    * Constructs an empty list with the specified initial capacity.
  85:    *
  86:    * @param capacity the initial capacity of the list.
  87:    * @see java.util.ArrayList#ArrayList(int)
  88:    */
  89:   public AttributeList(int capacity)
  90:   {
  91:     super(capacity);
  92:   }
  93: 
  94:   /**
  95:    * Adds the specified {@link Attribute} to the end of the list.
  96:    *
  97:    * @param attribute the attribute to add.
  98:    * @see java.util.Arraylist#add(Object)
  99:    */
 100:   public void add(Attribute attribute)
 101:   {
 102:     super.add(attribute);
 103:   }
 104: 
 105:   /**
 106:    * <p>
 107:    * Adds the specified {@link Attribute} at the supplied index.
 108:    * Any attribute already at that index is moved up one place
 109:    * in the list to the position <code>(index + 1)</code>.
 110:    * Likewise, the attribute at <code>(index + 1)</code> is
 111:    * also moved up one place, continuing until the final
 112:    * attribute in the list moves to a new position, increasing
 113:    * the size of the list.
 114:    * </p>
 115:    * <p>
 116:    * If the index is invalid (i.e. it is smaller than zero, or
 117:    * greater than the current size of the list), a
 118:    * @link{RuntimeOperationsException} is thrown, which wraps
 119:    * the @link{IndexOutOfBoundsException} from the underlying
 120:    * array list.
 121:    * </p>
 122:    * 
 123:    * @param index the index at which to place the new attribute.
 124:    * @param attribute the new attribute to add.
 125:    * @throws RuntimeOperationsException if <code>index < 0</code>
 126:    *                                    or <code>index > size()</code>
 127:    * @see java.util.ArrayList#add(int, Object)
 128:    */
 129:   public void add(int index, Attribute attribute)
 130:   {
 131:     try
 132:       {
 133:     super.add(index, attribute);
 134:       }
 135:     catch (IndexOutOfBoundsException e)
 136:       {
 137:     throw new RuntimeOperationsException(e, "Invalid index.");
 138:       }
 139:   }
 140: 
 141:   /**
 142:    * Adds all the {@link Attribute}s from the supplied list
 143:    * to the end of this list, in the order they are returned
 144:    * by the list's {@link java.util.Iterator}.
 145:    *
 146:    * @param list the list of attributes to add.
 147:    * @return true if the list changed.
 148:    * @see java.util.ArrayList#addAll(Collection)
 149:    */
 150:   public boolean addAll(AttributeList list)
 151:   {
 152:     return super.addAll(list);
 153:   }
 154: 
 155:   /**
 156:    * <p>
 157:    * Adds all the {@link Attribute}s from the supplied list
 158:    * to this list, at the specified index.  The attributes
 159:    * are added in the order they are returned by the
 160:    * list's {@link java.util.Iterator}.  Any attribute already
 161:    * at that index is moved up one place in the list to the
 162:    * position <code>(index + list.size())</code>.
 163:    * Likewise, the attribute at <code>(index + list.size())</code>
 164:    * is also moved up one place, continuing until the final
 165:    * attribute in the original list.
 166:    * </p>
 167:    * <p>
 168:    * If the index is invalid (i.e. it is smaller than zero, or
 169:    * greater than the current size of the list), a
 170:    * @link{RuntimeOperationsException} is thrown, which wraps
 171:    * the @link{IndexOutOfBoundsException} from the underlying
 172:    * array list.
 173:    * </p>
 174:    * 
 175:    * @param index the index at which to place the new attribute.
 176:    * @param list the list of attributes to add.
 177:    * @return true if the list changed.
 178:    * @throws RuntimeOperationsException if <code>index < 0</code>
 179:    *                                    or <code>index > size()</code>
 180:    * @see java.util.ArrayList#addAll(int, Collection)
 181:    */
 182:   public boolean addAll(int index, AttributeList list)
 183:   {
 184:     try
 185:       {
 186:     return super.addAll(index, list);
 187:       }
 188:     catch (IndexOutOfBoundsException e)
 189:       {
 190:     throw new RuntimeOperationsException(e, "Invalid index.");
 191:       }
 192:   }
 193: 
 194:   /**
 195:    * Replaces the attribute at the specified index with the one
 196:    * supplied. If the index is invalid (i.e. it is smaller than
 197:    * zero, or greater than the current size of the list), a
 198:    * @link{RuntimeOperationsException} is thrown, which wraps
 199:    * the @link{IndexOutOfBoundsException} from the underlying
 200:    * array list.
 201:    *
 202:    * @param index the index at which to place the new attribute.
 203:    * @param attribute the new attribute to add.
 204:    * @throws RuntimeOperationsException if <code>index < 0</code>
 205:    *                                    or <code>index > size()</code>
 206:    * @see java.util.ArrayList#set(int, Object)
 207:    */
 208:   public void set(int index, Attribute attribute)
 209:   {
 210:     try
 211:       {
 212:     super.set(index, attribute);
 213:       }
 214:     catch (IndexOutOfBoundsException e)
 215:       {
 216:     throw new RuntimeOperationsException(e, "Invalid index.");
 217:       }
 218:   }
 219:     
 220: }