FileDocCategorySizeDatePackage
XObject.javaAPI DocJava SE 6 API19315Tue Jun 10 00:23:16 BST 2008com.sun.org.apache.xpath.internal.objects

XObject

public class XObject extends Expression implements Serializable, Cloneable
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.
xsl.usage
general

Fields Summary
static final long
serialVersionUID
protected Object
m_obj
The java object which this object wraps.
public static final int
CLASS_NULL
Constant for NULL object type
public static final int
CLASS_UNKNOWN
Constant for UNKNOWN object type
public static final int
CLASS_BOOLEAN
Constant for BOOLEAN object type
public static final int
CLASS_NUMBER
Constant for NUMBER object type
public static final int
CLASS_STRING
Constant for STRING object type
public static final int
CLASS_NODESET
Constant for NODESET object type
public static final int
CLASS_RTREEFRAG
Constant for RESULT TREE FRAGMENT object type
public static final int
CLASS_UNRESOLVEDVARIABLE
Represents an unresolved variable type as an integer.
Constructors Summary
public XObject()
Create an XObject.

  // This may be NULL!!!

        
   
public XObject(Object obj)
Create an XObject.

param
obj Can be any object, should be a specific type for derived classes, or null.

    m_obj = obj;
  
Methods Summary
public voidallowDetachToRelease(boolean allowRelease)
Specify if it's OK for detach to release the iterator for reuse. This function should be called with a value of false for objects that are stored in variables. Calling this with a value of false on a XNodeSet will cause the nodeset to be cached.

param
allowRelease true if it is OK for detach to release this iterator for pooling.

public voidappendToFsb(com.sun.org.apache.xml.internal.utils.FastStringBuffer fsb)
Cast result object to a string. NEEDSDOC @param fsb

return
The string this wraps or the empty string if null

    fsb.append(str());
  
public booleanbool()
Cast result object to a boolean. Always issues an error.

return
false
throws
javax.xml.transform.TransformerException


    error(XPATHErrorResources.ER_CANT_CONVERT_TO_NUMBER,
          new Object[]{ getTypeString() });  //"Can not convert "+getTypeString()+" to a number");

    return false;
  
public booleanboolWithSideEffects()
Cast result object to a boolean, but allow side effects, such as the incrementing of an iterator.

return
True if there is a next node in the nodeset

    return bool();
  
public voidcallVisitors(com.sun.org.apache.xpath.internal.ExpressionOwner owner, com.sun.org.apache.xpath.internal.XPathVisitor visitor)

see
com.sun.org.apache.xpath.internal.XPathVisitable#callVisitors(ExpressionOwner, XPathVisitor)

  	assertion(false, "callVisitors should not be called for this object!!!");
  
public java.lang.ObjectcastToType(int t, com.sun.org.apache.xpath.internal.XPathContext support)
Cast object to type t.

param
t Type of object to cast this to
param
support XPath context to use for the conversion
return
This object as the given type t
throws
javax.xml.transform.TransformerException


    Object result;

    switch (t)
    {
    case CLASS_STRING :
      result = str();
      break;
    case CLASS_NUMBER :
      result = new Double(num());
      break;
    case CLASS_NODESET :
      result = iter();
      break;
    case CLASS_BOOLEAN :
      result = new Boolean(bool());
      break;
    case CLASS_UNKNOWN :
      result = m_obj;
      break;

    // %TBD%  What to do here?
    //    case CLASS_RTREEFRAG :
    //      result = rtree(support);
    //      break;
    default :
      error(XPATHErrorResources.ER_CANT_CONVERT_TO_TYPE,
            new Object[]{ getTypeString(),
                          Integer.toString(t) });  //"Can not convert "+getTypeString()+" to a type#"+t);

      result = null;
    }

    return result;
  
public static com.sun.org.apache.xpath.internal.objects.XObjectcreate(java.lang.Object val, com.sun.org.apache.xpath.internal.XPathContext xctxt)
Create the right XObject based on the type of the object passed. This function can make an XObject that exposes DOM Nodes, NodeLists, and NodeIterators to the XSLT stylesheet as node-sets.

param
val The java object which this object will wrap.
param
xctxt The XPath context.
return
the right XObject based on the type of the object passed.

    return XObjectFactory.create(val, xctxt);
  
public static com.sun.org.apache.xpath.internal.objects.XObjectcreate(java.lang.Object val)
Create the right XObject based on the type of the object passed. This function can not make an XObject that exposes DOM Nodes, NodeLists, and NodeIterators to the XSLT stylesheet as node-sets.

param
val The java object which this object will wrap.
return
the right XObject based on the type of the object passed.

    return XObjectFactory.create(val);
  
public booleandeepEquals(com.sun.org.apache.xpath.internal.Expression expr)

see
Expression#deepEquals(Expression)

  	if(!isSameClass(expr))
  		return false;
  		
  	// If equals at the expression level calls deepEquals, I think we're 
  	// still safe from infinite recursion since this object overrides 
  	// equals.  I hope.
  	if(!this.equals((XObject)expr))
  		return false;
  		
  	return true;
  
