1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /*
  17. * $Id: XRTreeFragSelectWrapper.java,v 1.11 2004/02/17 04:34:38 minchau Exp $
  18. */
  19. package com.sun.org.apache.xpath.internal.objects;
  20. import com.sun.org.apache.xalan.internal.res.XSLMessages;
  21. import com.sun.org.apache.xml.internal.dtm.DTMIterator;
  22. import com.sun.org.apache.xml.internal.utils.XMLString;
  23. import com.sun.org.apache.xpath.internal.Expression;
  24. import com.sun.org.apache.xpath.internal.XPathContext;
  25. import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
  26. /**
  27. * This class makes an select statement act like an result tree fragment.
  28. */
  29. public class XRTreeFragSelectWrapper extends XRTreeFrag implements Cloneable
  30. {
  31. XObject m_selected;
  32. public XRTreeFragSelectWrapper(Expression expr)
  33. {
  34. super(expr);
  35. }
  36. /**
  37. * This function is used to fixup variables from QNames to stack frame
  38. * indexes at stylesheet build time.
  39. * @param vars List of QNames that correspond to variables. This list
  40. * should be searched backwards for the first qualified name that
  41. * corresponds to the variable reference qname. The position of the
  42. * QName in the vector from the start of the vector will be its position
  43. * in the stack frame (but variables above the globalsTop value will need
  44. * to be offset to the current stack frame).
  45. */
  46. public void fixupVariables(java.util.Vector vars, int globalsSize)
  47. {
  48. ((Expression)m_obj).fixupVariables(vars, globalsSize);
  49. }
  50. /**
  51. * For support of literal objects in xpaths.
  52. *
  53. * @param xctxt The XPath execution context.
  54. *
  55. * @return the result of executing the select expression
  56. *
  57. * @throws javax.xml.transform.TransformerException
  58. */
  59. public XObject execute(XPathContext xctxt)
  60. throws javax.xml.transform.TransformerException
  61. {
  62. m_selected = ((Expression)m_obj).execute(xctxt);
  63. m_selected.allowDetachToRelease(m_allowRelease);
  64. if (m_selected.getType() == CLASS_STRING)
  65. return m_selected;
  66. else
  67. return new XString(m_selected.str());
  68. }
  69. /**
  70. * Detaches the <code>DTMIterator</code> from the set which it iterated
  71. * over, releasing any computational resources and placing the iterator
  72. * in the INVALID state. After <code>detach</code> has been invoked,
  73. * calls to <code>nextNode</code> or <code>previousNode</code> will
  74. * raise a runtime exception.
  75. *
  76. * In general, detach should only be called once on the object.
  77. */
  78. public void detach()
  79. {
  80. if(m_allowRelease)
  81. {
  82. m_selected.detach();
  83. m_selected = null;
  84. }
  85. super.detach();
  86. }
  87. /**
  88. * Cast result object to a number.
  89. *
  90. * @return The result tree fragment as a number or NaN
  91. */
  92. public double num()
  93. throws javax.xml.transform.TransformerException
  94. {
  95. return m_selected.num();
  96. }
  97. /**
  98. * Cast result object to an XMLString.
  99. *
  100. * @return The document fragment node data or the empty string.
  101. */
  102. public XMLString xstr()
  103. {
  104. return m_selected.xstr();
  105. }
  106. /**
  107. * Cast result object to a string.
  108. *
  109. * @return The document fragment node data or the empty string.
  110. */
  111. public String str()
  112. {
  113. return m_selected.str();
  114. }
  115. /**
  116. * Tell what kind of class this is.
  117. *
  118. * @return the string type
  119. */
  120. public int getType()
  121. {
  122. return CLASS_STRING;
  123. }
  124. /**
  125. * Cast result object to a result tree fragment.
  126. *
  127. * @return The document fragment this wraps
  128. */
  129. public int rtf()
  130. {
  131. throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_RTF_NOT_SUPPORTED_XRTREEFRAGSELECTWRAPPER, null)); //"rtf() not supported by XRTreeFragSelectWrapper!");
  132. }
  133. /**
  134. * Cast result object to a DTMIterator.
  135. *
  136. * @return The document fragment as a DTMIterator
  137. */
  138. public DTMIterator asNodeIterator()
  139. {
  140. throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_RTF_NOT_SUPPORTED_XRTREEFRAGSELECTWRAPPER, null)); //"asNodeIterator() not supported by XRTreeFragSelectWrapper!");
  141. }
  142. }