org.ejen.ext
Class JavaClassToXML

java.lang.Object
  |
  +--org.ejen.ext.JavaClassToXML

public class JavaClassToXML
extends Object

Class reflection 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:jcx="org.ejen.ext.JavaClassToXML"
                  version="1.0">

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

    <xsl:template match="ejen">

      <xsl:copy-of select="jcx:process('java.lang.String')"/>
      <xsl:value-of select="jcx:stripType('[LLjava.lang.Object;')"/>
      <xsl:value-of select="jcx:stripTypeDims('[LLjava.lang.Object;')"/>
      <xsl:value-of select="jcx:dimsOfType('[LLjava.lang.Object;')"/>
      <xsl:value-of select="jcx:packageOfType('[LLjava.lang.Object;')"/>

    </xsl:template>

  </xsl:stylesheet>
 

Version:
1.0
Author:
F. Wolff

Field Summary
static String DIM_STR
          String that represents one array dimension: []
 
Constructor Summary
protected JavaClassToXML()
          Protected constructor (prevents instanciation).
 
Method Summary
static String dimsOfType(ExpressionContext context, String type)
          Returns type array dimensions in the form of "[][][]...
static String packageOfType(ExpressionContext context, String type)
          Returns type package information.
protected static Node process(Document doc, Class c)
          Returns a Node that represents a Class definition.
static Node process(ExpressionContext context, String className)
          Returns a Node that represents a Class definition.
static String stripType(ExpressionContext context, String type)
          Strips a type definition (see Java signature format), removing all array dimensions and package information.
static String stripTypeDims(ExpressionContext context, String type)
          Strips a type definition (see Java signature format), removing only array dimensions information.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DIM_STR

public static final String DIM_STR
String that represents one array dimension: []

See Also:
Constant Field Values
Constructor Detail

JavaClassToXML

protected JavaClassToXML()
Protected constructor (prevents instanciation).

Method Detail

process

public static Node process(ExpressionContext context,
                           String className)
Returns a Node that represents a Class definition.


  <xsl:copy-of select="jcx:process('java.lang.String')"/>
 

The class definition returned is recursive (for each class/interface definition, all extended or implemented class/interface definitions are also provided).

