8054834: Modular Source Code

Co-authored-by: Alan Bateman <alan.bateman@oracle.com>
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Magnus Ihse Bursie <magnus.ihse.bursie@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Paul Sandoz <paul.sandoz@oracle.com>
Reviewed-by: alanb, chegar, ihse, mduigou
This commit is contained in:
Chris Hegarty 2014-08-17 15:51:56 +01:00
parent e35087b430
commit 786f3dbbdf
2059 changed files with 0 additions and 1770 deletions

View file

@ -0,0 +1,160 @@
/*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.xpath;
import java.net.URL;
import java.security.*;
import java.net.*;
import java.io.*;
import java.util.*;
/**
* This class is duplicated for each JAXP subpackage so keep it in sync.
* It is package private and therefore is not exposed as part of the JAXP
* API.
*
* Security related methods that only work on J2SE 1.2 and newer.
*/
class SecuritySupport {
ClassLoader getContextClassLoader() {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader cl = null;
try {
cl = Thread.currentThread().getContextClassLoader();
} catch (SecurityException ex) { }
return cl;
}
});
}
String getSystemProperty(final String propName) {
return (String)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(propName);
}
});
}
FileInputStream getFileInputStream(final File file)
throws FileNotFoundException
{
try {
return (FileInputStream)
AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws FileNotFoundException {
return new FileInputStream(file);
}
});
} catch (PrivilegedActionException e) {
throw (FileNotFoundException)e.getException();
}
}
InputStream getURLInputStream(final URL url)
throws IOException
{
try {
return (InputStream)
AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws IOException {
return url.openStream();
}
});
} catch (PrivilegedActionException e) {
throw (IOException)e.getException();
}
}
URL getResourceAsURL(final ClassLoader cl,
final String name)
{
return (URL)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
URL url;
if (cl == null) {
url = Object.class.getResource(name);
} else {
url = cl.getResource(name);
}
return url;
}
});
}
Enumeration getResources(final ClassLoader cl,
final String name) throws IOException
{
try{
return (Enumeration)
AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws IOException{
Enumeration enumeration;
if (cl == null) {
enumeration = ClassLoader.getSystemResources(name);
} else {
enumeration = cl.getResources(name);
}
return enumeration;
}
});
}catch(PrivilegedActionException e){
throw (IOException)e.getException();
}
}
InputStream getResourceAsStream(final ClassLoader cl,
final String name)
{
return (InputStream)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
InputStream ris;
if (cl == null) {
ris = Object.class.getResourceAsStream(name);
} else {
ris = cl.getResourceAsStream(name);
}
return ris;
}
});
}
boolean doesFileExist(final File f) {
return ((Boolean)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return new Boolean(f.exists());
}
})).booleanValue();
}
}

View file

@ -0,0 +1,319 @@
/*
* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.xpath;
import org.xml.sax.InputSource;
import javax.xml.namespace.QName;
import javax.xml.namespace.NamespaceContext;
/**
* <p><code>XPath</code> provides access to the XPath evaluation environment and expressions.</p>
*
* <a name="XPath-evaluation"/>
* <table border="1" cellpadding="2">
* <thead>
* <tr>
* <th colspan="2">Evaluation of XPath Expressions.</th>
* </tr>
* </thead>
* <tbody>
* <tr>
* <td>context</td>
* <td>
* If a request is made to evaluate the expression in the absence
* of a context item, an empty document node will be used for the context.
* For the purposes of evaluating XPath expressions, a DocumentFragment
* is treated like a Document node.
* </td>
* </tr>
* <tr>
* <td>variables</td>
* <td>
* If the expression contains a variable reference, its value will be found through the {@link XPathVariableResolver}
* set with {@link #setXPathVariableResolver(XPathVariableResolver resolver)}.
* An {@link XPathExpressionException} is raised if the variable resolver is undefined or
* the resolver returns <code>null</code> for the variable.
* The value of a variable must be immutable through the course of any single evaluation.</p>
* </td>
* </tr>
* <tr>
* <td>functions</td>
* <td>
* If the expression contains a function reference, the function will be found through the {@link XPathFunctionResolver}
* set with {@link #setXPathFunctionResolver(XPathFunctionResolver resolver)}.
* An {@link XPathExpressionException} is raised if the function resolver is undefined or
* the function resolver returns <code>null</code> for the function.</p>
* </td>
* </tr>
* <tr>
* <td>QNames</td>
* <td>
* QNames in the expression are resolved against the XPath namespace context
* set with {@link #setNamespaceContext(NamespaceContext nsContext)}.
* </td>
* </tr>
* <tr>
* <td>result</td>
* <td>
* This result of evaluating an expression is converted to an instance of the desired return type.
* Valid return types are defined in {@link XPathConstants}.
* Conversion to the return type follows XPath conversion rules.</p>
* </td>
* </tr>
* </table>
*
* <p>An XPath object is not thread-safe and not reentrant.
* In other words, it is the application's responsibility to make
* sure that one {@link XPath} object is not used from
* more than one thread at any given time, and while the <code>evaluate</code>
* method is invoked, applications may not recursively call
* the <code>evaluate</code> method.
* <p>
*
* @author <a href="Norman.Walsh@Sun.com">Norman Walsh</a>
* @author <a href="Jeff.Suttor@Sun.com">Jeff Suttor</a>
* @see <a href="http://www.w3.org/TR/xpath">XML Path Language (XPath) Version 1.0</a>
* @since 1.5
*/
public interface XPath {
/**
* <p>Reset this <code>XPath</code> to its original configuration.</p>
*
* <p><code>XPath</code> is reset to the same state as when it was created with
* {@link XPathFactory#newXPath()}.
* <code>reset()</code> is designed to allow the reuse of existing <code>XPath</code>s
* thus saving resources associated with the creation of new <code>XPath</code>s.</p>
*
* <p>The reset <code>XPath</code> is not guaranteed to have the same {@link XPathFunctionResolver}, {@link XPathVariableResolver}
* or {@link NamespaceContext} <code>Object</code>s, e.g. {@link Object#equals(Object obj)}.
* It is guaranteed to have a functionally equal <code>XPathFunctionResolver</code>, <code>XPathVariableResolver</code>
* and <code>NamespaceContext</code>.</p>
*/
public void reset();
/**
* <p>Establish a variable resolver.</p>
*
* <p>A <code>NullPointerException</code> is thrown if <code>resolver</code> is <code>null</code>.</p>
*
* @param resolver Variable resolver.
*
* @throws NullPointerException If <code>resolver</code> is <code>null</code>.
*/
public void setXPathVariableResolver(XPathVariableResolver resolver);
/**
* <p>Return the current variable resolver.</p>
*
* <p><code>null</code> is returned in no variable resolver is in effect.</p>
*
* @return Current variable resolver.
*/
public XPathVariableResolver getXPathVariableResolver();
/**
* <p>Establish a function resolver.</p>
*
* <p>A <code>NullPointerException</code> is thrown if <code>resolver</code> is <code>null</code>.</p>
*
* @param resolver XPath function resolver.
*
* @throws NullPointerException If <code>resolver</code> is <code>null</code>.
*/
public void setXPathFunctionResolver(XPathFunctionResolver resolver);
/**
* <p>Return the current function resolver.</p>
*
* <p><code>null</code> is returned in no function resolver is in effect.</p>
*
* @return Current function resolver.
*/
public XPathFunctionResolver getXPathFunctionResolver();
/**
* <p>Establish a namespace context.</p>
*
* <p>A <code>NullPointerException</code> is thrown if <code>nsContext</code> is <code>null</code>.</p>
*
* @param nsContext Namespace context to use.
*
* @throws NullPointerException If <code>nsContext</code> is <code>null</code>.
*/
public void setNamespaceContext(NamespaceContext nsContext);
/**
* <p>Return the current namespace context.</p>
*
* <p><code>null</code> is returned in no namespace context is in effect.</p>
*
* @return Current Namespace context.
*/
public NamespaceContext getNamespaceContext();
/**
* <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> contains any variables, the
* {@link XPathVariableResolver} in effect
* <strong>at compile time</strong> will be used to resolve them.</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;
/**
* <p>Evaluate an <code>XPath</code> expression in the specified context and return the result as the specified type.</p>
*
* <p>See <a href="#XPath-evaluation">Evaluation of XPath Expressions</a> for context item evaluation,
* variable, function and <code>QName</code> resolution and return type conversion.</p>
*
* <p>If <code>returnType</code> is not one of the types defined in {@link XPathConstants} (
* {@link XPathConstants#NUMBER NUMBER},
* {@link XPathConstants#STRING STRING},
* {@link XPathConstants#BOOLEAN BOOLEAN},
* {@link XPathConstants#NODE NODE} or
* {@link XPathConstants#NODESET NODESET})
* then an <code>IllegalArgumentException</code> is thrown.</p>
*
* <p>If a <code>null</code> value is provided for
* <code>item</code>, an empty document will be used for the
* context.
* If <code>expression</code> or <code>returnType</code> is <code>null</code>, then a
* <code>NullPointerException</code> is thrown.</p>
*
* @param expression The XPath expression.
* @param item The starting context (a node, for example).
* @param returnType The desired return type.
*
* @return Result of evaluating an XPath expression as an <code>Object</code> of <code>returnType</code>.
*
* @throws XPathExpressionException If <code>expression</code> cannot be evaluated.
* @throws IllegalArgumentException If <code>returnType</code> is not one of the types defined in {@link XPathConstants}.
* @throws NullPointerException If <code>expression</code> or <code>returnType</code> is <code>null</code>.
*/
public Object evaluate(String expression, Object item, QName returnType)
throws XPathExpressionException;
/**
* <p>Evaluate an XPath expression in the specified context and return the result as a <code>String</code>.</p>
*
* <p>This method calls {@link #evaluate(String expression, Object item, QName returnType)} with a <code>returnType</code> of
* {@link XPathConstants#STRING}.</p>
*
* <p>See <a href="#XPath-evaluation">Evaluation of XPath Expressions</a> for context item evaluation,
* variable, function and QName resolution and return type conversion.</p>
*
* <p>If a <code>null</code> value is provided for
* <code>item</code>, an empty document will be used for the
* context.
* If <code>expression</code> is <code>null</code>, then a <code>NullPointerException</code> is thrown.</p>
*
* @param expression The XPath expression.
* @param item The starting context (a node, for example).
*
* @return The <code>String</code> that is the result of evaluating the expression and
* converting the result to a <code>String</code>.
*
* @throws XPathExpressionException If <code>expression</code> cannot be evaluated.
* @throws NullPointerException If <code>expression</code> is <code>null</code>.
*/
public String evaluate(String expression, Object item)
throws XPathExpressionException;
/**
* <p>Evaluate an XPath expression in the context of the specified <code>InputSource</code>
* and return the result as the specified type.</p>
*
* <p>This method builds a data model for the {@link InputSource} and calls
* {@link #evaluate(String expression, Object item, QName returnType)} on the resulting document object.</p>
*
* <p>See <a href="#XPath-evaluation">Evaluation of XPath Expressions</a> for context item evaluation,
* variable, function and QName resolution and return type conversion.</p>
*
* <p>If <code>returnType</code> is not one of the types defined in {@link XPathConstants},
* then an <code>IllegalArgumentException</code> is thrown.</p>
*
* <p>If <code>expression</code>, <code>source</code> or <code>returnType</code> is <code>null</code>,
* then a <code>NullPointerException</code> is thrown.</p>
*
* @param expression The XPath expression.
* @param source The input source of the document to evaluate over.
* @param returnType The desired return type.
*
* @return The <code>Object</code> that encapsulates the result of evaluating the expression.
*
* @throws XPathExpressionException If expression cannot be evaluated.
* @throws IllegalArgumentException If <code>returnType</code> is not one of the types defined in {@link XPathConstants}.
* @throws NullPointerException If <code>expression</code>, <code>source</code> or <code>returnType</code>
* is <code>null</code>.
*/
public Object evaluate(
String expression,
InputSource source,
QName returnType)
throws XPathExpressionException;
/**
* <p>Evaluate an XPath expression in the context of the specified <code>InputSource</code>
* and return the result as a <code>String</code>.</p>
*
* <p>This method calls {@link #evaluate(String expression, InputSource source, QName returnType)} with a
* <code>returnType</code> of {@link XPathConstants#STRING}.</p>
*
* <p>See <a href="#XPath-evaluation">Evaluation of XPath Expressions</a> for context item evaluation,
* variable, function and QName resolution and return type conversion.</p>
*
* <p>If <code>expression</code> or <code>source</code> is <code>null</code>,
* then a <code>NullPointerException</code> is thrown.</p>
*
* @param expression The XPath expression.
* @param source The <code>InputSource</code> of the document to evaluate over.
*
* @return The <code>String</code> that is the result of evaluating the expression and
* converting the result to a <code>String</code>.
*
* @throws XPathExpressionException If expression cannot be evaluated.
* @throws NullPointerException If <code>expression</code> or <code>source</code> is <code>null</code>.
*/
public String evaluate(String expression, InputSource source)
throws XPathExpressionException;
}

