org.apache.xpath.res.XPATHErrorResources Java Examples

The following examples show how to use org.apache.xpath.res.XPATHErrorResources. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VariableStack.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Get a local variable or parameter in the current stack frame.
 *
 *
 * @param xctxt The XPath context, which must be passed in order to
 * lazy evaluate variables.
 *
 * @param index Local variable index relative to the current stack
 * frame bottom.
 *
 * @return The value of the variable.
 *
 * @throws TransformerException
 */
public XObject getLocalVariable(XPathContext xctxt, int index, boolean destructiveOK)
        throws TransformerException
{

  index += _currentFrameBottom;

  XObject val = _stackFrames[index];
  
  if(null == val)
    throw new TransformerException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_VARIABLE_ACCESSED_BEFORE_BIND, null),
                   xctxt.getSAXLocator());
    // "Variable accessed before it is bound!", xctxt.getSAXLocator());

  // Lazy execution of variables.
  if (val.getType() == XObject.CLASS_UNRESOLVEDVARIABLE)
    return (_stackFrames[index] = val.execute(xctxt));

  return destructiveOK ? val : val.getFresh();
}
 
Example #2
Source File: XPathParser.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 *
 * Basis    ::=    AxisName '::' NodeTest
 * | AbbreviatedBasis
 *
 * @return FROM_XXX axes type, found in {@link org.apache.xpath.compiler.Keywords}.
 *
 * @throws javax.xml.transform.TransformerException
 */
protected int AxisName() throws javax.xml.transform.TransformerException
{

  Object val = Keywords.getAxisName(m_token);

  if (null == val)
  {
    error(XPATHErrorResources.ER_ILLEGAL_AXIS_NAME,
          new Object[]{ m_token });  //"illegal axis name: "+m_token);
  }

  int axesType = ((Integer) val).intValue();

  appendOp(2, axesType);

  return axesType;
}
 
Example #3
Source File: AxesWalker.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Set the root node of the TreeWalker.
 * (Not part of the DOM2 TreeWalker interface).
 *
 * @param root The context node of this step.
 */
public void setRoot(int root)
{
  // %OPT% Get this directly from the lpi.
  XPathContext xctxt = wi().getXPathContext();
  m_dtm = xctxt.getDTM(root);
  m_traverser = m_dtm.getAxisTraverser(m_axis);
  m_isFresh = true;
  m_foundLast = false;
  m_root = root;
  m_currentNode = root;

  if (DTM.NULL == root)
  {
    throw new RuntimeException(
      XSLMessages.createXPATHMessage(XPATHErrorResources.ER_SETTING_WALKER_ROOT_TO_NULL, null)); //"\n !!!! Error! Setting the root of a walker to null!!!");
  }

  resetProximityPositions();
}
 
Example #4
Source File: NodeSetDTM.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 *  Returns the previous node in the set and moves the position of the
 * iterator backwards in the set.
 * @return  The previous <code>Node</code> in the set being iterated over,
 *   or<code>DTM.NULL</code> if there are no more members in that set.
 * @throws DOMException
 *    INVALID_STATE_ERR: Raised if this method is called after the
 *   <code>detach</code> method was invoked.
 * @throws RuntimeException thrown if this NodeSetDTM is not of 
 * a cached type, and hence doesn't know what the previous node was.
 */
public int previousNode()
{

  if (!m_cacheNodes)
    throw new RuntimeException(
      XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_CANNOT_ITERATE, null)); //"This NodeSetDTM can not iterate to a previous node!");

  if ((m_next - 1) > 0)
  {
    m_next--;

    return this.elementAt(m_next);
  }
  else
    return DTM.NULL;
}
 
Example #5
Source File: NodeSet.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Copy NodeList members into this nodelist, adding in
 * document order.  If a node is null, don't add it.
 *
 * @param nodelist List of nodes to be added
 * @param support The XPath runtime context.
 * @throws RuntimeException thrown if this NodeSet is not of 
 * a mutable type.
 */
