001: /*
002: * Copyright 1999-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: /*
017: * $Id: XRTreeFragSelectWrapper.java,v 1.13 2004/08/17 19:25:39 jycli Exp $
018: */
019: package org.apache.xpath.objects;
020:
021: import org.apache.xalan.res.XSLMessages;
022: import org.apache.xml.dtm.DTMIterator;
023: import org.apache.xml.utils.XMLString;
024: import org.apache.xpath.Expression;
025: import org.apache.xpath.XPathContext;
026: import org.apache.xpath.res.XPATHErrorResources;
027:
028: /**
029: * This class makes an select statement act like an result tree fragment.
030: */
031: public class XRTreeFragSelectWrapper extends XRTreeFrag implements
032: Cloneable {
033: static final long serialVersionUID = -6526177905590461251L;
034:
035: public XRTreeFragSelectWrapper(Expression expr) {
036: super (expr);
037: }
038:
039: /**
040: * This function is used to fixup variables from QNames to stack frame
041: * indexes at stylesheet build time.
042: * @param vars List of QNames that correspond to variables. This list
043: * should be searched backwards for the first qualified name that
044: * corresponds to the variable reference qname. The position of the
045: * QName in the vector from the start of the vector will be its position
046: * in the stack frame (but variables above the globalsTop value will need
047: * to be offset to the current stack frame).
048: */
049: public void fixupVariables(java.util.Vector vars, int globalsSize) {
050: ((Expression) m_obj).fixupVariables(vars, globalsSize);
051: }
052:
053: /**
054: * For support of literal objects in xpaths.
055: *
056: * @param xctxt The XPath execution context.
057: *
058: * @return the result of executing the select expression
059: *
060: * @throws javax.xml.transform.TransformerException
061: */
062: public XObject execute(XPathContext xctxt)
063: throws javax.xml.transform.TransformerException {
064: XObject m_selected;
065: m_selected = ((Expression) m_obj).execute(xctxt);
066: m_selected.allowDetachToRelease(m_allowRelease);
067: if (m_selected.getType() == CLASS_STRING)
068: return m_selected;
069: else
070: return new XString(m_selected.str());
071: }
072:
073: /**
074: * Detaches the <code>DTMIterator</code> from the set which it iterated
075: * over, releasing any computational resources and placing the iterator
076: * in the INVALID state. After <code>detach</code> has been invoked,
077: * calls to <code>nextNode</code> or <code>previousNode</code> will
078: * raise a runtime exception.
079: *
080: * In general, detach should only be called once on the object.
081: */
082: public void detach() {
083: throw new RuntimeException(
084: XSLMessages
085: .createXPATHMessage(
086: XPATHErrorResources.ER_DETACH_NOT_SUPPORTED_XRTREEFRAGSELECTWRAPPER,
087: null)); //"detach() not supported by XRTreeFragSelectWrapper!");
088: }
089:
090: /**
091: * Cast result object to a number.
092: *
093: * @return The result tree fragment as a number or NaN
094: */
095: public double num() throws javax.xml.transform.TransformerException {
096:
097: throw new RuntimeException(
098: XSLMessages
099: .createXPATHMessage(
100: XPATHErrorResources.ER_NUM_NOT_SUPPORTED_XRTREEFRAGSELECTWRAPPER,
101: null)); //"num() not supported by XRTreeFragSelectWrapper!");
102: }
103:
104: /**
105: * Cast result object to an XMLString.
106: *
107: * @return The document fragment node data or the empty string.
108: */
109: public XMLString xstr() {
110: throw new RuntimeException(
111: XSLMessages
112: .createXPATHMessage(
113: XPATHErrorResources.ER_XSTR_NOT_SUPPORTED_XRTREEFRAGSELECTWRAPPER,
114: null)); //"xstr() not supported by XRTreeFragSelectWrapper!");
115: }
116:
117: /**
118: * Cast result object to a string.
119: *
120: * @return The document fragment node data or the empty string.
121: */
122: public String str() {
123: throw new RuntimeException(
124: XSLMessages
125: .createXPATHMessage(
126: XPATHErrorResources.ER_STR_NOT_SUPPORTED_XRTREEFRAGSELECTWRAPPER,
127: null)); //"str() not supported by XRTreeFragSelectWrapper!");
128: }
129:
130: /**
131: * Tell what kind of class this is.
132: *
133: * @return the string type
134: */
135: public int getType() {
136: return CLASS_STRING;
137: }
138:
139: /**
140: * Cast result object to a result tree fragment.
141: *
142: * @return The document fragment this wraps
143: */
144: public int rtf() {
145: throw new RuntimeException(
146: XSLMessages
147: .createXPATHMessage(
148: XPATHErrorResources.ER_RTF_NOT_SUPPORTED_XRTREEFRAGSELECTWRAPPER,
149: null)); //"rtf() not supported by XRTreeFragSelectWrapper!");
150: }
151:
152: /**
153: * Cast result object to a DTMIterator.
154: *
155: * @return The document fragment as a DTMIterator
156: */
157: public DTMIterator asNodeIterator() {
158: throw new RuntimeException(
159: XSLMessages
160: .createXPATHMessage(
161: XPATHErrorResources.ER_RTF_NOT_SUPPORTED_XRTREEFRAGSELECTWRAPPER,
162: null)); //"asNodeIterator() not supported by XRTreeFragSelectWrapper!");
163: }
164:
165: }
|