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