public voiddestruct()
Forces the object to release it's resources. This is more harsh than detach().


    if (null != m_obj)
    {
      allowDetachToRelease(true);
      detach();

      m_obj = null;
    }
  
public voiddetach()
Detaches the DTMIterator from the set which it iterated over, releasing any computational resources and placing the iterator in the INVALID state. After detach has been invoked, calls to nextNode or previousNode will raise a runtime exception.

public voiddispatchCharactersEvents(org.xml.sax.ContentHandler ch)
Directly call the characters method on the passed ContentHandler for the string-value. Multiple calls to the ContentHandler's characters methods may well occur for a single call to this method.

param
ch A non-null reference to a ContentHandler.
throws
org.xml.sax.SAXException

    xstr().dispatchCharactersEvents(ch);
  
public booleanequals(com.sun.org.apache.xpath.internal.objects.XObject obj2)
Tell if two objects are functionally equal.

param
obj2 Object to compare this to
return
True if this object is equal to the given object
throws
javax.xml.transform.TransformerException


    // In order to handle the 'all' semantics of 
    // nodeset comparisons, we always call the 
    // nodeset function.
    if (obj2.getType() == XObject.CLASS_NODESET)
      return obj2.equals(this);

    if (null != m_obj)
    {
      return m_obj.equals(obj2.m_obj);
    }
    else
    {
      return obj2.m_obj == null;
    }
  
protected voiderror(java.lang.String msg)
Tell the user of an error, and probably throw an exception.

param
msg Error message to issue
throws
javax.xml.transform.TransformerException

    error(msg, null);
  
protected voiderror(java.lang.String msg, java.lang.Object[] args)
Tell the user of an error, and probably throw an exception.

param
msg Error message to issue
param
args Arguments to use in the message
throws
javax.xml.transform.TransformerException


    String fmsg = XSLMessages.createXPATHMessage(msg, args);

    // boolean shouldThrow = support.problem(m_support.XPATHPROCESSOR, 
    //                                      m_support.ERROR,
    //                                      null, 
    //                                      null, fmsg, 0, 0);
    // if(shouldThrow)
    {
      throw new XPathException(fmsg, this);
    }
  
public com.sun.org.apache.xpath.internal.objects.XObjectexecute(com.sun.org.apache.xpath.internal.XPathContext xctxt)
For support of literal objects in xpaths.

param
xctxt The XPath execution context.
return
This object.
throws
javax.xml.transform.TransformerException

    return this;
  
public voidfixupVariables(java.util.Vector vars, int globalsSize)
XObjects should not normally need to fix up variables.

    // no-op
  
public com.sun.org.apache.xpath.internal.objects.XObjectgetFresh()
Get a fresh copy of the object. For use with variables.

return
This object, unless overridden by subclass.

    return this;
  
public intgetType()
Tell what kind of class this is.

return
CLASS_UNKNOWN


              
    
  
    return CLASS_UNKNOWN;
  
public java.lang.StringgetTypeString()
Given a request type, return the equivalent string. For diagnostic purposes.

return
type string "#UNKNOWN" + object class name

    return "#UNKNOWN (" + object().getClass().getName() + ")";
  
public booleangreaterThan(com.sun.org.apache.xpath.internal.objects.XObject obj2)
Tell if one object is greater than the other.

param
obj2 Object to compare this to
return
True if this object is greater than the given object
throws
javax.xml.transform.TransformerException


    // In order to handle the 'all' semantics of 
    // nodeset comparisons, we always call the 
    // nodeset function.  Because the arguments 
    // are backwards, we call the opposite comparison
    // function.
    if (obj2.getType() == XObject.CLASS_NODESET)
      return obj2.lessThan(this);

    return this.num() > obj2.num();
  
public booleangreaterThanOrEqual(com.sun.org.apache.xpath.internal.objects.XObject obj2)
Tell if one object is greater than or equal to the other.

param
obj2 Object to compare this to
return
True if this object is greater than or equal to the given object
throws
javax.xml.transform.TransformerException


    // In order to handle the 'all' semantics of 
    // nodeset comparisons, we always call the 
    // nodeset function.  Because the arguments 
    // are backwards, we call the opposite comparison
    // function.
    if (obj2.getType() == XObject.CLASS_NODESET)
      return obj2.lessThanOrEqual(this);

    return this.num() >= obj2.num();
  
public com.sun.org.apache.xml.internal.dtm.DTMIteratoriter()
Cast result object to a nodelist. Always issues an error.

return
null
throws
javax.xml.transform.TransformerException


    error(XPATHErrorResources.ER_CANT_CONVERT_TO_NODELIST,
          new Object[]{ getTypeString() });  //"Can not convert "+getTypeString()+" to a NodeList!");

    return null;
  
public booleanlessThan(com.sun.org.apache.xpath.internal.objects.XObject obj2)
Tell if one object is less than the other.

