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

📄 contextsupport.java

📁 XML的解析、编译、查询等技术的JAVA源代码。
💻 JAVA
字号:
package org.jaxen;/* $Id: ContextSupport.java,v 1.13 2006/06/03 20:06:06 elharo Exp $ Copyright 2003 The Werken Company. All Rights Reserved. Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditions aremet:  * Redistributions of source code must retain the above copyright    notice, this list of conditions and the following disclaimer.  * Redistributions in binary form must reproduce the above copyright    notice, this list of conditions and the following disclaimer in the    documentation and/or other materials provided with the distribution.  * Neither the name of the Jaxen Project nor the names of its    contributors may be used to endorse or promote products derived     from this software without specific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "ASIS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITEDTO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR APARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNEROR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, ORPROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDINGNEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THISSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */import java.io.Serializable;/** Supporting context information for resolving *  namespace prefixes, functions, and variables. *  *  <p> *  <strong>NOTE:</strong> This class is not typically used directly, *  but is exposed for writers of implementation-specific *  XPath packages. *  </p> * *  @see org.jaxen.dom4j.Dom4jXPath XPath for dom4j *  @see org.jaxen.jdom.JDOMXPath   XPath for JDOM *  @see org.jaxen.dom.DOMXPath     XPath for W3C DOM * *  @author <a href="mailto:bob@eng.werken.com">bob mcwhirter</a> * *  @version $Id: ContextSupport.java,v 1.13 2006/06/03 20:06:06 elharo Exp $ */public class ContextSupport implements Serializable {    /**     *      */    private static final long serialVersionUID = 4494082174713652559L;    /** Function context. */    private transient FunctionContext functionContext;        /** Namespace context. */    private NamespaceContext namespaceContext;    /** Variable context. */    private VariableContext variableContext;        /** Model navigator. */    private Navigator navigator;    // ----------------------------------------------------------------------    //     Constructors    // ----------------------------------------------------------------------        /** Construct an empty <code>ContextSupport</code>.     */    public ContextSupport()    {        // intentionally left blank    }    /** Create a new ContextSupport object.     *     *  @param namespaceContext the NamespaceContext     *  @param functionContext the FunctionContext     *  @param variableContext the VariableContext     *  @param navigator the model navigator     */    public ContextSupport(NamespaceContext namespaceContext,                          FunctionContext functionContext,                          VariableContext variableContext,                          Navigator navigator)    {        setNamespaceContext( namespaceContext );        setFunctionContext( functionContext );        setVariableContext( variableContext );        this.navigator = navigator;    }    // ----------------------------------------------------------------------    //     Instance methods    // ----------------------------------------------------------------------    /** Set the <code>NamespaceContext</code>.     *     *  @param namespaceContext the namespace context     */    public void setNamespaceContext(NamespaceContext namespaceContext)    {        this.namespaceContext = namespaceContext;    }    /** Retrieve the <code>NamespaceContext</code>.     *     *  @return the namespace context     */    public NamespaceContext getNamespaceContext()    {        return this.namespaceContext;    }    /** Set the <code>FunctionContext</code>.     *     *  @param functionContext the function context     */    public void setFunctionContext(FunctionContext functionContext)    {        this.functionContext  = functionContext;    }    /** Retrieve the <code>FunctionContext</code>.     *     *  @return the function context     */    public FunctionContext getFunctionContext()    {        return this.functionContext;    }    /** Set the <code>VariableContext</code>.     *     *  @param variableContext the variable context     */    public void setVariableContext(VariableContext variableContext)    {        this.variableContext  = variableContext;    }    /** Retrieve the <code>VariableContext</code>.     *     *  @return the variable context     */    public VariableContext getVariableContext()    {        return this.variableContext;    }    /** Retrieve the <code>Navigator</code>.     *     *  @return the navigator     */    public Navigator getNavigator()    {        return this.navigator;    }    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -     /** Translate a namespace prefix to its URI.     *     *  @param prefix The prefix     *     *  @return the namespace URI mapped to the prefix     */    public String translateNamespacePrefixToUri(String prefix)    {                if ("xml".equals(prefix)) {            return "http://www.w3.org/XML/1998/namespace";        }        NamespaceContext context = getNamespaceContext();        if ( context != null )        {            return context.translateNamespacePrefixToUri( prefix );        }        return null;    }    /** Retrieve a variable value.     *     *  @param namespaceURI the function namespace URI     *  @param prefix the function prefix     *  @param localName the function name     *     *  @return the variable value.     *     *  @throws UnresolvableException if unable to locate a bound variable.     */    public Object getVariableValue( String namespaceURI,                                    String prefix,                                    String localName )        throws UnresolvableException    {        VariableContext context = getVariableContext();        if ( context != null )        {            return context.getVariableValue( namespaceURI, prefix, localName );        }        else        {            throw new UnresolvableException( "No variable context installed" );        }    }    /** Retrieve a <code>Function</code>.     *     *  @param namespaceURI the function namespace URI     *  @param prefix the function prefix     *  @param localName the function name     *     *  @return the function object     *     *  @throws UnresolvableException if unable to locate a bound function     */    public Function getFunction( String namespaceURI,                                 String prefix,                                 String localName )        throws UnresolvableException    {        FunctionContext context = getFunctionContext();        if ( context != null )        {            return context.getFunction( namespaceURI, prefix, localName );        }        else        {            throw new UnresolvableException( "No function context installed" );        }    }    }

⌨️ 快捷键说明

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