org.ejen.ext.parsers.java_1_2
Class JavaSourceToXML

java.lang.Object
  |
  +--org.ejen.ext.parsers.java_1_2.JavaSourceToXML
All Implemented Interfaces:
JavaParserConstants, JavaParserTreeConstants

public class JavaSourceToXML
extends Object
implements JavaParserTreeConstants, JavaParserConstants

Java source file compilation utility (static methods).

Usage (XSL stylesheet)

  <?xml version="1.0" encoding="iso-8859-1"?>

  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  ...
                  xmlns:jsx="org.ejen.ext.parsers.java_1_2.JavaSourceToXML"
                  version="1.0">

    <xsl:output method="xml" encoding="iso-8859-1"/>

    <xsl:template match="ejen">

      <xsl:copy-of select="jsx:process('{$name}.java')"/>
      <xsl:copy-of select="jsx:process('{$name}.java',true)"/>
      <xsl:copy-of select="jsx:process('{$name}.java','','')"/>
      <xsl:copy-of select="jsx:process('{$name}.java','','',true)"/>
      <xsl:copy-of select="jsx:parseJavadoc(tok/stok[@ki=10])"/>

    </xsl:template>

  </xsl:stylesheet>
 

Version:
1.0
Author:
F. Wolff

Field Summary
 
Fields inherited from interface org.ejen.ext.parsers.java_1_2.JavaParserTreeConstants
JJTADDITIVEEXPRESSION, JJTALLOCATIONEXPRESSION, JJTANDEXPRESSION, JJTARGUMENTLIST, JJTARGUMENTS, JJTARRAYDIMSANDINITS, JJTARRAYINITIALIZER, JJTASSIGNMENTOPERATOR, JJTBLOCK, JJTBLOCKSTATEMENT, JJTBOOLEANLITERAL, JJTBREAKSTATEMENT, JJTCASTEXPRESSION, JJTCASTLOOKAHEAD, JJTCLASSBODY, JJTCLASSBODYDECLARATION, JJTCLASSDECLARATION, JJTCOMPILATIONUNIT, JJTCONDITIONALANDEXPRESSION, JJTCONDITIONALEXPRESSION, JJTCONDITIONALOREXPRESSION, JJTCONSTRUCTORDECLARATION, JJTCONTINUESTATEMENT, JJTDOSTATEMENT, JJTEMPTYSTATEMENT, JJTEQUALITYEXPRESSION, JJTEXCLUSIVEOREXPRESSION, JJTEXPLICITCONSTRUCTORINVOCATION, JJTEXPRESSION, JJTFIELDDECLARATION, JJTFORINIT, JJTFORMALPARAMETER, JJTFORMALPARAMETERS, JJTFORSTATEMENT, JJTFORUPDATE, JJTIFSTATEMENT, JJTIMPORTDECLARATION, JJTINCLUSIVEOREXPRESSION, JJTINITIALIZER, JJTINSTANCEOFEXPRESSION, JJTINTERFACEDECLARATION, JJTINTERFACEMEMBERDECLARATION, JJTLABELEDSTATEMENT, JJTLITERAL, JJTLOCALVARIABLEDECLARATION, JJTMETHODDECLARATION, JJTMETHODDECLARATIONLOOKAHEAD, JJTMETHODDECLARATOR, JJTMULTIPLICATIVEEXPRESSION, JJTNAME, JJTNAMELIST, JJTNESTEDCLASSDECLARATION, JJTNESTEDINTERFACEDECLARATION, jjtNodeName, JJTNULLLITERAL, JJTPACKAGEDECLARATION, JJTPOSTFIXEXPRESSION, JJTPREDECREMENTEXPRESSION, JJTPREINCREMENTEXPRESSION, JJTPRIMARYEXPRESSION, JJTPRIMARYPREFIX, JJTPRIMARYSUFFIX, JJTPRIMITIVETYPE, JJTRELATIONALEXPRESSION, JJTRESULTTYPE, JJTRETURNSTATEMENT, JJTSHIFTEXPRESSION, JJTSTATEMENT, JJTSTATEMENTEXPRESSION, JJTSTATEMENTEXPRESSIONLIST, JJTSWITCHLABEL, JJTSWITCHSTATEMENT, JJTSYNCHRONIZEDSTATEMENT, JJTTHROWSTATEMENT, JJTTRYSTATEMENT, JJTTYPE, JJTTYPEDECLARATION, JJTUNARYEXPRESSION, JJTUNARYEXPRESSIONNOTPLUSMINUS, JJTUNMODIFIEDCLASSDECLARATION, JJTUNMODIFIEDINTERFACEDECLARATION, JJTVARIABLEDECLARATOR, JJTVARIABLEDECLARATORID, JJTVARIABLEINITIALIZER, JJTWHILESTATEMENT
 