For "java.lang.String", the returned tree as the following structure:


  <class-definition interface="false">
    <package><![CDATA[java.lang]]></package>
    <modifiers><![CDATA[public final]]></modifiers>
    <name><![CDATA[String]]></name>
    <extends>
      <class-definition interface="false">
        <package><![CDATA[java.lang]]></package>
        <modifiers><![CDATA[public]]></modifiers>
        <name><![CDATA[Object]]></name>
        ...
      </class-definition>
    </extends>
    <implements>
      <class-definition interface="true">
        <package><![CDATA[java.io]]></package>
        <modifiers><![CDATA[public abstract interface]]></modifiers>
        <name><![CDATA[Serializable]]></name>
      </class-definition>
      <class-definition interface="true">
        <package><![CDATA[java.lang]]></package>
        <modifiers><![CDATA[public abstract interface]]></modifiers>
        <name><![CDATA[Comparable]]></name>
        <method>
          <modifiers><![CDATA[public abstract]]></modifiers>
          <return-type><![CDATA[int]]></return-type>
          <name><![CDATA[compareTo]]></name>
          <parameter><![CDATA[java.lang.Object]]></parameter>
        </method>
      </class-definition>
    </implements>
    <field>
      <modifiers><![CDATA[private]]></modifiers>
      <type><![CDATA[[C]]></type>
      <name><![CDATA[value]]></name>
    </field>
    ...
    <constructor>
      <modifiers><![CDATA[public]]></modifiers>
    </constructor>
    <constructor>
      <modifiers><![CDATA[public]]></modifiers>
      <parameter><![CDATA[java.lang.String]]></parameter>
    </constructor>
    ...
    <method>
      <modifiers><![CDATA[public]]></modifiers>
      <return-type><![CDATA[int]]></return-type>
      <name><![CDATA[hashCode]]></name>
    </method>
    <method>
      <modifiers><![CDATA[public]]></modifiers>
      <return-type><![CDATA[int]]></return-type>
      <name><![CDATA[compareTo]]></name>
      <parameter><![CDATA[java.lang.String]]></parameter>
    </method>
    ...
    <class-definition interface="false">
      <package><![CDATA[java.lang]]></package>
      <modifiers/>
      <name><![CDATA[String$1]]></name>
      ...
    </class-definition>
    <class-definition interface="false">
      <package><![CDATA[java.lang]]></package>
      <modifiers><![CDATA[private static]]></modifiers>
      <name><![CDATA[String$CaseInsensitiveComparator]]></name>
      ...
    </class-definition>
      ...
  </class-definition>
 

Note: the two last "class-definitions" are inner class definitions in java.lang.String.

XSLT parameters:
[Mandatory/AVT] full Class name.

Parameters:
context - automatically passed by the xalan extension mechanism.
className - Class name.
Returns:
a Node that represents a Class definition.
Throws:
WrappedRuntimeException - errors (...).

process

protected static Node process(Document doc,
                              Class c)
Returns a Node that represents a Class definition.

Parameters:
doc - the current Document.
c - the Class to get definition from..
Returns:
a Node that represents a Class definition.
Throws:
WrappedRuntimeException - errors (...).

stripType

public static String stripType(ExpressionContext context,
                               String type)
Strips a type definition (see Java signature format), removing all array dimensions and package information.


  <xsl:value-of select="jcx:stripType('[[Ljava.lang.String;')"/>
 

For example, the function will return "Object" for "[LLjava.lang.Object;" (ie: java.lang.Object[][]) or "int" for "[[[I" (ie: int[][][]).

XSLT parameters:
[Mandatory/AVT] the Java type in the "Java signature format".

Parameters:
context - automatically passed by the xalan extension mechanism.
type - the Java type in the "Java signature format".
Returns:
the stripped type.
Throws:
WrappedRuntimeException - errors (...).

stripTypeDims

public static String stripTypeDims(ExpressionContext context,
                                   String type)
Strips a type definition (see Java signature format), removing only array dimensions information.


  <xsl:value-of select="jcx:stripTypeDims('[[I')"/>
 

For example, the function will return "java.lang.Object" for "[LLjava.lang.Object;" (ie: java.lang.Object[][]) or "int" for "[[[I" (ie: int[][][]).

XSLT parameters:
[Mandatory/AVT] the Java type in the "Java signature format".

Parameters:
context - automatically passed by the xalan extension mechanism.
type - [AVT] - a type definition in the "Java signature format".
Returns:
the stripped type.
Throws:
WrappedRuntimeException - errors (...).

dimsOfType

public static String dimsOfType(ExpressionContext context,
                                String type)
Returns type array dimensions in the form of "[][][]...".


  <xsl:value-of select="jcx:stripTypeDims('[[I')"/>
 

For example, the function will return "[][]" for "[LLjava.lang.Object;" (ie: java.lang.Object[][]) or "[][][]" for "[[[I" (ie: int[][][]).

XSLT parameters:
[Mandatory/AVT] the Java type in the "Java signature format".

Parameters:
context - automatically passed by the xalan extension mechanism.
type - [AVT] - a type definition in the "Java signature format".
Returns:
the type array dimensions (may be "").
Throws:
WrappedRuntimeException - errors (...).

packageOfType

public static String packageOfType(ExpressionContext context,
                                   String type)
Returns type package information.


  <xsl:value-of select="jcx:stripTypeDims('[[java.lang.Object;')"/>
 

For example, the function will return "java.lang" for "[LLjava.lang.Object;" (ie: java.lang.Object[][]) or "" for "[[[I" (ie: int[][][]).

XSLT parameters:
[Mandatory/AVT] the Java type in the "Java signature format".

Parameters:
context - automatically passed by the xalan extension mechanism.
type - [AVT] - a type definition in the "Java signature format".
Returns:
the type package (may be "").
Throws:
WrappedRuntimeException - errors (...).