1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 /* 19 * $Id: XRTreeFragSelectWrapper.java 468655 2006-10-28 07:12:06Z minchau $ 20 */ 21 package org.apache.xpath.objects; 22 23 import org.apache.xalan.res.XSLMessages; 24 import org.apache.xml.dtm.DTMIterator; 25 import org.apache.xml.utils.XMLString; 26 import org.apache.xpath.Expression; 27 import org.apache.xpath.XPathContext; 28 import org.apache.xpath.res.XPATHErrorResources; 29 30 /** 31 * This class makes an select statement act like an result tree fragment. 32 */ 33 public class XRTreeFragSelectWrapper extends XRTreeFrag implements Cloneable 34 { 35 static final long serialVersionUID = -6526177905590461251L; XRTreeFragSelectWrapper(Expression expr)36 public XRTreeFragSelectWrapper(Expression expr) 37 { 38 super(expr); 39 } 40 41 /** 42 * This function is used to fixup variables from QNames to stack frame 43 * indexes at stylesheet build time. 44 * @param vars List of QNames that correspond to variables. This list 45 * should be searched backwards for the first qualified name that 46 * corresponds to the variable reference qname. The position of the 47 * QName in the vector from the start of the vector will be its position 48 * in the stack frame (but variables above the globalsTop value will need 49 * to be offset to the current stack frame). 50 */ fixupVariables(java.util.Vector vars, int globalsSize)51 public void fixupVariables(java.util.Vector vars, int globalsSize) 52 { 53 ((Expression)m_obj).fixupVariables(vars, globalsSize); 54 } 55 56 /** 57 * For support of literal objects in xpaths. 58 * 59 * @param xctxt The XPath execution context. 60 * 61 * @return the result of executing the select expression 62 * 63 * @throws javax.xml.transform.TransformerException 64 */ execute(XPathContext xctxt)65 public XObject execute(XPathContext xctxt) 66 throws javax.xml.transform.TransformerException 67 { 68 XObject m_selected; 69 m_selected = ((Expression)m_obj).execute(xctxt); 70 m_selected.allowDetachToRelease(m_allowRelease); 71 if (m_selected.getType() == CLASS_STRING) 72 return m_selected; 73 else 74 return new XString(m_selected.str()); 75 } 76 77 /** 78 * Detaches the <code>DTMIterator</code> from the set which it iterated 79 * over, releasing any computational resources and placing the iterator 80 * in the INVALID state. After <code>detach</code> has been invoked, 81 * calls to <code>nextNode</code> or <code>previousNode</code> will 82 * raise a runtime exception. 83 * 84 * In general, detach should only be called once on the object. 85 */ detach()86 public void detach() 87 { 88 throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_DETACH_NOT_SUPPORTED_XRTREEFRAGSELECTWRAPPER, null)); //"detach() not supported by XRTreeFragSelectWrapper!"); 89 } 90 91 /** 92 * Cast result object to a number. 93 * 94 * @return The result tree fragment as a number or NaN 95 */ num()96 public double num() 97 throws javax.xml.transform.TransformerException 98 { 99 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 */ xstr()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 */ str()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 */ getType()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 */ rtf()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 */ asNodeIterator()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 } 155