KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xpath > objects > XRTreeFragSelectWrapper


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 org.apache.xpath.objects;
20
21 import org.apache.xalan.res.XSLMessages;
22 import org.apache.xml.dtm.DTMIterator;
23 import org.apache.xml.utils.XMLString;
24 import org.apache.xpath.Expression;
25 import org.apache.xpath.XPathContext;
26 import org.apache.xpath.res.XPATHErrorResources;
27
28 /**
29  * This class makes an select statement act like an result tree fragment.
30  */

31 public class XRTreeFragSelectWrapper extends XRTreeFrag implements Cloneable JavaDoc
32 {
33   XObject m_selected;
34
35   public XRTreeFragSelectWrapper(Expression expr)
36   {
37     super(expr);
38   }
39   
40   /**
41    * This function is used to fixup variables from QNames to stack frame
42    * indexes at stylesheet build time.
43    * @param vars List of QNames that correspond to variables. This list
44    * should be searched backwards for the first qualified name that
45    * corresponds to the variable reference qname. The position of the
46    * QName in the vector from the start of the vector will be its position
47    * in the stack frame (but variables above the globalsTop value will need
48    * to be offset to the current stack frame).
49    */

50   public void fixupVariables(java.util.Vector JavaDoc vars, int globalsSize)
51   {
52     ((Expression)m_obj).fixupVariables(vars, globalsSize);
53   }
54   
55   /**
56    * For support of literal objects in xpaths.
57    *
58    * @param xctxt The XPath execution context.
59    *
60    * @return the result of executing the select expression
61    *
62    * @throws javax.xml.transform.TransformerException
63    */

64   public XObject execute(XPathContext xctxt)
65           throws javax.xml.transform.TransformerException JavaDoc
66   {
67      m_selected = ((Expression)m_obj).execute(xctxt);
68      m_selected.allowDetachToRelease(m_allowRelease);
69      if (m_selected.getType() == CLASS_STRING)
70        return m_selected;
71      else
72        return new XString(m_selected.str());
73   }
74     
75   /**
76    * Detaches the <code>DTMIterator</code> from the set which it iterated
77    * over, releasing any computational resources and placing the iterator
78    * in the INVALID state. After <code>detach</code> has been invoked,
79    * calls to <code>nextNode</code> or <code>previousNode</code> will
80    * raise a runtime exception.
81    *
82    * In general, detach should only be called once on the object.
83    */

84   public void detach()
85   {
86     if(m_allowRelease)
87     {
88       m_selected.detach();
89       m_selected = null;
90     }
91     
92     super.detach();
93   }
94   
95   /**
96    * Cast result object to a number.
97    *
98    * @return The result tree fragment as a number or NaN
99    */

100   public double num()
101     throws javax.xml.transform.TransformerException JavaDoc
102   {
103
104     return m_selected.num();
105   }
106
107   
108   /**
109    * Cast result object to an XMLString.
110    *
111    * @return The document fragment node data or the empty string.
112    */

113   public XMLString xstr()
114   {
115     return m_selected.xstr();
116   }
117
118   /**
119    * Cast result object to a string.
120    *
121    * @return The document fragment node data or the empty string.
122    */

123   public String JavaDoc str()
124   {
125     return m_selected.str();
126   }
127   
128   /**
129    * Tell what kind of class this is.
130    *
131    * @return the string type
132    */

133   public int getType()
134   {
135     return CLASS_STRING;
136   }
137
138   /**
139    * Cast result object to a result tree fragment.
140    *
141    * @return The document fragment this wraps
142    */

143   public int rtf()
144   {
145     throw new RuntimeException JavaDoc(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_RTF_NOT_SUPPORTED_XRTREEFRAGSELECTWRAPPER, null)); //"rtf() not supported by XRTreeFragSelectWrapper!");
146
}
147
148   /**
149    * Cast result object to a DTMIterator.
150    *
151    * @return The document fragment as a DTMIterator
152    */

153   public DTMIterator asNodeIterator()
154   {
155     throw new RuntimeException JavaDoc(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_RTF_NOT_SUPPORTED_XRTREEFRAGSELECTWRAPPER, null)); //"asNodeIterator() not supported by XRTreeFragSelectWrapper!");
156
}
157
158 }
159
Popular Tags