Hi All
I am not understanding how to overcome with this issue
If I execute directly I am getting exception.
If I execute using xBootClassPath params say something like java
-Xbootclasspath/p:c:\jars\xsltc.jar then I am not getting exception.
Basically I don't want to use xBootClassPath.
I know instead of depending on Translets I can directly use XALAn API.
But our client team insisting on translets only and they don't want to
set the xBootClasspath param while executing application.
Basically the problem is with below lines
System.setProperty ( "javax.xml.transform.TransformerFactory" ,
"org.apache.xalan.xsltc.trax.TransformerFactoryImpl" ) ;
TransformerFactory factory = TransformerFactory.newInstance () ;
Templates templates = factory.newTemplates ( stylesheet ) ;
I need to set the Transformer Factory Implementation class (i.e
org.apache.xalan.xsltc.trax.TransformerFactoryImpl which is from Trax
API) so that I can get the results.
But it seems before setting the System property, JRE's class loader is
loading the default implementation class i.e is from xalan API
And also we have same interface for both XALAN api and JAXP
TransformerFactory
http://xml.apache.org/xalan-j/apidocs/javax/xml/transform/TransformerFactory.html
http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/transform/TransformerFactory.html
I thought, if I use XALAN's class instead of JAXP's class I can get
rid of this error.
For this I need to have a custom class loader.I tried to write the
Custom class loader. But I have failed in implementing so :-(
Plz help me resolve this issue.
Source code :
import java.io.* ;
import javax.xml.transform.* ;
import javax.xml.transform.stream.* ;
public class XSLCompiler1
{
public static void main ( String[] args )
throws Exception
{
try{
XSLCompiler1 app = new XSLCompiler1 () ;
app.transform ( "c:/eml.xsl") ;
}
catch(Throwable e)
{
System.out.println ( "Exception: " + e ) ;
StringWriter sw=new StringWriter();
PrintWriter pw=new PrintWriter(sw);
e.printStackTrace (pw) ;
System.out.println(sw);
}
}
/**
* Compiles an XSL stylesheet into a translet, wraps tshe translet
* inside a Templates object and dumps it to a file.
*/
public Transformer getTransformer ( String xsl ) throws Exception
{
try
{
// Set XSLTC's TransformerFactory implementation as the default
System.setProperty ( "javax.xml.transform.TransformerFactory" ,
"org.apache.xalan.xsltc.trax.TransformerFactoryImpl" ) ;
// Get an input stream for the XSL stylesheet
StreamSource stylesheet = new StreamSource ( xsl ) ;
// The TransformerFactory will compile the stylesheet and
// put the translet classes inside the Templates object
TransformerFactory factory = TransformerFactory.newInstance () ;
factory.setAttribute ( "generate-translet" , Boolean.TRUE ) ;
Templates templates = factory.newTemplates ( stylesheet ) ;
Transformer transformer = templates.newTransformer () ;
return transformer ;
}
catch ( Exception e )
{
//System.out.println ( "Exception: " + e ) ;
StringWriter sw=new StringWriter();
PrintWriter pw=new PrintWriter(sw);
e.printStackTrace (pw) ;
System.out.println(sw);
throw new Exception("Error ",e);
}
}
public void transform ( String xslFileName )
throws Exception
{
Transformer transformer = getTransformer ( xslFileName ) ;
if ( transformer == null )
{
throw new RuntimeException ( "Bad XSL File or transformer
creation problem" ) ;
}
ByteArrayOutputStream transformmedStream = new
ByteArrayOutputStream () ;
FileInputStream fin = new FileInputStream ( "c:/111.xml" ) ;
transformer.transform ( new StreamSource ( fin ) , new
StreamResult ( transformmedStream ) ) ;
System.out.println(transformmedStream.toString());
}
private void usage ()
{
System.out.println ( "Usage: XSLCompiler1 <xsl_file>" ) ;
System.exit ( 1 ) ;
}
}
Exception Stack Trace :
Exception: java.lang.IllegalAccessError: class
org.apache.xml.dtm.ref.sax2dtm.SAX2DTM2$AncestorIterator cannot access
its superclass
org.apache.xml.dtm.ref.DTMDefaultBaseIterators$InternalAxisIteratorBase
java.lang.IllegalAccessError: class
org.apache.xml.dtm.ref.sax2dtm.SAX2DTM2$AncestorIterator cannot access
its superclass
org.apache.xml.dtm.ref.DTMDefaultBaseIterators$InternalAxisIteratorBase
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:250)
at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
at
org.apache.xalan.xsltc.dom.XSLTCDTMManager.getDTM(XSLTCDTMManager.java:351)
at
org.apache.xalan.xsltc.dom.XSLTCDTMManager.getDTM(XSLTCDTMManager.java:228)
at
org.apache.xalan.xsltc.trax.TransformerImpl.getDOM(TransformerImpl.java:437)
at
org.apache.xalan.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:597)
at
org.apache.xalan.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:277)
at XSLCompiler1.transform(XSLCompiler1.java:73)
at XSLCompiler1.main(XSLCompiler1.java:13)