org.acplt.oncrpc.apps.jrpcgen
Class JavaSourceGenerator

java.lang.Object
  extended by org.acplt.oncrpc.apps.jrpcgen.JavaSourceGenerator

public class JavaSourceGenerator
extends java.lang.Object

Author:
rbreuss

Field Summary
 java.lang.String baseClassname
          Name of class containing global constants.
static org.apache.maven.plugin.logging.Log log
          The logger.
 
Constructor Summary
JavaSourceGenerator()
           
 
Method Summary
 org.acplt.oncrpc.apps.jrpcgen.JrpcgenEnDecodingInfo baseEnDecodingSyllable(org.acplt.oncrpc.apps.jrpcgen.JrpcgenDeclaration decl)
          Return the en-/decoding syllable XXX appropriate for a base data type including arrays of base data types.
 java.lang.String checkForEnumValue(java.lang.String value)
          Checks whether a given value references an identifier and then returns the qualified identifier (interface where the value is defined in) or simply the value in case of an integer literal.
 java.lang.String checkForSpecials(java.lang.String dataType)
          Checks whether a given data type identifier refers to an enumeration type and then returns Java's int data type instead.
 void closeJavaSourceFile(java.io.PrintWriter writer)
          Closes the source code file previously opened with createJavaSourceFile.
 java.lang.String codingMethod(org.acplt.oncrpc.apps.jrpcgen.JrpcgenDeclaration decl, boolean encode)
          Return en- or decoding method appropriate for a struct or union member.
 java.lang.String codingMethod(org.acplt.oncrpc.apps.jrpcgen.JrpcgenDeclaration decl, boolean encode, java.lang.String oref)
          Return en- or decoding method appropriate for a struct or union member.
 java.io.PrintWriter createJavaSourceFile(java.lang.String classname)
          Creates a new source code file for a Java class based on its class name.
 java.io.PrintWriter createJavaSourceFile(java.lang.String classname, boolean emitImports)
          Creates a new source code file for a Java class based on its class name.
 org.acplt.oncrpc.apps.jrpcgen.JrpcgenSHA createSHA(java.lang.String classname)
          Create a new hash function object and initialize it using a class and package name.
 void doParse()
          The real parsing and code generation part.
 void dumpClasses()
          Generate source code files for all structures, unions and enumerations as well as constants.
 void dumpClient(org.acplt.oncrpc.apps.jrpcgen.JrpcgenProgramInfo programInfo)
          Generate source code for the client stub proxy object.
 void dumpClientStubMethods(org.acplt.oncrpc.apps.jrpcgen.JrpcgenVersionInfo versionInfo, java.io.PrintWriter writer)
          Generate source code for client-side stub methods for a particular remote program version.
 void dumpConstantAndDependency(org.acplt.oncrpc.apps.jrpcgen.JrpcgenConst c)
          Dump the value of a constant and optionally first dump all constants it depends on.
 void dumpConstants()
          Generate source code file containing all constants defined in the x-file as well as all implicitely defined constants, like program, version and procedure numbers, etc.
 void dumpEnum(org.acplt.oncrpc.apps.jrpcgen.JrpcgenEnum e)
          Generate a source code file containing all elements of an enumeration defined in a x-file.
 void dumpFiles(java.util.Hashtable glIdentifiers)
          Create the source code files based on the parsed information from the x-file.
 void dumpServer(org.acplt.oncrpc.apps.jrpcgen.JrpcgenProgramInfo programInfo)
           
 void dumpServerStubMethodCall(org.acplt.oncrpc.apps.jrpcgen.JrpcgenProcedureInfo proc, java.io.PrintWriter writer)
           
 void dumpServerStubMethods(org.acplt.oncrpc.apps.jrpcgen.JrpcgenVersionInfo versionInfo, java.io.PrintWriter writer)
          Generate public abstract method signatures for all remote procedure calls.
 void dumpStruct(org.acplt.oncrpc.apps.jrpcgen.JrpcgenStruct s)
          Generate a source code file containing all elements of a struct defined in a x-file.
 void dumpTypedef(org.acplt.oncrpc.apps.jrpcgen.JrpcgenDeclaration d)
          Generate a source code file containing a wrapper class for a typedef defined in a x-file.
 void dumpUnion(org.acplt.oncrpc.apps.jrpcgen.JrpcgenUnion u)
          Generate a source code file containing all elements of a union defined in a x-file.
 void dumpUnionClasses(org.acplt.oncrpc.apps.jrpcgen.JrpcgenUnion u)
           
 boolean isVisitorUsesReflection()
           
 void setAdditionalImports(java.util.List<java.lang.String> additionalImports)
           
 void setDestinationDir(java.io.File destinationDir)
           
 void setEnumType(java.lang.String enumType)
           
 void setMakeBean(boolean makeBean)
           
 void setMakeSerializable(boolean makeSerializable)
           
 void setNoBackups(boolean noBackups)
           
 void setOneClassForUnions(boolean oneCLassForUnions)
           
 void setPackageName(java.lang.String packageName)
           
 void setSuperClassName(java.lang.String superClassName)
           
 void setUseXdrStream(boolean useXdrStream)
           
 void setVerbose(boolean verbose)
           
 void setVersionString(java.lang.String versionString)
           
 void setVisitorName(java.lang.String visitorName)
           
 void setVisitorUsesReflection(boolean visitorUsesReflection)
           
 void setXFile(java.io.File file)
           
