org.apache.xalan.xsltc.compiler
Class XSLTC

java.lang.Object
  extended by org.apache.xalan.xsltc.compiler.XSLTC

public final class XSLTC
extends java.lang.Object


Field Summary
private  java.util.Hashtable _attributes
           
private  int _attributeSetSerial
           
private  java.util.Vector _bcelClasses
           
private  boolean _callsNodeset
           
private  java.util.Vector _classes
           
private  java.lang.String _className
           
private  boolean _debug
           
private  java.io.File _destDir
           
private  java.util.Hashtable _elements
           
private  boolean _hasIdCall
           
private  int _helperClassSerial
           
private  boolean _isSecureProcessing
          State of the secure processing feature.
private  java.lang.String _jarFileName
           
private  SourceLoader _loader
           
private  int _modeSerial
           
private  boolean _multiDocument
           
private  java.util.Vector _namesIndex
           
private  java.util.Vector _namespaceIndex
           
private  java.util.Hashtable _namespacePrefixes
           
private  java.util.Hashtable _namespaces
           
private  int _nextGType
           
private  int _nextNSType
           
private  int[] _numberFieldIndexes
           
private  int _outputType
           
private  java.lang.String _packageName
           
private  Parser _parser
           
private  java.util.Vector _prefixURIPairs
           
private  java.util.Vector _prefixURIPairsIdx
           
private  org.xml.sax.XMLReader _reader
           
private  int _stepPatternSerial
           
private  Stylesheet _stylesheet
           
private  java.util.Vector _stylesheetNSAncestorPointers
           
private  int _stylesheetSerial
           
private  boolean _templateInlining
          Set to true if template inlining is requested.
static int BYTEARRAY_AND_FILE_OUTPUT
           
static int BYTEARRAY_AND_JAR_OUTPUT
           
static int BYTEARRAY_OUTPUT
           
static int CLASSLOADER_OUTPUT
           
static int FILE_OUTPUT
           
static int JAR_OUTPUT
           
private  java.util.Vector m_characterData
           
 
Constructor Summary
XSLTC()
          XSLTC compiler constructor
 
Method Summary
 int addCharacterData(java.lang.String newData)
          Add literal text to char arrays that will be used to store character data in the stylesheet.
 boolean callsNodeset()
           
private  java.lang.String classFileName(java.lang.String className)
          Convert for Java class name of local system file name.
 boolean compile(org.xml.sax.InputSource input, java.lang.String name)
          Compiles an XSL stylesheet passed in through an InputStream
 boolean compile(java.io.InputStream stream, java.lang.String name)
          Compiles an XSL stylesheet passed in through an InputStream
 byte[][] compile(java.lang.String name, org.xml.sax.InputSource input)
          Compiles a stylesheet pointed to by a URL.
 byte[][] compile(java.lang.String name, org.xml.sax.InputSource input, int outputType)
          Compiles a stylesheet pointed to by a URL.
 boolean compile(java.net.URL url)
          Compiles an XSL stylesheet pointed to by a URL
 boolean compile(java.net.URL url, java.lang.String name)
          Compiles an XSL stylesheet pointed to by a URL
 boolean compile(java.util.Vector stylesheets)
          Compiles a set of stylesheets pointed to by a Vector of URLs
 boolean debug()
          Get current debugging message setting
 void dumpClass(JavaClass clazz)
           
private  java.lang.String entryName(java.io.File f)
          File separators are converted to forward slashes for ZIP files.
 byte[][] getBytecodes()
          Returns an array of bytecode arrays generated by a compilation.
 java.lang.String getCharacterData(int index)
          Retrieve a string representation of the character data to be stored in the translet as a char[].
 int getCharacterDataCount()
          Get the number of char[] arrays, thus far, that will be created to store literal text in the stylesheet.
 java.lang.String getClassName()
          Get the class name for the generated translet.
 java.util.Vector getErrors()
          Get a Vector containing all compile error messages
 java.lang.String getHelperClassName()
          Returns a unique name for every helper class needed to execute a translet.
 java.lang.String getJarFileName()
           
 java.util.Vector getNamesIndex()
           
 java.util.Vector getNamespaceIndex()
           
 java.util.Vector getNSAncestorPointers()
           
 int[] getNumberFieldIndexes()
           