public void addNodesInDocOrder(NodeList nodelist, XPathContext support)
{

  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");

  int nChildren = nodelist.getLength();

  for (int i = 0; i < nChildren; i++)
  {
    Node node = nodelist.item(i);

    if (null != node)
    {
      addNodeInDocOrder(node, support);
    }
  }
}
 
Example #6
Source File: NodeSet.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Copy NodeList members into this nodelist, adding in
 * document order.  Null references are not added.
 *
 * @param iterator NodeIterator which yields the nodes to be added.
 * @throws RuntimeException thrown if this NodeSet is not of 
 * a mutable type.
 */
public void addNodes(NodeIterator iterator)
{

  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");

  if (null != iterator)  // defensive to fix a bug that Sanjiva reported.
  {
    Node obj;

    while (null != (obj = iterator.nextNode()))
    {
      addElement(obj);
    }
  }

  // checkDups();
}
 
Example #7
Source File: XPathContext.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Tell the user of an assertion error, and probably throw an
 * exception.
 *
 * @param b  If false, a TransformerException will be thrown.
 * @param msg The assertion message, which should be informative.
 * 
 * @throws javax.xml.transform.TransformerException if b is false.
 */
private void assertion(boolean b, String msg) throws javax.xml.transform.TransformerException
{
  if (!b) 
  {
    ErrorListener errorHandler = getErrorListener();

    if (errorHandler != null)
    {
      errorHandler.fatalError(
        new TransformerException(
          XSLMessages.createMessage(
            XPATHErrorResources.ER_INCORRECT_PROGRAMMER_ASSERTION,
            new Object[]{ msg }), (SAXSourceLocator)this.getSAXLocator()));
    }
  }
}
 
Example #8
Source File: NodeSet.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Copy NodeList members into this nodelist, adding in
 * document order.  If a node is null, don't add it.
 *
 * @param nodelist List of nodes which should now be referenced by
 * this NodeSet.
 * @throws RuntimeException thrown if this NodeSet is not of 
 * a mutable type.
 */
public void addNodes(NodeList nodelist)
{

  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");

  if (null != nodelist)  // defensive to fix a bug that Sanjiva reported.
  {
    int nChildren = nodelist.getLength();

    for (int i = 0; i < nChildren; i++)
    {
      Node obj = nodelist.item(i);

      if (null != obj)
      {
        addElement(obj);
      }
    }
  }

  // checkDups();
}
 
Example #9
Source File: NodeSet.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 *  Returns the previous node in the set and moves the position of the
 * iterator backwards in the set.
 * @return  The previous <code>Node</code> in the set being iterated over,
 *   or<code>null</code> if there are no more members in that set.
 * @throws DOMException
 *    INVALID_STATE_ERR: Raised if this method is called after the
 *   <code>detach</code> method was invoked.
 * @throws RuntimeException thrown if this NodeSet is not of 
 * a cached type, and hence doesn't know what the previous node was.
 */
public Node previousNode() throws DOMException
{

  if (!m_cacheNodes)
    throw new RuntimeException(
      XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_CANNOT_ITERATE, null)); //"This NodeSet can not iterate to a previous node!");

  if ((m_next - 1) > 0)
  {
    m_next--;

    return this.elementAt(m_next);
  }
  else
    return null;
}
 
Example #10
Source File: XPathImpl.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * <p>Compile an XPath expression for later evaluation.</p>
 *
 * <p>If <code>expression</code> contains any {@link XPathFunction}s,
 * they must be available via the {@link XPathFunctionResolver}.
 * An {@link XPathExpressionException} will be thrown if the <code>XPathFunction</code>
 * cannot be resovled with the <code>XPathFunctionResolver</code>.</p>
 * 
 * <p>If <code>expression</code> is <code>null</code>, a <code>NullPointerException</code> is thrown.</p>
 *
 * @param expression The XPath expression.
 *
 * @return Compiled XPath expression.

 * @throws XPathExpressionException If <code>expression</code> cannot be compiled.
 * @throws NullPointerException If <code>expression</code> is <code>null</code>.
 */
