You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Kyle Adams <ka...@gfs.com> on 2003/05/21 22:59:46 UTC

Adding support for XMLCatalog in EjbJar

I've taken a first stab at adding support for nested <xmlcatalog>
elements within <ejbjar>, but I'm running into some problems I thought
I'd run by the list.

First glance, it appeared pretty easy.  Add a few methods and insert
the following bit of code in the execute method:

if (xmlCatalog != null) {
    saxParser.getXMLReader().setEntityResolver(xmlCatalog);
}

Since saxParser gets passed into the various vendor-specific deployment
tool classes, I thought that would do the trick.  But it's not (why
would I be writing this otherwise :-) ?).  The problem is that I'm not
familiar enough with SAX; previous hacking involved adding XMLCatalog
support to tasks that used DOM.  Also, I'm not intimately familiar with
the inner workings of the org.apache.tools.ant.taskdefs.optional.ejb.*
classes.

So I thought I'd throw this out there and see if I'm doing something
stupid/easily fixed.  Diff included below for full disclosure.

Thanks,
Kyle

===

--- EjbJar.java.old	2003-05-21 16:54:44.000000000 -0400
+++ EjbJar.java	2003-05-21 16:52:50.000000000 -0400
@@ -74,6 +74,7 @@
 import org.apache.tools.ant.types.Path;
 import org.apache.tools.ant.types.EnumeratedAttribute;
 import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.types.XMLCatalog;
 
 /**
  * Provides automated EJB JAR file creation.
@@ -226,6 +227,18 @@
     /** The list of deployment tools we are going to run. */
     private ArrayList deploymentTools = new ArrayList();
 
+    /** for resolving entities such as dtds */
+    private XMLCatalog xmlCatalog = new XMLCatalog();
+
+
+    /**
+     * Add the catalog to our internal catalog
+     *
+     * @param xmlCatalog the XMLCatalog instance to use to look up
DTDs
+     */
+    public void addConfiguredXMLCatalog(XMLCatalog xmlCatalog) {
+        this.xmlCatalog.addConfiguredXMLCatalog(xmlCatalog);
+    }
 
     /**
      * Add a deployment tool to the list of deployment tools that will
be
@@ -538,6 +551,14 @@
     }
 
     /**
+     * Initialize internal instance of XMLCatalog
+     */
+    public void init() throws BuildException {
+        super.init();
+        xmlCatalog.setProject(getProject());
+    }
+
+    /**
      * Invoked by Ant after the task is prepared, when it is ready to
execute
      * this task.
      *
@@ -574,6 +595,9 @@
             SAXParserFactory saxParserFactory =
SAXParserFactory.newInstance();
             saxParserFactory.setValidating(true);
             SAXParser saxParser = saxParserFactory.newSAXParser();
+            if (xmlCatalog != null) {
+               
saxParser.getXMLReader().setEntityResolver(xmlCatalog);
+            }
 
             DirectoryScanner ds =
getDirectoryScanner(config.descriptorDir);
             ds.scan();