net.sf.joost.stx
Class Value

java.lang.Object
  extended by net.sf.joost.stx.Value
All Implemented Interfaces:
Cloneable

public class Value
extends Object
implements Cloneable

Container class for concrete values (of XPath types)

Version:
$Revision: 1.26 $ $Date: 2009/08/21 14:58:42 $
Author:
Oliver Becker

Field Summary
private  boolean bool
          for type == BOOLEAN
static int BOOLEAN
          type constant
static int EMPTY
          type constant
private  SAXEvent event
          for type == NODE
 Value next
          The next value of the sequence.
static int NODE
          type constant
private  double number
          for type == NUMBER
static int NUMBER
          type constant
private static NumberFormat numberFormat
           
private  Object object
          for type == OBJECT
static int OBJECT
          type constant
private  String string
          for type == STRING
static int STRING
          type constant
 int type
          type of this value
static Value VAL_EMPTY
           
static Value VAL_EMPTY_STRING
           
static Value VAL_FALSE
           
static Value VAL_NAN
           
static Value VAL_TRUE
           
static Value VAL_ZERO
           
 
Constructor Summary
private Value()
          Constructs an empty sequence
private Value(boolean b)
          Constructs a Value containing a boolean
  Value(CharSequence s)
          Constructs a Value containing a string
  Value(double d)
          Constructs a Value containing a number
  Value(Object obj)
          Constructs a Value containing a custom Java object, possibly converting the object to a known STX type
  Value(SAXEvent e)
          Constructs a Value containing a node (SAXEvent).
 
Method Summary
static Value concat(Value v1, Value v2)
          Creates a sequence by concatenating two values (which are possibly already sequences
 Value copy()
          Creates a full copy of the sequence represented by this value.
static Value getBoolean(boolean b)
          Returns a Value object representing the given boolean value
 boolean getBooleanValue()
          returns the value of this object converted to a boolean
 double getDistanceTo(Class target)
          Determines the conversion distance of the contained value to the specified target Java class.
 SAXEvent getNode()
           
 double getNumberValue()
          returns the value of this object converted to a number
 Object getObject()
           
 String getString()
           
 String getStringValue()
          returns the value of this object converted to a string
 Value singleCopy()
          Returns a single value that is a copy of this value
 Object toJavaObject(Class target)
          Converts this value to a Java object.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

numberFormat

private static NumberFormat numberFormat

VAL_TRUE

public static final Value VAL_TRUE

VAL_FALSE

public static final Value VAL_FALSE

VAL_EMPTY

public static final Value VAL_EMPTY

VAL_EMPTY_STRING

public static final Value VAL_EMPTY_STRING

VAL_ZERO

public static final Value VAL_ZERO

VAL_NAN

public static final Value VAL_NAN

EMPTY

public static final int EMPTY
type constant

See Also:
Constant Field Values

NODE

public static final int NODE
type constant

See Also:
Constant Field Values

BOOLEAN

public static final int BOOLEAN
type constant

See Also:
Constant Field Values

NUMBER

public static final int NUMBER
type constant

See Also:
Constant Field Values

STRING

public static final int STRING
type constant

See Also:
Constant Field Values

OBJECT

public static final int OBJECT
type constant

See Also:
Constant Field Values

type

public int type
type of this value


event

private SAXEvent event
for type == NODE


bool

private boolean bool
for type == BOOLEAN


number

private double number
for type == NUMBER


string

private String string
for type == STRING


object

private Object object
for type == OBJECT


next

public Value next
The next value of the sequence. A sequence is simply a chained list of Value objects. The empty sequence is represented by a type set to NODE and event set to null (next must be null in this case, too).

Constructor Detail

Value

private Value()
Constructs an empty sequence


Value

public Value(double d)
Constructs a Value containing a number


Value

private Value(boolean b)
Constructs a Value containing a boolean


Value

public Value(CharSequence s)
Constructs a Value containing a string


Value

public Value(SAXEvent e)
Constructs a Value containing a node (SAXEvent).

Parameters:
e - the event

Value

public Value(Object obj)
Constructs a Value containing a custom Java object, possibly converting the object to a known STX type

Method Detail

getBoolean

public static Value getBoolean(boolean b)
Returns a Value object representing the given boolean value


getString

public String getString()

getNode

public SAXEvent getNode()

getObject

public Object getObject()

getNumberValue

public double getNumberValue()
returns the value of this object converted to a number


getStringValue

public String getStringValue()
returns the value of this object converted to a string


getBooleanValue

public boolean getBooleanValue()
returns the value of this object converted to a boolean


copy

public Value copy()
Creates a full copy of the sequence represented by this value.


singleCopy

public Value singleCopy()
Returns a single value that is a copy of this value


concat

public static Value concat(Value v1,
                           Value v2)
Creates a sequence by concatenating two values (which are possibly already sequences

Parameters:
v1 - first value (first part of the resulting sequence)
v2 - second value (second part of the resulting sequence)
Returns:
a sequence that consists of v1 and v2

getDistanceTo

public double getDistanceTo(Class target)
Determines the conversion distance of the contained value to the specified target Java class. Lower results indicate higher preferences.

Parameters:
target - the class to which a conversion is desired
Returns:
an individual distance value, or Double.POSITIVE_INFINITY if a conversion is not possible

toJavaObject

public Object toJavaObject(Class target)
                    throws EvalException
Converts this value to a Java object.

Returns:
a Java object representing the current value
Throws:
EvalException - if the conversion is not possible

toString

public String toString()
Overrides:
toString in class Object