|
| |
XSLTC's native API is represented by the
org.apache.xalan.xsltc.compiler.XSLTC class. Any application
using XSLTC's native API should only have to access methods in this class
in order to compile a stylesheet (or a set or stylesheets) into one or
more Java classes. The XSLTC has an empty constructor. The
class needs to be initialized before each compilation by a call to:
| |
There is a set of methods for compiling one or more stylesheets into a
set of Java classes. The stylesheet can be specified either as a
URL , InputStream , InputSource or
a Vector containing a set of URL s pointing to
stylesheets: | | | |
public boolean compile(URL url);
public boolean compile(URL url, String transletName);
public boolean compile(InputStream stream, String transletName);
public boolean compile(InputSource input, String transletName);
public boolean compile(Vector stylesheets); | | | | |
The default behaviour is to output the compiled Java class(es) to one or
more Java classes in the current working directory. The name of the main
translet class will be obtained from (in order of priority):
- that specified in the
compile() method
- if none is specified (if the parameter is 'null') the name will be
generated from the filename specified by the input URL/file/stream
- the default translet name (set by
setClassName() )
- the built-in default class name
"GregorSamsa"
Additional Java classes will be generated for complex stylesheets. These
classes represent elements such as predicates, sort-records, etc. in the
stylesheet. Additional classes share the same root name as the main translet
class, with a suffix containing a '$'-sign and a sequence number. The result
of a single compilation of a complex stylesheet could be: | | | |
GregorSamsa.java
GregorSamsa$0.java
GregorSamsa$1.java
GregorSamsa$2.java
GregorSamsa$3.java | | | | |
It is not always desireable having these classes dumped to files in the
current working directory. There is one compile() method that
will return the Java class definitions as bytecodes. The bytecodes are
returned in a two-dimmensional byte array. Each byte-array
contains the bytecodes for one Java class: | | | |
public byte[][] compile(String name, InputSource input); | | | | |
Alternatively, one can first compile the stylesheet into one or more
Java class files, and then also retrieve the bytecodes from the compiler: | | | |
public byte[][] getBytecodes(); | | | | |
|
|
| |
The steps described in this chapter are covered in these sample
source code files:
org.apache.xalan.xsltc.cmdline.Transform
xml-xalan/java/samples/CompiledApplet/TransformApplet.java
xml-xalan/java/samples/CompiledBrazil/TransformHandler.java
xml-xalan/java/samples/CompiledEJB/TransformBean.java
xml-xalan/java/samples/CompiledEJB/TransformHome.java
xml-xalan/java/samples/CompiledEJB/TransformRemote.java
xml-xalan/java/samples/CompiledEJB/TransformServlet.java
xml-xalan/java/samples/CompiledServlet/CompileServlet.java
xml-xalan/java/samples/CompiledServlet/TransformServlet.java
|
|
|