1 /*
   2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package javax.xml.catalog;
  26 
  27 
  28 /**
  29  * The Catalog Manager manages the creation of XML Catalogs and Catalog Resolvers.
  30  *
  31  * @since 9
  32  */
  33 public final class CatalogManager {
  34     /**
  35      * Creating CatalogManager instance is not allowed.
  36      */
  37     private CatalogManager() {
  38     }
  39 
  40     /**
  41      * Creates a Catalog object using the specified feature settings and path to
  42      * a catalog file. If the features is null, the default features will be used.
  43      * If the path is empty, System property {@code javax.xml.catalog.files} will
  44      * be read to locate the initial list of catalog files.
  45      * <p>
  46      * If more than one catalog files are specified through the path argument or
  47      * {@code javax.xml.catalog.files} property, the first entry is considered
  48      * the main catalog, while others are treated as alternative catalogs after
  49      * those referenced by the {@code nextCatalog} elements in the main catalog.
  50      *
  51      * @param features the catalog features
  52      * @param path path(s) to one or more catalogs.
  53      *
  54      * @return a catalog instance
  55      * @throws CatalogException If no catalog can be found whether through the
  56      * specified path or the System property {@code javax.xml.catalog.files}, or
  57      * an error occurs while parsing the catalog
  58      */
  59     public static Catalog catalog(CatalogFeatures features, String... path) {
  60         return new CatalogImpl(features, path);
  61     }
  62 
  63     /**
  64      * Creates an instance of a CatalogResolver using the specified catalog.
  65      *
  66      * @param catalog the catalog instance
  67      * @return an instance of a CatalogResolver
  68      */
  69     public static CatalogResolver catalogResolver(Catalog catalog) {
  70         if (catalog == null) CatalogMessages.reportNPEOnNull("catalog", null);
  71         return new CatalogResolverImpl(catalog);
  72     }
  73 
  74     /**
  75      * Creates an instance of a CatalogUriResolver using the specified catalog.
  76      *
  77      * @param catalog the catalog instance
  78      * @return an instance of a CatalogResolver
  79      */
  80     public static CatalogUriResolver catalogUriResolver(Catalog catalog) {
  81         if (catalog == null) CatalogMessages.reportNPEOnNull("catalog", null);
  82         return new CatalogUriResolverImpl(catalog);
  83     }
  84 
  85     /**
  86      * Creates an instance of a CatalogResolver using the specified feature settings
  87      * and path to a catalog file. If the features is null, the default features will
  88      * be used. If the path is empty, System property {@code javax.xml.catalog.files}
  89      * will be read to locate the initial list of catalog files.
  90      * <p>
  91      * If more than one catalog files are specified through the path argument or
  92      * {@code javax.xml.catalog.files} property, the first entry is considered
  93      * the main catalog, while others are treated as alternative catalogs after
  94      * those referenced by the {@code nextCatalog} elements in the main catalog.
  95      *
  96      * @param features the catalog features
  97      * @param path the path(s) to one or more catalogs
  98      *
  99      * @return an instance of a CatalogResolver
 100      * @throws CatalogException If no catalog can be found whether through the
 101      * specified path or the System property {@code javax.xml.catalog.files}, or
 102      * an error occurs while parsing the catalog
 103      */
 104     public static CatalogResolver catalogResolver(CatalogFeatures features, String... path) {
 105         Catalog catalog = catalog(features, path);
 106         return new CatalogResolverImpl(catalog);
 107     }
 108 
 109     /**
 110      * Creates an instance of a CatalogUriResolver using the specified feature settings
 111      * and path to a catalog file. If the features is null, the default features will
 112      * be used. If the path is empty, System property {@code javax.xml.catalog.files}
 113      * will be read to locate the initial list of catalog files.
 114      * <p>
 115      * If more than one catalog files are specified through the path argument or
 116      * {@code javax.xml.catalog.files} property, the first entry is considered
 117      * the main catalog, while others are treated as alternative catalogs after
 118      * those referenced by the {@code nextCatalog} elements in the main catalog.
 119      *
 120      * @param features the catalog features
 121      * @param path the path(s) to one or more catalogs
 122      *
 123      * @return an instance of a CatalogResolver
 124      * @throws CatalogException If no catalog can be found whether through the
 125      * specified path or the System property {@code javax.xml.catalog.files}, or
 126      * an error occurs while parsing the catalog
 127      */
 128     public static CatalogUriResolver catalogUriResolver(CatalogFeatures features, String... path) {
 129         Catalog catalog = catalog(features, path);
 130         return new CatalogUriResolverImpl(catalog);
 131     }
 132 }