arch@glassfish.java.net

Re: [arch] Re: [Issue 2888] [admin] Try to use standard JDK classes only

From: Thomas Mueller <tmueller64_at_gmail.com>
Date: Thu, 21 Oct 2010 09:11:01 -0500

On Wed, Oct 20, 2010 at 7:31 PM, Bill Shannon <bill.shannon_at_oracle.com>wrote:

> Tom Mueller wrote on 10/20/10 05:04 PM:
>
> com.sun.org.apache.xerces.internal.parsers.DOMParser
>>>> This is used in two places. Once for setting the default parser to use
>>>> when
>>>> parsing deployment descriptors (DeploymentDescriptorFile) and the other
>>>> in the
>>>> flashlight/framework module. The later case can probabably void using
>>>> DOMParser
>>>> altogether.
>>>>
>>>
>>> For the former, is it trying to override the default, or is it trying to
>>> make sure no one else who overrides the default effects this code?
>>>
>> The latter. It sets the parser to DOMParser, parses the document, and then
>> restores the previous value.
>>
>
> You can't just clear the property or set it to null or something to force
> the default, without knowing the name of the default parser?
>

After a closer look, it turns out that this particular case is not a use of
DOMParser and it isn't a compilation error. It is a use of a class within
the com.sun.org.apache.xerces.internal package,
specifically, com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl.

Here's the code:

            // always use system default to parse DD
             System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
"com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
            DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();

 System.clearProperty("javax.xml.parsers.DocumentBuilderFactory");

The DocumentBuilderFactory class provides a specific order for looking up
how to create a document builder. And the first choice it uses is this
system property. I as misled by the comment that says to use the system
default. It is actually specifying its own builder which may actually be
different than the system default. However, I expect that the value being
set is probably the typical system default for the Sun JDK.

I don't know the ramifications of just removing the System.setProperty and
System.clearProperty statements.

Tom