< prev index next >
src/java.xml/share/classes/javax/xml/catalog/GroupEntry.java
Print this page
@@ -133,11 +133,12 @@
}
/**
* Constructs a GroupEntry
*
- * @param type The type of the entry
+ * @param type the type of the entry
+ * @param parent the parent Catalog
*/
public GroupEntry(CatalogEntryType type, CatalogImpl parent) {
super(type);
this.parent = parent;
}
@@ -163,21 +164,30 @@
longestSuffixMatch = 0;
systemEntrySearched = false;
}
/**
* Constructs a group entry.
- * @param catalog The catalog this GroupEntry belongs
- * @param base The baseURI attribute
- * @param attributes The attributes
+ * @param catalog the catalog this GroupEntry belongs to
+ * @param base the baseURI attribute
+ * @param attributes the attributes
*/
public GroupEntry(CatalogImpl catalog, String base, String... attributes) {
super(CatalogEntryType.GROUP, base);
setPrefer(attributes[ATTRIBUTE_PREFER]);
this.catalog = catalog;
}
/**
+ * Sets the catalog for this GroupEntry.
+ *
+ * @param catalog the catalog this GroupEntry belongs to
+ */
+ void setCatalog(CatalogImpl catalog) {
+ this.catalog = catalog;
+ }
+
+ /**
* Adds an entry.
*
* @param entry The entry to be added.
*/
public void addEntry(BaseEntry entry) {
@@ -380,14 +390,13 @@
}
/**
* Matches delegatePublic or delegateSystem against the specified id
*
- * @param isSystem The flag to indicate whether the delegate is system or
- * public
- * @param id The system or public id to be matched
- * @return The URI string if a mapping is found, or null otherwise.
+ * @param type the type of the Catalog entry
+ * @param id the system or public id to be matched
+ * @return the URI string if a mapping is found, or null otherwise.
*/
private String matchDelegate(CatalogEntryType type, String id) {
String match = null;
int longestMatch = 0;
URI catalogId = null;
@@ -410,11 +419,11 @@
}
}
//Check delegate Catalogs
if (catalogId != null) {
- Catalog delegateCatalog = loadCatalog(catalogId);
+ Catalog delegateCatalog = loadDelegateCatalog(catalog, catalogId);
if (delegateCatalog != null) {
if (type == CatalogEntryType.DELEGATESYSTEM) {
match = delegateCatalog.matchSystem(id);
} else if (type == CatalogEntryType.DELEGATEPUBLIC) {
@@ -428,34 +437,38 @@
return match;
}
/**
* Loads all delegate catalogs.
+ *
+ * @param parent the parent catalog of the delegate catalogs
*/
- void loadDelegateCatalogs() {
+ void loadDelegateCatalogs(CatalogImpl parent) {
entries.stream()
.filter((entry) -> (entry.type == CatalogEntryType.DELEGATESYSTEM ||
entry.type == CatalogEntryType.DELEGATEPUBLIC ||
entry.type == CatalogEntryType.DELEGATEURI))
.map((entry) -> (AltCatalog)entry)
.forEach((altCatalog) -> {
- loadCatalog(altCatalog.getCatalogURI());
+ loadDelegateCatalog(parent, altCatalog.getCatalogURI());
});
}
/**
* Loads a delegate catalog by the catalogId specified.
- * @param catalogId the catalog Id
+ *
+ * @param parent the parent catalog of the delegate catalog
+ * @param catalogURI the URI to the catalog
*/
- Catalog loadCatalog(URI catalogURI) {
+ Catalog loadDelegateCatalog(CatalogImpl parent, URI catalogURI) {
CatalogImpl delegateCatalog = null;
if (catalogURI != null) {
String catalogId = catalogURI.toASCIIString();
+ if (verifyCatalogFile(parent, catalogURI)) {
delegateCatalog = getLoadedCatalog(catalogId);
if (delegateCatalog == null) {
- if (verifyCatalogFile(catalogURI)) {
- delegateCatalog = new CatalogImpl(catalog, features, catalogURI);
+ delegateCatalog = new CatalogImpl(parent, features, catalogURI);
delegateCatalog.load();
delegateCatalogs.put(catalogId, delegateCatalog);
}
}
}
@@ -471,11 +484,11 @@
* list
*/
CatalogImpl getLoadedCatalog(String catalogId) {
CatalogImpl c = null;
- //checl delegate Catalogs
+ //check delegate Catalogs
c = delegateCatalogs.get(catalogId);
if (c == null) {
//check other loaded Catalogs
c = loadedCatalogs.get(catalogId);
}
@@ -490,15 +503,16 @@
* specification, section 8. Resource Failures.
* <p>
* Verifies that the catalog represented by the catalogId has not been
* searched or is not circularly referenced.
*
- * @param catalogId The URI to a catalog
+ * @param parent the parent of the catalog to be loaded
+ * @param catalogURI the URI to the catalog
* @throws CatalogException if circular reference is found.
* @return true if the catalogId passed verification, false otherwise
*/
- final boolean verifyCatalogFile(URI catalogURI) {
+ final boolean verifyCatalogFile(CatalogImpl parent, URI catalogURI) {
if (catalogURI == null) {
return false;
}
//Ignore it if it doesn't exist
@@ -506,30 +520,34 @@
!Util.isFileUriExist(catalogURI, false)) {
return false;
}
String catalogId = catalogURI.toASCIIString();
- if (catalogsSearched.contains(catalogId) || isCircular(catalogId)) {
+ if (catalogsSearched.contains(catalogId) || isCircular(parent, catalogId)) {
CatalogMessages.reportRunTimeError(CatalogMessages.ERR_CIRCULAR_REFERENCE,
new Object[]{CatalogMessages.sanitize(catalogId)});
}
return true;
}
/**
* Checks whether the catalog is circularly referenced
+ *
+ * @param parent the parent of the catalog to be loaded
* @param systemId the system identifier of the catalog to be loaded
* @return true if is circular, false otherwise
*/
- boolean isCircular(String systemId) {
+ boolean isCircular(CatalogImpl parent, String systemId) {
+ // first, check the parent of the catalog to be loaded
if (parent == null) {
return false;
}
if (parent.systemId.equals(systemId)) {
return true;
}
- return parent.isCircular(systemId);
+ // next, check parent's parent
+ return parent.isCircular(parent.parent, systemId);
}
}
< prev index next >