1 16 19 package org.apache.xpath.compiler; 20 21 import org.apache.xalan.res.XSLMessages; 22 import org.apache.xml.utils.ObjectVector; 23 import org.apache.xpath.patterns.NodeTest; 24 import org.apache.xpath.res.XPATHErrorResources; 25 26 30 public class OpMap 31 { 32 33 36 protected String m_currentPattern; 37 38 43 public String toString() 44 { 45 return m_currentPattern; 46 } 47 48 53 public String getPatternString() 54 { 55 return m_currentPattern; 56 } 57 58 61 static final int MAXTOKENQUEUESIZE = 500; 62 63 66 static final int BLOCKTOKENQUEUESIZE = 500; 67 68 73 ObjectVector m_tokenQueue = new ObjectVector(MAXTOKENQUEUESIZE, BLOCKTOKENQUEUESIZE); 74 75 80 public ObjectVector getTokenQueue() 81 { 82 return m_tokenQueue; 83 } 84 85 92 public Object getToken(int pos) 93 { 94 return m_tokenQueue.elementAt(pos); 95 } 96 97 100 102 107 public int getTokenQueueSize() 108 { 109 return m_tokenQueue.size(); 110 111 } 112 113 119 OpMapVector m_opMap = null; 120 121 129 public OpMapVector getOpMap() 130 { 131 return m_opMap; 132 } 133 134 136 141 public static final int MAPINDEX_LENGTH = 1; 142 143 147 void shrink() 148 { 149 150 int n = m_opMap.elementAt(MAPINDEX_LENGTH); 151 m_opMap.setToSize(n + 4); 152 153 m_opMap.setElementAt(0,n); 154 m_opMap.setElementAt(0,n+1); 155 m_opMap.setElementAt(0,n+2); 156 157 158 n = m_tokenQueue.size(); 159 m_tokenQueue.setToSize(n + 4); 160 161 m_tokenQueue.setElementAt(null,n); 162 m_tokenQueue.setElementAt(null,n + 1); 163 m_tokenQueue.setElementAt(null,n + 2); 164 } 165 166 172 public int getOp(int opPos) 173 { 174 return m_opMap.elementAt(opPos); 175 } 176 177 183 public void setOp(int opPos, int value) 184 { 185 m_opMap.setElementAt(value,opPos); 186 } 187 188 196 public int getNextOpPos(int opPos) 197 { 198 return opPos + m_opMap.elementAt(opPos + 1); 199 } 200 201 208 public int getNextStepPos(int opPos) 209 { 210 211 int stepType = getOp(opPos); 212 213 if ((stepType >= OpCodes.AXES_START_TYPES) 214 && (stepType <= OpCodes.AXES_END_TYPES)) 215 { 216 return getNextOpPos(opPos); 217 } 218 else if ((stepType >= OpCodes.FIRST_NODESET_OP) 219 && (stepType <= OpCodes.LAST_NODESET_OP)) 220 { 221 int newOpPos = getNextOpPos(opPos); 222 223 while (OpCodes.OP_PREDICATE == getOp(newOpPos)) 224 { 225 newOpPos = getNextOpPos(newOpPos); 226 } 227 228 stepType = getOp(newOpPos); 229 230 if (!((stepType >= OpCodes.AXES_START_TYPES) 231 && (stepType <= OpCodes.AXES_END_TYPES))) 232 { 233 return OpCodes.ENDOP; 234 } 235 236 return newOpPos; 237 } 238 else 239 { 240 throw new RuntimeException ( 241 XSLMessages.createXPATHMessage(XPATHErrorResources.ER_UNKNOWN_STEP, new Object []{new Integer (stepType).toString()})); 242 } 244 } 245 246 254 public static int getNextOpPos(int[] opMap, int opPos) 255 { 256 return opPos + opMap[opPos + 1]; 257 } 258 259 271 public int getFirstPredicateOpPos(int opPos) 272 throws javax.xml.transform.TransformerException 273 { 274 275 int stepType = m_opMap.elementAt(opPos); 276 277 if ((stepType >= OpCodes.AXES_START_TYPES) 278 && (stepType <= OpCodes.AXES_END_TYPES)) 279 { 280 return opPos + m_opMap.elementAt(opPos + 2); 281 } 282 else if ((stepType >= OpCodes.FIRST_NODESET_OP) 283 && (stepType <= OpCodes.LAST_NODESET_OP)) 284 { 285 return opPos + m_opMap.elementAt(opPos + 1); 286 } 287 else if(-2 == stepType) 288 { 289 return -2; 290 } 291 else 292 { 293 error(org.apache.xpath.res.XPATHErrorResources.ER_UNKNOWN_OPCODE, 294 new Object []{ String.valueOf(stepType) }); return -1; 296 } 297 } 298 299 312 public void error(String msg, Object [] args) throws javax.xml.transform.TransformerException 313 { 314 315 java.lang.String fmsg = org.apache.xalan.res.XSLMessages.createXPATHMessage(msg, args); 316 317 318 throw new javax.xml.transform.TransformerException (fmsg); 319 } 320 321 322 329 public static int getFirstChildPos(int opPos) 330 { 331 return opPos + 2; 332 } 333 334 341 public int getArgLength(int opPos) 342 { 343 return m_opMap.elementAt(opPos + MAPINDEX_LENGTH); 344 } 345 346 353 public int getArgLengthOfStep(int opPos) 354 { 355 return m_opMap.elementAt(opPos + MAPINDEX_LENGTH + 1) - 3; 356 } 357 358 365 public static int getFirstChildPosOfStep(int opPos) 366 { 367 return opPos + 3; 368 } 369 370 377 public int getStepTestType(int opPosOfStep) 378 { 379 return m_opMap.elementAt(opPosOfStep + 3); } 381 382 389 public String getStepNS(int opPosOfStep) 390 { 391 392 int argLenOfStep = getArgLengthOfStep(opPosOfStep); 393 394 if (argLenOfStep == 3) 396 { 397 int index = m_opMap.elementAt(opPosOfStep + 4); 398 399 if (index >= 0) 400 return (String ) m_tokenQueue.elementAt(index); 401 else if (OpCodes.ELEMWILDCARD == index) 402 return NodeTest.WILD; 403 else 404 return null; 405 } 406 else 407 return null; 408 } 409 410 416 public String getStepLocalName(int opPosOfStep) 417 { 418 419 int argLenOfStep = getArgLengthOfStep(opPosOfStep); 420 421 int index; 423 424 switch (argLenOfStep) 425 { 426 case 0 : 427 index = OpCodes.EMPTY; 428 break; 429 case 1 : 430 index = OpCodes.ELEMWILDCARD; 431 break; 432 case 2 : 433 index = m_opMap.elementAt(opPosOfStep + 4); 434 break; 435 case 3 : 436 index = m_opMap.elementAt(opPosOfStep + 5); 437 break; 438 default : 439 index = OpCodes.EMPTY; 440 break; } 442 443 if (index >= 0) 446 return (String ) m_tokenQueue.elementAt(index).toString(); 447 else if (OpCodes.ELEMWILDCARD == index) 448 return NodeTest.WILD; 449 else 450 return null; 451 } 452 453 } 454 | Popular Tags |