src/java.xml/share/classes/javax/xml/catalog/CatalogManager.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 43121 jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogManager.java@e73af7b6ce47
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     1
/*
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     4
 *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    10
 *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    15
 * accompanied this code).
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    16
 *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    20
 *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    23
 * questions.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    24
 */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    25
package javax.xml.catalog;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    26
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
    27
import java.net.URI;
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    28
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    29
/**
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    30
 * The Catalog Manager manages the creation of XML Catalogs and Catalog Resolvers.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    31
 *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    32
 * @since 9
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    33
 */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    34
public final class CatalogManager {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    35
    /**
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    36
     * Creating CatalogManager instance is not allowed.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    37
     */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    38
    private CatalogManager() {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    39
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    40
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    41
    /**
34984
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
    42
     * Creates a {@code Catalog} object using the specified feature settings and
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
    43
     * uri(s) to one or more catalog files.
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    44
     * <p>
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
    45
     * If {@code uris} is empty, system property {@code javax.xml.catalog.files},
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
    46
     * as defined in {@link CatalogFeatures}, will be read to locate the initial
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
    47
     * list of catalog files.
34984
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
    48
     * <p>
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
    49
     * If multiple catalog files are specified through the {@code uris} argument or
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    50
     * {@code javax.xml.catalog.files} property, the first entry is considered
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    51
     * the main catalog, while others are treated as alternative catalogs after
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    52
     * those referenced by the {@code nextCatalog} elements in the main catalog.
34984
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
    53
     * <p>
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
    54
     * As specified in
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
    55
     * <a href="https://www.oasis-open.org/committees/download.php/14809/xml-catalogs.html#s.res.fail">
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
    56
     * XML Catalogs, OASIS Standard V1.1</a>, if a catalog entry is invalid, it
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
    57
     * is ignored. In case all entries are invalid, the resulting Catalog object
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
    58
     * will contain no Catalog elements. Any matching operation using the Catalog
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
    59
     * will return null.
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    60
     *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    61
     * @param features the catalog features
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
    62
     * @param uris uri(s) to one or more catalogs.
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    63
     *
34984
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
    64
     * @return an instance of a {@code Catalog}
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
    65
     * @throws IllegalArgumentException if either the URIs are not absolute
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
    66
     * or do not have a URL protocol handler for the URI scheme
34984
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
    67
     * @throws CatalogException If an error occurs while parsing the catalog
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
    68
     * @throws SecurityException if access to the resource is denied by the security manager
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    69
     */
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
    70
    public static Catalog catalog(CatalogFeatures features, URI... uris) {
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
    71
        Util.validateUrisSyntax(uris);
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
    72
        CatalogImpl catalog = new CatalogImpl(features, uris);
40753
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 40582
diff changeset
    73
        catalog.load();
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 40582
diff changeset
    74
        return catalog;
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    75
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    76
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    77
    /**
34984
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
    78
     * Creates an instance of a {@code CatalogResolver} using the specified catalog.
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    79
     *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    80
     * @param catalog the catalog instance
34984
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
    81
     * @return an instance of a {@code CatalogResolver}
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    82
     */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    83
    public static CatalogResolver catalogResolver(Catalog catalog) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    84
        if (catalog == null) CatalogMessages.reportNPEOnNull("catalog", null);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    85
        return new CatalogResolverImpl(catalog);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    86
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    87
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    88
    /**
34984
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
    89
     * Creates an instance of a {@code CatalogResolver} using the specified feature
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
    90
     * settings and uri(s) to one or more catalog files.
34984
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
    91
     * <p>
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
    92
     * If {@code uris} is empty, system property {@code javax.xml.catalog.files},
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
    93
     * as defined in {@link CatalogFeatures}, will be read to locate the initial
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
    94
     * list of catalog files.
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    95
     * <p>
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
    96
     * If multiple catalog files are specified through the {@code uris} argument or
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    97
     * {@code javax.xml.catalog.files} property, the first entry is considered
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    98
     * the main catalog, while others are treated as alternative catalogs after
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    99
     * those referenced by the {@code nextCatalog} elements in the main catalog.
34984
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   100
     * <p>
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   101
     * As specified in
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   102
     * <a href="https://www.oasis-open.org/committees/download.php/14809/xml-catalogs.html#s.res.fail">
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
   103
     * XML Catalogs, OASIS Standard V1.1</a>, if a catalog entry is invalid, it
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
   104
     * is ignored. In case all entries are invalid, the resulting CatalogResolver
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
   105
     * object will contain no valid catalog. Any resolution operation using the
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
   106
     * resolver therefore will return as no mapping is found. See {@link CatalogResolver}
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
   107
     * for the behavior when no mapping is found.
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   108
     *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   109
     * @param features the catalog features
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
   110
     * @param uris the uri(s) to one or more catalogs
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   111
     *
34984
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   112
     * @return an instance of a {@code CatalogResolver}
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
   113
     * @throws IllegalArgumentException if either the URIs are not absolute
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
   114
     * or do not have a URL protocol handler for the URI scheme
34984
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   115
     * @throws CatalogException If an error occurs while parsing the catalog
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
   116
     * @throws SecurityException if access to the resource is denied by the security manager
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   117
     */
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
   118
    public static CatalogResolver catalogResolver(CatalogFeatures features, URI... uris) {
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
   119
        Catalog catalog = catalog(features, uris);
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   120
        return new CatalogResolverImpl(catalog);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   121
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   122
}