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