public XPathExpression compile(String expression)
    throws XPathExpressionException {
    if ( expression == null ) {
        String fmsg = XSLMessages.createXPATHMessage( 
                XPATHErrorResources.ER_ARG_CANNOT_BE_NULL,
                new Object[] {"XPath expression"} );
        throw new NullPointerException ( fmsg );
    }
    try {
        org.apache.xpath.XPath xpath = new XPath (expression, null,
                prefixResolver, org.apache.xpath.XPath.SELECT );
        // Can have errorListener
        XPathExpressionImpl ximpl = new XPathExpressionImpl (xpath,
                prefixResolver, functionResolver, variableResolver,
                featureSecureProcessing );
        return ximpl;
    } catch ( javax.xml.transform.TransformerException te ) {
        throw new XPathExpressionException ( te ) ;
    }
}
 
Example #11
Source File: JAXPExtensionsProvider.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Is the extension function available?
 */

public boolean functionAvailable(String ns, String funcName)
      throws javax.xml.transform.TransformerException {
  try {
    if ( funcName == null ) {
        String fmsg = XSLMessages.createXPATHMessage( 
            XPATHErrorResources.ER_ARG_CANNOT_BE_NULL,
            new Object[] {"Function Name"} );
        throw new NullPointerException ( fmsg ); 
    }
    //Find the XPathFunction corresponding to namespace and funcName
    javax.xml.namespace.QName myQName = new QName( ns, funcName );
    javax.xml.xpath.XPathFunction xpathFunction = 
        resolver.resolveFunction ( myQName, 0 );
    if (  xpathFunction == null ) {
        return false;
    }
    return true;
  } catch ( Exception e ) {
    return false;
  }
   

}
 
Example #12
Source File: XPath.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Construct an XPath object.  
 *
 * (Needs review -sc) This method initializes an XPathParser/
 * Compiler and compiles the expression.
 * @param exprString The XPath expression.
 * @param locator The location of the expression, may be null.
 * @param prefixResolver A prefix resolver to use to resolve prefixes to 
 *                       namespace URIs.
 * @param type one of {@link #SELECT} or {@link #MATCH}.
 * @param errorListener The error listener, or null if default should be used.
 *
 * @throws javax.xml.transform.TransformerException if syntax or other error.
 */
public XPath(
        String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type,
        ErrorListener errorListener)
          throws javax.xml.transform.TransformerException
{ 
  initFunctionTable();     
  if(null == errorListener)
    errorListener = new org.apache.xml.utils.DefaultErrorHandler();
  
  m_patternString = exprString;

  XPathParser parser = new XPathParser(errorListener, locator);
  Compiler compiler = new Compiler(errorListener, locator, m_funcTable);

  if (SELECT == type)
    parser.initXPath(compiler, exprString, prefixResolver);
  else if (MATCH == type)
    parser.initMatchPattern(compiler, exprString, prefixResolver);
  else
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_CANNOT_DEAL_XPATH_TYPE, new Object[]{Integer.toString(type)})); //"Can not deal with XPath type: " + type);

  // System.out.println("----------------");
  Expression expr = compiler.compile(0);

  // System.out.println("expr: "+expr);
  this.setExpression(expr);
  
  if((null != locator) && locator instanceof ExpressionNode)
  {
  	expr.exprSetParent((ExpressionNode)locator);
  }

}
 
Example #13
Source File: NodeSet.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Removes the first occurrence of the argument from this vector.
 * If the object is found in this vector, each component in the vector
 * with an index greater or equal to the object's index is shifted
 * downward to have an index one smaller than the value it had
 * previously.
 *
 * @param s Node to remove from the list
 *
 * @return True if the node was successfully removed
 */
public boolean removeElement(Node s)
{
  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");

  if (null == m_map)
    return false;

  for (int i = 0; i < m_firstFree; i++)
  {
    Node node = m_map[i];

    if ((null != node) && node.equals(s))
    {
      if (i < m_firstFree - 1)
        System.arraycopy(m_map, i + 1, m_map, i, m_firstFree - i - 1);

      m_firstFree--;
      m_map[m_firstFree] = null;

      return true;
    }
  }

  return false;
}
 
