FileDocCategorySizeDatePackage
OpMap.javaAPI DocJava SE 6 API11838Tue Jun 10 00:23:14 BST 2008com.sun.org.apache.xpath.internal.compiler

OpMap

public class OpMap extends Object
This class represents the data structure basics of the XPath object.

Fields Summary
protected String
m_currentPattern
The current pattern string, for diagnostics purposes
static final int
MAXTOKENQUEUESIZE
The starting size of the token queue.
static final int
BLOCKTOKENQUEUESIZE
ObjectVector
m_tokenQueue
TokenStack is the queue of used tokens. The current token is the token at the end of the m_tokenQueue. The idea is that the queue can be marked and a sequence of tokens can be reused.
OpMapVector
m_opMap
An operations map is used instead of a proper parse tree. It contains operations codes and indexes into the m_tokenQueue. I use an array instead of a full parse tree in order to cut down on the number of objects created.
public static final int
MAPINDEX_LENGTH
The length is always the opcode position + 1. Length is always expressed as the opcode+length bytes, so it is always 2 or greater.
Constructors Summary
Methods Summary
public voiderror(java.lang.String msg, java.lang.Object[] args)
Tell the user of an error, and probably throw an exception.

param
msg An error msgkey that corresponds to one of the constants found in {@link com.sun.org.apache.xpath.internal.res.XPATHErrorResources}, which is a key for a format string.
param
args An array of arguments represented in the format string, which may be null.
throws
TransformerException if the current ErrorListoner determines to throw an exception.


    java.lang.String fmsg = com.sun.org.apache.xalan.internal.res.XSLMessages.createXPATHMessage(msg, args);
    

    throw new javax.xml.transform.TransformerException(fmsg);
  
public intgetArgLength(int opPos)
Get the length of an operation.

param
opPos The position of the operation in the op map.
return
The size of the operation.

    return m_opMap.elementAt(opPos + MAPINDEX_LENGTH);
  
public intgetArgLengthOfStep(int opPos)
Given a location step, get the length of that step.

param
opPos Position of location step in op map.
return
The length of the step.

    return m_opMap.elementAt(opPos + MAPINDEX_LENGTH + 1) - 3;
  
public static intgetFirstChildPos(int opPos)
Go to the first child of a given operation.

param
opPos position of operation.
return
The position of the first child of the operation.

    return opPos + 2;
  
public static intgetFirstChildPosOfStep(int opPos)
Get the first child position of a given location step.

param
opPos Position of location step in the location map.
return
The first child position of the step.

    return opPos + 3;
  
public intgetFirstPredicateOpPos(int opPos)
Given an FROM_stepType position, return the position of the first predicate, if there is one, or else this will point to the end of the FROM_stepType. Example: int posOfPredicate = xpath.getNextOpPos(stepPos); boolean hasPredicates = OpCodes.OP_PREDICATE == xpath.getOp(posOfPredicate);

param
opPos position of FROM_stepType op.
return
position of predicate in FROM_stepType structure.


    int stepType = m_opMap.elementAt(opPos);

    if ((stepType >= OpCodes.AXES_START_TYPES)
            && (stepType <= OpCodes.AXES_END_TYPES))
    {
      return opPos + m_opMap.elementAt(opPos + 2);
    }
    else if ((stepType >= OpCodes.FIRST_NODESET_OP)
             && (stepType <= OpCodes.LAST_NODESET_OP))
    {
      return opPos + m_opMap.elementAt(opPos + 1);
    }
    else if(-2 == stepType)
    {
      return -2;
    }
    else
    {
      error(com.sun.org.apache.xpath.internal.res.XPATHErrorResources.ER_UNKNOWN_OPCODE,
            new Object[]{ String.valueOf(stepType) });  //"ERROR! Unknown op code: "+m_opMap[opPos]);
      return -1;
    }
  
public intgetNextOpPos(int opPos)
Given an operation position, return the end position, i.e. the beginning of the next operation.

param
opPos An op position of an operation for which there is a size entry following.
return
position of next operation in m_opMap.

    return opPos + m_opMap.elementAt(opPos + 1);
  
public static intgetNextOpPos(int[] opMap, int opPos)
Given an operation position, return the end position, i.e. the beginning of the next operation.

param
opMap The operations map.
param
opPos index to operation, for which there is a size entry following.
return
position of next operation in m_opMap.

    return opPos + opMap[opPos + 1];
  
public intgetNextStepPos(int opPos)
Given a location step position, return the end position, i.e. the beginning of the next step.