static java.lang.String xdrBaseType(java.lang.String type)
          Given a name of a data type return the name of the equivalent Java data type (if it exists), otherwise return null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public static org.apache.maven.plugin.logging.Log log
The logger.


baseClassname

public java.lang.String baseClassname
Name of class containing global constants. It is derived from the filename with the extension (".x") and path removed.

Constructor Detail

JavaSourceGenerator

public JavaSourceGenerator()
Method Detail

createJavaSourceFile

public java.io.PrintWriter createJavaSourceFile(java.lang.String classname)
Creates a new source code file for a Java class based on its class name. Same as createJavaSourceFile(String, boolean) with the emitImport parameter set to true.

Parameters:
classname - Name of Java class to generate. Must not contain a file extension -- especially ".java" is invalid. When the source code file is created, ".java" is appended automatically.
Returns:
PrintWriter to send source code to.

createJavaSourceFile

public java.io.PrintWriter createJavaSourceFile(java.lang.String classname,
                                                boolean emitImports)
Creates a new source code file for a Java class based on its class name. If an old version of the source file exists, it is renamed first. The backup will have the same name as the original file with "~" appended.

Parameters:
classname - Name of Java class to generate. Must not contain a file extension -- especially ".java" is invalid. When the source code file is created, ".java" is appended automatically.
emitImports - if true, then import statements for the remotetea ONC/RPC package and IOExceptions.
Returns:
PrintWriter to send source code to.

createSHA

public org.acplt.oncrpc.apps.jrpcgen.JrpcgenSHA createSHA(java.lang.String classname)
Create a new hash function object and initialize it using a class and package name.

Parameters:
classname - Name of class.
Returns:
hash function object.

closeJavaSourceFile

public void closeJavaSourceFile(java.io.PrintWriter writer)
Closes the source code file previously opened with createJavaSourceFile. This method writes a trailer before closing the file.


dumpConstantAndDependency

public void dumpConstantAndDependency(org.acplt.oncrpc.apps.jrpcgen.JrpcgenConst c)
Dump the value of a constant and optionally first dump all constants it depends on.


dumpConstants

public void dumpConstants()
Generate source code file containing all constants defined in the x-file as well as all implicitely defined constants, like program, version and procedure numbers, etc. This method creates a public interface with the constants as public static final integers.


dumpEnum

public void dumpEnum(org.acplt.oncrpc.apps.jrpcgen.JrpcgenEnum e)
Generate a source code file containing all elements of an enumeration defined in a x-file.

Parameters:
e - Description of XDR enumeration.

xdrBaseType

public static java.lang.String xdrBaseType(java.lang.String type)
Given a name of a data type return the name of the equivalent Java data type (if it exists), otherwise return null. NOTE: "opaque" is considered like "byte" to be a base type... FIXME: char/byte?

Returns:
Name of Java base data type or null if the given data type is not equivalent to one of Java's base data types.

baseEnDecodingSyllable

public org.acplt.oncrpc.apps.jrpcgen.JrpcgenEnDecodingInfo baseEnDecodingSyllable(org.acplt.oncrpc.apps.jrpcgen.JrpcgenDeclaration decl)
Return the en-/decoding syllable XXX appropriate for a base data type including arrays of base data types.

Parameters:
decl - declaration of a member of RPC struct or union.
Returns:
null, if the declaration does not specify a base data type. Otherwise a three-element String array, with [0] containing the type syllable for base type (including arrays), [1] containing parameter options when encoding (like maximum sizes, etc), and [2] containing options for decoding.

codingMethod

public java.lang.String codingMethod(org.acplt.oncrpc.apps.jrpcgen.JrpcgenDeclaration decl,
                                     boolean encode)
Return en- or decoding method appropriate for a struct or union member.


codingMethod

public java.lang.String codingMethod(org.acplt.oncrpc.apps.jrpcgen.JrpcgenDeclaration decl,
                                     boolean encode,
                                     java.lang.String oref)
Return en- or decoding method appropriate for a struct or union member.

Parameters:
decl - declaration for which the en-/decoding Java source code be returned.
encode - true if encoding method should be returned, false if decoding method is to be returned.
oref - name of object reference or null if "this" should be used instead.

checkForSpecials

public java.lang.String checkForSpecials(java.lang.String dataType)
Checks whether a given data type identifier refers to an enumeration type and then returns Java's int data type instead. In case of the pseudo-type "opaque" return Java's byte data type. For all other data types, the data type identifier is returned unaltered.

Parameters:
dataType - data type identifier to check.
Returns:
data type identifier.

checkForEnumValue

public java.lang.String checkForEnumValue(java.lang.String value)
Checks whether a given value references an identifier and then returns the qualified identifier (interface where the value is defined in) or simply the value in case of an integer literal.