View file

@ -0,0 +1,84 @@
/*
* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.xpath;
import javax.xml.namespace.QName;
/**
* <p>XPath constants.</p>
*
* @author <a href="mailto:Norman.Walsh@Sun.COM">Norman Walsh</a>
* @author <a href="mailto:Jeff.Suttor@Sun.COM">Jeff Suttor</a>
* @see <a href="http://www.w3.org/TR/xpath">XML Path Language (XPath) Version 1.0</a>
* @since 1.5
*/
public class XPathConstants {
/**
* <p>Private constructor to prevent instantiation.</p>
*/
private XPathConstants() { }
/**
* <p>The XPath 1.0 number data type.</p>
*
* <p>Maps to Java {@link Double}.</p>
*/
public static final QName NUMBER = new QName("http://www.w3.org/1999/XSL/Transform", "NUMBER");
/**
* <p>The XPath 1.0 string data type.</p>
*
* <p>Maps to Java {@link String}.</p>
*/
public static final QName STRING = new QName("http://www.w3.org/1999/XSL/Transform", "STRING");
/**
* <p>The XPath 1.0 boolean data type.</p>
*
* <p>Maps to Java {@link Boolean}.</p>
*/
public static final QName BOOLEAN = new QName("http://www.w3.org/1999/XSL/Transform", "BOOLEAN");
/**
* <p>The XPath 1.0 NodeSet data type.</p>
*
* <p>Maps to Java {@link org.w3c.dom.NodeList}.</p>
*/
public static final QName NODESET = new QName("http://www.w3.org/1999/XSL/Transform", "NODESET");
/**
* <p>The XPath 1.0 NodeSet data type.
*
* <p>Maps to Java {@link org.w3c.dom.Node}.</p>
*/
public static final QName NODE = new QName("http://www.w3.org/1999/XSL/Transform", "NODE");
/**
* <p>The URI for the DOM object model, "http://java.sun.com/jaxp/xpath/dom".</p>
*/
public static final String DOM_OBJECT_MODEL = "http://java.sun.com/jaxp/xpath/dom";
}

View file

