Browse Source

Change the check for the external resolver catalog impl to

ensure it can be loaded by the resolver classes.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275038 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 22 years ago
parent
commit
130d4ee759
1 changed files with 35 additions and 8 deletions
  1. +35
    -8
      src/main/org/apache/tools/ant/types/XMLCatalog.java

+ 35
- 8
src/main/org/apache/tools/ant/types/XMLCatalog.java View File

@@ -188,7 +188,13 @@ public class XMLCatalog extends DataType
public static final String APACHE_RESOLVER public static final String APACHE_RESOLVER
= "org.apache.tools.ant.types.resolver.ApacheCatalogResolver"; = "org.apache.tools.ant.types.resolver.ApacheCatalogResolver";


//-- Methods ---------------------------------------------------------------
/**
* Resolver base class
*/
public static final String CATALOG_RESOLVER
= "org.apache.xml.resolver.tools.CatalogResolver";

//-- Methods ---------------------------------------------------------------


/** /**
* Default constructor * Default constructor
@@ -534,13 +540,34 @@ public class XMLCatalog extends DataType
loader = getProject().createClassLoader(Path.systemClasspath); loader = getProject().createClassLoader(Path.systemClasspath);


try { try {
Class clazz = loader.forceLoadSystemClass(APACHE_RESOLVER);
Class clazz = Class.forName(CATALOG_RESOLVER, true, loader);
Class clazz = Class.forName(APACHE_RESOLVER, true, loader);

// The Apache resolver is present - Need to check if it can
// be seen by the catalog resolver class. Start by getting
// the actual loader
ClassLoader apacheResolverLoader = clazz.getClassLoader();

// load the base class through this loader.
Class baseResolverClass
= Class.forName(CATALOG_RESOLVER, true, apacheResolverLoader);

// and find its actual loader
ClassLoader baseResolverLoader
= baseResolverClass.getClassLoader();

// We have the loader which is being used to load the
// CatalogResolver. Can it see the ApacheResolver? The
// base resolver will only be able to create the ApacheResolver
// if it can see it - doesn't use the context loader.
clazz = Class.forName(APACHE_RESOLVER, true, baseResolverLoader);

Object obj = clazz.newInstance(); Object obj = clazz.newInstance();
// //
// Success! The xml-commons resolver library is // Success! The xml-commons resolver library is
// available, so use it. // available, so use it.
// //
catalogResolver = new ApacheResolver(clazz, obj);
catalogResolver = new ExternalResolver(clazz, obj);
} catch (Throwable ex) { } catch (Throwable ex) {
// //
// The xml-commons resolver library is not // The xml-commons resolver library is not
@@ -789,7 +816,7 @@ public class XMLCatalog extends DataType


/** /**
* Interface implemented by both the InternalResolver strategy and * Interface implemented by both the InternalResolver strategy and
* the ApacheResolver strategy.
* the ExternalResolver strategy.
*/ */
private interface CatalogResolver extends URIResolver, EntityResolver { private interface CatalogResolver extends URIResolver, EntityResolver {


@@ -894,13 +921,13 @@ public class XMLCatalog extends DataType
} }


/** /**
* The ApacheResolver strategy is used if the Apache resolver
* The ExternalResolver strategy is used if the Apache resolver
* library (Norm Walsh's library from xml-commons) is available in * library (Norm Walsh's library from xml-commons) is available in
* the classpath. The ApacheResolver is a essentially a superset
* the classpath. The ExternalResolver is a essentially a superset
* of the InternalResolver. * of the InternalResolver.
* *
*/ */
private class ApacheResolver implements CatalogResolver {
private class ExternalResolver implements CatalogResolver {


private Method setXMLCatalog = null; private Method setXMLCatalog = null;
private Method parseCatalog = null; private Method parseCatalog = null;
@@ -912,7 +939,7 @@ public class XMLCatalog extends DataType


private boolean externalCatalogsProcessed = false; private boolean externalCatalogsProcessed = false;


public ApacheResolver(Class resolverImplClass,
public ExternalResolver(Class resolverImplClass,
Object resolverImpl) { Object resolverImpl) {


this.resolverImpl = resolverImpl; this.resolverImpl = resolverImpl;


Loading…
Cancel
Save