jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogImpl.java
changeset 44380 0197177795e9
parent 43121 e73af7b6ce47
equal deleted inserted replaced
44379:247797605d63 44380:0197177795e9
    86     SAXParser parser;
    86     SAXParser parser;
    87 
    87 
    88     /**
    88     /**
    89      * Construct a Catalog with specified URI.
    89      * Construct a Catalog with specified URI.
    90      *
    90      *
       
    91      * @param f the features object
    91      * @param uris the uri(s) to one or more catalogs
    92      * @param uris the uri(s) to one or more catalogs
    92      * @throws CatalogException If an error happens while parsing the specified
    93      * @throws CatalogException If an error happens while parsing the specified
    93      * catalog file.
    94      * catalog file.
    94      */
    95      */
    95     public CatalogImpl(CatalogFeatures f, URI... uris) throws CatalogException {
    96     public CatalogImpl(CatalogFeatures f, URI... uris) throws CatalogException {
    98 
    99 
    99     /**
   100     /**
   100      * Construct a Catalog with specified URI.
   101      * Construct a Catalog with specified URI.
   101      *
   102      *
   102      * @param parent The parent catalog
   103      * @param parent The parent catalog
       
   104      * @param f the features object
   103      * @param uris the uri(s) to one or more catalogs
   105      * @param uris the uri(s) to one or more catalogs
   104      * @throws CatalogException If an error happens while parsing the specified
   106      * @throws CatalogException If an error happens while parsing the specified
   105      * catalog file.
   107      * catalog file.
   106      */
   108      */
   107     public CatalogImpl(CatalogImpl parent, CatalogFeatures f, URI... uris) throws CatalogException {
   109     public CatalogImpl(CatalogImpl parent, CatalogFeatures f, URI... uris) throws CatalogException {
   135             int start = 0;
   137             int start = 0;
   136             URI uri = null;
   138             URI uri = null;
   137             for (String temp : catalogFile) {
   139             for (String temp : catalogFile) {
   138                 uri = URI.create(temp);
   140                 uri = URI.create(temp);
   139                 start++;
   141                 start++;
   140                 if (verifyCatalogFile(uri)) {
   142                 if (verifyCatalogFile(null, uri)) {
   141                     systemId = temp;
   143                     systemId = temp;
   142                     try {
   144                     try {
   143                         baseURI = new URL(systemId);
   145                         baseURI = new URL(systemId);
   144                     } catch (MalformedURLException e) {
   146                     } catch (MalformedURLException e) {
   145                         CatalogMessages.reportRunTimeError(CatalogMessages.ERR_INVALID_PATH,
   147                         CatalogMessages.reportRunTimeError(CatalogMessages.ERR_INVALID_PATH,
   167     void load() {
   169     void load() {
   168         if (systemId != null) {
   170         if (systemId != null) {
   169             parse(systemId);
   171             parse(systemId);
   170         }
   172         }
   171 
   173 
       
   174         setCatalog(this);
       
   175 
   172         //save this catalog before loading the next
   176         //save this catalog before loading the next
   173         loadedCatalogs.put(systemId, this);
   177         loadedCatalogs.put(systemId, this);
   174 
   178 
   175         //Load delegate and alternative catalogs if defer is false.
   179         //Load delegate and alternative catalogs if defer is false.
   176         if (!isDeferred()) {
   180         if (!isDeferred()) {
   177            loadDelegateCatalogs();
   181            loadDelegateCatalogs(this);
   178            loadNextCatalogs();
   182            loadNextCatalogs();
   179         }
   183         }
   180     }
   184     }
   181 
   185 
   182     private void init(CatalogFeatures f) {
   186     private void init(CatalogFeatures f) {
   363                 Catalog c = null;
   367                 Catalog c = null;
   364 
   368 
   365                 //Check those specified in nextCatalogs
   369                 //Check those specified in nextCatalogs
   366                 if (nextCatalogs != null) {
   370                 if (nextCatalogs != null) {
   367                     while (c == null && nextCatalogIndex < nextCatalogs.size()) {
   371                     while (c == null && nextCatalogIndex < nextCatalogs.size()) {
   368                         c = getCatalog(nextCatalogs.get(nextCatalogIndex++).getCatalogURI());
   372                         c = getCatalog(catalog,
       
   373                                 nextCatalogs.get(nextCatalogIndex++).getCatalogURI());
   369                     }
   374                     }
   370                 }
   375                 }
   371 
   376 
   372                 //Check the input list
   377                 //Check the input list
   373                 if (c == null && inputFiles != null) {
   378                 if (c == null && inputFiles != null) {
   374                     while (c == null && inputFilesIndex < inputFiles.size()) {
   379                     while (c == null && inputFilesIndex < inputFiles.size()) {
   375                         c = getCatalog(URI.create(inputFiles.get(inputFilesIndex++)));
   380                         c = getCatalog(null,
       
   381                                 URI.create(inputFiles.get(inputFilesIndex++)));
   376                     }
   382                     }
   377                 }
   383                 }
   378 
   384 
   379                 return c;
   385                 return c;
   380             }
   386             }
   406      */
   412      */
   407     void loadNextCatalogs() {
   413     void loadNextCatalogs() {
   408         //loads catalogs specified in nextCatalogs
   414         //loads catalogs specified in nextCatalogs
   409         if (nextCatalogs != null) {
   415         if (nextCatalogs != null) {
   410             nextCatalogs.stream().forEach((next) -> {
   416             nextCatalogs.stream().forEach((next) -> {
   411                 getCatalog(next.getCatalogURI());
   417                 getCatalog(this, next.getCatalogURI());
   412             });
   418             });
   413         }
   419         }
   414 
   420 
   415         //loads catalogs from the input list
   421         //loads catalogs from the input list
   416         if (inputFiles != null) {
   422         if (inputFiles != null) {
   417             inputFiles.stream().forEach((uri) -> {
   423             inputFiles.stream().forEach((uri) -> {
   418                 getCatalog(URI.create(uri));
   424                 getCatalog(null, URI.create(uri));
   419             });
   425             });
   420         }
   426         }
   421     }
   427     }
   422 
   428 
   423     /**
   429     /**
   424      * Returns a Catalog object by the specified path.
   430      * Returns a Catalog object by the specified path.
   425      *
   431      *
   426      * @param path the path to a catalog
   432      * @param parent the parent catalog for the alternative catalogs to be loaded.
       
   433      * It will be null if the ones to be loaded are from the input list.
       
   434      * @param uri the path to a catalog
   427      * @return a Catalog object
   435      * @return a Catalog object
   428      */
   436      */
   429     Catalog getCatalog(URI uri) {
   437     Catalog getCatalog(CatalogImpl parent, URI uri) {
   430         if (uri == null) {
   438         if (uri == null) {
   431             return null;
   439             return null;
   432         }
   440         }
   433 
   441 
   434         CatalogImpl c = null;
   442         CatalogImpl c = null;
   435 
   443 
   436         if (verifyCatalogFile(uri)) {
   444         if (verifyCatalogFile(parent, uri)) {
   437             c = getLoadedCatalog(uri.toASCIIString());
   445             c = getLoadedCatalog(uri.toASCIIString());
   438             if (c == null) {
   446             if (c == null) {
   439                 c = new CatalogImpl(this, features, uri);
   447                 c = new CatalogImpl(this, features, uri);
   440                 c.load();
   448                 c.load();
   441             }
   449             }
   457      * Returns a count of all loaded catalogs, including delegate catalogs.
   465      * Returns a count of all loaded catalogs, including delegate catalogs.
   458      *
   466      *
   459      * @return a count of all loaded catalogs
   467      * @return a count of all loaded catalogs
   460      */
   468      */
   461     int loadedCatalogCount() {
   469     int loadedCatalogCount() {
   462         return loadedCatalogs.size() + delegateCatalogs.size();
   470         return loadedCatalogs.size();
   463     }
   471     }
   464 }
   472 }