@ -0,0 +1,176 @@
/*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.xpath;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamField;
import java.io.InvalidClassException;
/**
* <code>XPathException</code> represents a generic XPath exception.</p>
*
* @author <a href="Norman.Walsh@Sun.com">Norman Walsh</a>
* @author <a href="mailto:Jeff.Suttor@Sun.COM">Jeff Suttor</a>
* @since 1.5
*/
public class XPathException extends Exception {
private static final ObjectStreamField[] serialPersistentFields = {
new ObjectStreamField( "cause", Throwable.class )
};
/**
* <p>Stream Unique Identifier.</p>
*/
private static final long serialVersionUID = -1837080260374986980L;
/**
* <p>Constructs a new <code>XPathException</code>
* with the specified detail <code>message</code>.</p>
*
* <p>The <code>cause</code> is not initialized.</p>
*
* <p>If <code>message</code> is <code>null</code>,
* then a <code>NullPointerException</code> is thrown.</p>
*
* @param message The detail message.
*
* @throws NullPointerException When <code>message</code> is
* <code>null</code>.
*/
public XPathException(String message) {
super(message);
if ( message == null ) {
throw new NullPointerException ( "message can't be null");
}
}
/**
* <p>Constructs a new <code>XPathException</code>
* with the specified <code>cause</code>.</p>
*
* <p>If <code>cause</code> is <code>null</code>,
* then a <code>NullPointerException</code> is thrown.</p>
*
* @param cause The cause.
*
* @throws NullPointerException if <code>cause</code> is <code>null</code>.
*/
public XPathException(Throwable cause) {
super(cause);
if ( cause == null ) {
throw new NullPointerException ( "cause can't be null");
}
}
/**
* <p>Get the cause of this XPathException.</p>
*
* @return Cause of this XPathException.
*/
public Throwable getCause() {
return super.getCause();
}
/**
* Writes "cause" field to the stream.
* The cause is got from the parent class.
*
* @param out stream used for serialization.
* @throws IOException thrown by <code>ObjectOutputStream</code>
*
*/
private void writeObject(ObjectOutputStream out)
throws IOException
{
ObjectOutputStream.PutField fields = out.putFields();
fields.put("cause", (Throwable) super.getCause());
out.writeFields();
}
/**
* Reads the "cause" field from the stream.
* And initializes the "cause" if it wasn't
* done before.
*
* @param in stream used for deserialization
* @throws IOException thrown by <code>ObjectInputStream</code>
* @throws ClassNotFoundException thrown by <code>ObjectInputStream</code>
*/
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException
{
ObjectInputStream.GetField fields = in.readFields();
Throwable scause = (Throwable) fields.get("cause", null);
if (super.getCause() == null && scause != null) {
try {
super.initCause(scause);
} catch(IllegalStateException e) {
throw new InvalidClassException("Inconsistent state: two causes");
}
}
}
/**
* <p>Print stack trace to specified <code>PrintStream</code>.</p>
*
* @param s Print stack trace to this <code>PrintStream</code>.
*/
public void printStackTrace(java.io.PrintStream s) {
if (getCause() != null) {
getCause().printStackTrace(s);
s.println("--------------- linked to ------------------");
}
super.printStackTrace(s);
}
/**
* <p>Print stack trace to <code>System.err</code>.</p>
*/
public void printStackTrace() {
printStackTrace(System.err);
}
/**
* <p>Print stack trace to specified <code>PrintWriter</code>.</p>
*
* @param s Print stack trace to this <code>PrintWriter</code>.
*/
public void printStackTrace(PrintWriter s) {
if (getCause() != null) {
getCause().printStackTrace(s);
s.println("--------------- linked to ------------------");
}
super.printStackTrace(s);
}
}

View file

@ -0,0 +1,200 @@
/*
* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.xpath;
import org.xml.sax.InputSource;
import javax.xml.namespace.QName;
/**
* <p><code>XPathExpression</code> provides access to compiled XPath expressions.</p>
*
* <a name="XPathExpression-evaluation"/>
* <table border="1" cellpadding="2">
* <thead>
* <tr>
* <th colspan="2">Evaluation of XPath Expressions.</th>
* </tr>
* </thead>
* <tbody>
* <tr>
* <td>context</td>
* <td>
* If a request is made to evaluate the expression in the absence
* of a context item, an empty document node will be used for the context.
* For the purposes of evaluating XPath expressions, a DocumentFragment
* is treated like a Document node.
* </td>
* </tr>
* <tr>
* <td>variables</td>
* <td>
* If the expression contains a variable reference, its value will be found through the {@link XPathVariableResolver}.
* An {@link XPathExpressionException} is raised if the variable resolver is undefined or
* the resolver returns <code>null</code> for the variable.
* The value of a variable must be immutable through the course of any single evaluation.</p>
* </td>
* </tr>
* <tr>
* <td>functions</td>
* <td>
* If the expression contains a function reference, the function will be found through the {@link XPathFunctionResolver}.
* An {@link XPathExpressionException} is raised if the function resolver is undefined or
* the function resolver returns <code>null</code> for the function.</p>
* </td>
* </tr>
* <tr>
* <td>QNames</td>
* <td>
* QNames in the expression are resolved against the XPath namespace context.
* </td>
* </tr>
* <tr>
* <td>result</td>
* <td>
* This result of evaluating an expression is converted to an instance of the desired return type.
* Valid return types are defined in {@link XPathConstants}.
* Conversion to the return type follows XPath conversion rules.</p>
* </td>
* </tr>
* </table>
*
* <p>An XPath expression is not thread-safe and not reentrant.
* In other words, it is the application's responsibility to make
* sure that one {@link XPathExpression} object is not used from
* more than one thread at any given time, and while the <code>evaluate</code>
* method is invoked, applications may not recursively call
* the <code>evaluate</code> method.
* <p>
*
* @author <a href="mailto:Norman.Walsh@Sun.com">Norman Walsh</a>
* @author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a>
* @see <a href="http://www.w3.org/TR/xpath#section-Expressions">XML Path Language (XPath) Version 1.0, Expressions</a>
* @since 1.5
*/
public interface XPathExpression {
/**
* <p>Evaluate the compiled XPath expression in the specified context and return the result as the specified type.</p>
*
* <p>See <a href="#XPathExpression-evaluation">Evaluation of XPath Expressions</a> for context item evaluation,
* variable, function and QName resolution and return type conversion.</p>
*
* <p>If <code>returnType</code> is not one of the types defined in {@link XPathConstants},
* then an <code>IllegalArgumentException</code> is thrown.</p>
*
* <p>If a <code>null</code> value is provided for
* <code>item</code>, an empty document will be used for the
* context.
* If <code>returnType</code> is <code>null</code>, then a <code>NullPointerException</code> is thrown.</p>
*
* @param item The starting context (a node, for example).
* @param returnType The desired return type.
*
* @return The <code>Object</code> that is the result of evaluating the expression and converting the result to
* <code>returnType</code>.
*
* @throws XPathExpressionException If the expression cannot be evaluated.
* @throws IllegalArgumentException If <code>returnType</code> is not one of the types defined in {@link XPathConstants}.
* @throws NullPointerException If <code>returnType</code> is <code>null</code>.
*/
public Object evaluate(Object item, QName returnType)
throws XPathExpressionException;
/**
* <p>Evaluate the compiled XPath expression in the specified context and return the result as a <code>String</code>.</p>
*
* <p>This method calls {@link #evaluate(Object item, QName returnType)} with a <code>returnType</code> of
* {@link XPathConstants#STRING}.</p>
*
* <p>See <a href="#XPathExpression-evaluation">Evaluation of XPath Expressions</a> for context item evaluation,
* variable, function and QName resolution and return type conversion.</p>
*
* <p>If a <code>null</code> value is provided for
* <code>item</code>, an empty document will be used for the
* context.
*
* @param item The starting context (a node, for example).
*
* @return The <code>String</code> that is the result of evaluating the expression and converting the result to a
* <code>String</code>.
*
* @throws XPathExpressionException If the expression cannot be evaluated.
*/
public String evaluate(Object item)
throws XPathExpressionException;
/**
* <p>Evaluate the compiled XPath expression in the context of the specified <code>InputSource</code> and return the result as the
* specified type.</p>
*
* <p>This method builds a data model for the {@link InputSource} and calls
* {@link #evaluate(Object item, QName returnType)} on the resulting document object.</p>
*
* <p>See <a href="#XPathExpression-evaluation">Evaluation of XPath Expressions</a> for context item evaluation,
* variable, function and QName resolution and return type conversion.</p>
*
* <p>If <code>returnType</code> is not one of the types defined in {@link XPathConstants},
* then an <code>IllegalArgumentException</code> is thrown.</p>
*
* <p>If <code>source</code> or <code>returnType</code> is <code>null</code>,
* then a <code>NullPointerException</code> is thrown.</p>
*
* @param source The <code>InputSource</code> of the document to evaluate over.
* @param returnType The desired return type.
*
* @return The <code>Object</code> that is the result of evaluating the expression and converting the result to
* <code>returnType</code>.
*
* @throws XPathExpressionException If the expression cannot be evaluated.
* @throws IllegalArgumentException If <code>returnType</code> is not one of the types defined in {@link XPathConstants}.
* @throws NullPointerException If <code>source</code> or <code>returnType</code> is <code>null</code>.
*/
public Object evaluate(InputSource source, QName returnType)
throws XPathExpressionException;
/**
* <p>Evaluate the compiled XPath expression in the context of the specified <code>InputSource</code> and return the result as a
* <code>String</code>.</p>
*
* <p>This method calls {@link #evaluate(InputSource source, QName returnType)} with a <code>returnType</code> of
* {@link XPathConstants#STRING}.</p>
*
* <p>See <a href="#XPathExpression-evaluation">Evaluation of XPath Expressions</a> for context item evaluation,
* variable, function and QName resolution and return type conversion.</p>
*
* <p>If <code>source</code> is <code>null</code>, then a <code>NullPointerException</code> is thrown.</p>
*
* @param source The <code>InputSource</code> of the document to evaluate over.
*
* @return The <code>String</code> that is the result of evaluating the expression and converting the result to a
* <code>String</code>.
*
* @throws XPathExpressionException If the expression cannot be evaluated.
* @throws NullPointerException If <code>source</code> is <code>null</code>.
*/
public String evaluate(InputSource source)
throws XPathExpressionException;
}