Example #14
Source File: NodeSet.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Inserts the specified node in this vector at the specified index.
 * Each component in this vector with an index greater or equal to
 * the specified index is shifted upward to have an index one greater
 * than the value it had previously.
 *
 * @param value Node to insert
 * @param at Position where to insert
 */
public void insertElementAt(Node value, int at)
{
  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");

  if (null == m_map)
  {
    m_map = new Node[m_blocksize];
    m_mapSize = m_blocksize;
  }
  else if ((m_firstFree + 1) >= m_mapSize)
  {
    m_mapSize += m_blocksize;

    Node newMap[] = new Node[m_mapSize];

    System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1);

    m_map = newMap;
  }

  if (at <= (m_firstFree - 1))
  {
    System.arraycopy(m_map, at, m_map, at + 1, m_firstFree - at);
  }

  m_map[at] = value;

  m_firstFree++;
}
 
Example #15
Source File: NodeSet.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Append a Node onto the vector.
 *
 * @param value Node to add to the vector
 */
public void addElement(Node value)
{
  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");

  if ((m_firstFree + 1) >= m_mapSize)
  {
    if (null == m_map)
    {
      m_map = new Node[m_blocksize];
      m_mapSize = m_blocksize;
    }
    else
    {
      m_mapSize += m_blocksize;

      Node newMap[] = new Node[m_mapSize];

      System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1);

      m_map = newMap;
    }
  }

  m_map[m_firstFree] = value;

  m_firstFree++;
}
 
