Package org.htmlunit.xpath.objects
Class XObject
- java.lang.Object
-
- org.htmlunit.xpath.Expression
-
- org.htmlunit.xpath.objects.XObject
-
- All Implemented Interfaces:
javax.xml.transform.SourceLocator,ExpressionNode,XPathVisitable
- Direct Known Subclasses:
NodeSequence,XBoolean,XNumber,XString
public class XObject extends Expression
This class represents an XPath object, and is capable of converting the object to various types, such as a string. This class acts as the base class to other XPath type objects, such as XString, and provides polymorphic casting capabilities.
-
-
Field Summary
Fields Modifier and Type Field Description static intCLASS_BOOLEANConstant for BOOLEAN object typestatic intCLASS_NODESETConstant for NODESET object typestatic intCLASS_NULLConstant for NULL object typestatic intCLASS_NUMBERConstant for NUMBER object typestatic intCLASS_RTREEFRAGConstant for RESULT TREE FRAGMENT object typestatic intCLASS_STRINGConstant for STRING object typestatic intCLASS_UNKNOWNConstant for UNKNOWN object typeprotected java.lang.Objectm_objThe java object which this object wraps.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanbool()Cast result object to a boolean.booleanboolWithSideEffects()Cast result object to a boolean, but allow side effects, such as the incrementing of an iterator.voidcallVisitors(XPathVisitor visitor)This will traverse the hierarchy, calling the visitor for each member.booleandeepEquals(Expression expr)Compare this object with another object and see if they are equal, include the sub heararchy.voiddetach()Detaches theDTMIteratorfrom the set which it iterated over, releasing any computational resources and placing the iterator in the INVALID state.booleanequals(XObject obj2)Tell if two objects are functionally equal.protected voiderror(java.lang.String msg)Tell the user of an error, and probably throw an exception.protected voiderror(java.lang.String msg, java.lang.Object[] args)Tell the user of an error, and probably throw an exception.XObjectexecute(XPathContext xctxt)Execute an expression in the XPath runtime context, and return the result of the expression.intgetType()Tell what kind of class this is.java.lang.StringgetTypeString()Given a request type, return the equivalent string.booleangreaterThan(XObject obj2)Tell if one object is greater than the other.booleangreaterThanOrEqual(XObject obj2)Tell if one object is greater than or equal to the other.DTMIteratoriter()Cast result object to a nodelist.booleanlessThan(XObject obj2)Tell if one object is less than the other.booleanlessThanOrEqual(XObject obj2)Tell if one object is less than or equal to the other.NodeSetDTMmutableNodeset()Cast result object to a nodelist.org.w3c.dom.NodeListnodelist()Cast result object to a nodelist.org.w3c.dom.traversal.NodeIteratornodeset()Cast result object to a nodelist.booleannotEquals(XObject obj2)Tell if two objects are functionally not equal.doublenum()Cast result object to a number.doublenumWithSideEffects()Cast result object to a number, but allow side effects, such as the incrementing of an iterator.java.lang.Objectobject()Return a java object that's closest to the representation that should be handed to an extension.protected voidsetObject(java.lang.Object obj)java.lang.Stringstr()Cast result object to a string.java.lang.StringtoString()XStringxstr()Cast result object to a string.-
Methods inherited from class org.htmlunit.xpath.Expression
asIterator, asNode, assertion, bool, canTraverseOutsideSubtree, error, execute, execute, execute, exprGetParent, exprSetParent, getColumnNumber, getExpressionOwner, getLineNumber, getPublicId, getSystemId, isSameClass, isStableNumber, num
-
-
-
-
Field Detail
-
m_obj
protected java.lang.Object m_obj
The java object which this object wraps.
-
CLASS_NULL
public static final int CLASS_NULL
Constant for NULL object type- See Also:
- Constant Field Values
-
CLASS_UNKNOWN
public static final int CLASS_UNKNOWN
Constant for UNKNOWN object type- See Also:
- Constant Field Values
-
CLASS_BOOLEAN
public static final int CLASS_BOOLEAN
Constant for BOOLEAN object type- See Also:
- Constant Field Values
-
CLASS_NUMBER
public static final int CLASS_NUMBER
Constant for NUMBER object type- See Also:
- Constant Field Values
-
CLASS_STRING
public static final int CLASS_STRING
Constant for STRING object type- See Also:
- Constant Field Values
-
CLASS_NODESET
public static final int CLASS_NODESET
Constant for NODESET object type- See Also:
- Constant Field Values
-
CLASS_RTREEFRAG
public static final int CLASS_RTREEFRAG
Constant for RESULT TREE FRAGMENT object type- See Also:
- Constant Field Values
-
-
Method Detail
-
setObject
protected void setObject(java.lang.Object obj)
-
execute
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
Execute an expression in the XPath runtime context, and return the result of the expression.- Specified by:
executein classExpression- Parameters:
xctxt- The XPath runtime context.- Returns:
- The result of the expression in the form of a
XObject. - Throws:
javax.xml.transform.TransformerException- if a runtime exception occurs.
-
detach
public void detach()
Detaches theDTMIteratorfrom the set which it iterated over, releasing any computational resources and placing the iterator in the INVALID state. Afterdetachhas been invoked, calls tonextNodeorpreviousNodewill raise a runtime exception.
-
getType
public int getType()
Tell what kind of class this is.- Returns:
- CLASS_UNKNOWN
-
getTypeString
public java.lang.String getTypeString()
Given a request type, return the equivalent string. For diagnostic purposes.- Returns:
- type string "#UNKNOWN" + object class name
-
num
public double num() throws javax.xml.transform.TransformerExceptionCast result object to a number. Always issues an error.- Returns:
- 0.0
- Throws:
javax.xml.transform.TransformerException- in case of error
-
numWithSideEffects
public double numWithSideEffects() throws javax.xml.transform.TransformerExceptionCast result object to a number, but allow side effects, such as the incrementing of an iterator.- Returns:
- numeric value of the string conversion from the next node in the NodeSetDTM, or NAN if no node was found
- Throws:
javax.xml.transform.TransformerException
-
bool
public boolean bool() throws javax.xml.transform.TransformerExceptionCast result object to a boolean. Always issues an error.- Returns:
- false
- Throws:
javax.xml.transform.TransformerException- in case of error
-
boolWithSideEffects
public boolean boolWithSideEffects() throws javax.xml.transform.TransformerExceptionCast result object to a boolean, but allow side effects, such as the incrementing of an iterator.- Returns:
- True if there is a next node in the nodeset
- Throws:
javax.xml.transform.TransformerException
-
xstr
public XString xstr()
Cast result object to a string.- Returns:
- The string this wraps or the empty string if null
-
str
public java.lang.String str()
Cast result object to a string.- Returns:
- The object as a string
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
object
public java.lang.Object object()
Return a java object that's closest to the representation that should be handed to an extension.- Returns:
- The object that this class wraps
-
iter
public DTMIterator iter() throws javax.xml.transform.TransformerException
Cast result object to a nodelist. Always issues an error.- Returns:
- null
- Throws:
javax.xml.transform.TransformerException- in case of error
-
nodeset
public org.w3c.dom.traversal.NodeIterator nodeset() throws javax.xml.transform.TransformerExceptionCast result object to a nodelist. Always issues an error.- Returns:
- null
- Throws:
javax.xml.transform.TransformerException- in case of error
-
nodelist
public org.w3c.dom.NodeList nodelist() throws javax.xml.transform.TransformerExceptionCast result object to a nodelist. Always issues an error.- Returns:
- null
- Throws:
javax.xml.transform.TransformerException- in case of error
-
mutableNodeset
public NodeSetDTM mutableNodeset() throws javax.xml.transform.TransformerException
Cast result object to a nodelist. Always issues an error.- Returns:
- The object as a NodeSetDTM.
- Throws:
javax.xml.transform.TransformerException- in case of error
-
lessThan
public boolean lessThan(XObject obj2) throws javax.xml.transform.TransformerException
Tell if one object is less than the other.- Parameters:
obj2- Object to compare this to- Returns:
- True if this object is less than the given object
- Throws:
javax.xml.transform.TransformerException- in case of error
-
lessThanOrEqual
public boolean lessThanOrEqual(XObject obj2) throws javax.xml.transform.TransformerException
Tell if one object is less than or equal to the other.- Parameters:
obj2- Object to compare this to- Returns:
- True if this object is less than or equal to the given object
- Throws:
javax.xml.transform.TransformerException- in case of error
-
greaterThan
public boolean greaterThan(XObject obj2) throws javax.xml.transform.TransformerException
Tell if one object is greater than the other.- Parameters:
obj2- Object to compare this to- Returns:
- True if this object is greater than the given object
- Throws:
javax.xml.transform.TransformerException- in case of error
-
greaterThanOrEqual
public boolean greaterThanOrEqual(XObject obj2) throws javax.xml.transform.TransformerException
Tell if one object is greater than or equal to the other.- Parameters:
obj2- Object to compare this to- Returns:
- True if this object is greater than or equal to the given object
- Throws:
javax.xml.transform.TransformerException- in case of error
-
equals
public boolean equals(XObject obj2)
Tell if two objects are functionally equal.- Parameters:
obj2- Object to compare this to- Returns:
- True if this object is equal to the given object
-
notEquals
public boolean notEquals(XObject obj2) throws javax.xml.transform.TransformerException
Tell if two objects are functionally not equal.- Parameters:
obj2- Object to compare this to- Returns:
- True if this object is not equal to the given object
- Throws:
javax.xml.transform.TransformerException- in case of error
-
error
protected void error(java.lang.String msg) throws javax.xml.transform.TransformerExceptionTell the user of an error, and probably throw an exception.- Parameters:
msg- Error message to issue- Throws:
javax.xml.transform.TransformerException- in case of error
-
error
protected void error(java.lang.String msg, java.lang.Object[] args) throws javax.xml.transform.TransformerExceptionTell the user of an error, and probably throw an exception.- Parameters:
msg- Error message to issueargs- Arguments to use in the message- Throws:
javax.xml.transform.TransformerException- in case of error
-
callVisitors
public void callVisitors(XPathVisitor visitor)
This will traverse the hierarchy, calling the visitor for each member. If the called visitor method returns false, the subtree should not be called.- Parameters:
visitor- The visitor whose appropriate method will be called.
-
deepEquals
public boolean deepEquals(Expression expr)
Compare this object with another object and see if they are equal, include the sub heararchy.- Specified by:
deepEqualsin classExpression- Parameters:
expr- Another expression object.- Returns:
- true if this objects class and the expr object's class are the same, and the data contained within both objects are considered equal.
-
-