View file

@ -0,0 +1,74 @@
/*
* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.xpath;
/**
* <code>XPathExpressionException</code> represents an error in an XPath expression.</p>
*
* @author <a href="mailto:Norman.Walsh@Sun.com">Norman Walsh</a>
* @author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a>
* @since 1.5
*/
public class XPathExpressionException extends XPathException {
/**
* <p>Stream Unique Identifier.</p>
*/
private static final long serialVersionUID = -1837080260374986980L;
/**
* <p>Constructs a new <code>XPathExpressionException</code>
* with the specified detail <code>message</code>.</p>
*
* <p>The <code>cause</code> is not initialized.</p>
*
* <p>If <code>message</code> is <code>null</code>,
* then a <code>NullPointerException</code> is thrown.</p>
*
* @param message The detail message.
*
* @throws NullPointerException When <code>message</code> is
* <code>null</code>.
*/
public XPathExpressionException(String message) {
super(message);
}
/**
* <p>Constructs a new <code>XPathExpressionException</code>
* with the specified <code>cause</code>.</p>
*
* <p>If <code>cause</code> is <code>null</code>,
* then a <code>NullPointerException</code> is thrown.</p>
*
* @param cause The cause.
*
* @throws NullPointerException if <code>cause</code> is <code>null</code>.
*/
public XPathExpressionException(Throwable cause) {
super(cause);
}
}

View file