Example #16
Source File: XPath.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Construct an XPath object.  
 *
 * (Needs review -sc) This method initializes an XPathParser/
 * Compiler and compiles the expression.
 * @param exprString The XPath expression.
 * @param locator The location of the expression, may be null.
 * @param prefixResolver A prefix resolver to use to resolve prefixes to 
 *                       namespace URIs.
 * @param type one of {@link #SELECT} or {@link #MATCH}.
 * @param errorListener The error listener, or null if default should be used.
 *
 * @throws javax.xml.transform.TransformerException if syntax or other error.
 */
public XPath(
        String exprString, SourceLocator locator, 
        PrefixResolver prefixResolver, int type,
        ErrorListener errorListener, FunctionTable aTable)
          throws javax.xml.transform.TransformerException
{ 
  m_funcTable = aTable;     
  if(null == errorListener)
    errorListener = new org.apache.xml.utils.DefaultErrorHandler();
  
  m_patternString = exprString;

  XPathParser parser = new XPathParser(errorListener, locator);
  Compiler compiler = new Compiler(errorListener, locator, m_funcTable);

  if (SELECT == type)
    parser.initXPath(compiler, exprString, prefixResolver);
  else if (MATCH == type)
    parser.initMatchPattern(compiler, exprString, prefixResolver);
  else
    throw new RuntimeException(XSLMessages.createXPATHMessage(
          XPATHErrorResources.ER_CANNOT_DEAL_XPATH_TYPE, 
          new Object[]{Integer.toString(type)})); 
          //"Can not deal with XPath type: " + type);

  // System.out.println("----------------");
  Expression expr = compiler.compile(0);

  // System.out.println("expr: "+expr);
  this.setExpression(expr);
  
  if((null != locator) && locator instanceof ExpressionNode)
  {
  	expr.exprSetParent((ExpressionNode)locator);
  }

}
 
Example #17
Source File: XPath.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Tell the user of an assertion error, and probably throw an
 * exception.
 *
 * @param b  If false, a runtime exception will be thrown.
 * @param msg The assertion message, which should be informative.
 * 
 * @throws RuntimeException if the b argument is false.
 */
public void assertion(boolean b, String msg)
{

  if (!b)
  {
    String fMsg = XSLMessages.createXPATHMessage(
      XPATHErrorResources.ER_INCORRECT_PROGRAMMER_ASSERTION,
      new Object[]{ msg });

    throw new RuntimeException(fMsg);
  }
}
 
Example #18
Source File: XPathImpl.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * <p>Establishes a variable resolver.</p>
 *
 * @param resolver Variable Resolver
 */
public void setXPathVariableResolver(XPathVariableResolver resolver) {
    if ( resolver == null ) {
        String fmsg = XSLMessages.createXPATHMessage( 
                XPATHErrorResources.ER_ARG_CANNOT_BE_NULL,
                new Object[] {"XPathVariableResolver"} );
        throw new NullPointerException( fmsg );
    }
    this.variableResolver = resolver;
}
 
Example #19
Source File: XPathImpl.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * <p>Establishes a function resolver.</p>
 *
 * @param resolver XPath function resolver
 */
public void setXPathFunctionResolver(XPathFunctionResolver resolver) {
    if ( resolver == null ) {
        String fmsg = XSLMessages.createXPATHMessage( 
                XPATHErrorResources.ER_ARG_CANNOT_BE_NULL,
                new Object[] {"XPathFunctionResolver"} );
        throw new NullPointerException( fmsg );
    }
    this.functionResolver = resolver;
}
 
Example #20
Source File: XPathImpl.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private Object getResultAsType( XObject resultObject, QName returnType )
    throws javax.xml.transform.TransformerException {
    // XPathConstants.STRING
    if ( returnType.equals( XPathConstants.STRING ) ) { 
        return resultObject.str();
    }
    // XPathConstants.NUMBER
    if ( returnType.equals( XPathConstants.NUMBER ) ) { 
        return new Double ( resultObject.num());
    }
    // XPathConstants.BOOLEAN
    if ( returnType.equals( XPathConstants.BOOLEAN ) ) { 
        return new Boolean( resultObject.bool());
    }
    // XPathConstants.NODESET ---ORdered, UNOrdered???
    if ( returnType.equals( XPathConstants.NODESET ) ) { 
        return resultObject.nodelist();
    }
    // XPathConstants.NODE
    if ( returnType.equals( XPathConstants.NODE ) ) { 
        NodeIterator ni = resultObject.nodeset(); 
        //Return the first node, or null
        return ni.nextNode();
    }
    String fmsg = XSLMessages.createXPATHMessage(
            XPATHErrorResources.ER_UNSUPPORTED_RETURN_TYPE,
            new Object[] { returnType.toString()});
    throw new IllegalArgumentException( fmsg );
}
 
Example #21
Source File: XPathExpressionImpl.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private Object getResultAsType( XObject resultObject, QName returnType )
    throws javax.xml.transform.TransformerException {
    // XPathConstants.STRING
    if ( returnType.equals( XPathConstants.STRING ) ) {
        return resultObject.str();
    }
    // XPathConstants.NUMBER
    if ( returnType.equals( XPathConstants.NUMBER ) ) {
        return new Double ( resultObject.num());
    }
    // XPathConstants.BOOLEAN
    if ( returnType.equals( XPathConstants.BOOLEAN ) ) {
        return new Boolean( resultObject.bool());
    }
    // XPathConstants.NODESET ---ORdered, UNOrdered???
    if ( returnType.equals( XPathConstants.NODESET ) ) {
        return resultObject.nodelist();
    }
    // XPathConstants.NODE
    if ( returnType.equals( XPathConstants.NODE ) ) {
        NodeIterator ni = resultObject.nodeset();
        //Return the first node, or null
        return ni.nextNode();
    }
    // If isSupported check is already done then the execution path 
    // shouldn't come here. Being defensive
    String fmsg = XSLMessages.createXPATHMessage( 
            XPATHErrorResources.ER_UNSUPPORTED_RETURN_TYPE,
            new Object[] { returnType.toString()});
    throw new IllegalArgumentException ( fmsg );
}
 
Example #22
Source File: FuncExtFunction.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs and throws a WrongNumberArgException with the appropriate
 * message for this function object.  This class supports an arbitrary
 * number of arguments, so this method must never be called.
 *
 * @throws WrongNumberArgsException
 */
protected void reportWrongNumberArgs() throws WrongNumberArgsException {
  String fMsg = XSLMessages.createXPATHMessage(
      XPATHErrorResources.ER_INCORRECT_PROGRAMMER_ASSERTION,
      new Object[]{ "Programmer's assertion:  the method FunctionMultiArgs.reportWrongNumberArgs() should never be called." });

  throw new RuntimeException(fMsg);
}
 
Example #23
Source File: NodeSet.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Copy NodeList members into this nodelist, adding in
 * document order.  If a node is null, don't add it.
 *
 * @param iterator NodeIterator which yields the nodes to be added.
 * @param support The XPath runtime context.
 * @throws RuntimeException thrown if this NodeSet is not of 
 * a mutable type.
 */
public void addNodesInDocOrder(NodeIterator iterator, XPathContext support)
{

  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");

  Node node;

  while (null != (node = iterator.nextNode()))
  {
    addNodeInDocOrder(node, support);
  }
}
 
Example #24
Source File: NodeSetDTM.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Same as setElementAt.
 *
 * @param node  The node to be set.
 * @param index The index of the node to be replaced.
 * @throws RuntimeException thrown if this NodeSetDTM is not of 
 * a mutable type.
 */
public void setItem(int node, int index)
{

  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_NOT_MUTABLE, null)); //"This NodeSetDTM is not mutable!");

  super.setElementAt(node, index);
}
 