private  java.io.File getOutputFile(java.lang.String className)
          Generate an output File object to send the translet to
 java.util.Properties getOutputProperties()
          Only for user by the internal TrAX implementation.
 Parser getParser()
          Only for user by the internal TrAX implementation.
 java.util.Vector getPrefixURIPairs()
           
 java.util.Vector getPrefixURIPairsIdx()
           
 Stylesheet getStylesheet()
          Returns the top-level stylesheet
 boolean getTemplateInlining()
          Return the state of the template inlining feature.
 java.util.Vector getWarnings()
          Get a Vector containing all compile warning messages
 org.xml.sax.XMLReader getXMLReader()
          Get the XMLReader to use for parsing the next input stylesheet
 boolean hasIdCall()
           
 void init()
          Initializes the compiler to compile a new stylesheet
 boolean isMultiDocument()
           
 boolean isSecureProcessing()
          Return the state of the secure processing feature.
 int nextAttributeSetSerial()
           
 int nextHelperClassSerial()
           
 int nextModeSerial()
           
 int nextStepPatternSerial()
           
 int nextStylesheetSerial()
           
 void outputToJar()
          Generate output JAR-file and packages
 void printErrors()
          Print all compile error messages to standard output
 void printWarnings()
          Print all compile warning messages to standard output
 int registerAttribute(QName name)
          Registers an attribute and gives it a type so that it can be mapped to DOM attribute types at run-time.
 int registerElement(QName name)
          Registers an element and gives it a type so that it can be mapped to DOM element types at run-time.
 int registerNamespace(java.lang.String namespaceURI)
          Registers a namespace and gives it a type so that it can be mapped to DOM namespace types at run-time.
 int registerNamespacePrefix(QName name)
          Registers a namespace prefix and gives it a type so that it can be mapped to DOM namespace types at run-time.
 int registerNamespacePrefix(java.lang.String name)
          Registers a namespace and gives it a type so that it can be mapped to DOM namespace types at run-time.
 int registerStylesheetPrefixMappingForRuntime(java.util.Hashtable prefixMap, int ancestorID)
          Registers namespace declarations that the stylesheet might need to look up dynamically - for instance, if an xsl:element has a a name attribute with variable parts and has no namespace attribute.
private  void reset()
          Initializes the compiler to produce a new translet
protected  void setCallsNodeset(boolean flag)
          This method is called by the XPathParser when it encounters a call to the nodeset() extension function.
 void setClassName(java.lang.String className)
          Set the class name for the generated translet.
 void setDebug(boolean debug)
          Turn debugging messages on/off
 boolean setDestDirectory(java.lang.String dstDirName)
          Set the destination directory for the translet.
protected  void setHasIdCall(boolean flag)
           
 void setJarFileName(java.lang.String jarFileName)
          Set the name of an optional JAR-file to dump the translet and auxiliary classes to
protected  void setMultiDocument(boolean flag)
          This method is called by the XPathParser when it encounters a call to the document() function.
 void setOutputType(int type)
          Only for user by the internal TrAX implementation.
 void setPackageName(java.lang.String packageName)
          Set an optional package name for the translet and auxiliary classes
 void setPIParameters(java.lang.String media, java.lang.String title, java.lang.String charset)
          Set the parameters to use to locate the correct processing instruction in the case where the input document to the compiler (and parser) is an XML document.
 void setSecureProcessing(boolean flag)
          Set the state of the secure processing feature.
 void setSourceLoader(SourceLoader loader)
          Defines an external SourceLoader to provide the compiler with documents referenced in xsl:include/import
 void setStylesheet(Stylesheet stylesheet)
          Set the top-level stylesheet
 void setTemplateInlining(boolean templateInlining)
          Set a flag indicating if templates are to be inlined or not.
 void setXMLReader(org.xml.sax.XMLReader reader)
          Set the XMLReader to use for parsing the next input stylesheet
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_parser

private Parser _parser

_reader

private org.xml.sax.XMLReader _reader

_loader

private SourceLoader _loader

_stylesheet

private Stylesheet _stylesheet

_modeSerial

private int _modeSerial

_stylesheetSerial

private int _stylesheetSerial

_stepPatternSerial

private int _stepPatternSerial

_helperClassSerial

private int _helperClassSerial

_attributeSetSerial

private int _attributeSetSerial

_numberFieldIndexes

private int[] _numberFieldIndexes

_nextGType

private int _nextGType

_namesIndex

private java.util.Vector _namesIndex

_elements

private java.util.Hashtable _elements

_attributes

private java.util.Hashtable _attributes

_nextNSType

private int _nextNSType

_namespaceIndex

private java.util.Vector _namespaceIndex

_namespaces

private java.util.Hashtable _namespaces

_namespacePrefixes

private java.util.Hashtable _namespacePrefixes

m_characterData

private java.util.Vector m_characterData

FILE_OUTPUT

public static final int FILE_OUTPUT
See Also:
Constant Field Values

JAR_OUTPUT

public static final int JAR_OUTPUT
See Also:
Constant Field Values

BYTEARRAY_OUTPUT

public static final int BYTEARRAY_OUTPUT
See Also:
Constant Field Values

CLASSLOADER_OUTPUT

public static final int CLASSLOADER_OUTPUT
See Also:
Constant Field Values

BYTEARRAY_AND_FILE_OUTPUT

public static final int BYTEARRAY_AND_FILE_OUTPUT
See Also:
Constant Field Values

BYTEARRAY_AND_JAR_OUTPUT

public static final int BYTEARRAY_AND_JAR_OUTPUT
See Also:
Constant Field Values

_debug

private boolean _debug

_jarFileName

private java.lang.String _jarFileName

_className

private java.lang.String _className

_packageName

private java.lang.String _packageName

_destDir

private java.io.File _destDir

_outputType

private int _outputType

_classes

private java.util.Vector _classes

_bcelClasses

private java.util.Vector _bcelClasses

_callsNodeset

private boolean _callsNodeset

_multiDocument

private boolean _multiDocument

_hasIdCall

private boolean _hasIdCall

_stylesheetNSAncestorPointers

private java.util.Vector _stylesheetNSAncestorPointers

_prefixURIPairs

private java.util.Vector _prefixURIPairs

_prefixURIPairsIdx

private java.util.Vector _prefixURIPairsIdx

_templateInlining

private boolean _templateInlining
Set to true if template inlining is requested. Template inlining used to be the default, but we have found that Hotspots does a better job with shorter methods, so the default is *not* to inline now.


_isSecureProcessing

private boolean _isSecureProcessing
State of the secure processing feature.

Constructor Detail

XSLTC

public XSLTC()
XSLTC compiler constructor

Method Detail

setSecureProcessing

public void setSecureProcessing(boolean flag)
Set the state of the secure processing feature.


isSecureProcessing

public boolean isSecureProcessing()
Return the state of the secure processing feature.


getParser

public Parser getParser()
Only for user by the internal TrAX implementation.


setOutputType

public void setOutputType(int type)
Only for user by the internal TrAX implementation.


getOutputProperties

public java.util.Properties getOutputProperties()
Only for user by the internal TrAX implementation.


init

public void init()
Initializes the compiler to compile a new stylesheet


reset

private void reset()
Initializes the compiler to produce a new translet


setSourceLoader

public void setSourceLoader(SourceLoader loader)
Defines an external SourceLoader to provide the compiler with documents referenced in xsl:include/import

Parameters:
loader - The SourceLoader to use for include/import

setTemplateInlining

public void setTemplateInlining(boolean templateInlining)
Set a flag indicating if templates are to be inlined or not. The default is to do inlining, but this causes problems when the stylesheets have a large number of templates (e.g. branch targets exceeding 64K or a length of a method exceeding 64K).


getTemplateInlining

public boolean getTemplateInlining()
Return the state of the template inlining feature.


setPIParameters

public void setPIParameters(java.lang.String media,
                            java.lang.String title,
                            java.lang.String charset)
Set the parameters to use to locate the correct processing instruction in the case where the input document to the compiler (and parser) is an XML document.

Parameters:
media - The media attribute to be matched. May be null, in which case the prefered templates will be used (i.e. alternate = no).
title - The value of the title attribute to match. May be null.
charset - The value of the charset attribute to match. May be null.

compile

public boolean compile(java.net.URL url)
Compiles an XSL stylesheet pointed to by a URL

Parameters:
url - An URL containing the input XSL stylesheet

compile

public boolean compile(java.net.URL url,
                       java.lang.String name)
Compiles an XSL stylesheet pointed to by a URL

Parameters:
url - An URL containing the input XSL stylesheet
name - The name to assign to the translet class

compile

public boolean compile(java.io.InputStream stream,
                       java.lang.String name)
Compiles an XSL stylesheet passed in through an InputStream

Parameters:
stream - An InputStream that will pass in the stylesheet contents
name - The name of the translet class to generate
Returns:
'true' if the compilation was successful

compile

public boolean compile(org.xml.sax.InputSource input,
                       java.lang.String name)
Compiles an XSL stylesheet passed in through an InputStream

Parameters:
input - An InputSource that will pass in the stylesheet contents
name - The name of the translet class to generate - can be null
Returns:
'true' if the compilation was successful

compile

public boolean compile(java.util.Vector stylesheets)
Compiles a set of stylesheets pointed to by a Vector of URLs

Parameters:
stylesheets - A Vector containing URLs pointing to the stylesheets
Returns:
'true' if the compilation was successful

getBytecodes

public byte[][] getBytecodes()
Returns an array of bytecode arrays generated by a compilation.

Returns:
JVM bytecodes that represent translet class definition

compile

public byte[][] compile(java.lang.String name,
                        org.xml.sax.InputSource input,
                        int outputType)
Compiles a stylesheet pointed to by a URL. The result is put in a set of byte arrays. One byte array for each generated class.

Parameters:
name - The name of the translet class to generate
input - An InputSource that will pass in the stylesheet contents
outputType - The output type
Returns:
JVM bytecodes that represent translet class definition

compile

public byte[][] compile(java.lang.String name,
                        org.xml.sax.InputSource input)
Compiles a stylesheet pointed to by a URL. The result is put in a set of byte arrays. One byte array for each generated class.

Parameters:
name - The name of the translet class to generate
input - An InputSource that will pass in the stylesheet contents
Returns:
JVM bytecodes that represent translet class definition

setXMLReader

public void setXMLReader(org.xml.sax.XMLReader reader)
Set the XMLReader to use for parsing the next input stylesheet

Parameters:
reader - XMLReader (SAX2 parser) to use

getXMLReader

public org.xml.sax.XMLReader getXMLReader()
Get the XMLReader to use for parsing the next input stylesheet


getErrors

public java.util.Vector getErrors()
Get a Vector containing all compile error messages

Returns:
A Vector containing all compile error messages

getWarnings

public java.util.Vector getWarnings()
Get a Vector containing all compile warning messages

Returns:
A Vector containing all compile error messages

printErrors

public void printErrors()
Print all compile error messages to standard output


printWarnings

public void printWarnings()
Print all compile warning messages to standard output


setMultiDocument

protected void setMultiDocument(boolean flag)
This method is called by the XPathParser when it encounters a call to the document() function. Affects the DOM used by the translet.


isMultiDocument

public boolean isMultiDocument()

setCallsNodeset

protected void setCallsNodeset(boolean flag)
This method is called by the XPathParser when it encounters a call to the nodeset() extension function. Implies multi document.


callsNodeset

public boolean callsNodeset()

setHasIdCall

protected void setHasIdCall(boolean flag)

hasIdCall

public boolean hasIdCall()

setClassName

public void setClassName(java.lang.String className)
Set the class name for the generated translet. This class name is overridden if multiple stylesheets are compiled in one go using the compile(Vector urls) method.

Parameters:
className - The name to assign to the translet class

getClassName

public java.lang.String getClassName()
Get the class name for the generated translet.


classFileName

