1 /*
2 (C) Copyright IBM Corp. 2006, 2009
3
4 THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
5 ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
6 CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
7
8 You can obtain a current copy of the Eclipse Public License from
9 http://www.opensource.org/licenses/eclipse-1.0.php
10
11 @author : Endre Bak, ebak@de.ibm.com
12 *
13 * Flag Date Prog Description
14 * -------------------------------------------------------------------------------
15 * 1565892 2006-11-05 ebak Make SBLIM client JSR48 compliant
16 * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL
17 * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1)
18 * 2823494 2009-08-03 rgummada Change Boolean constructor to static
19 */
20
21 package org.metricshub.wbem.sblim.cimclient.internal.uri;
22
23 /*-
24 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
25 * WBEM Java Client
26 * ჻჻჻჻჻჻
27 * Copyright 2023 - 2025 MetricsHub
28 * ჻჻჻჻჻჻
29 * Licensed under the Apache License, Version 2.0 (the "License");
30 * you may not use this file except in compliance with the License.
31 * You may obtain a copy of the License at
32 *
33 * http://www.apache.org/licenses/LICENSE-2.0
34 *
35 * Unless required by applicable law or agreed to in writing, software
36 * distributed under the License is distributed on an "AS IS" BASIS,
37 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38 * See the License for the specific language governing permissions and
39 * limitations under the License.
40 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
41 */
42
43 import org.metricshub.wbem.sblim.cimclient.internal.util.MOF;
44
45 /**
46 * Class BooleanValue parses and encapsulates a boolean value.
47 */
48 public class BooleanValue extends Value {
49 private boolean iValue;
50
51 /**
52 * parse
53 *
54 * @param pUriStr
55 * @param pThrow
56 * @return <code>Value</code> or <code>null</code> if <code>pThrow</code> is
57 * <code>false</code> and parsing failed
58 * @throws IllegalArgumentException
59 * if parsing failed and <code>pThrow</code> is
60 * <code>true</code>
61 */
62 public static Value parse(URIString pUriStr, boolean pThrow) throws IllegalArgumentException {
63 URIString uriStr = pUriStr.deepCopy();
64 boolean value;
65 if (uriStr.cutStarting("true", true)) value = true; else if (uriStr.cutStarting("false", true)) value =
66 false; else {
67 if (pThrow) {
68 String msg = "Boolean value not found!\n" + uriStr.markPosition();
69 throw new IllegalArgumentException(msg);
70 }
71 return null;
72 }
73 // next char must be ',' or nothing
74 if (uriStr.length() != 0 && uriStr.charAt(0) != ',') return null;
75 pUriStr.set(uriStr);
76 return new BooleanValue(value);
77 }
78
79 /**
80 * Parses an untyped boolean value.
81 *
82 * @param pUriStr
83 * @return Value
84 */
85 public static Value parse(URIString pUriStr) {
86 return parse(pUriStr, false);
87 }
88
89 private BooleanValue(boolean pValue) {
90 this.iValue = pValue;
91 }
92
93 /**
94 * getValue
95 *
96 * @return the <code>boolean</code> value.
97 */
98 public boolean getValue() {
99 return this.iValue;
100 }
101
102 /**
103 * getBoolean
104 *
105 * @return Boolean
106 */
107 public Boolean getBoolean() {
108 return Boolean.valueOf(this.iValue);
109 }
110
111 /**
112 * @see java.lang.Object#toString()
113 */
114 @Override
115 public String toString() {
116 return Boolean.toString(this.iValue);
117 }
118
119 /**
120 * @see Value#getTypeInfo()
121 */
122 @Override
123 public String getTypeInfo() {
124 return MOF.DT_BOOL;
125 }
126 }