@ -0,0 +1,390 @@
/*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.xpath;
/**
* <p>An <code>XPathFactory</code> instance can be used to create
* {@link javax.xml.xpath.XPath} objects.</p>
*
*<p>See {@link #newInstance(String uri)} for lookup mechanism.</p>
*
* <p>The {@link XPathFactory} class is not thread-safe. In other words,
* it is the application's responsibility to ensure that at most
* one thread is using a {@link XPathFactory} object at any
* given moment. Implementations are encouraged to mark methods
* as <code>synchronized</code> to protect themselves from broken clients.
*
* <p>{@link XPathFactory} is not re-entrant. While one of the
* <code>newInstance</code> methods is being invoked, applications
* may not attempt to recursively invoke a <code>newInstance</code> method,
* even from the same thread.
*
* @author <a href="mailto:Norman.Walsh@Sun.com">Norman Walsh</a>
* @author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a>
*
* @since 1.5
*/
public abstract class XPathFactory {
/**
* <p>The default property name according to the JAXP spec.</p>
*/
public static final String DEFAULT_PROPERTY_NAME = "javax.xml.xpath.XPathFactory";
/**
* <p>Default Object Model URI.</p>
*/
public static final String DEFAULT_OBJECT_MODEL_URI = "http://java.sun.com/jaxp/xpath/dom";
/**
*<p> Take care of restrictions imposed by java security model </p>
*/
private static SecuritySupport ss = new SecuritySupport() ;
/**
* <p>Protected constructor as {@link #newInstance()} or {@link #newInstance(String uri)}
* or {@link #newInstance(String uri, String factoryClassName, ClassLoader classLoader)}
* should be used to create a new instance of an <code>XPathFactory</code>.</p>
*/
protected XPathFactory() {
}
/**
* <p>Get a new <code>XPathFactory</code> instance using the default object model,
* {@link #DEFAULT_OBJECT_MODEL_URI},
* the W3C DOM.</p>
*
* <p>This method is functionally equivalent to:</p>
* <pre>
* newInstance(DEFAULT_OBJECT_MODEL_URI)
* </pre>
*
* <p>Since the implementation for the W3C DOM is always available, this method will never fail.</p>
*
* @return Instance of an <code>XPathFactory</code>.
*
* @throws RuntimeException When there is a failure in creating an
* <code>XPathFactory</code> for the default object model.
*/
public static XPathFactory newInstance() {
try {
return newInstance(DEFAULT_OBJECT_MODEL_URI);
} catch (XPathFactoryConfigurationException xpathFactoryConfigurationException) {
throw new RuntimeException(
"XPathFactory#newInstance() failed to create an XPathFactory for the default object model: "
+ DEFAULT_OBJECT_MODEL_URI
+ " with the XPathFactoryConfigurationException: "
+ xpathFactoryConfigurationException.toString()
);
}
}
/**
* <p>Get a new <code>XPathFactory</code> instance using the specified object model.</p>
*
* <p>To find a <code>XPathFactory</code> object,
* this method looks the following places in the following order where "the class loader" refers to the context class loader:</p>
* <ol>
* <li>
* If the system property {@link #DEFAULT_PROPERTY_NAME} + ":uri" is present,
* where uri is the parameter to this method, then its value is read as a class name.
* The method will try to create a new instance of this class by using the class loader,
* and returns it if it is successfully created.
* </li>
* <li>
* ${java.home}/lib/jaxp.properties is read and the value associated with the key being the system property above is looked for.
* If present, the value is processed just like above.
* </li>
* <li>
* Use the service-provider loading facilities, defined by the
* {@link java.util.ServiceLoader} class, to attempt to locate and load an
* implementation of the service using the {@linkplain
* java.util.ServiceLoader#load(java.lang.Class) default loading mechanism}:
* the service-provider loading facility will use the {@linkplain
* java.lang.Thread#getContextClassLoader() current thread's context class loader}
* to attempt to load the service. If the context class
* loader is null, the {@linkplain
* ClassLoader#getSystemClassLoader() system class loader} will be used.
* <br>
* Each potential service provider is required to implement the method
* {@link #isObjectModelSupported(String objectModel)}.
* The first service provider found that supports the specified object
* model is returned.
* <br>
* In case of {@link java.util.ServiceConfigurationError} an
* {@link XPathFactoryConfigurationException} will be thrown.
* </li>
* <li>
* Platform default <code>XPathFactory</code> is located in a platform specific way.
* There must be a platform default XPathFactory for the W3C DOM, i.e. {@link #DEFAULT_OBJECT_MODEL_URI}.
* </li>
* </ol>
* <p>If everything fails, an <code>XPathFactoryConfigurationException</code> will be thrown.</p>
*
* <p>Tip for Trouble-shooting:</p>
* <p>See {@link java.util.Properties#load(java.io.InputStream)} for exactly how a property file is parsed.
* In particular, colons ':' need to be escaped in a property file, so make sure the URIs are properly escaped in it.
* For example:</p>
* <pre>
* http\://java.sun.com/jaxp/xpath/dom=org.acme.DomXPathFactory
* </pre>
*
* @param uri Identifies the underlying object model.
* The specification only defines the URI {@link #DEFAULT_OBJECT_MODEL_URI},
* <code>http://java.sun.com/jaxp/xpath/dom</code> for the W3C DOM,
* the org.w3c.dom package, and implementations are free to introduce other URIs for other object models.
*
* @return Instance of an <code>XPathFactory</code>.
*
* @throws XPathFactoryConfigurationException If the specified object model
* is unavailable, or if there is a configuration error.
* @throws NullPointerException If <code>uri</code> is <code>null</code>.
* @throws IllegalArgumentException If <code>uri</code> is <code>null</code>
* or <code>uri.length() == 0</code>.
*/
public static XPathFactory newInstance(final String uri)
throws XPathFactoryConfigurationException {
if (uri == null) {
throw new NullPointerException(
"XPathFactory#newInstance(String uri) cannot be called with uri == null");
}
if (uri.length() == 0) {
throw new IllegalArgumentException(
"XPathFactory#newInstance(String uri) cannot be called with uri == \"\"");
}
ClassLoader classLoader = ss.getContextClassLoader();
if (classLoader == null) {
//use the current class loader
classLoader = XPathFactory.class.getClassLoader();
}
XPathFactory xpathFactory = new XPathFactoryFinder(classLoader).newFactory(uri);
if (xpathFactory == null) {
throw new XPathFactoryConfigurationException(
"No XPathFactory implementation found for the object model: "
+ uri);
}
return xpathFactory;
}
/**
* <p>Obtain a new instance of a <code>XPathFactory</code> from a factory class name. <code>XPathFactory</code>
* is returned if specified factory class supports the specified object model.
* This function is useful when there are multiple providers in the classpath.
* It gives more control to the application as it can specify which provider
* should be loaded.</p>
*
*
* <h2>Tip for Trouble-shooting</h2>
* <p>Setting the <code>jaxp.debug</code> system property will cause
* this method to print a lot of debug messages
* to <code>System.err</code> about what it is doing and where it is looking at.</p>
*
* <p> If you have problems try:</p>
* <pre>
* java -Djaxp.debug=1 YourProgram ....
* </pre>
*
* @param uri Identifies the underlying object model. The specification only defines the URI
* {@link #DEFAULT_OBJECT_MODEL_URI},<code>http://java.sun.com/jaxp/xpath/dom</code>
* for the W3C DOM, the org.w3c.dom package, and implementations are free to introduce
* other URIs for other object models.
*
* @param factoryClassName fully qualified factory class name that provides implementation of <code>javax.xml.xpath.XPathFactory</code>.
*
* @param classLoader <code>ClassLoader</code> used to load the factory class. If <code>null</code>
* current <code>Thread</code>'s context classLoader is used to load the factory class.
*
*
* @return New instance of a <code>XPathFactory</code>
*
* @throws XPathFactoryConfigurationException
* if <code>factoryClassName</code> is <code>null</code>, or
* the factory class cannot be loaded, instantiated
* or the factory class does not support the object model specified
* in the <code>uri</code> parameter.
*
* @throws NullPointerException If <code>uri</code> is <code>null</code>.
* @throws IllegalArgumentException If <code>uri</code> is <code>null</code>
* or <code>uri.length() == 0</code>.
*
* @see #newInstance()
* @see #newInstance(String uri)
*
* @since 1.6
*/
public static XPathFactory newInstance(String uri, String factoryClassName, ClassLoader classLoader)
throws XPathFactoryConfigurationException{
ClassLoader cl = classLoader;
if (uri == null) {
throw new NullPointerException(
"XPathFactory#newInstance(String uri) cannot be called with uri == null");
}
if (uri.length() == 0) {
throw new IllegalArgumentException(
"XPathFactory#newInstance(String uri) cannot be called with uri == \"\"");
}
if (cl == null) {
cl = ss.getContextClassLoader();
}
XPathFactory f = new XPathFactoryFinder(cl).createInstance(factoryClassName);
if (f == null) {
throw new XPathFactoryConfigurationException(
"No XPathFactory implementation found for the object model: "
+ uri);
}
//if this factory supports the given schemalanguage return this factory else thrown exception
if (f.isObjectModelSupported(uri)) {
return f;
} else {
throw new XPathFactoryConfigurationException("Factory "
+ factoryClassName + " doesn't support given " + uri
+ " object model");
}
}
/**
* <p>Is specified object model supported by this <code>XPathFactory</code>?</p>
*
* @param objectModel Specifies the object model which the returned <code>XPathFactory</code> will understand.
*
* @return <code>true</code> if <code>XPathFactory</code> supports <code>objectModel</code>, else <code>false</code>.
*
* @throws NullPointerException If <code>objectModel</code> is <code>null</code>.
* @throws IllegalArgumentException If <code>objectModel.length() == 0</code>.
*/
public abstract boolean isObjectModelSupported(String objectModel);
/**
* <p>Set a feature for this <code>XPathFactory</code> and
* <code>XPath</code>s created by this factory.</p>
*
* <p>
* Feature names are fully qualified {@link java.net.URI}s.
* Implementations may define their own features.
* An {@link XPathFactoryConfigurationException} is thrown if this
* <code>XPathFactory</code> or the <code>XPath</code>s
* it creates cannot support the feature.
* It is possible for an <code>XPathFactory</code> to expose a feature value
* but be unable to change its state.
* </p>
*
* <p>
* All implementations are required to support the {@link javax.xml.XMLConstants#FEATURE_SECURE_PROCESSING} feature.
* When the feature is <code>true</code>, any reference to an external function is an error.
* Under these conditions, the implementation must not call the {@link XPathFunctionResolver}
* and must throw an {@link XPathFunctionException}.
* </p>
*
* @param name Feature name.
* @param value Is feature state <code>true</code> or <code>false</code>.
*
* @throws XPathFactoryConfigurationException if this <code>XPathFactory</code> or the <code>XPath</code>s
* it creates cannot support this feature.
* @throws NullPointerException if <code>name</code> is <code>null</code>.
*/
public abstract void setFeature(String name, boolean value)
throws XPathFactoryConfigurationException;
/**
* <p>Get the state of the named feature.</p>
*
* <p>
* Feature names are fully qualified {@link java.net.URI}s.
* Implementations may define their own features.
* An {@link XPathFactoryConfigurationException} is thrown if this
* <code>XPathFactory</code> or the <code>XPath</code>s
* it creates cannot support the feature.
* It is possible for an <code>XPathFactory</code> to expose a feature value
* but be unable to change its state.
* </p>
*
* @param name Feature name.
*
* @return State of the named feature.
*
* @throws XPathFactoryConfigurationException if this
* <code>XPathFactory</code> or the <code>XPath</code>s
* it creates cannot support this feature.
* @throws NullPointerException if <code>name</code> is <code>null</code>.
*/
public abstract boolean getFeature(String name)
throws XPathFactoryConfigurationException;
/**
* <p>Establish a default variable resolver.</p>
*
* <p>Any <code>XPath</code> objects constructed from this factory will use
* the specified resolver by default.</p>
*
* <p>A <code>NullPointerException</code> is thrown if <code>resolver</code>
* is <code>null</code>.</p>
*
* @param resolver Variable resolver.
*
* @throws NullPointerException If <code>resolver</code> is
* <code>null</code>.
*/
public abstract void setXPathVariableResolver(XPathVariableResolver resolver);
/**
* <p>Establish a default function resolver.</p>
*
* <p>Any <code>XPath</code> objects constructed from this factory will
* use the specified resolver by default.</p>
*
* <p>A <code>NullPointerException</code> is thrown if
* <code>resolver</code> is <code>null</code>.</p>
*
* @param resolver XPath function resolver.
*
* @throws NullPointerException If <code>resolver</code> is
* <code>null</code>.
*/
public abstract void setXPathFunctionResolver(XPathFunctionResolver resolver);
/**
* <p>Return a new <code>XPath</code> using the underlying object
* model determined when the <code>XPathFactory</code> was instantiated.</p>
*
* @return New instance of an <code>XPath</code>.
*/
public abstract XPath newXPath();
}

View file

@ -0,0 +1,73 @@
/*
* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.xpath;
/**
* <code>XPathFactoryConfigurationException</code> represents a configuration error in a <code>XPathFactory</code> environment.</p>
*
* @author <a href="mailto:Norman.Walsh@Sun.com">Norman Walsh</a>
* @author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a>
* @since 1.5
*/
public class XPathFactoryConfigurationException extends XPathException {
/**
* <p>Stream Unique Identifier.</p>
*/
private static final long serialVersionUID = -1837080260374986980L;
/**
* <p>Constructs a new <code>XPathFactoryConfigurationException</code> with the specified detail <code>message</code>.</p>
*
* <p>The <code>cause</code> is not initialized.</p>
*
* <p>If <code>message</code> is <code>null</code>,
* then a <code>NullPointerException</code> is thrown.</p>
*
* @param message The detail message.
*
* @throws NullPointerException When <code>message</code> is
* <code>null</code>.
*/
public XPathFactoryConfigurationException(String message) {
super(message);
}
/**
* <p>Constructs a new <code>XPathFactoryConfigurationException</code>
* with the specified <code>cause</code>.</p>
*
* <p>If <code>cause</code> is <code>null</code>,
* then a <code>NullPointerException</code> is thrown.</p>
*
* @param cause The cause.
*
* @throws NullPointerException if <code>cause</code> is <code>null</code>.
*/
public XPathFactoryConfigurationException(Throwable cause) {
super(cause);
}
}