param
obj2 Object to compare this to
return
True if this object is less than the given object
throws
javax.xml.transform.TransformerException


    // In order to handle the 'all' semantics of 
    // nodeset comparisons, we always call the 
    // nodeset function.  Because the arguments 
    // are backwards, we call the opposite comparison
    // function.
    if (obj2.getType() == XObject.CLASS_NODESET)
      return obj2.greaterThan(this);

    return this.num() < obj2.num();
  
public booleanlessThanOrEqual(com.sun.org.apache.xpath.internal.objects.XObject obj2)
Tell if one object is less than or equal to the other.

param
obj2 Object to compare this to
return
True if this object is less than or equal to the given object
throws
javax.xml.transform.TransformerException


    // In order to handle the 'all' semantics of 
    // nodeset comparisons, we always call the 
    // nodeset function.  Because the arguments 
    // are backwards, we call the opposite comparison
    // function.
    if (obj2.getType() == XObject.CLASS_NODESET)
      return obj2.greaterThanOrEqual(this);

    return this.num() <= obj2.num();
  
public com.sun.org.apache.xpath.internal.NodeSetDTMmutableNodeset()
Cast result object to a nodelist. Always issues an error.

return
The object as a NodeSetDTM.
throws
javax.xml.transform.TransformerException


    error(XPATHErrorResources.ER_CANT_CONVERT_TO_MUTABLENODELIST,
          new Object[]{ getTypeString() });  //"Can not convert "+getTypeString()+" to a NodeSetDTM!");

    return (NodeSetDTM) m_obj;
  
public org.w3c.dom.NodeListnodelist()
Cast result object to a nodelist. Always issues an error.

return
null
throws
javax.xml.transform.TransformerException


    error(XPATHErrorResources.ER_CANT_CONVERT_TO_NODELIST,
          new Object[]{ getTypeString() });  //"Can not convert "+getTypeString()+" to a NodeList!");

    return null;
  
public org.w3c.dom.traversal.NodeIteratornodeset()
Cast result object to a nodelist. Always issues an error.

return
null
throws
javax.xml.transform.TransformerException


    error(XPATHErrorResources.ER_CANT_CONVERT_TO_NODELIST,
          new Object[]{ getTypeString() });  //"Can not convert "+getTypeString()+" to a NodeList!");

    return null;
  
public booleannotEquals(com.sun.org.apache.xpath.internal.objects.XObject obj2)
Tell if two objects are functionally not equal.

param
obj2 Object to compare this to
return
True if this object is not equal to the given object
throws
javax.xml.transform.TransformerException


    // In order to handle the 'all' semantics of 
    // nodeset comparisons, we always call the 
    // nodeset function.
    if (obj2.getType() == XObject.CLASS_NODESET)
      return obj2.notEquals(this);

    return !equals(obj2);
  
public doublenum()
Cast result object to a number. Always issues an error.

return
0.0
throws
javax.xml.transform.TransformerException


    error(XPATHErrorResources.ER_CANT_CONVERT_TO_NUMBER,
          new Object[]{ getTypeString() });  //"Can not convert "+getTypeString()+" to a number");

    return 0.0;
  
public doublenumWithSideEffects()
Cast result object to a number, but allow side effects, such as the incrementing of an iterator.

return
numeric value of the string conversion from the next node in the NodeSetDTM, or NAN if no node was found

    return num();
  
public java.lang.Objectobject()
Return a java object that's closest to the representation that should be handed to an extension.

return
The object that this class wraps

    return m_obj;
  
public voidreset()
Reset for fresh reuse.

  
public intrtf(com.sun.org.apache.xpath.internal.XPathContext support)
Cast result object to a result tree fragment.

param
support XPath context to use for the conversion
return
the objec as a result tree fragment.


    int result = rtf();

    if (DTM.NULL == result)
    {
      DTM frag = support.createDocumentFragment();

      // %OPT%
      frag.appendTextChild(str());

      result = frag.getDocument();
    }

    return result;
  
public intrtf()
For functions to override.

return
null

    return DTM.NULL;
  
public org.w3c.dom.DocumentFragmentrtree(com.sun.org.apache.xpath.internal.XPathContext support)
Cast result object to a result tree fragment.

param
support XPath context to use for the conversion
return
the objec as a result tree fragment.

    DocumentFragment docFrag = null;
    int result = rtf();

    if (DTM.NULL == result)
    {
      DTM frag = support.createDocumentFragment();

      // %OPT%
      frag.appendTextChild(str());

      docFrag = (DocumentFragment)frag.getNode(frag.getDocument());
    }
    else
    {
      DTM frag = support.getDTM(result);
      docFrag = (DocumentFragment)frag.getNode(frag.getDocument());
    }

    return docFrag;
  
public org.w3c.dom.DocumentFragmentrtree()
For functions to override.

return
null

    return null;
  
public java.lang.Stringstr()
Cast result object to a string.

return
The object as a string

    return (m_obj != null) ? m_obj.toString() : "";
  
public java.lang.StringtoString()
Return the string representation of the object

return
the string representation of the object

    return str();
  
public com.sun.org.apache.xml.internal.utils.XMLStringxstr()
Cast result object to a string.

return
The string this wraps or the empty string if null

    return XMLStringFactoryImpl.getFactory().newstr(str());