1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License, Version 1.0 only
   6  * (the "License").  You may not use this file except in compliance
   7  * with the License.
   8  *
   9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10  * or http://www.opensolaris.org/os/licensing.
  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 /*
  23  * ident        "%Z%%M% %I%     %E% SMI"
  24  *
  25  * Copyright 1999-2002 Sun Microsystems, Inc.  All rights reserved.
  26  * Use is subject to license terms.
  27  */
  28 
  29 package com.sun.dhcpmgr.data;
  30 
  31 import java.util.Vector;
  32 import java.util.Enumeration;
  33 
  34 /**
  35  * This class provides a way for us to handle errors in the dhcptab which
  36  * may have been introduced through the command line or direct editing of
  37  * the table.  The idea is for the OptionValueFactory to trap bad option
  38  * names or values and store them in an instance of this class so that the
  39  * user can then be told about the error and allowed to fix it.
  40  */
  41 public class BogusOptionValue extends OptionValue {
  42     private String name;
  43     private String value;
  44 
  45     // Serialization id for this class
  46     static final long serialVersionUID = 8573418100554161901L;
  47 
  48     protected BogusOptionValue(String name) {
  49         this.name = name;
  50         value = null;
  51     }
  52     
  53     protected BogusOptionValue(String name, Object value) {
  54         this.name = name;
  55         setValue(value);
  56     }
  57 
  58     public String getName() {
  59         return name;
  60     }
  61     
  62     public String getValue() {
  63         return value;
  64     }
  65     
  66     public void setValue(Object value) {
  67         if (value instanceof Vector) {
  68             /*
  69              * We generate the value by creating a blank-separated list of
  70              * tokens; each token is the product of a toString() on the
  71              * vector's elements.
  72              */
  73             StringBuffer b = new StringBuffer();
  74             Enumeration en = ((Vector)value).elements();
  75             while (en.hasMoreElements()) {
  76                 if (b.length() != 0) {
  77                     b.append(' ');
  78                 }
  79                 b.append(en.nextElement().toString());
  80             }
  81             setValue(b.toString());
  82         } else if (value instanceof String) {
  83             this.value = (String)value;
  84         } else {
  85             // Anything else should just tell us what it looks like as a string.
  86             setValue(value.toString());
  87         }
  88     }
  89     
  90     public String toString() {
  91         return (getName() + "=\"" + getValue() + "\"");
  92     }
  93     
  94     public boolean isValid() {
  95         // This kind of option is never valid
  96         return false;
  97     }
  98     
  99     public Object clone() {
 100         return new BogusOptionValue(name, value);
 101     }
 102 }