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 2002 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
27 */
28
29 package com.sun.dhcpmgr.data.qualifier;
30
31 /**
32 * An implementation of the qualifier type that provide a boolean type.
33 * The symbolic values for true and false can be set in two ways during
34 * object construction. Either no arguments are given the constructor and the
35 * Java Boolean.TRUE and Boolean.FALSE are used. Alternatively a pair of
36 * Strings can be passed to the constructor, the first representing true
37 * and the second false.
38 */
39 public class QualifierBoolean extends QualifierStringEnum {
40
41 /**
42 * True value.
43 */
44 protected String trueValue;
45
46 /**
47 * False value.
48 */
49 protected String falseValue;
50
51 /**
52 * Contruct a boolean qualifier type using the Java string representations
53 * of true and false.
54 */
55 public QualifierBoolean() {
56 this(Boolean.TRUE.toString(), Boolean.FALSE.toString());
57 }
58
59 /**
60 * Contruct a boolean qualifier using the supplied string representations
61 * of true and false.
62 *
63 * @param trueValue
64 * True value.
65 * @param falseValue
66 * False value.
67 */
68 public QualifierBoolean(String trueValue, String falseValue) {
69 super(new String[] {trueValue, falseValue});
70
71 this.trueValue = trueValue;
72 this.falseValue = falseValue;
73 }
74
75 /**
76 * Get the string representing true.
77 *
78 * @return
79 * True value.
80 */
81 public String getTrue() {
82 return trueValue;
83 }
84
85 /**
86 * Get the string representing false.
87 *
88 * @return
89 * False value.
90 */
91 public String getFalse() {
92 return falseValue;
93 }
94
95 public Object parseValue(String value) {
96 if (value == null) {
97 return null;
98 }
99
100 value = value.trim();
101
102 if (value.equals(trueValue) || value.equals(falseValue)) {
103 return new Boolean(value);
104 } else {
105 return null;
106 }
107 }
108
109 public String formatValue(String value) {
110 if (value == null || parseValue(value) == null) {
111 return null;
112 }
113
114 return value.trim();
115 }
116
117 public Class getJavaType() {
118 return Boolean.class;
119 }
120
121 }