2
* Licensed to the Apache Software Foundation (ASF) under one
3
* or more contributor license agreements. See the NOTICE file
4
* distributed with this work for additional information
5
* regarding copyright ownership. The ASF licenses this file
6
* to you under the Apache License, Version 2.0 (the "License");
7
* you may not use this file except in compliance with the License.
8
* You may obtain a copy of the License at
10
* http://www.apache.org/licenses/LICENSE-2.0
12
* Unless required by applicable law or agreed to in writing, software
13
* distributed under the License is distributed on an "AS IS" BASIS,
14
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
* See the License for the specific language governing permissions and
16
* limitations under the License.
19
* $Id: XBoolean.java,v 1.2 2009/12/10 03:18:30 matthewoliver Exp $
21
package org.apache.xpath.objects;
24
* This class represents an XPath boolean object, and is capable of
25
* converting the boolean to other types, such as a string.
28
public class XBoolean extends XObject
30
static final long serialVersionUID = -2964933058866100881L;
33
* A true boolean object so we don't have to keep creating them.
36
public static final XBoolean S_TRUE = new XBooleanStatic(true);
39
* A true boolean object so we don't have to keep creating them.
42
public static final XBoolean S_FALSE = new XBooleanStatic(false);
44
/** Value of the object.
46
private final boolean m_val;
49
* Construct a XBoolean object.
51
* @param b Value of the boolean object
53
public XBoolean(boolean b)
62
* Construct a XBoolean object.
64
* @param b Value of the boolean object
66
public XBoolean(Boolean b)
71
m_val = b.booleanValue();
77
* Tell that this is a CLASS_BOOLEAN.
79
* @return type of CLASS_BOOLEAN
87
* Given a request type, return the equivalent string.
88
* For diagnostic purposes.
90
* @return type string "#BOOLEAN"
92
public String getTypeString()
98
* Cast result object to a number.
100
* @return numeric value of the object value
104
return m_val ? 1.0 : 0.0;
108
* Cast result object to a boolean.
110
* @return The object value as a boolean
112
public boolean bool()
118
* Cast result object to a string.
120
* @return The object's value as a string
124
return m_val ? "true" : "false";
128
* Return a java object that's closest to the representation
129
* that should be handed to an extension.
131
* @return The object's value as a java object
133
public Object object()
136
setObject(new Boolean(m_val));
141
* Tell if two objects are functionally equal.
143
* @param obj2 Object to compare to this
145
* @return True if the two objects are equal
147
* @throws javax.xml.transform.TransformerException
149
public boolean equals(XObject obj2)
152
// In order to handle the 'all' semantics of
153
// nodeset comparisons, we always call the
155
if (obj2.getType() == XObject.CLASS_NODESET)
156
return obj2.equals(this);
160
return m_val == obj2.bool();
162
catch(javax.xml.transform.TransformerException te)
164
throw new org.apache.xml.utils.WrappedRuntimeException(te);