⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basexpath.java

📁 XML的解析、编译、查询等技术的JAVA源代码。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     *  that is not a <code>SimpleNamespaceContext</code>,     *  then this method will throw a <code>JaxenException</code>.     *  </p>     *     *  @param prefix the namespace prefix     *  @param uri the namespace URI     *     *  @throws JaxenException if the <code>NamespaceContext</code>     *          used by this XPath is not a <code>SimpleNamespaceContext</code>     */    public void addNamespace(String prefix,                             String uri) throws JaxenException    {        NamespaceContext nsContext = getNamespaceContext();        if ( nsContext instanceof SimpleNamespaceContext )        {            ((SimpleNamespaceContext)nsContext).addNamespace( prefix,                                                              uri );            return;        }        throw new JaxenException("Operation not permitted while using a non-simple namespace context.");    }    // ------------------------------------------------------------    // ------------------------------------------------------------    //     Properties    // ------------------------------------------------------------    // ------------------------------------------------------------        /** Set a <code>NamespaceContext</code> for use with this     *  XPath expression.     *     *  <p>     *  A <code>NamespaceContext</code> is responsible for translating     *  namespace prefixes within the expression into namespace URIs.     *  </p>     *     *  @param namespaceContext the <code>NamespaceContext</code> to     *         install for this expression     *     *  @see NamespaceContext     *  @see NamespaceContext#translateNamespacePrefixToUri     */    public void setNamespaceContext(NamespaceContext namespaceContext)    {        getContextSupport().setNamespaceContext(namespaceContext);    }    /** Set a <code>FunctionContext</code> for use with this XPath     *  expression.     *     *  <p>     *  A <code>FunctionContext</code> is responsible for resolving     *  all function calls used within the expression.     *  </p>     *     *  @param functionContext the <code>FunctionContext</code> to     *         install for this expression     *     *  @see FunctionContext     *  @see FunctionContext#getFunction     */    public void setFunctionContext(FunctionContext functionContext)    {        getContextSupport().setFunctionContext(functionContext);    }    /** Set a <code>VariableContext</code> for use with this XPath     *  expression.     *     *  <p>     *  A <code>VariableContext</code> is responsible for resolving     *  all variables referenced within the expression.     *  </p>     *     *  @param variableContext The <code>VariableContext</code> to     *         install for this expression     *     *  @see VariableContext     *  @see VariableContext#getVariableValue     */    public void setVariableContext(VariableContext variableContext)    {        getContextSupport().setVariableContext(variableContext);    }    /** Retrieve the <code>NamespaceContext</code> used by this XPath     *  expression.     *     *  <p>     *  A <code>NamespaceContext</code> is responsible for mapping     *  prefixes used within the expression to namespace URIs.     *  </p>     *     *  <p>     *  If this XPath expression has not previously had a <code>NamespaceContext</code>     *  installed, a new default <code>NamespaceContext</code> will be created,     *  installed and returned.     *  </p>     *     *  @return the <code>NamespaceContext</code> used by this expression     *     *  @see NamespaceContext     */    public NamespaceContext getNamespaceContext()    {        return getContextSupport().getNamespaceContext();    }    /** Retrieve the <code>FunctionContext</code> used by this XPath     *  expression.     *     *  <p>     *  A <code>FunctionContext</code> is responsible for resolving     *  all function calls used within the expression.     *  </p>     *     *  <p>     *  If this XPath expression has not previously had a <code>FunctionContext</code>     *  installed, a new default <code>FunctionContext</code> will be created,     *  installed and returned.     *  </p>     *     *  @return the <code>FunctionContext</code> used by this expression     *     *  @see FunctionContext     */    public FunctionContext getFunctionContext()    {        return getContextSupport().getFunctionContext();    }    /** Retrieve the <code>VariableContext</code> used by this XPath     *  expression.     *     *  <p>     *  A <code>VariableContext</code> is responsible for resolving     *  all variables referenced within the expression.     *  </p>     *     *  <p>     *  If this XPath expression has not previously had a <code>VariableContext</code>     *  installed, a new default <code>VariableContext</code> will be created,     *  installed and returned.     *  </p>     *       *  @return the <code>VariableContext</code> used by this expression     *     *  @see VariableContext     */    public VariableContext getVariableContext()    {        return getContextSupport().getVariableContext();    }            /** Retrieve the root expression of the internal     *  compiled form of this XPath expression.     *     *  <p>     *  Internally, Jaxen maintains a form of Abstract Syntax     *  Tree (AST) to represent the structure of the XPath expression.     *  This is normally not required during normal consumer-grade     *  usage of Jaxen.  This method is provided for hard-core users     *  who wish to manipulate or inspect a tree-based version of     *  the expression.     *  </p>     *     *  @return the root of the AST of this expression     */    public Expr getRootExpr()     {        return xpath.getRootExpr();    }        /** Return the original expression text.     *     *  @return the normalized XPath expression string     */    public String toString()    {        return this.exprText;    }    /** Returns a string representation of the parse tree.     *     *  @return a string representation of the parse tree.     */    public String debug()    {        return this.xpath.toString();    }        // ------------------------------------------------------------    // ------------------------------------------------------------    //     Implementation methods    // ------------------------------------------------------------    // ------------------------------------------------------------        /** Create a {@link Context} wrapper for the provided     *  implementation-specific object.     *     *  @param node the implementation-specific object      *         to be used as the context     *     *  @return a <code>Context</code> wrapper around the object     */    protected Context getContext(Object node)    {        if ( node instanceof Context )        {            return (Context) node;        }        Context fullContext = new Context( getContextSupport() );        if ( node instanceof List )        {            fullContext.setNodeSet( (List) node );        }        else        {            List list = new SingletonList(node);            fullContext.setNodeSet( list );        }        return fullContext;    }    /** Retrieve the {@link ContextSupport} aggregation of     *  <code>NamespaceContext</code>, <code>FunctionContext</code>,     *  <code>VariableContext</code>, and {@link Navigator}.     *     *  @return aggregate <code>ContextSupport</code> for this     *          XPath expression     */    protected ContextSupport getContextSupport()    {        if ( support == null )        {            support = new ContextSupport(                 createNamespaceContext(),                createFunctionContext(),                createVariableContext(),                getNavigator()             );        }        return support;    }    /** Retrieve the XML object-model-specific {@link Navigator}      *  for us in evaluating this XPath expression.     *     *  @return the implementation-specific <code>Navigator</code>     */    public Navigator getNavigator()    {        return navigator;    }            // ------------------------------------------------------------    // ------------------------------------------------------------    //     Factory methods for default contexts    // ------------------------------------------------------------    // ------------------------------------------------------------    /** Create a default <code>FunctionContext</code>.     *     *  @return a default <code>FunctionContext</code>     */    protected FunctionContext createFunctionContext()    {        return XPathFunctionContext.getInstance();    }        /** Create a default <code>NamespaceContext</code>.     *     *  @return a default <code>NamespaceContext</code> instance     */    protected NamespaceContext createNamespaceContext()    {        return new SimpleNamespaceContext();    }        /** Create a default <code>VariableContext</code>.     *     *  @return a default <code>VariableContext</code> instance     */    protected VariableContext createVariableContext()    {        return new SimpleVariableContext();    }        /** Select all nodes that match this XPath     *  expression on the given Context object.      *  If multiple nodes match, multiple nodes     *  will be returned in document-order, as defined by the XPath     *  specification. If the expression selects a non-node-set     *  (i.e. a number, boolean, or string) then a List     *  containing just that one object is returned.     *  </p>     *     * @param context the Context which gets evaluated     *     * @return the node-set of all items selected     *          by this XPath expression     * @throws JaxenException if an XPath error occurs during expression evaluation     *     */    protected List selectNodesForContext(Context context) throws JaxenException    {        List list = this.xpath.asList( context );        return list;            }     /** Return only the first node that is selected by this XPath     *  expression.  If multiple nodes match, only one node will be     *  returned. The selected node will be the first     *  selected node in document-order, as defined by the XPath     *  specification. If the XPath expression selects a double,     *  String, or boolean, then that object is returned.     *  </p>     *     * @param context the Context against which this expression is evaluated     *     * @return the first node in document order of all nodes selected     *          by this XPath expression     * @throws JaxenException if an XPath error occurs during expression evaluation     *     *  @see #selectNodesForContext     */    protected Object selectSingleNodeForContext(Context context) throws JaxenException    {        List results = selectNodesForContext( context );        if ( results.isEmpty() )        {            return null;        }        return results.get( 0 );    }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -