How does jaxp internal classes work?

182 Views Asked by At

I have a very basic doubt. Please help me understand the following lines from this link http://docs.oracle.com/javase/1.5.0/docs/guide/xml/jaxp/JAXP-Compatibility_150.html

"The solution in the JAXP 1.3 reference name is to change the package names of the Apache libraries used in the implementation. That change lets you reference newer Apache libraries in the classpath, so application developers can use them in the same way that would use any other additions to the Java platform"

How to override the internal implementation class of the jre with a class of same name from reference library in the classpath? Note: I'm assuming they only gave wrapper package to change the name of internal package names, so the internal package name should still exist.

Please explain in detail.

Thanks in advance!!! Anand

1

There are 1 best solutions below

7
On BEST ANSWER

Previously some org.apache packages where included in JRE jars "as-is", with complete org.apache package names.

This means that, if a class of mine wanted to use, say, Xerces DomUtil, and had an

import org.apache.xerces.util.DOMUtil;

the root classloader would resolve this class to the version of Xerces in the JRE.

If I wanted to use a newer or different version of Xerces, I could not include it in my application classpath, because the classloader system would give precedence to the Xerces packaged in the JRE.

Now this situation has changed. They took the org.apache packages, and changed them to com.sun.org.apache...internal...

So, if I want to directly use the Xerces packaged with the JRE, i can import :

import com.sun.org.apache.xerces.internal.util.DOMUtil;

(Eclipse will give error telling us not to use packages inside com.sun .. but still the class is there and we can change the access restrictions if we want)

This version is used by all the JRE classes, like JAXP.

This let me free to put in my classpath a newer version if Xerces, and use it from my application without interfering with the JRE ones.

They were repackaged by simply renaming the package. This means moving it from, for example, the folder

org/apache/xerces/util

to the folder

com/sun/org/apache/xerces/internal/util

on the hard drive of some JRE guy, and then changing inside .java files the

package org.apache.xerces.util;

to

package com.sun.org.apache.xerces.internal.util;

So, from a JVM point of view, they are totally different classes.