Fields inherited from interface org.ejen.ext.parsers.java_1_2.JavaParserConstants
_DEFAULT, ABSTRACT, ANDASSIGN, ASSIGN, BANG, BIT_AND, BIT_OR, BOOLEAN, BREAK, BYTE, CASE, CATCH, CHAR, CHARACTER_LITERAL, CLASS, COLON, COMMA, CONST, CONTINUE, DECIMAL_LITERAL, DECR, DEFAULT, DIGIT, DO, DOT, DOUBLE, ELSE, EOF, EQ, EXPONENT, EXTENDS, FALSE, FINAL, FINALLY, FLOAT, FLOATING_POINT_LITERAL, FOR, FORMAL_COMMENT, GE, GOTO, GT, HEX_LITERAL, HOOK, IDENTIFIER, IF, IMPLEMENTS, IMPORT, IN_FORMAL_COMMENT, IN_MULTI_LINE_COMMENT, IN_SINGLE_LINE_COMMENT, INCR, INSTANCEOF, INT, INTEGER_LITERAL, INTERFACE, LBRACE, LBRACKET, LE, LETTER, LONG, LPAREN, LSHIFT, LSHIFTASSIGN, LT, MINUS, MINUSASSIGN, MULTI_LINE_COMMENT, NATIVE, NE, NEW, NULL, OCTAL_LITERAL, ORASSIGN, PACKAGE, PLUS, PLUSASSIGN, PRIVATE, PROTECTED, PUBLIC, RBRACE, RBRACKET, REM, REMASSIGN, RETURN, RPAREN, RSIGNEDSHIFT, RSIGNEDSHIFTASSIGN, RUNSIGNEDSHIFT, RUNSIGNEDSHIFTASSIGN, SC_AND, SC_OR, SEMICOLON, SHORT, SINGLE_LINE_COMMENT, SLASH, SLASHASSIGN, STAR, STARASSIGN, STATIC, STRICTFP, STRING_LITERAL, SUPER, SWITCH, SYNCHRONIZED, THIS, THROW, THROWS, TILDE, tokenImage, TRANSIENT, TRUE, TRY, VOID, VOLATILE, WHILE, XOR, XORASSIGN
 
Constructor Summary
protected JavaSourceToXML()
          Protected constructor (prevents instanciation).
 
Method Summary
protected static int[] getMap(String arl, int[] defaultMap, Hashtable cache)
          Returns an int array based on the 'arl' expression.
static NodeSet parseJavadoc(ExpressionContext context, String comment)
          Returns a NodeSet that contains all non empty lines in a Javadoc comment.
protected static NodeSet process(Document doc, String fileName, String nodesArl, String tokensArl, boolean tokensPos)
          Returns a Node that represents a java source file.
static NodeSet process(ExpressionContext context, String fileName)
          Returns a Node that represents a java source file.
static NodeSet process(ExpressionContext context, String fileName, boolean tokensPos)
          Returns a Node that represents a java source file.
static NodeSet process(ExpressionContext context, String fileName, String nodesArl, String tokensArl)
          Returns a Node that represents a java source file.
static NodeSet process(ExpressionContext context, String fileName, String nodesArl, String tokensArl, boolean tokensPos)
          Returns a Node that represents a java source file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaSourceToXML

protected JavaSourceToXML()
Protected constructor (prevents instanciation).

Method Detail

process

public static NodeSet process(ExpressionContext context,
                              String fileName)
Returns a Node that represents a java source file.


  <xsl:copy-of select="jsx:process($java-file)"/>
 

Token positions are not included (see process(ExpressionContext,String,boolean)).

XSLT parameters:
[Mandatory/AVT] name of the java source file.

Parameters:
context - automatically passed by the xalan extension mechanism.
fileName - name of the java source file.
Returns:
a NodeSet that represents the java source file.
Throws:
WrappedRuntimeException - errors (file not found...).

process

public static NodeSet process(ExpressionContext context,
                              String fileName,
                              boolean tokensPos)
Returns a Node that represents a java source file.


  <xsl:copy-of select="jsx:process($java-file)"/>
 

XSLT parameters:
[Mandatory/AVT] name of the java source file.

