jaxp/src/share/classes/javax/xml/xpath/XPathFactory.java
author ohair
Mon, 14 Apr 2008 14:52:27 -0700
changeset 311 3c14f21bf3f7
parent 6 7f561c08de6b
permissions -rw-r--r--
6484686: The next directory looks like it is no longer part of the build (deploy makefiles) Summary: Getting rid of the _OUTPUTDIR settings. Using BUILD_PARENT_DIRECTORY instead. This solves problems with the "/build/windows-i586*" paths getting mangled on Windows builds (fastdebug builds in particular). Reviewed-by: tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * Copyright 2003-2006 Sun Microsystems, Inc.  All Rights Reserved.
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
 * have any questions.
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
package javax.xml.xpath;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
 * <p>An <code>XPathFactory</code> instance can be used to create
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
 * {@link javax.xml.xpath.XPath} objects.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
 *<p>See {@link #newInstance(String uri)} for lookup mechanism.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
 * <p>The {@link XPathFactory} class is not thread-safe. In other words,
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
 * it is the application's responsibility to ensure that at most
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
 * one thread is using a {@link XPathFactory} object at any
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 * given moment. Implementations are encouraged to mark methods
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
 * as <code>synchronized</code> to protect themselves from broken clients.
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
 * <p>{@link XPathFactory} is not re-entrant. While one of the
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 * <code>newInstance</code> methods is being invoked, applications
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 * may not attempt to recursively invoke a <code>newInstance</code> method,
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
 * even from the same thread.
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
 * @author  <a href="mailto:Norman.Walsh@Sun.com">Norman Walsh</a>
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
 * @author  <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a>
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
 * @since 1.5
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
public abstract class XPathFactory {
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
     * <p>The default property name according to the JAXP spec.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
    public static final String DEFAULT_PROPERTY_NAME = "javax.xml.xpath.XPathFactory";
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
     * <p>Default Object Model URI.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
    public static final String DEFAULT_OBJECT_MODEL_URI = "http://java.sun.com/jaxp/xpath/dom";
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
     *<p> Take care of restrictions imposed by java security model </p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
    private static SecuritySupport ss = new SecuritySupport() ;
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
     * <p>Protected constructor as {@link #newInstance()} or {@link #newInstance(String uri)}
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
     * or {@link #newInstance(String uri, String factoryClassName, ClassLoader classLoader)}
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
     * should be used to create a new instance of an <code>XPathFactory</code>.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
    protected XPathFactory() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
     * <p>Get a new <code>XPathFactory</code> instance using the default object model,
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
     * {@link #DEFAULT_OBJECT_MODEL_URI},
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
     * the W3C DOM.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
     * <p>This method is functionally equivalent to:</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
     * <pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
     *   newInstance(DEFAULT_OBJECT_MODEL_URI)
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
     * </pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
     * <p>Since the implementation for the W3C DOM is always available, this method will never fail.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
     * @return Instance of an <code>XPathFactory</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
     * @throws RuntimeException When there is a failure in creating an
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
     *   <code>XPathFactory</code> for the default object model.
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
    public static final XPathFactory newInstance() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
                return newInstance(DEFAULT_OBJECT_MODEL_URI);
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
        } catch (XPathFactoryConfigurationException xpathFactoryConfigurationException) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
                throw new RuntimeException(
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
                        "XPathFactory#newInstance() failed to create an XPathFactory for the default object model: "
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
                        + DEFAULT_OBJECT_MODEL_URI
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
                        + " with the XPathFactoryConfigurationException: "
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
                        + xpathFactoryConfigurationException.toString()
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
                );
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
    * <p>Get a new <code>XPathFactory</code> instance using the specified object model.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
    *
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
    * <p>To find a <code>XPathFactory</code> object,
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
    * this method looks the following places in the following order where "the class loader" refers to the context class loader:</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
    * <ol>
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
    *   <li>
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
    *     If the system property {@link #DEFAULT_PROPERTY_NAME} + ":uri" is present,
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
    *     where uri is the parameter to this method, then its value is read as a class name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
    *     The method will try to create a new instance of this class by using the class loader,
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
    *     and returns it if it is successfully created.
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
    *   </li>
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
    *   <li>
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
    *     ${java.home}/lib/jaxp.properties is read and the value associated with the key being the system property above is looked for.
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
    *     If present, the value is processed just like above.
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
    *   </li>
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
    *   <li>
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
    *     The class loader is asked for service provider provider-configuration files matching <code>javax.xml.xpath.XPathFactory</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
    *     in the resource directory META-INF/services.
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
    *     See the JAR File Specification for file format and parsing rules.
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
    *     Each potential service provider is required to implement the method:
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
    *     <pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
    *       {@link #isObjectModelSupported(String objectModel)}
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
    *     </pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
    *     The first service provider found in class loader order that supports the specified object model is returned.
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
    *   </li>
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
    *   <li>
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
    *     Platform default <code>XPathFactory</code> is located in a platform specific way.
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
    *     There must be a platform default XPathFactory for the W3C DOM, i.e. {@link #DEFAULT_OBJECT_MODEL_URI}.
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
    *   </li>
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
    * </ol>
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
    * <p>If everything fails, an <code>XPathFactoryConfigurationException</code> will be thrown.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
    *
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
    * <p>Tip for Trouble-shooting:</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
    * <p>See {@link java.util.Properties#load(java.io.InputStream)} for exactly how a property file is parsed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
    * In particular, colons ':' need to be escaped in a property file, so make sure the URIs are properly escaped in it.
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
    * For example:</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
    * <pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
    *   http\://java.sun.com/jaxp/xpath/dom=org.acme.DomXPathFactory
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
    * </pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
    *
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
    * @param uri Identifies the underlying object model.
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
    *   The specification only defines the URI {@link #DEFAULT_OBJECT_MODEL_URI},
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
    *   <code>http://java.sun.com/jaxp/xpath/dom</code> for the W3C DOM,
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
    *   the org.w3c.dom package, and implementations are free to introduce other URIs for other object models.
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
    *
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
    * @return Instance of an <code>XPathFactory</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
    *
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
    * @throws XPathFactoryConfigurationException If the specified object model is unavailable.
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
    * @throws NullPointerException If <code>uri</code> is <code>null</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
        * @throws IllegalArgumentException If <code>uri</code> is <code>null</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
    *   or <code>uri.length() == 0</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
    */
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
    public static final XPathFactory newInstance(final String uri)
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
        throws XPathFactoryConfigurationException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
        if (uri == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
                throw new NullPointerException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
                        "XPathFactory#newInstance(String uri) cannot be called with uri == null"
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
                );
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
                if (uri.length() == 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
                        throw new IllegalArgumentException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
                                "XPathFactory#newInstance(String uri) cannot be called with uri == \"\""
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
                        );
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
                ClassLoader classLoader = ss.getContextClassLoader();
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
        if (classLoader == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
            //use the current class loader
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
            classLoader = XPathFactory.class.getClassLoader();
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
                XPathFactory xpathFactory = new XPathFactoryFinder(classLoader).newFactory(uri);
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
                if (xpathFactory == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
                        throw new XPathFactoryConfigurationException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
                                "No XPathFactory implementation found for the object model: "
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
                                + uri
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
                        );
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
                return xpathFactory;
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
     * <p>Obtain a new instance of a <code>XPathFactory</code> from a factory class name. <code>XPathFactory</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
     * is returned if specified factory class supports the specified object model.
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
     * This function is useful when there are multiple providers in the classpath.
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
     * It gives more control to the application as it can specify which provider
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
     * should be loaded.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
     * <h2>Tip for Trouble-shooting</h2>
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
     * <p>Setting the <code>jaxp.debug</code> system property will cause
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
     * this method to print a lot of debug messages
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
     * to <code>System.err</code> about what it is doing and where it is looking at.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
     * <p> If you have problems try:</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
     * <pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
     * java -Djaxp.debug=1 YourProgram ....
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
     * </pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
     * @param uri         Identifies the underlying object model. The specification only defines the URI
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
     *                    {@link #DEFAULT_OBJECT_MODEL_URI},<code>http://java.sun.com/jaxp/xpath/dom</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
     *                    for the W3C DOM, the org.w3c.dom package, and implementations are free to introduce
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
     *                    other URIs for other object models.
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
     * @param factoryClassName fully qualified factory class name that provides implementation of <code>javax.xml.xpath.XPathFactory</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
     * @param classLoader <code>ClassLoader</code> used to load the factory class. If <code>null</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
     *                     current <code>Thread</code>'s context classLoader is used to load the factory class.
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
     * @return New instance of a <code>XPathFactory</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
     * @throws XPathFactoryConfigurationException
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
     *                   if <code>factoryClassName</code> is <code>null</code>, or
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
     *                   the factory class cannot be loaded, instantiated
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
     *                   or the factory class does not support the object model specified
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
     *                   in the <code>uri</code> parameter.
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
     * @throws NullPointerException If <code>uri</code> is <code>null</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
     * @throws IllegalArgumentException If <code>uri</code> is <code>null</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
     *          or <code>uri.length() == 0</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
     * @see #newInstance()
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
     * @see #newInstance(String uri)
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
     * @since 1.6
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
    public static XPathFactory newInstance(String uri, String factoryClassName, ClassLoader classLoader)
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
        throws XPathFactoryConfigurationException{
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
        ClassLoader cl = classLoader;
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
        if (uri == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
                throw new NullPointerException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
                        "XPathFactory#newInstance(String uri) cannot be called with uri == null"
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
                );
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
                if (uri.length() == 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
                        throw new IllegalArgumentException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
                                "XPathFactory#newInstance(String uri) cannot be called with uri == \"\""
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
                        );
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
        if (cl == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
            cl = ss.getContextClassLoader();
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
        XPathFactory f = new XPathFactoryFinder(cl).createInstance(factoryClassName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
        if (f == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
                        throw new XPathFactoryConfigurationException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
                                "No XPathFactory implementation found for the object model: "
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
                                + uri
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
                        );
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
        //if this factory supports the given schemalanguage return this factory else thrown exception
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
        if(f.isObjectModelSupported(uri)){
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
            return f;
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
        }else{
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
            throw new XPathFactoryConfigurationException("Factory " + factoryClassName + " doesn't support given " + uri + " object model");
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
         * <p>Is specified object model supported by this <code>XPathFactory</code>?</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
         * @param objectModel Specifies the object model which the returned <code>XPathFactory</code> will understand.
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
         * @return <code>true</code> if <code>XPathFactory</code> supports <code>objectModel</code>, else <code>false</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
         * @throws NullPointerException If <code>objectModel</code> is <code>null</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
         * @throws IllegalArgumentException If <code>objectModel.length() == 0</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
        public abstract boolean isObjectModelSupported(String objectModel);
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
     * <p>Set a feature for this <code>XPathFactory</code> and
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
     * <code>XPath</code>s created by this factory.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
     * Feature names are fully qualified {@link java.net.URI}s.
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
     * Implementations may define their own features.
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
     * An {@link XPathFactoryConfigurationException} is thrown if this
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
     * <code>XPathFactory</code> or the <code>XPath</code>s
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
     * it creates cannot support the feature.
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
     * It is possible for an <code>XPathFactory</code> to expose a feature value
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
     * but be unable to change its state.
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
     * </p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
     * All implementations are required to support the {@link javax.xml.XMLConstants#FEATURE_SECURE_PROCESSING} feature.
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
     * When the feature is <code>true</code>, any reference to  an external function is an error.
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
     * Under these conditions, the implementation must not call the {@link XPathFunctionResolver}
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
     * and must throw an {@link XPathFunctionException}.
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
     * </p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
     * @param name Feature name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
     * @param value Is feature state <code>true</code> or <code>false</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
     * @throws XPathFactoryConfigurationException if this <code>XPathFactory</code> or the <code>XPath</code>s
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
     *   it creates cannot support this feature.
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
     * @throws NullPointerException if <code>name</code> is <code>null</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
        public abstract void setFeature(String name, boolean value)
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
                throws XPathFactoryConfigurationException;
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
     * <p>Get the state of the named feature.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
     * Feature names are fully qualified {@link java.net.URI}s.
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
     * Implementations may define their own features.
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
     * An {@link XPathFactoryConfigurationException} is thrown if this
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
     * <code>XPathFactory</code> or the <code>XPath</code>s
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
     * it creates cannot support the feature.
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
     * It is possible for an <code>XPathFactory</code> to expose a feature value
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
     * but be unable to change its state.
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
     * </p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
     * @param name Feature name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
     * @return State of the named feature.
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
     * @throws XPathFactoryConfigurationException if this
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
     *   <code>XPathFactory</code> or the <code>XPath</code>s
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
     *   it creates cannot support this feature.
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
     * @throws NullPointerException if <code>name</code> is <code>null</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
        public abstract boolean getFeature(String name)
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
                throws XPathFactoryConfigurationException;
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
     * <p>Establish a default variable resolver.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
     * <p>Any <code>XPath</code> objects constructed from this factory will use
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
     * the specified resolver by default.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
     * <p>A <code>NullPointerException</code> is thrown if <code>resolver</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
     * is <code>null</code>.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
     * @param resolver Variable resolver.
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
     * @throws NullPointerException If <code>resolver</code> is
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
     *   <code>null</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
    public abstract void setXPathVariableResolver(XPathVariableResolver resolver);
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
       * <p>Establish a default function resolver.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
       *
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
       * <p>Any <code>XPath</code> objects constructed from this factory will
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
       * use the specified resolver by default.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
       *
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
       * <p>A <code>NullPointerException</code> is thrown if
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
       * <code>resolver</code> is <code>null</code>.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
       *
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
       * @param resolver XPath function resolver.
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
       *
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
       * @throws NullPointerException If <code>resolver</code> is
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
       *   <code>null</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
       */
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
    public abstract void setXPathFunctionResolver(XPathFunctionResolver resolver);
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
    * <p>Return a new <code>XPath</code> using the underlying object
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
    * model determined when the <code>XPathFactory</code> was instantiated.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
    *
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
    * @return New instance of an <code>XPath</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
    */
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
    public abstract XPath newXPath();
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
}