Parameters:
value - Either an identifier to resolve or an integer literal.
Returns:
Integer literal or qualified identifier.

dumpStruct

public void dumpStruct(org.acplt.oncrpc.apps.jrpcgen.JrpcgenStruct s)
Generate a source code file containing all elements of a struct defined in a x-file.

Parameters:
s - Description of XDR struct.

dumpUnionClasses

public void dumpUnionClasses(org.acplt.oncrpc.apps.jrpcgen.JrpcgenUnion u)

dumpUnion

public void dumpUnion(org.acplt.oncrpc.apps.jrpcgen.JrpcgenUnion u)
Generate a source code file containing all elements of a union defined in a x-file.

Parameters:
u - Description of XDR union.

dumpTypedef

public void dumpTypedef(org.acplt.oncrpc.apps.jrpcgen.JrpcgenDeclaration d)
Generate a source code file containing a wrapper class for a typedef defined in a x-file.

Parameters:
d - Description of XDR typedef.

dumpClasses

public void dumpClasses()
Generate source code files for all structures, unions and enumerations as well as constants. All constants, which do not belong to enumerations, are emitted to a single interface.


dumpClientStubMethods

public void dumpClientStubMethods(org.acplt.oncrpc.apps.jrpcgen.JrpcgenVersionInfo versionInfo,
                                  java.io.PrintWriter writer)
Generate source code for client-side stub methods for a particular remote program version. The client-side stub methods take the parameter(s) from the caller, encode them and throw them over to the server. After receiving a reply, they will unpack and return it as the outcome of the method call.

Parameters:
versionInfo - Information about the remote program version for which source code is to be generated.

dumpClient

public void dumpClient(org.acplt.oncrpc.apps.jrpcgen.JrpcgenProgramInfo programInfo)
Generate source code for the client stub proxy object. This client stub proxy object is then used by client applications to make remote procedure (aka method) calls to an ONC/RPC server.


dumpServerStubMethodCall

public void dumpServerStubMethodCall(org.acplt.oncrpc.apps.jrpcgen.JrpcgenProcedureInfo proc,
                                     java.io.PrintWriter writer)

dumpServerStubMethods

public void dumpServerStubMethods(org.acplt.oncrpc.apps.jrpcgen.JrpcgenVersionInfo versionInfo,
                                  java.io.PrintWriter writer)
Generate public abstract method signatures for all remote procedure calls. This ensures that they have to be implemented before any derived server class gets usefull.


dumpServer

public void dumpServer(org.acplt.oncrpc.apps.jrpcgen.JrpcgenProgramInfo programInfo)

dumpFiles

public void dumpFiles(java.util.Hashtable glIdentifiers)
Create the source code files based on the parsed information from the x-file.


doParse

public void doParse()
             throws java.io.FileNotFoundException,
                    java.lang.Exception
The real parsing and code generation part. This has been factored out of main() in order to make it available as an Ant task.

Throws:
java.io.FileNotFoundException
java.lang.Exception

setPackageName

public void setPackageName(java.lang.String packageName)
Parameters:
packageName - the packageName to set

setMakeBean

public void setMakeBean(boolean makeBean)
Parameters:
makeBean - the makeBean to set

setVisitorName

public void setVisitorName(java.lang.String visitorName)
Parameters:
visitorName - the visitorName to set

setSuperClassName

public void setSuperClassName(java.lang.String superClassName)
Parameters:
superClassName - the superClassName to set

setDestinationDir

public void setDestinationDir(java.io.File destinationDir)
Parameters:
destinationDir - the destinationDir to set

setVerbose

public void setVerbose(boolean verbose)
Parameters:
verbose - the verbose to set

setNoBackups

public void setNoBackups(boolean noBackups)
Parameters:
noBackups - the noBackups to set

setXFile

public void setXFile(java.io.File file)
Parameters:
file - the xFile to set

setMakeSerializable

public void setMakeSerializable(boolean makeSerializable)
Parameters:
makeSerializable - the makeSerializable to set

setVersionString

public void setVersionString(java.lang.String versionString)
Parameters:
versionString - the versionString to set

setAdditionalImports

public void setAdditionalImports(java.util.List<java.lang.String> additionalImports)
Parameters:
additionalImports - the additionalImports to set

isVisitorUsesReflection

public boolean isVisitorUsesReflection()
Returns:
the visitorUsesReflection

setVisitorUsesReflection

public void setVisitorUsesReflection(boolean visitorUsesReflection)
Parameters:
visitorUsesReflection - the visitorUsesReflection to set

setOneClassForUnions

public void setOneClassForUnions(boolean oneCLassForUnions)
Parameters:
oneClassForUnions - the oneClassForUnions to set

setUseXdrStream

public void setUseXdrStream(boolean useXdrStream)
Parameters:
useXdrStream - the useXdrStream to set

setEnumType

public void setEnumType(java.lang.String enumType)
Parameters:
enumType - the enumType to set


Copyright © 2009. All Rights Reserved.