param
opPos the position of a location step.
return
the position of the next location step.


    int stepType = getOp(opPos);

    if ((stepType >= OpCodes.AXES_START_TYPES)
            && (stepType <= OpCodes.AXES_END_TYPES))
    {
      return getNextOpPos(opPos);
    }
    else if ((stepType >= OpCodes.FIRST_NODESET_OP)
             && (stepType <= OpCodes.LAST_NODESET_OP))
    {
      int newOpPos = getNextOpPos(opPos);

      while (OpCodes.OP_PREDICATE == getOp(newOpPos))
      {
        newOpPos = getNextOpPos(newOpPos);
      }

      stepType = getOp(newOpPos);

      if (!((stepType >= OpCodes.AXES_START_TYPES)
            && (stepType <= OpCodes.AXES_END_TYPES)))
      {
        return OpCodes.ENDOP;
      }

      return newOpPos;
    }
    else
    {
      throw new RuntimeException(
        XSLMessages.createXPATHMessage(XPATHErrorResources.ER_UNKNOWN_STEP, new Object[]{new Integer(stepType).toString()})); 
      //"Programmer's assertion in getNextStepPos: unknown stepType: " + stepType);
    }
  
public intgetOp(int opPos)
Given an operation position, return the current op.

param
opPos index into op map.
return
the op that corresponds to the opPos argument.

    return m_opMap.elementAt(opPos);
  
public com.sun.org.apache.xpath.internal.compiler.OpMapVectorgetOpMap()
Get the opcode list that describes the XPath operations. It contains operations codes and indexes into the m_tokenQueue. I use an array instead of a full parse tree in order to cut down on the number of objects created.

return
An IntVector that is the opcode list that describes the XPath operations.


                                                          
    
  
    return m_opMap;
  
public java.lang.StringgetPatternString()
Return the expression as a string for diagnostics.

return
The expression string.

    return m_currentPattern;
  
public java.lang.StringgetStepLocalName(int opPosOfStep)
Get the local name of the step.

param
opPosOfStep The position of the FROM_XXX step.
return
OpCodes.EMPTY, OpCodes.ELEMWILDCARD, or the local name.


    int argLenOfStep = getArgLengthOfStep(opPosOfStep);

    // System.out.println("getStepLocalName.argLenOfStep: "+argLenOfStep);
    int index;

    switch (argLenOfStep)
    {
    case 0 :
      index = OpCodes.EMPTY;
      break;
    case 1 :
      index = OpCodes.ELEMWILDCARD;
      break;
    case 2 :
      index = m_opMap.elementAt(opPosOfStep + 4);
      break;
    case 3 :
      index = m_opMap.elementAt(opPosOfStep + 5);
      break;
    default :
      index = OpCodes.EMPTY;
      break;  // Should assert error
    }

    // int index = (argLenOfStep == 3) ? m_opMap[opPosOfStep+5] 
    //                                  : ((argLenOfStep == 1) ? -3 : -2);
    if (index >= 0)
      return (String) m_tokenQueue.elementAt(index).toString();
    else if (OpCodes.ELEMWILDCARD == index)
      return NodeTest.WILD;
    else
      return null;
  
public java.lang.StringgetStepNS(int opPosOfStep)
Get the namespace of the step.

param
opPosOfStep The position of the FROM_XXX step.
return
The step's namespace, NodeTest.WILD, or null for null namespace.


    int argLenOfStep = getArgLengthOfStep(opPosOfStep);

    // System.out.println("getStepNS.argLenOfStep: "+argLenOfStep);
    if (argLenOfStep == 3)
    {
      int index = m_opMap.elementAt(opPosOfStep + 4);

      if (index >= 0)
        return (String) m_tokenQueue.elementAt(index);
      else if (OpCodes.ELEMWILDCARD == index)
        return NodeTest.WILD;
      else
        return null;
    }
    else
      return null;
  
public intgetStepTestType(int opPosOfStep)
Get the test type of the step, i.e. NODETYPE_XXX value.

param
opPosOfStep The position of the FROM_XXX step.
return
NODETYPE_XXX value.

    return m_opMap.elementAt(opPosOfStep + 3);  // skip past op, len, len without predicates
  
public java.lang.ObjectgetToken(int pos)
Get the XPath as a list of tokens.

param
pos index into token queue.
return
The token, normally a string.

    return m_tokenQueue.elementAt(pos);
  
public com.sun.org.apache.xml.internal.utils.ObjectVectorgetTokenQueue()
Get the XPath as a list of tokens.

return
ObjectVector of tokens.


                 
    
  
    return m_tokenQueue;
  
public intgetTokenQueueSize()
Get size of the token queue.

return
The size of the token queue.

    return m_tokenQueue.size();
    
  
public voidsetOp(int opPos, int value)
Set the op at index to the given int.

param
opPos index into op map.
param
value Value to set

     m_opMap.setElementAt(value,opPos);
  
voidshrink()
Replace the large arrays with a small array.


             
   
  

    int n = m_opMap.elementAt(MAPINDEX_LENGTH);
    m_opMap.setToSize(n + 4);

    m_opMap.setElementAt(0,n);
    m_opMap.setElementAt(0,n+1);
    m_opMap.setElementAt(0,n+2);


    n = m_tokenQueue.size();
    m_tokenQueue.setToSize(n + 4);

    m_tokenQueue.setElementAt(null,n);
    m_tokenQueue.setElementAt(null,n + 1);
    m_tokenQueue.setElementAt(null,n + 2);
  
public java.lang.StringtoString()
Return the expression as a string for diagnostics.

return
The expression string.

    return m_currentPattern;