Example #25
Source File: XObject.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Cast result object to a boolean. Always issues an error.
 *
 * @return false
 *
 * @throws javax.xml.transform.TransformerException
 */
public boolean bool() throws javax.xml.transform.TransformerException
{

  error(XPATHErrorResources.ER_CANT_CONVERT_TO_NUMBER,
        new Object[]{ getTypeString() });  //"Can not convert "+getTypeString()+" to a number");

  return false;
}
 
Example #26
Source File: NodeSetDTM.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Set the current position in the node set.
 * @param i Must be a valid index.
 * @throws RuntimeException thrown if this NodeSetDTM is not of 
 * a cached type, and thus doesn't permit indexed access.
 */
public void setCurrentPos(int i)
{

  if (!m_cacheNodes)
    throw new RuntimeException(
      XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_CANNOT_INDEX, null)); //"This NodeSetDTM can not do indexing or counting functions!");

  m_next = i;
}
 
Example #27
Source File: OpMap.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * 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.
 */
public int getNextStepPos(int opPos)
{

  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[]{String.valueOf(stepType)})); 
    //"Programmer's assertion in getNextStepPos: unknown stepType: " + stepType);
  }
}
 
Example #28
Source File: NodeSet.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * If an index is requested, NodeSet will call this method
 * to run the iterator to the index.  By default this sets
 * m_next to the index.  If the index argument is -1, this
 * signals that the iterator should be run to the end.
 *
 * @param index Position to advance (or retreat) to, with
 * 0 requesting the reset ("fresh") position and -1 (or indeed
 * any out-of-bounds value) requesting the final position.
 * @throws RuntimeException thrown if this NodeSet is not
 * one of the types which supports indexing/counting.
 */
public void runTo(int index)
{

  if (!m_cacheNodes)
    throw new RuntimeException(
      XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_CANNOT_INDEX, null)); //"This NodeSet can not do indexing or counting functions!");

  if ((index >= 0) && (m_next < m_firstFree))
    m_next = index;
  else
    m_next = m_firstFree - 1;
}
 
Example #29
Source File: XPathParser.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Notify the user of an assertion error, and probably throw an
 * exception.
 *
 * @param b  If false, a runtime exception will be thrown.
 * @param msg The assertion message, which should be informative.
 * 
 * @throws RuntimeException if the b argument is false.
 */
private void assertion(boolean b, String msg)
{

  if (!b)
  {
    String fMsg = XSLMessages.createXPATHMessage(
      XPATHErrorResources.ER_INCORRECT_PROGRAMMER_ASSERTION,
      new Object[]{ msg });

    throw new RuntimeException(fMsg);
  }
}
 
Example #30
Source File: NodeSet.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Add a node to the NodeSet. Not all types of NodeSets support this
 * operation
 *
 * @param n Node to be added
 * @throws RuntimeException thrown if this NodeSet is not of 
 * a mutable type.
 */
public void addNode(Node n)
{

  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");

  this.addElement(n);
}