View file

@ -0,0 +1,443 @@
/*
* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.xpath;
import java.io.File;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.URL;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Properties;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
/**
* Implementation of {@link XPathFactory#newInstance(String)}.
*
* @author <a href="Kohsuke.Kawaguchi@Sun.com">Kohsuke Kawaguchi</a>
* @since 1.5
*/
class XPathFactoryFinder {
private static final String DEFAULT_PACKAGE = "com.sun.org.apache.xpath.internal";
private static final SecuritySupport ss = new SecuritySupport() ;
/** debug support code. */
private static boolean debug = false;
static {
// Use try/catch block to support applets
try {
debug = ss.getSystemProperty("jaxp.debug") != null;
} catch (Exception unused) {
debug = false;
}
}
/**
* <p>Cache properties for performance.</p>
*/
private static final Properties cacheProps = new Properties();
/**
* <p>First time requires initialization overhead.</p>
*/
private volatile static boolean firstTime = true;
/**
* <p>Conditional debug printing.</p>
*
* @param msg to print
*/
private static void debugPrintln(String msg) {
if (debug) {
System.err.println("JAXP: " + msg);
}
}
/**
* <p><code>ClassLoader</code> to use to find <code>XPathFactory</code>.</p>
*/
private final ClassLoader classLoader;
/**
* <p>Constructor that specifies <code>ClassLoader</code> to use
* to find <code>XPathFactory</code>.</p>
*
* @param loader
* to be used to load resource and {@link XPathFactory}
* implementations during the resolution process.
* If this parameter is null, the default system class loader
* will be used.
*/
public XPathFactoryFinder(ClassLoader loader) {
this.classLoader = loader;
if( debug ) {
debugDisplayClassLoader();
}
}
private void debugDisplayClassLoader() {
try {
if( classLoader == ss.getContextClassLoader() ) {
debugPrintln("using thread context class loader ("+classLoader+") for search");
return;
}
} catch( Throwable unused ) {
// getContextClassLoader() undefined in JDK1.1
}
if( classLoader==ClassLoader.getSystemClassLoader() ) {
debugPrintln("using system class loader ("+classLoader+") for search");
return;
}
debugPrintln("using class loader ("+classLoader+") for search");
}
/**
* <p>Creates a new {@link XPathFactory} object for the specified
* object model.</p>
*
* @param uri
* Identifies the underlying object model.
*
* @return <code>null</code> if the callee fails to create one.
*
* @throws NullPointerException
* If the parameter is null.
*/
public XPathFactory newFactory(String uri) throws XPathFactoryConfigurationException {
if (uri == null) {
throw new NullPointerException();
}
XPathFactory f = _newFactory(uri);
if (f != null) {
debugPrintln("factory '" + f.getClass().getName() + "' was found for " + uri);
} else {
debugPrintln("unable to find a factory for " + uri);
}
return f;
}
/**
* <p>Lookup a {@link XPathFactory} for the given object model.</p>
*
* @param uri identifies the object model.
*
* @return {@link XPathFactory} for the given object model.
*/
private XPathFactory _newFactory(String uri) throws XPathFactoryConfigurationException {
XPathFactory xpathFactory = null;
String propertyName = SERVICE_CLASS.getName() + ":" + uri;
// system property look up
try {
debugPrintln("Looking up system property '"+propertyName+"'" );
String r = ss.getSystemProperty(propertyName);
if(r!=null) {
debugPrintln("The value is '"+r+"'");
xpathFactory = createInstance(r, true);
if (xpathFactory != null) {
return xpathFactory;
}
} else
debugPrintln("The property is undefined.");
} catch( Throwable t ) {
if( debug ) {
debugPrintln("failed to look up system property '"+propertyName+"'" );
t.printStackTrace();
}
}
String javah = ss.getSystemProperty( "java.home" );
String configFile = javah + File.separator +
"lib" + File.separator + "jaxp.properties";
// try to read from $java.home/lib/jaxp.properties
try {
if(firstTime){
synchronized(cacheProps){
if(firstTime){
File f=new File( configFile );
firstTime = false;
if(ss.doesFileExist(f)){
debugPrintln("Read properties file " + f);
cacheProps.load(ss.getFileInputStream(f));
}
}
}
}
final String factoryClassName = cacheProps.getProperty(propertyName);
debugPrintln("found " + factoryClassName + " in $java.home/jaxp.properties");
if (factoryClassName != null) {
xpathFactory = createInstance(factoryClassName, true);
if(xpathFactory != null){
return xpathFactory;
}
}
} catch (Exception ex) {
if (debug) {
ex.printStackTrace();
}
}
// Try with ServiceLoader
assert xpathFactory == null;
xpathFactory = findServiceProvider(uri);
// The following assertion should always be true.
// Uncomment it, recompile, and run with -ea in case of doubts:
// assert xpathFactory == null || xpathFactory.isObjectModelSupported(uri);
if (xpathFactory != null) {
return xpathFactory;
}
// platform default
if(uri.equals(XPathFactory.DEFAULT_OBJECT_MODEL_URI)) {
debugPrintln("attempting to use the platform default W3C DOM XPath lib");
return createInstance("com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl", true);
}
debugPrintln("all things were tried, but none was found. bailing out.");
return null;
}
/** <p>Create class using appropriate ClassLoader.</p>
*
* @param className Name of class to create.
* @return Created class or <code>null</code>.
*/
private Class<?> createClass(String className) {
Class clazz;
// make sure we have access to restricted packages
boolean internal = false;
if (System.getSecurityManager() != null) {
if (className != null && className.startsWith(DEFAULT_PACKAGE)) {
internal = true;
}
}
// use approprite ClassLoader
try {
if (classLoader != null && !internal) {
clazz = Class.forName(className, false, classLoader);
} else {
clazz = Class.forName(className);
}
} catch (Throwable t) {
if(debug) {
t.printStackTrace();
}
return null;
}
return clazz;
}
/**
* <p>Creates an instance of the specified and returns it.</p>
*
* @param className
* fully qualified class name to be instantiated.
*
* @return null
* if it fails. Error messages will be printed by this method.
*/
XPathFactory createInstance( String className )
throws XPathFactoryConfigurationException
{
return createInstance( className, false );
}
XPathFactory createInstance( String className, boolean useServicesMechanism )
throws XPathFactoryConfigurationException
{
XPathFactory xPathFactory = null;
debugPrintln("createInstance(" + className + ")");
// get Class from className
Class<?> clazz = createClass(className);
if (clazz == null) {
debugPrintln("failed to getClass(" + className + ")");
return null;
}
debugPrintln("loaded " + className + " from " + which(clazz));
// instantiate Class as a XPathFactory
try {
if (!useServicesMechanism) {
xPathFactory = newInstanceNoServiceLoader(clazz);
}
if (xPathFactory == null) {
xPathFactory = (XPathFactory) clazz.newInstance();
}
} catch (ClassCastException classCastException) {
debugPrintln("could not instantiate " + clazz.getName());
if (debug) {
classCastException.printStackTrace();
}
return null;
} catch (IllegalAccessException illegalAccessException) {
debugPrintln("could not instantiate " + clazz.getName());
if (debug) {
illegalAccessException.printStackTrace();
}
return null;
} catch (InstantiationException instantiationException) {
debugPrintln("could not instantiate " + clazz.getName());
if (debug) {
instantiationException.printStackTrace();
}
return null;
}
return xPathFactory;
}
/**
* Try to construct using newXPathFactoryNoServiceLoader
* method if available.
*/
private static XPathFactory newInstanceNoServiceLoader(
Class<?> providerClass
) throws XPathFactoryConfigurationException {
// Retain maximum compatibility if no security manager.
if (System.getSecurityManager() == null) {
return null;
}
try {
Method creationMethod =
providerClass.getDeclaredMethod(
"newXPathFactoryNoServiceLoader"
);
final int modifiers = creationMethod.getModifiers();
// Do not call "newXPathFactoryNoServiceLoader" if it's
// not public static.
if (!Modifier.isStatic(modifiers) || !Modifier.isPublic(modifiers)) {
return null;
}
// Only calls "newXPathFactoryNoServiceLoader" if it's
// declared to return an instance of XPathFactory.
final Class<?> returnType = creationMethod.getReturnType();
if (SERVICE_CLASS.isAssignableFrom(returnType)) {
return SERVICE_CLASS.cast(creationMethod.invoke(null, (Object[])null));
} else {
// Should not happen since
// XPathFactoryImpl.newXPathFactoryNoServiceLoader is
// declared to return XPathFactory.
throw new ClassCastException(returnType
+ " cannot be cast to " + SERVICE_CLASS);
}
} catch (ClassCastException e) {
throw new XPathFactoryConfigurationException(e);
} catch (NoSuchMethodException exc) {
return null;
} catch (Exception exc) {
return null;
}
}
// Call isObjectModelSupportedBy with initial context.
private boolean isObjectModelSupportedBy(final XPathFactory factory,
final String objectModel,
AccessControlContext acc) {
return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
public Boolean run() {
return factory.isObjectModelSupported(objectModel);
}
}, acc);
}
/**
* Finds a service provider subclass of XPathFactory that supports the
* given object model using the ServiceLoader.
*
* @param objectModel URI of object model to support.
* @return An XPathFactory supporting the specified object model, or null
* if none is found.
* @throws XPathFactoryConfigurationException if a configuration error is found.
*/
private XPathFactory findServiceProvider(final String objectModel)
throws XPathFactoryConfigurationException {
assert objectModel != null;
// store current context.
final AccessControlContext acc = AccessController.getContext();
try {
return AccessController.doPrivileged(new PrivilegedAction<XPathFactory>() {
public XPathFactory run() {
final ServiceLoader<XPathFactory> loader =
ServiceLoader.load(SERVICE_CLASS);
for (XPathFactory factory : loader) {
// restore initial context to call
// factory.isObjectModelSupportedBy
if (isObjectModelSupportedBy(factory, objectModel, acc)) {
return factory;
}
}
return null; // no factory found.
}
});
} catch (ServiceConfigurationError error) {
throw new XPathFactoryConfigurationException(error);
}
}
private static final Class<XPathFactory> SERVICE_CLASS = XPathFactory.class;
private static String which( Class clazz ) {
return which( clazz.getName(), clazz.getClassLoader() );
}
/**
* <p>Search the specified classloader for the given classname.</p>
*
* @param classname the fully qualified name of the class to search for
* @param loader the classloader to search
*
* @return the source location of the resource, or null if it wasn't found
*/
private static String which(String classname, ClassLoader loader) {
String classnameAsResource = classname.replace('.', '/') + ".class";
if( loader==null ) loader = ClassLoader.getSystemClassLoader();
//URL it = loader.getResource(classnameAsResource);
URL it = ss.getResourceAsURL(loader, classnameAsResource);
if (it != null) {
return it.toString();
} else {
return null;
}
}
}

