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 1998-2002 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
27 */
28 package com.sun.dhcpmgr.data;
29
30 import java.util.Vector;
31 import java.util.Enumeration;
32
33 public class OctetOptionValue extends OptionValue {
34 private String name;
35 private String value;
36 private boolean valid;
37
38 // Serialization id for this class
39 static final long serialVersionUID = -3267221437949696358L;
40
41 protected OctetOptionValue(String name) {
42 this.name = name;
43 value = "";
44 valid = false;
45 }
46
47 public void setValue(Object value) throws ValidationException {
48 // Find option in option definition table in order to validate the data
49 Option option = OptionsTable.getTable().get(name);
50 if (option == null) {
51 Object [] args = { name };
52 throwException("invalid_option", args);
53 }
54 if (value instanceof String) {
55 if (((String)value).length() == 0) {
56 // Empty values are not acceptable
57 Object [] args = { name,
58 Option.getTypeDhcptabString(option.getType()) };
59 throwException("invalid_option_value", args);
60 }
61 // Just make a copy of the reference
62 this.value = (String)value;
63 valid = true;
64 } else if (value instanceof Vector) {
65 /*
66 * Generate the value by concatenating toString()'s on the
67 * vector's elements
68 */
69 StringBuffer b = new StringBuffer();
70 Enumeration en = ((Vector)value).elements();
71 while (en.hasMoreElements()) {
72 b.append(en.nextElement().toString());
73 }
74 setValue(b.toString());
75 } else {
76 // Convert anything else to a string
77 setValue(value.toString());
78 }
79 }
80
81 public String getName() {
82 return name;
83 }
84
85 public String getValue() {
86 return value;
87 }
88
89 public String toString() {
90 return (getName() + "=" + getValue());
91 }
92
93 public boolean isValid() {
94 return valid;
95 }
96
97 public Object clone() {
98 OctetOptionValue v = new OctetOptionValue(name);
99 v.value = value;
100 v.valid = valid;
101 return v;
102 }
103 }