1. package org.apache.xpath.objects;
  2. import org.apache.xml.dtm.DTM;
  3. import org.apache.xml.dtm.DTMIterator;
  4. import org.apache.xml.dtm.DTMFilter;
  5. import org.apache.xml.utils.XMLString;
  6. import org.apache.xpath.DOMHelper;
  7. import org.apache.xpath.XPathContext;
  8. import org.apache.xpath.Expression;
  9. import org.apache.xalan.res.XSLMessages;
  10. import org.apache.xpath.res.XPATHErrorResources;
  11. /**
  12. * This class makes an select statement act like an result tree fragment.
  13. */
  14. public class XRTreeFragSelectWrapper extends XRTreeFrag implements Cloneable
  15. {
  16. XObject m_selected;
  17. public XRTreeFragSelectWrapper(Expression expr)
  18. {
  19. super(expr);
  20. }
  21. /**
  22. * This function is used to fixup variables from QNames to stack frame
  23. * indexes at stylesheet build time.
  24. * @param vars List of QNames that correspond to variables. This list
  25. * should be searched backwards for the first qualified name that
  26. * corresponds to the variable reference qname. The position of the
  27. * QName in the vector from the start of the vector will be its position
  28. * in the stack frame (but variables above the globalsTop value will need
  29. * to be offset to the current stack frame).
  30. */
  31. public void fixupVariables(java.util.Vector vars, int globalsSize)
  32. {
  33. ((Expression)m_obj).fixupVariables(vars, globalsSize);
  34. }
  35. /**
  36. * For support of literal objects in xpaths.
  37. *
  38. * @param xctxt The XPath execution context.
  39. *
  40. * @return the result of executing the select expression
  41. *
  42. * @throws javax.xml.transform.TransformerException
  43. */
  44. public XObject execute(XPathContext xctxt)
  45. throws javax.xml.transform.TransformerException
  46. {
  47. m_selected = ((Expression)m_obj).execute(xctxt);
  48. m_selected.allowDetachToRelease(m_allowRelease);
  49. return m_selected;
  50. }
  51. /**
  52. * Detaches the <code>DTMIterator</code> from the set which it iterated
  53. * over, releasing any computational resources and placing the iterator
  54. * in the INVALID state. After <code>detach</code> has been invoked,
  55. * calls to <code>nextNode</code> or <code>previousNode</code> will
  56. * raise a runtime exception.
  57. *
  58. * In general, detach should only be called once on the object.
  59. */
  60. public void detach()
  61. {
  62. if(m_allowRelease)
  63. {
  64. m_selected.detach();
  65. m_selected = null;
  66. }
  67. super.detach();
  68. }
  69. /**
  70. * Cast result object to a number.
  71. *
  72. * @return The result tree fragment as a number or NaN
  73. */
  74. public double num()
  75. throws javax.xml.transform.TransformerException
  76. {
  77. return m_selected.num();
  78. }
  79. /**
  80. * Cast result object to an XMLString.
  81. *
  82. * @return The document fragment node data or the empty string.
  83. */
  84. public XMLString xstr()
  85. {
  86. return m_selected.xstr();
  87. }
  88. /**
  89. * Cast result object to a string.
  90. *
  91. * @return The document fragment node data or the empty string.
  92. */
  93. public String str()
  94. {
  95. return m_selected.str();
  96. }
  97. /**
  98. * Tell what kind of class this is.
  99. *
  100. * @return the type of the select expression
  101. */
  102. public int getType()
  103. {
  104. return m_selected.getType();
  105. }
  106. /**
  107. * Cast result object to a result tree fragment.
  108. *
  109. * @return The document fragment this wraps
  110. */
  111. public int rtf()
  112. {
  113. throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_RTF_NOT_SUPPORTED_XRTREEFRAGSELECTWRAPPER, null)); //"rtf() not supported by XRTreeFragSelectWrapper!");
  114. }
  115. /**
  116. * Cast result object to a DTMIterator.
  117. *
  118. * @return The document fragment as a DTMIterator
  119. */
  120. public DTMIterator asNodeIterator()
  121. {
  122. throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_RTF_NOT_SUPPORTED_XRTREEFRAGSELECTWRAPPER, null)); //"asNodeIterator() not supported by XRTreeFragSelectWrapper!");
  123. }
  124. }