1 16 package com.sun.org.apache.xpath.internal.operations; 17 18 import javax.xml.transform.TransformerException ; 19 20 import com.sun.org.apache.xalan.internal.res.XSLMessages; 21 import com.sun.org.apache.xml.internal.utils.QName; 22 import com.sun.org.apache.xpath.internal.Expression; 23 import com.sun.org.apache.xpath.internal.ExpressionOwner; 24 import com.sun.org.apache.xpath.internal.XPath; 25 import com.sun.org.apache.xpath.internal.XPathContext; 26 import com.sun.org.apache.xpath.internal.XPathVisitor; 27 import com.sun.org.apache.xpath.internal.axes.PathComponent; 28 import com.sun.org.apache.xpath.internal.axes.WalkerFactory; 29 import com.sun.org.apache.xpath.internal.objects.XNodeSet; 30 import com.sun.org.apache.xpath.internal.objects.XObject; 31 import com.sun.org.apache.xpath.internal.res.XPATHErrorResources; 32 33 34 37 public class Variable extends Expression implements PathComponent 38 { 39 41 private boolean m_fixUpWasCalled = false; 42 43 45 protected QName m_qname; 46 47 52 protected int m_index; 53 54 60 public void setIndex(int index) 61 { 62 m_index = index; 63 } 64 65 70 public int getIndex() 71 { 72 return m_index; 73 } 74 75 80 public void setIsGlobal(boolean isGlobal) 81 { 82 m_isGlobal = isGlobal; 83 } 84 85 90 public boolean getGlobal() 91 { 92 return m_isGlobal; 93 } 94 95 96 97 98 99 protected boolean m_isGlobal = false; 100 101 111 public void fixupVariables(java.util.Vector vars, int globalsSize) 112 { 113 m_fixUpWasCalled = true; 114 int sz = vars.size(); 115 116 for (int i = vars.size()-1; i >= 0; i--) 117 { 118 QName qn = (QName)vars.elementAt(i); 119 if(qn.equals(m_qname)) 121 { 122 123 if(i < globalsSize) 124 { 125 m_isGlobal = true; 126 m_index = i; 127 } 128 else 129 { 130 m_index = i-globalsSize; 131 } 132 133 return; 134 } 135 } 136 137 java.lang.String msg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_COULD_NOT_FIND_VAR, 138 new Object []{m_qname.toString()}); 139 140 TransformerException te = new TransformerException (msg, this); 141 142 throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(te); 143 144 } 145 146 147 152 public void setQName(QName qname) 153 { 154 m_qname = qname; 155 } 156 157 162 public QName getQName() 163 { 164 return m_qname; 165 } 166 167 179 public XObject execute(XPathContext xctxt) 180 throws javax.xml.transform.TransformerException 181 { 182 return execute(xctxt, false); 183 } 184 185 186 198 public XObject execute(XPathContext xctxt, boolean destructiveOK) throws javax.xml.transform.TransformerException 199 { 200 com.sun.org.apache.xml.internal.utils.PrefixResolver xprefixResolver = xctxt.getNamespaceContext(); 201 202 XObject result; 203 204 if(m_fixUpWasCalled) 207 { 208 if(m_isGlobal) 209 result = xctxt.getVarStack().getGlobalVariable(xctxt, m_index, destructiveOK); 210 else 211 result = xctxt.getVarStack().getLocalVariable(xctxt, m_index, destructiveOK); 212 } else { 213 result = xctxt.getVarStack().getVariableOrParam(xctxt,m_qname); 214 } 215 216 if (null == result) 217 { 218 warn(xctxt, XPATHErrorResources.WG_ILLEGAL_VARIABLE_REFERENCE, 220 new Object []{ m_qname.getLocalPart() }); 225 result = new XNodeSet(xctxt.getDTMManager()); 226 } 227 228 return result; 229 } 248 249 254 308 309 317 public boolean isStableNumber() 318 { 319 return true; 320 } 321 322 326 public int getAnalysisBits() 327 { 328 334 return WalkerFactory.BIT_FILTER; 335 } 336 337 338 341 public void callVisitors(ExpressionOwner owner, XPathVisitor visitor) 342 { 343 visitor.visitVariableRef(owner, this); 344 } 345 346 349 public boolean deepEquals(Expression expr) 350 { 351 if(!isSameClass(expr)) 352 return false; 353 354 if(!m_qname.equals(((Variable)expr).m_qname)) 355 return false; 356 357 365 return true; 366 } 367 368 static final java.lang.String PSUEDOVARNAMESPACE = "http://xml.apache.org/xalan/psuedovar"; 369 370 374 public boolean isPsuedoVarRef() 375 { 376 java.lang.String ns = m_qname.getNamespaceURI(); 377 if((null != ns) && ns.equals(PSUEDOVARNAMESPACE)) 378 { 379 if(m_qname.getLocalName().startsWith("#")) 380 return true; 381 } 382 return false; 383 } 384 385 386 } 387 | Popular Tags |