db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Army <qoz...@gmail.com>
Subject Checking for required classes from within Derby?
Date Tue, 01 Aug 2006 18:16:55 GMT
As part of my work for DERBY-688 I've made some slight changes to the XML 
operators that were added in DERBY-334 and I've also added a new operator, XMLQUERY.

These operators depend on the presence of classes that are technically 
"external" to Derby.  Or more specifically, they expect that the user's 
classpath will include 1) an implementation of JAXP (such as Xerces or Crimson) 
and 2) Apache Xalan.

In preparation for the 10.2 exposure of the XML datatype and corresponding 
operators I want to add checks in the Derby code to see if the required classes 
exist and to throw a more user-friendly error if they don't (instead of some 
ClassNotFoundException (or worse) in the middle of processing, which isn't very 
intuitive).  I currently have code working that does this by calling 
Class.forName(...) and passing in the name of one of the required classes, and 
then catching the resultant exception (if there is one) and converting it to 
something more meaningful.


             try {

                 /* If the w3c Document class exists, then we
                  * assume a JAXP implementation is present in
                  * the classpath.
                  * Note: The JAXP API and implementation are
                  * provided as part the JVM if it is JDBC 3.0 or
                  * greater.
                 try {

                     /* If the XPath class exists, then we assume that our XML
                      * query processor (in this case, Xalan), is present in the
                      * classpath.

                 } catch (java.lang.ClassNotFoundException e) {
                 // couldn't find query processor (Xalan).
                     <user-friendly error processing>

             } catch (java.lang.ClassNotFoundException e) {
             // couldn't find JAXP parser.
                 <user-friendly error processing>

While this works, I can't help but wonder if Derby has some sort of existing 
mechanism/utilities to check for the existence of required classes in a cleaner 
(and perhaps more correct?) way.

Does anyone know if such a utility/mechanism exists, and if so, can I get some 
pointers to code/documentation?  I admit I haven't done much searching of the 
code yet; I figured I'd start with the list and maybe save some time...

Thanks much,

View raw message