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