private java.lang.String classFileName(java.lang.String className)
Convert for Java class name of local system file name. (Replace '.' with '/' on UNIX and replace '.' by '\' on Windows/DOS.)


getOutputFile

private java.io.File getOutputFile(java.lang.String className)
Generate an output File object to send the translet to


setDestDirectory

public boolean setDestDirectory(java.lang.String dstDirName)
Set the destination directory for the translet. The current working directory will be used by default.


setPackageName

public void setPackageName(java.lang.String packageName)
Set an optional package name for the translet and auxiliary classes


setJarFileName

public void setJarFileName(java.lang.String jarFileName)
Set the name of an optional JAR-file to dump the translet and auxiliary classes to


getJarFileName

public java.lang.String getJarFileName()

setStylesheet

public void setStylesheet(Stylesheet stylesheet)
Set the top-level stylesheet


getStylesheet

public Stylesheet getStylesheet()
Returns the top-level stylesheet


registerAttribute

public int registerAttribute(QName name)
Registers an attribute and gives it a type so that it can be mapped to DOM attribute types at run-time.


registerElement

public int registerElement(QName name)
Registers an element and gives it a type so that it can be mapped to DOM element types at run-time.


registerNamespacePrefix

public int registerNamespacePrefix(QName name)
Registers a namespace prefix and gives it a type so that it can be mapped to DOM namespace types at run-time.


registerNamespacePrefix

public int registerNamespacePrefix(java.lang.String name)
Registers a namespace and gives it a type so that it can be mapped to DOM namespace types at run-time.


registerNamespace

public int registerNamespace(java.lang.String namespaceURI)
Registers a namespace and gives it a type so that it can be mapped to DOM namespace types at run-time.


registerStylesheetPrefixMappingForRuntime

public int registerStylesheetPrefixMappingForRuntime(java.util.Hashtable prefixMap,
                                                     int ancestorID)
Registers namespace declarations that the stylesheet might need to look up dynamically - for instance, if an xsl:element has a a name attribute with variable parts and has no namespace attribute.

Parameters:
prefixMap - a Hashtable mapping namespace prefixes to URIs. Must not be null. The default namespace and namespace undeclarations are represented by a zero-length string.
ancestorID - The int node ID of the nearest ancestor in the stylesheet that declares namespaces, or a value less than zero if there is no such ancestor
Returns:
A new node ID for the stylesheet element

getNSAncestorPointers

public java.util.Vector getNSAncestorPointers()

getPrefixURIPairs

public java.util.Vector getPrefixURIPairs()

getPrefixURIPairsIdx

public java.util.Vector getPrefixURIPairsIdx()

nextModeSerial

public int nextModeSerial()

nextStylesheetSerial

public int nextStylesheetSerial()

nextStepPatternSerial

public int nextStepPatternSerial()

getNumberFieldIndexes

public int[] getNumberFieldIndexes()

nextHelperClassSerial

public int nextHelperClassSerial()

nextAttributeSetSerial

public int nextAttributeSetSerial()

getNamesIndex

public java.util.Vector getNamesIndex()

getNamespaceIndex

public java.util.Vector getNamespaceIndex()

getHelperClassName

public java.lang.String getHelperClassName()
Returns a unique name for every helper class needed to execute a translet.


dumpClass

public void dumpClass(JavaClass clazz)

entryName

private java.lang.String entryName(java.io.File f)
                            throws java.io.IOException
File separators are converted to forward slashes for ZIP files.

Throws:
java.io.IOException

outputToJar

public void outputToJar()
                 throws java.io.IOException
Generate output JAR-file and packages

Throws:
java.io.IOException

setDebug

public void setDebug(boolean debug)
Turn debugging messages on/off


debug

public boolean debug()
Get current debugging message setting


getCharacterData

public java.lang.String getCharacterData(int index)
Retrieve a string representation of the character data to be stored in the translet as a char[]. There may be more than one such array required.

Parameters:
index - The index of the char[]. Zero-based.
Returns:
String The character data to be stored in the corresponding char[].

getCharacterDataCount

public int getCharacterDataCount()
Get the number of char[] arrays, thus far, that will be created to store literal text in the stylesheet.


addCharacterData

public int addCharacterData(java.lang.String newData)
Add literal text to char arrays that will be used to store character data in the stylesheet.

Parameters:
newData - String data to be added to char arrays. Pre-condition: newData.length() ≤ 21845
Returns:
int offset at which character data will be stored