    1   /* SimpleType
    2    *
    3    * $Id: SimpleType.java 4661 2006-09-25 23:11:16Z paul_jack $
    4    *
    5    * Created on Jan 8, 2004
    6    *
    7    * Copyright (C) 2004 Internet Archive.
    8    *
    9    * This file is part of the Heritrix web crawler (crawler.archive.org).
    10   *
    11   * Heritrix is free software; you can redistribute it and/or modify
    12   * it under the terms of the GNU Lesser Public License as published by
    13   * the Free Software Foundation; either version 2.1 of the License, or
    14   * any later version.
    15   *
    16   * Heritrix is distributed in the hope that it will be useful,
    17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    19   * GNU Lesser Public License for more details.
    20   *
    21   * You should have received a copy of the GNU Lesser Public License
    22   * along with Heritrix; if not, write to the Free Software
    23   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    24   */
    25  package org.archive.crawler.settings;
    26
    27  /***
    28   * A type that holds a Java type.
    29   *
    30   * @author John Erik Halse
    31   *
    32   */
    33  public class SimpleType extends Type {
    34
    35      private static final long serialVersionUID = -5134952907004648419L;
    36
    37      private final String description;
    38      private Object[] legalValues = null;
    39
    40      /***
    41       * Create a new instance of SimpleType.
    42       *
    43       * @param name the name of the type.
    44       * @param description a description suitable for the UI.
    45       * @param defaultValue the default value for this type. This also set what
    46       *            kind of Java type that this Type can hold.
    47       */
    48      public SimpleType(String name, String description, Object defaultValue) {
    49          super(name, defaultValue);
    50          this.description = description;
    51      }
    52
    53      /***
    54       * Create a new instance of SimpleType.
    55       *
    56       * @param name the name of the type.
    57       * @param description a description suitable for the UI.
    58       * @param defaultValue the default value for this type. This also set what
    59       *            kind of Java type that this Type can hold.
    60       * @param legalValues an array of legal values for this simple type. The
    61       *            objects in this array must be of the same type as the default
    62       *            value.
    63       */
    64      public SimpleType(String name, String description, Object defaultValue,
    65              Object[] legalValues) {
    66          this(name, description, defaultValue);
    67          setLegalValues(legalValues);
    68      }
    69
    70      /* (non-Javadoc)
    71       * @see org.archive.crawler.settings.Type#getDescription()
    72       */
    73      public String getDescription() {
    74          return description;
    75      }
    76
    77      /* (non-Javadoc)
    78       * @see org.archive.crawler.settings.Type#getDefaultValue()
    79       */
    80      public Object getDefaultValue() {
    81          return getValue();
    82      }
    83
    84      /***
    85       * Get the array of legal values for this Type.
    86       */
    87      public Object[] getLegalValues() {
    88          return legalValues;
    89      }
    90
    91      /***
    92       * Set the array of legal values for this type.
    93       * <p>
    94       *
    95       * The objects in this array must be of the same type as the default value.
    96       *
    97       * @param legalValues
    98       */
    99      public void setLegalValues(Object[] legalValues) {
    100         this.legalValues = legalValues;
    101         if (legalValues != null) {
    102             addConstraint(new LegalValueListConstraint());
    103         }
    104     }
    105 }