In examples on using Xerces specific features I see the way
DOMImplementationRegistry instance is obtained is:
System.setProperty(DOMImplementationRegistry.PROPERTY,
"org.apache.xerces.dom.DOMXSImplementationSourceImpl");
DOMImplementationRegistry registry =
DOMImplementationRegistry.newInstance();
I've wondered if it is the best way when using it from a shared
library code as the user application may have setup (through the
"org.w3c.dom.DOMImplementationSourceList" system property) and rely
on other implementation.
As I don't see a reliable way (is there?) to synchronize the
execution of the following example registry instantiation:
String backupRegistry =
System.getProperty(DOMImplementationRegistry.PROPERTY);
System.setProperty(DOMImplementationRegistry.PROPERTY,
"org.apache.xerces.dom.DOMXSImplementationSourceImpl");
DOMImplementationRegistry registry =
DOMImplementationRegistry.newInstance();
if (backupRegistry == null) {
System.getProperties()
.remove(DOMImplementationRegistry.PROPERTY);
} else {
System.setProperty(DOMImplementationRegistry.PROPERTY,
backupRegistry);
}
Could direct instantiation be considered suitable?
DOMImplementationRegistry registry =
new DOMXSImplementationSourceImpl();
... given one uses the exact
|org.apache.xerces.dom.DOMXSImplementationSourceImpl| class name
(although it is marked as internal to the Xerces implementation)
even with the first example and the assertion it must(?) have a
default no-argument constructor.
There are two small drawbacks (or just differences) I see in the
last approach:
1. Creates a direct compilation dependency on the
|org.apache.xerces.dom.DOMXSImplementationSourceImpl| class (which
might be not a bad idea), but the constructor could be invoked
through reflection, also:
DOMImplementationRegistry registry = Class
.forName("org.apache.xerces.dom.DOMXSImplementationSourceImpl")
.newInstance();
2. Creates a new DOMImplementationRegistry instance while the static
factory method probably will return a shared instance. If only that
new instance is used throughout the library, I think that is o.k.
--
Stanimir
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]