com.sun.jdo.spi.persistence.utility.generator.io
Class IOJavaClassWriter

java.lang.Object
  extended by com.sun.jdo.spi.persistence.utility.generator.io.IOJavaClassWriter
All Implemented Interfaces:
JavaClassWriter

public final class IOJavaClassWriter
extends java.lang.Object
implements JavaClassWriter

This implementation of the JavaClassWriter interface is based on simple StringBuffer "println" type statements.

The order of the generated code in this implementation depends on the initialization. The default order is to accept fields and methods in any order and generate all fields together and all methods together (by member category). Specifying the ordered parameter in the constructor will lead to a slightly different order: generation of fields and methods interspersed among each other in exactly the order they were added (no member categories).

Author:
raccah

Constructor Summary
IOJavaClassWriter()
          Creates a new instance of IOJavaClassWriter which maintains the order of member input but groups them by category.
IOJavaClassWriter(boolean maintainCategories)
          Creates a new instance of IOJavaClassWriter in which the order of the generated code depends on the specified flag.
 
Method Summary
 void addClass(JavaClassWriter classWriter)
          Adds an inner class to this class.
 void addConstructor(java.lang.String name, int modifiers, java.lang.String[] parameterNames, java.lang.String[] parameterTypes, java.lang.String[] exceptions, java.lang.String[] body, java.lang.String[] comments)
          Adds a constructor to this class.
 void addField(java.lang.String name, int modifiers, java.lang.String type, java.lang.String initialValue, java.lang.String[] comments)
          Adds a field to the list of those declared by this class.
 void addInitializer(boolean isStatic, java.lang.String[] body, java.lang.String[] comments)
          Adds an initializer to this class.
 void addInterface(java.lang.String name)
          Adds an interface to the list of those implemented by this class.
 void addMethod(java.lang.String name, int modifiers, java.lang.String returnType, java.lang.String[] parameterNames, java.lang.String[] parameterTypes, java.lang.String[] exceptions, java.lang.String[] body, java.lang.String[] comments)
          Adds a method to this class.
 void setClassDeclaration(int modifiers, java.lang.String className, java.lang.String[] comments)
          Sets the information for the class declaration including modifiers, name, and comments.
 void setSuperclass(java.lang.String name)
          Sets the superclass of this class.
 java.lang.String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IOJavaClassWriter

public IOJavaClassWriter()
Creates a new instance of IOJavaClassWriter which maintains the order of member input but groups them by category.

See Also:
IOJavaClassWriter(boolean)

IOJavaClassWriter

public IOJavaClassWriter(boolean maintainCategories)
Creates a new instance of IOJavaClassWriter in which the order of the generated code depends on the specified flag.

Parameters:
maintainCategories - If true, the order of members is preserved within category groups. If false, the generation of fields and methods will be interspersed among each other in exactly the order they were added with no member categories.
Method Detail

setClassDeclaration

public void setClassDeclaration(int modifiers,
                                java.lang.String className,
                                java.lang.String[] comments)
Sets the information for the class declaration including modifiers, name, and comments. Note that the name must not be fully qualified.

Specified by:
setClassDeclaration in interface JavaClassWriter
Parameters:
modifiers - The modifier flags for this class.
className - The (non-qualified) name of this class.
comments - The comments shown just above the class declaration. The comments are passed as an array so the line separators can be added by the implementation. Note that not all implementations will choose to make use of this comment.
See Also:
Modifier

setSuperclass

public void setSuperclass(java.lang.String name)
Sets the superclass of this class. Note that the name format must be package style (that is - it can contain . but not / or $).

Specified by:
setSuperclass in interface JavaClassWriter
Parameters:
name - The name of the superclass.

addInterface

public void addInterface(java.lang.String name)
Adds an interface to the list of those implemented by this class.

Specified by:
addInterface in interface JavaClassWriter
Parameters:
name - The name of the interface.

addField

public void addField(java.lang.String name,
                     int modifiers,
                     java.lang.String type,
                     java.lang.String initialValue,
                     java.lang.String[] comments)
Adds a field to the list of those declared by this class. Note that the type format must be package style (that is - it can contain . but not / or $).

Specified by:
addField in interface JavaClassWriter
Parameters:
name - The name of the field.
modifiers - The modifier flags for this field.
type - A string representing the type of this field.
initialValue - A string representing the initial value of this field.
comments - The comments shown just above the declaration of this field. The comments are passed as an array so the line separators can be added by the implementation. Note that not all implementations will choose to make use of this comment.
See Also:
Modifier

addInitializer

public void addInitializer(boolean isStatic,
                           java.lang.String[] body,
                           java.lang.String[] comments)
Adds an initializer to this class.

Specified by:
addInitializer in interface JavaClassWriter
Parameters:
isStatic - True if this is a static initializer, false otherwise.
body - The implementation block of the initializer. The body of the implementation is passed as an array so the line separators can be added by the implementation.
comments - The comments shown just above the initializer block. The comments are passed as an array so the line separators can be added by the implementation. Note that not all implementations will choose to make use of this comment.

addConstructor

public void addConstructor(java.lang.String name,
                           int modifiers,
                           java.lang.String[] parameterNames,
                           java.lang.String[] parameterTypes,
                           java.lang.String[] exceptions,
                           java.lang.String[] body,
                           java.lang.String[] comments)
Adds a constructor to this class. Note that the type format in the parameter type strings must be package style (that is - it can contain . but not / or $).

Specified by:
addConstructor in interface JavaClassWriter
Parameters:
name - The name of the constructor - should be the same as the name of the class.
modifiers - The modifier flags for this constructor.
parameterNames - A list of parameter names.
parameterTypes - A list of parameter types.
exceptions - A list of exceptions.
body - The implementation block of the constructor. The body of the implementation is passed as an array so the line separators can be added by the implementation.
comments - The comments shown just above the constructor. The comments are passed as an array so the line separators can be added by the implementation. Note that not all implementations will choose to make use of this comment.
See Also:
Modifier

addMethod

public void addMethod(java.lang.String name,
                      int modifiers,
                      java.lang.String returnType,
                      java.lang.String[] parameterNames,
                      java.lang.String[] parameterTypes,
                      java.lang.String[] exceptions,
                      java.lang.String[] body,
                      java.lang.String[] comments)
Adds a method to this class. Note that the type format in the return type and parameter type strings must be package style (that is - it can contain . but not / or $).

Specified by:
addMethod in interface JavaClassWriter
Parameters:
name - The name of the method.
modifiers - The modifier flags for this method.
returnType - A string representing the return type of this method.
parameterNames - A list of parameter names.
parameterTypes - A list of parameter types.
exceptions - A list of exceptions.
body - The implementation block of the method. The body of the implementation is passed as an array so the line separators can be added by the implementation.
comments - The comments shown just above the method. The comments are passed as an array so the line separators can be added by the implementation. Note that not all implementations will choose to make use of this comment.
See Also:
Modifier

addClass

public void addClass(JavaClassWriter classWriter)
Adds an inner class to this class.

Specified by:
addClass in interface JavaClassWriter
Parameters:
classWriter - The definition of the inner class.

toString

public java.lang.String toString()
Returns a string representation of this object.

Overrides:
toString in class java.lang.Object
Returns:
The string representation of the generated class.


Copyright © 2012 GlassFish Community. All Rights Reserved.