Parameters:
context - automatically passed by the xalan extension mechanism.
fileName - name of the java source file.
tokensPos - if true, each "tok" or "stok" Node will include positions coordinates (see Token.toNode(...)).
Returns:
a NodeSet that represents the java source file.
Throws:
WrappedRuntimeException - errors (file not found...).

process

public static NodeSet process(ExpressionContext context,
                              String fileName,
                              String nodesArl,
                              String tokensArl)
Returns a Node that represents a java source file.


  <xsl:copy-of select="jsx:process($java-file,'','')"/>
 

Token positions are not included (see process(ExpressionContext,String,String,String,boolean)).

XSLT parameters:
[Mandatory/AVT] name of the java source file.
[Mandatory/AVT] arl sequence that defines which nodes should be accepted/removed/crossed. If the this parameter is equals to "default", then default is used.
[Mandatory/AVT] arl sequence that defines which tokens should be accepted/removed/crossed. If the this parameter is equals to "default", then default is used.

Parameters:
context - automatically passed by the xalan extension mechanism.
fileName - name of the java source file.
nodesArl - arl sequence that defines which nodes should be accepted/removed/crossed.
tokensArl - arl sequence that defines which tokens should be accepted/removed/crossed.
Returns:
a NodeSet that represents the java source file.
Throws:
WrappedRuntimeException - errors (file not found...).

process

public static NodeSet process(ExpressionContext context,
                              String fileName,
                              String nodesArl,
                              String tokensArl,
                              boolean tokensPos)
Returns a Node that represents a java source file.


  <xsl:copy-of select="jsx:process($java-file,'','')"/>
 

XSLT parameters:
[Mandatory/AVT] name of the java source file.
[Mandatory/AVT] arl sequence that defines which nodes should be accepted/removed/crossed.
[Mandatory/AVT] arl sequence that defines which tokens should be accepted/removed/crossed.

Parameters:
context - automatically passed by the xalan extension mechanism.
fileName - name of the java source file.
nodesArl - arl sequence that defines which nodes should be accepted/removed/crossed. If the this parameter is equals to "default", then default is used.
tokensArl - arl sequence that defines which tokens should be accepted/removed/crossed. If the this parameter is equals to "default", then default is used.
tokensPos - if true, each "tok" or "stok" Node will include positions coordinates (see Token.toNode(...)).
Returns:
a NodeSet that represents the java source file.
Throws:
WrappedRuntimeException - errors (file not found...).

process

protected static NodeSet process(Document doc,
                                 String fileName,
                                 String nodesArl,
                                 String tokensArl,
                                 boolean tokensPos)
Returns a Node that represents a java source file.

Parameters:
fileName - name of the java source file.
nodesArl - arl sequence that defines which nodes should be accepted/removed/crossed.
tokensArl - arl sequence that defines which tokens should be accepted/removed/crossed.
Returns:
a NodeSet that represents the java source file.
Throws:
WrappedRuntimeException - errors (file not found...).

getMap

protected static int[] getMap(String arl,
                              int[] defaultMap,
                              Hashtable cache)
Returns an int array based on the 'arl' expression. If the 'arl' expression is already in the 'cache', just returns the existing int array, otherwise creates a new one and puts it in the 'cache'.

Parameters:
arl - arl expression.
defaultMap - int array used by default (if 'arl' is null).
cache - cache used for this kind of arl (SimpleNode or Token).
Returns:
the corresponding int array.

parseJavadoc

public static NodeSet parseJavadoc(ExpressionContext context,
                                   String comment)
Returns a NodeSet that contains all non empty lines in a Javadoc comment.


  <xsl:copy-of select="jsx:parseJavadoc(tok/stok[@ki=10])"/>
 

For example,


  /**
   * Says "Hello <msg> !"
   *
   * @param msg the message to use in salutation.
   * @throws java.lang.IllegalArgumentException ...
   */
 

will be parsed into


  <doc-line>
    <![CDATA[ Says "Hello <msg> !"]]>
  </doc-line>
  <doc-line>
    <![CDATA[ @param msg the message to use in salutations.]]>
  </doc-line>
  <doc-line>
    <![CDATA[ @throws java.lang.IllegalArgumentException ...]]>
  </doc-line>
 

XSLT parameters:
[Mandatory] Javadoc comment to be parsed.

Parameters:
context - automatically passed by the xalan extension mechanism.
comment - the Javadoc comment to be parsed.
Returns:
a NodeSet with parsed lines.
Throws:
WrappedRuntimeException - errors (DOM error).