View file

@ -0,0 +1,56 @@
/*
* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.xpath;
import java.util.List;
/**
* <p><code>XPathFunction</code> provides access to XPath functions.</p>
*
* <p>Functions are identified by QName and arity in XPath.</p>
*
* @author <a href="mailto:Norman.Walsh@Sun.com">Norman Walsh</a>
* @author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a>
* @since 1.5
*/
public interface XPathFunction {
/**
* <p>Evaluate the function with the specified arguments.</p>
*
* <p>To the greatest extent possible, side-effects should be avoided in the
* definition of extension functions. The implementation evaluating an
* XPath expression is under no obligation to call extension functions in
* any particular order or any particular number of times.</p>
*
* @param args The arguments, <code>null</code> is a valid value.
*
* @return The result of evaluating the <code>XPath</code> function as an <code>Object</code>.
*
* @throws XPathFunctionException If <code>args</code> cannot be evaluated with this <code>XPath</code> function.
*/
public Object evaluate(List args)
throws XPathFunctionException;
}

View file

@ -0,0 +1,72 @@
/*
* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.xpath;
/**
* <code>XPathFunctionException</code> represents an error with an XPath function.</p>
*
* @author <a href="mailto:Norman.Walsh@Sun.com">Norman Walsh</a>
* @author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a>
* @since 1.5
*/
public class XPathFunctionException extends XPathExpressionException {
/**
* <p>Stream Unique Identifier.</p>
*/
private static final long serialVersionUID = -1837080260374986980L;
/**
* <p>Constructs a new <code>XPathFunctionException</code> with the specified detail <code>message</code>.</p>
*
* <p>The <code>cause</code> is not initialized.</p>
*
* <p>If <code>message</code> is <code>null</code>,
* then a <code>NullPointerException</code> is thrown.</p>
*
* @param message The detail message.
*
* @throws NullPointerException When <code>message</code> is
* <code>null</code>.
*/
public XPathFunctionException(String message) {
super(message);
}
/**
* <p>Constructs a new <code>XPathFunctionException</code> with the specified <code>cause</code>.</p>
*
* <p>If <code>cause</code> is <code>null</code>,
* then a <code>NullPointerException</code> is thrown.</p>
*
* @param cause The cause.
*
* @throws NullPointerException if <code>cause</code> is <code>null</code>.
*/
public XPathFunctionException(Throwable cause) {
super(cause);
}
}

View file

@ -0,0 +1,66 @@
/*
* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.xpath;
import javax.xml.namespace.QName;
/**
* <p><code>XPathFunctionResolver</code> provides access to the set of user defined <code>XPathFunction</code>s.</p>
*
* <p>XPath functions are resolved by name and arity.
* The resolver is not needed for XPath built-in functions and the resolver
* <strong><em>cannot</em></strong> be used to override those functions.</p>
*
* <p>In particular, the resolver is only called for functions in an another
* namespace (functions with an explicit prefix). This means that you cannot
* use the <code>XPathFunctionResolver</code> to implement specifications
* like <a href="http://www.w3.org/TR/xmldsig-core/">XML-Signature Syntax
* and Processing</a> which extend the function library of XPath 1.0 in the
* same namespace. This is a consequence of the design of the resolver.</p>
*
* <p>If you wish to implement additional built-in functions, you will have to
* extend the underlying implementation directly.</p>
*
* @author <a href="mailto:Norman.Walsh@Sun.com">Norman Walsh</a>
* @author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a>
* @see <a href="http://www.w3.org/TR/xpath#corelib">XML Path Language (XPath) Version 1.0, Core Function Library</a>
* @since 1.5
*/
public interface XPathFunctionResolver {
/**
* <p>Find a function in the set of available functions.</p>
*
* <p>If <code>functionName</code> or <code>arity</code> is <code>null</code>, then a <code>NullPointerException</code> is thrown.</p>
*
* @param functionName The function name.
* @param arity The number of arguments that the returned function must accept.
*
* @return The function or <code>null</code> if no function named <code>functionName</code> with <code>arity</code> arguments exists.
*
* @throws NullPointerException If <code>functionName</code> or <code>arity</code> is <code>null</code>.
*/
public XPathFunction resolveFunction(QName functionName, int arity);
}

View file

@ -0,0 +1,58 @@
/*
* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.xpath;
import javax.xml.namespace.QName;
/**
* <p><code>XPathVariableResolver</code> provides access to the set of user defined XPath variables.</p>
*
* <p>The <code>XPathVariableResolver</code> and the XPath evaluator must adhere to a contract that
* cannot be directly enforced by the API. Although variables may be mutable,
* that is, an application may wish to evaluate the same XPath expression more
* than once with different variable values, in the course of evaluating any
* single XPath expression, a variable's value <strong><em>must</em></strong>
* not change.</p>
*
* @author <a href="mailto:Norman.Walsh@Sun.com">Norman Walsh</a>
* @author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a>
* @since 1.5
*/
public interface XPathVariableResolver {
/**
* <p>Find a variable in the set of available variables.</p>
*
* <p>If <code>variableName</code> is <code>null</code>, then a <code>NullPointerException</code> is thrown.</p>
*
* @param variableName The <code>QName</code> of the variable name.
*
* @return The variables value, or <code>null</code> if no variable named <code>variableName</code>
* exists. The value returned must be of a type appropriate for the underlying object model.
*
* @throws NullPointerException If <code>variableName</code> is <code>null</code>.
*/
public Object resolveVariable(QName variableName);
}

