< prev index next >
src/java.xml/share/classes/javax/xml/catalog/GroupEntry.java
Print this page
*** 46,66 ****
CatalogFeatures features;
//Value of the prefer attribute
boolean isPreferPublic = true;
//The catalog instance this group belongs to
CatalogImpl catalog;
//A list of all entries in a catalog or group
List<BaseEntry> entries = new ArrayList<>();
//loaded delegated catalog by system id
! Map<String, Catalog> delegateCatalogs = new HashMap<>();
//A list of all loaded Catalogs, including this, and next catalogs
! Map<String, Catalog> loadedCatalogs = new HashMap<>();
/*
A list of Catalog Ids that have already been searched in a matching
operation. Check this list before constructing new Catalog to avoid circular
reference.
--- 46,69 ----
CatalogFeatures features;
//Value of the prefer attribute
boolean isPreferPublic = true;
+ //The parent of the catalog instance
+ CatalogImpl parent = null;
+
//The catalog instance this group belongs to
CatalogImpl catalog;
//A list of all entries in a catalog or group
List<BaseEntry> entries = new ArrayList<>();
//loaded delegated catalog by system id
! Map<String, CatalogImpl> delegateCatalogs = new HashMap<>();
//A list of all loaded Catalogs, including this, and next catalogs
! Map<String, CatalogImpl> loadedCatalogs = new HashMap<>();
/*
A list of Catalog Ids that have already been searched in a matching
operation. Check this list before constructing new Catalog to avoid circular
reference.
*** 134,145 ****
/**
* Constructs a GroupEntry
*
* @param type The type of the entry
*/
! public GroupEntry(CatalogEntryType type) {
super(type);
}
/**
* Constructs a group entry.
*
--- 137,149 ----
/**
* Constructs a GroupEntry
*
* @param type The type of the entry
*/
! public GroupEntry(CatalogEntryType type, CatalogImpl parent) {
super(type);
+ this.parent = parent;
}
/**
* Constructs a group entry.
*
*** 161,171 ****
longestSuffixMatch = 0;
systemEntrySearched = false;
}
/**
* Constructs a group entry.
! * @param catalog The parent catalog
* @param base The baseURI attribute
* @param attributes The attributes
*/
public GroupEntry(CatalogImpl catalog, String base, String... attributes) {
super(CatalogEntryType.GROUP, base);
--- 165,175 ----
longestSuffixMatch = 0;
systemEntrySearched = false;
}
/**
* Constructs a group entry.
! * @param catalog The catalog this GroupEntry belongs
* @param base The baseURI attribute
* @param attributes The attributes
*/
public GroupEntry(CatalogImpl catalog, String base, String... attributes) {
super(CatalogEntryType.GROUP, base);
*** 443,459 ****
/**
* Loads a delegate catalog by the catalogId specified.
* @param catalogId the catalog Id
*/
Catalog loadCatalog(URI catalogURI) {
! Catalog delegateCatalog = null;
if (catalogURI != null) {
String catalogId = catalogURI.toASCIIString();
delegateCatalog = getLoadedCatalog(catalogId);
if (delegateCatalog == null) {
if (verifyCatalogFile(catalogURI)) {
delegateCatalog = new CatalogImpl(catalog, features, catalogId);
delegateCatalogs.put(catalogId, delegateCatalog);
}
}
}
--- 447,464 ----
/**
* Loads a delegate catalog by the catalogId specified.
* @param catalogId the catalog Id
*/
Catalog loadCatalog(URI catalogURI) {
! CatalogImpl delegateCatalog = null;
if (catalogURI != null) {
String catalogId = catalogURI.toASCIIString();
delegateCatalog = getLoadedCatalog(catalogId);
if (delegateCatalog == null) {
if (verifyCatalogFile(catalogURI)) {
delegateCatalog = new CatalogImpl(catalog, features, catalogId);
+ delegateCatalog.load();
delegateCatalogs.put(catalogId, delegateCatalog);
}
}
}
*** 465,476 ****
*
* @param catalogId The systemId of a catalog
* @return a Catalog object previously loaded, or null if none in the saved
* list
*/
! Catalog getLoadedCatalog(String catalogId) {
! Catalog c = null;
//checl delegate Catalogs
c = delegateCatalogs.get(catalogId);
if (c == null) {
//check other loaded Catalogs
--- 470,481 ----
*
* @param catalogId The systemId of a catalog
* @return a Catalog object previously loaded, or null if none in the saved
* list
*/
! CatalogImpl getLoadedCatalog(String catalogId) {
! CatalogImpl c = null;
//checl delegate Catalogs
c = delegateCatalogs.get(catalogId);
if (c == null) {
//check other loaded Catalogs
*** 502,515 ****
if (!Files.exists(Paths.get(catalogURI))) {
return false;
}
String catalogId = catalogURI.toASCIIString();
! if (catalogsSearched.contains(catalogId)) {
CatalogMessages.reportRunTimeError(CatalogMessages.ERR_CIRCULAR_REFERENCE,
new Object[]{CatalogMessages.sanitize(catalogId)});
}
return true;
}
}
--- 507,536 ----
if (!Files.exists(Paths.get(catalogURI))) {
return false;
}
String catalogId = catalogURI.toASCIIString();
! if (catalogsSearched.contains(catalogId) || isCircular(catalogId)) {
CatalogMessages.reportRunTimeError(CatalogMessages.ERR_CIRCULAR_REFERENCE,
new Object[]{CatalogMessages.sanitize(catalogId)});
}
return true;
}
+ /**
+ * Checks whether the catalog is circularly referenced
+ * @param systemId the system identifier of the catalog to be loaded
+ * @return true if is circular, false otherwise
+ */
+ boolean isCircular(String systemId) {
+ if (parent == null) {
+ return false;
+ }
+
+ if (parent.systemId.equals(systemId)) {
+ return true;
+ }
+
+ return parent.isCircular(systemId);
+ }
}
< prev index next >