EnumeratedMetaData.java
上传用户:zhengdagz
上传日期:2014-03-06
资源大小:1956k
文件大小:5k
源码类别:

xml/soap/webservice

开发平台:

Java

  1. /*
  2.  * $Id: EnumeratedMetaData.java,v 1.3 2005/10/10 17:01:07 rbair Exp $
  3.  *
  4.  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
  5.  * Santa Clara, California 95054, U.S.A. All rights reserved.
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  * 
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  * 
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  20.  */
  21. package org.jdesktop.binding.metadata;
  22. import java.util.List;
  23. /**
  24.  * <p>
  25.  * Class for representing meta-data for data fields which have a finite
  26.  * set of possible values.  The type of each value in the enumeration must
  27.  * match the type (&quot;elementClass&quot; property) of the meta-data object.
  28.  * Example usage:<br>
  29.  * <pre><code>
  30.  *     String weekdays[] = {&quot;Sunday&quot;,&quot;Monday&quot;,&quot;Tuesday&quot;,&quot;Wednesday&quot;,
  31.  *                          &quot;Thursday&quot;,&quot;Friday&quot;,&quot;Saturday&quot;};
  32.  *     EnumeratedMetaData metaData = new EnumeratedMetaData(&quot;weekday&quot;, String.class,
  33.  *                                                          &quot;Day of Week&quot;);
  34.  *     metaData.setEnumeration(weekdays);
  35.  * </code></pre>
  36.  * </p>
  37.  *
  38.  * @author Amy Fowler
  39.  * @version 1.0
  40.  */
  41. public class EnumeratedMetaData extends MetaData {
  42.     protected Object[] enumeration;
  43.     /**
  44.       * Instantiates a meta-data object with a default name &quot;enumvalue&quot; and
  45.       * a default field class equal to <code>java.lang.String</code>.
  46.       * This provides the no-argument constructor required for JavaBeans.
  47.       * It is recommended that the program explicitly set a meaningful
  48.       * &quot;name&quot; property.
  49.       */
  50.      public EnumeratedMetaData() {
  51.          this("enumvalue");
  52.      }
  53.     /**
  54.      * Instantiates a meta-data object with the specified name and
  55.      * a default field class equal to <code>java.lang.String</code>.
  56.      * @param name String containing the name of the data field
  57.      */
  58.     public EnumeratedMetaData(String name) {
  59.         super(name);
  60.     }
  61.     /**
  62.      * Instantiates a meta-data object with the specified name and
  63.      * field class.
  64.      * @param name String containing the name of the data field
  65.      * @param klass Class indicating type of data field
  66.      */
  67.     public EnumeratedMetaData(String name, Class klass) {
  68.         super(name, klass);
  69.     }
  70.     /**
  71.      * Instantiates a meta-data object with the specified name,
  72.      * field class, and label.
  73.      * @param name String containing the name of the data field
  74.      * @param klass Class indicating type of data field
  75.      * @param label String containing the user-displayable label for the
  76.      *        data field
  77.      */
  78.     public EnumeratedMetaData(String name, Class klass, String label) {
  79.         super(name, klass, label);
  80.     }
  81.     /**
  82.      * Gets the meta-data &quot;enumeration&quot; property which
  83.      * contains the set of possible values for the associated data field.
  84.      * The returned array is a copy, therefore modifications to that array
  85.      * will have no affect on the property.
  86.      * @see #setEnumeration
  87.      * @return array containing 0 or more enumerated values for the data field
  88.      */
  89.     public Object[] getEnumeration() {
  90.         Object[] evalues;
  91.         if (enumeration != null) {
  92.             evalues = new Object[enumeration.length];
  93.             System.arraycopy(enumeration, 0, evalues, 0,
  94.                              enumeration.length);
  95.         }
  96.         else {
  97.             evalues = new Object[0];
  98.         }
  99.         return evalues;
  100.     }
  101.     /**
  102.      * Sets the meta-data &quot;enumeration&quot; property by copying
  103.      * the values contained in the specified array to an internal representation.
  104.      * @see #getEnumeration
  105.      * @param enumeration array containing 0 or more enumerated values for the data field
  106.      */
  107.     public void setEnumeration(Object[] enumeration) {
  108.         Object oldEnumeration[] = this.enumeration;
  109.         this.enumeration = new Object[enumeration.length];
  110.         System.arraycopy(enumeration, 0, this.enumeration, 0,
  111.                          enumeration.length);
  112.         firePropertyChange("enumeration", oldEnumeration, enumeration);
  113.     }
  114.     /**
  115.      * Sets the meta-data &quot;enumeration&quot; property by copying
  116.      * the values contained in the specified list to an internal representation.
  117.      * @see #getEnumeration
  118.      * @param enumeration list containing 0 or more enumerated values for the data field
  119.      */
  120.     public void setEnumeration(List enumeration) {
  121.         setEnumeration(enumeration.toArray());
  122.     }
  123. }