View file

@ -0,0 +1,281 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>javax.xml.xpath</title>
<meta name="@author" content="mailto:Ben@galbraiths.org" />
<meta name="@author" content="mailto:Norman.Walsh@Sun.com" />
<meta name="@author" content="mailto:Jeff.Suttor@Sun.com" />
<meta name="@see" content="http://www.w3.org/TR/xpath" />
<meta name="@since" content="1.5" />
</head>
<body>
<p>This package provides an <em>object-model neutral</em> API for the
evaluation of XPath expressions and access to the evaluation
environment.
</p>
<p>The following XML standards apply:</p>
<ul>
<li><a href="http://www.w3.org/TR/xpath">XML Path Language (XPath) Version 1.0</a></li>
</ul>
<hr />
<h2>XPath Overview</h2>
<p>The XPath language provides a simple, concise syntax for selecting
nodes from an XML document. XPath also provides rules for converting a
node in an XML document object model (DOM) tree to a boolean, double,
or string value. XPath is a W3C-defined language and an official W3C
recommendation; the W3C hosts the XML Path Language (XPath) Version
1.0 specification.
</p>
<p>XPath started in life in 1999 as a supplement to the XSLT and
XPointer languages, but has more recently become popular as a
stand-alone language, as a single XPath expression can be used to
replace many lines of DOM API code.
</p>
<h3>XPath Expressions</h3>
<p>An XPath <em>expression</em> is composed of a <em>location
path</em> and one or more optional <em>predicates</em>. Expressions
may also include XPath variables.
</p>
<p>The following is an example of a simple XPath expression:</p>
<pre>
/foo/bar
</pre>
<p>This example would select the <code>&lt;bar&gt;</code> element in
an XML document such as the following:</p>
<pre>
&lt;foo&gt;
&lt;bar/&gt;
&lt;/foo&gt;
</pre>
<p>The expression <code>/foo/bar</code> is an example of a location
path. While XPath location paths resemble Unix-style file system
paths, an important distinction is that XPath expressions return
<em>all</em> nodes that match the expression. Thus, all three
<code>&lt;bar&gt;</code> elements in the following document would be
selected by the <code>/foo/bar</code> expression:</p>
<pre>
&lt;foo&gt;
&lt;bar/&gt;
&lt;bar/&gt;
&lt;bar/&gt;
&lt;/foo&gt;
</pre>
<p>A special location path operator, <code>//</code>, selects nodes at
any depth in an XML document. The following example selects all
<code>&lt;bar&gt;</code> elements regardless of their location in a
document:</p>
<pre>
//bar
</pre>
<p>A wildcard operator, *, causes all element nodes to be selected.
The following example selects all children elements of a
<code>&lt;foo&gt;</code> element:</p>
<pre>
/foo/*
</pre>
<p>In addition to element nodes, XPath location paths may also address
attribute nodes, text nodes, comment nodes, and processing instruction
nodes. The following table gives examples of location paths for each
of these node types:</p>
<table border="1">
<tr>
<td>Location Path</td>
<td>Description</td>
</tr>
<tr>
<td>
<code>/foo/bar/<strong>@id</strong></code>
</td>
<td>Selects the attribute <code>id</code> of the <code>&lt;bar&gt;</code> element
</td>
</tr>
<tr>
<td><code>/foo/bar/<strong>text()</strong></code>
</td>
<td>Selects the text nodes of the <code>&lt;bar&gt;</code> element. No
distinction is made between escaped and non-escaped character data.
</td>
</tr>
<tr>
<td><code>/foo/bar/<strong>comment()</strong></code>
</td>
<td>Selects all comment nodes contained in the <code>&lt;bar&gt;</code> element.
</td>
</tr>
<tr>
<td><code>/foo/bar/<strong>processing-instruction()</strong></code>
</td>
<td>Selects all processing-instruction nodes contained in the
<code>&lt;bar&gt;</code> element.
</td>
</tr>
</table>
<p>Predicates allow for refining the nodes selected by an XPath
location path. Predicates are of the form
<code>[<em>expression</em>]</code>. The following example selects all
<code>&lt;foo&gt;</code> elements that contain an <code>include</code>
attribute with the value of <code>true</code>:</p>
<pre>
//foo[@include='true']
</pre>
<p>Predicates may be appended to each other to further refine an
expression, such as:</p>
<pre>
//foo[@include='true'][@mode='bar']
</pre>
<h3>Using the XPath API</h3>
<p>
The following example demonstrates using the XPath API to select one
or more nodes from an XML document:</p>
<pre>
XPath xpath = XPathFactory.newInstance().newXPath();
String expression = "/widgets/widget";
InputSource inputSource = new InputSource("widgets.xml");
NodeList nodes = (NodeList) xpath.evaluate(expression, inputSource, XPathConstants.NODESET);
</pre>
<h3>XPath Expressions and Types</h3>
<p>While XPath expressions select nodes in the XML document, the XPath
API allows the selected nodes to be coalesced into one of the
following other data types:</p>
<ul>
<li><code>Boolean</code></li>
<li><code>Number</code></li>
<li><code>String</code></li>
</ul>
<p>The desired return type is specified by a {@link
javax.xml.namespace.QName} parameter in method call used to evaluate
the expression, which is either a call to
<code>XPathExpression.evalute(...)</code> or to one of the
<code>XPath.evaluate(...)</code> convenience methods. The allowed
QName values are specified as constants in the {@link
javax.xml.xpath.XPathConstants} class; they are:</p>
<ul>
<li>{@link javax.xml.xpath.XPathConstants#NODESET}</li>
<li>{@link javax.xml.xpath.XPathConstants#NODE}</li>
<li>{@link javax.xml.xpath.XPathConstants#STRING}</li>
<li>{@link javax.xml.xpath.XPathConstants#BOOLEAN}</li>
<li>{@link javax.xml.xpath.XPathConstants#NUMBER}</li>
</ul>
<p>When a <code>Boolean</code> return type is requested,
<code>Boolean.TRUE</code> is returned if one or more nodes were
selected; otherwise, <code>Boolean.FALSE</code> is returned.</p>
<p>The <code>String</code> return type is a convenience for retrieving
the character data from a text node, attribute node, comment node, or
processing-instruction node. When used on an element node, the value
of the child text nodes is returned.
</p>
<p>The <code>Number</code> return type attempts to coalesce the text
of a node to a <code>double</code> data type.
</p>
<h3>XPath Context</h3>
<p>XPath location paths may be relative to a particular node in the
document, known as the <code>context</code>. Consider the following
XML document:</p>
<pre>
&lt;widgets&gt;
&lt;widget&gt;
&lt;manufacturer/&gt;
&lt;dimensions/&gt;
&lt;/widget&gt;
&lt;/widgets&gt;
</pre>
<p>The <code>&lt;widget&gt;</code> element can be selected with the
following XPath API code:</p>
<pre>
// parse the XML as a W3C Document
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = builder.parse(new File("/widgets.xml"));
XPath xpath = XPathFactory.newInstance().newXPath();
String expression = "/widgets/widget";
Node widgetNode = (Node) xpath.evaluate(expression, document, XPathConstants.NODE);
</pre>
<p>With a reference to the <code>&lt;widget&gt;</code> element, a
relative XPath expression can now written to select the
<code>&lt;manufacturer&gt;</code> child element:</p>
<pre>
XPath xpath = XPathFactory.newInstance().newXPath();
<strong>String expression = "manufacturer";</strong>
Node manufacturerNode = (Node) xpath.evaluate(expression, <strong>widgetNode</strong>, XPathConstants.NODE);
</pre>
<ul>
<li>Author <a href="mailto:Ben@galbraiths.org">Ben Galbraith</a></li>
<li>Author <a href="mailto:Norman.Walsh@Sun.com">Norman Walsh</a></li>
<li>Author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a></li>
<li>See <a href="http://www.w3.org/TR/xpath">XML Path Language (XPath) Version 1.0</a></li>
<li>Since 1.5</li>
</ul>
</body>
</html>