Package org.acplt.oncrpc.apps.jrpcgen
Class jrpcgen
- java.lang.Object
-
- org.acplt.oncrpc.apps.jrpcgen.jrpcgen
-
public class jrpcgen extends java.lang.ObjectThe classjrpcgenimplements a Java-based rpcgen RPC protocol compiler. jrpcgen is a Java-based tool that generates source code of Java classes to implement an RPC protocol. The input to jrpcgen is a language similiar to C (but more probably much more similiar to FORTRAN) known as the RPC language (Remote Procedure Call Language).- Version:
- $Revision: 1.6 $ $Date: 2007/05/29 19:38:30 $ $State: Exp $ $Locker: $
- Author:
- Harald Albrecht
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringbaseClassnameName of class containing global constants.private static java.lang.String[]baseTypesJava base data types for which are XDR encoding and decoding helper methods available.static booleanclampProgAndVersClamp version and program number in client method stubs to the version and program number specified in the x-file.static java.lang.StringclientClassName of class containing the ONC/RPC client stubs.static java.lang.StringcurrentFilenameFull name of the current source code file.static java.io.WritercurrentFileWriterCurrent FileWriter object receiving generated source code.static java.io.PrintWritercurrentPrintWriterCurrent PrintWriter object sitting on top of thecurrentFileWriterobject receiving generated source code.static booleandebugEnable diagnostic messages when parsing the x-file.static java.io.FiledestinationDirDestination directory where to place the generated files.static java.util.HashtableglobalIdentifiersContains all global identifiers for type, structure and union specifiers as well as for constants and enumeration members.static booleaninitStringsEnable automatic initialization of String with empty Strings instead of null reference.static booleanmakeBeanEnable generation of accessors in order to use XDR classes as beans.static booleanmakeSerializableEnable tagging of XDR classes as being Serializablestatic booleannoBackupsDisable automatic backup of old source code files, iftrue.static booleannoClientDo not generate source code for the client proxy stub iftrue.static booleannoServerDo not generate source code for the server proxy stub iftrue.static java.lang.StringpackageNameSpecifies package name for generated source code, if notnull.static intPARAMS_MOREA remote procedure expects more than one parameter and thus needs an XDR wrapping class.static intPARAMS_SINGLEA remote procedure expects only a single parameter, which is a complex type (class).static intPARAMS_SINGLE_BASETYPEA remote procedure expects only a single parameter, which is of a base type, like integer, boolean, string, et cetera.static intPARAMS_VOIDA remote procedure has no parameters and thus needs to use the XDR void wrapper class as a dummy.static booleanparseOnlyParse x-file only but do not create source code files if set totrue.static java.util.VectorprogramInfosHolds information about the remote program defined in the jrpcgen x-file.static java.lang.StringserverClassName of class containing the ONC/RPC server stubs.static java.lang.StringstartDateString containing date/time when a jrpcgen run was started.static booleanverboseVerbosity flag.static java.lang.StringVERSIONCurrent version of jrpcgen.static booleanwithCallInfoSupply (additional) call information to server method stubs.static java.io.FilexFileThe x-file to parse (not: the X Files, the latter ones are something completely different).
-
Constructor Summary
Constructors Constructor Description jrpcgen()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static JrpcgenEnDecodingInfobaseEnDecodingSyllable(JrpcgenDeclaration decl)Return the en-/decoding syllable XXX appropriate for a base data type including arrays of base data types.static java.lang.StringcheckForEnumValue(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.static java.lang.StringcheckForSpecials(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.static voidcloseJavaSourceFile()Closes the source code file previously opened withcreateJavaSourceFile.static java.lang.StringcodingMethod(JrpcgenDeclaration decl, boolean encode)Return en- or decoding method appropriate for a struct or union member.static java.lang.StringcodingMethod(JrpcgenDeclaration decl, boolean encode, java.lang.String oref)Return en- or decoding method appropriate for a struct or union member.static java.io.PrintWritercreateJavaSourceFile(java.lang.String classname)Creates a new source code file for a Java class based on its class name.static java.io.PrintWritercreateJavaSourceFile(java.lang.String classname, boolean emitImports)Creates a new source code file for a Java class based on its class name.static JrpcgenSHAcreateSHA(java.lang.String classname)Create a new hash function object and initialize it using a class and package name.static voiddoParse()The real parsing and code generation part.static voiddumpClasses()Generate source code files for all structures, unions and enumerations as well as constants.static voiddumpClient(JrpcgenProgramInfo programInfo)Generate source code for the client stub proxy object.static voiddumpClientStubMethods(java.io.PrintWriter out, JrpcgenVersionInfo versionInfo)Generate source code for client-side stub methods for a particular remote program version.static voiddumpConstantAndDependency(java.io.PrintWriter out, JrpcgenConst c)Dump the value of a constant and optionally first dump all constants it depends on.static voiddumpConstants()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.static voiddumpEnum(JrpcgenEnum e)Generate a source code file containing all elements of an enumeration defined in a x-file.static voiddumpFiles()Create the source code files based on the parsed information from the x-file.static voiddumpServer(JrpcgenProgramInfo programInfo)static voiddumpServerStubMethodCall(java.io.PrintWriter out, JrpcgenProcedureInfo proc)static voiddumpServerStubMethods(java.io.PrintWriter out, JrpcgenVersionInfo versionInfo)Generate public abstract method signatures for all remote procedure calls.static voiddumpStruct(JrpcgenStruct s)Generate a source code file containing all elements of a struct defined in a x-file.static voiddumpTypedef(JrpcgenDeclaration d)Generate a source code file containing a wrapper class for a typedef defined in a x-file.static voiddumpUnion(JrpcgenUnion u)Generate a source code file containing all elements of a union defined in a x-file.static voidmain(java.lang.String[] args)The main part of jrpcgen where all things start.static voidprintHelp()Print the help message describing the available command line options.static java.lang.StringxdrBaseType(java.lang.String type)Given a name of a data type return the name of the equivalent Java data type (if it exists), otherwise returnnull.
-
-
-
Field Detail
-
VERSION
public static final java.lang.String VERSION
Current version of jrpcgen.- See Also:
- Constant Field Values
-
PARAMS_VOID
public static final int PARAMS_VOID
A remote procedure has no parameters and thus needs to use the XDR void wrapper class as a dummy.- See Also:
- Constant Field Values
-
PARAMS_SINGLE
public static final int PARAMS_SINGLE
A remote procedure expects only a single parameter, which is a complex type (class).- See Also:
- Constant Field Values
-
PARAMS_SINGLE_BASETYPE
public static final int PARAMS_SINGLE_BASETYPE
A remote procedure expects only a single parameter, which is of a base type, like integer, boolean, string, et cetera.- See Also:
- Constant Field Values
-
PARAMS_MORE
public static final int PARAMS_MORE
A remote procedure expects more than one parameter and thus needs an XDR wrapping class.- See Also:
- Constant Field Values
-
startDate
public static final java.lang.String startDate
String containing date/time when a jrpcgen run was started. This string is used in the headers of the generated source code files.
-
globalIdentifiers
public static java.util.Hashtable globalIdentifiers
Contains all global identifiers for type, structure and union specifiers as well as for constants and enumeration members. This static attribute is directly manipulated by the parser.
-
noBackups
public static boolean noBackups
Disable automatic backup of old source code files, iftrue.
-
programInfos
public static java.util.Vector programInfos
Holds information about the remote program defined in the jrpcgen x-file.
-
clampProgAndVers
public static boolean clampProgAndVers
Clamp version and program number in client method stubs to the version and program number specified in the x-file.
-
withCallInfo
public static boolean withCallInfo
Supply (additional) call information to server method stubs.
-
debug
public static boolean debug
Enable diagnostic messages when parsing the x-file.
-
verbose
public static boolean verbose
Verbosity flag. Iftrue, then jrpcgen will report about the steps it is taking when generating all the source code files.
-
parseOnly
public static boolean parseOnly
Parse x-file only but do not create source code files if set totrue.
-
xFile
public static java.io.File xFile
The x-file to parse (not: the X Files, the latter ones are something completely different).
-
destinationDir
public static java.io.File destinationDir
Destination directory where to place the generated files.
-
currentFileWriter
public static java.io.Writer currentFileWriter
Current FileWriter object receiving generated source code.
-
currentPrintWriter
public static java.io.PrintWriter currentPrintWriter
Current PrintWriter object sitting on top of thecurrentFileWriterobject receiving generated source code.
-
currentFilename
public static java.lang.String currentFilename
Full name of the current source code file.
-
packageName
public static java.lang.String packageName
Specifies package name for generated source code, if notnull. Ifnull, then no package statement is emitted.
-
baseClassname
public static java.lang.String baseClassname
Name of class containing global constants. It is derived from the filename with the extension (".x") and path removed.
-
noClient
public static boolean noClient
Do not generate source code for the client proxy stub iftrue.
-
noServer
public static boolean noServer
Do not generate source code for the server proxy stub iftrue.
-
serverClass
public static java.lang.String serverClass
Name of class containing the ONC/RPC server stubs.
-
clientClass
public static java.lang.String clientClass
Name of class containing the ONC/RPC client stubs.
-
makeSerializable
public static boolean makeSerializable
Enable tagging of XDR classes as being Serializable
-
makeBean
public static boolean makeBean
Enable generation of accessors in order to use XDR classes as beans.
-
initStrings
public static boolean initStrings
Enable automatic initialization of String with empty Strings instead of null reference.
-
baseTypes
private static java.lang.String[] baseTypes
Java base data types for which are XDR encoding and decoding helper methods available.
-
-
Method Detail
-
printHelp
public static void printHelp()
Print the help message describing the available command line options.
-
createJavaSourceFile
public static java.io.PrintWriter createJavaSourceFile(java.lang.String classname)
Creates a new source code file for a Java class based on its class name. Same ascreateJavaSourceFile(String, boolean)with theemitImportparameter set totrue.- 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 static 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- iftrue, then import statements for the remotetea ONC/RPC package and IOExceptions.- Returns:
- PrintWriter to send source code to.
-
createSHA
public static 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 static void closeJavaSourceFile()
Closes the source code file previously opened withcreateJavaSourceFile. This method writes a trailer before closing the file.
-
dumpConstantAndDependency
public static void dumpConstantAndDependency(java.io.PrintWriter out, JrpcgenConst c)Dump the value of a constant and optionally first dump all constants it depends on.
-
dumpConstants
public static 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 static void dumpEnum(JrpcgenEnum e)
Generate a source code file containing all elements of an enumeration defined in a x-file.- Parameters:
e-Descriptionof 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 returnnull. NOTE: "opaque" is considered like "byte" to be a base type... FIXME: char/byte?- Returns:
- Name of Java base data type or
nullif the given data type is not equivalent to one of Java's base data types.
-
baseEnDecodingSyllable
public static JrpcgenEnDecodingInfo baseEnDecodingSyllable(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 static java.lang.String codingMethod(JrpcgenDeclaration decl, boolean encode)
Return en- or decoding method appropriate for a struct or union member.
-
codingMethod
public static java.lang.String codingMethod(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-trueif encoding method should be returned,falseif decoding method is to be returned.oref- name of object reference ornullif "this" should be used instead.
-
checkForSpecials
public static 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 static 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 static void dumpStruct(JrpcgenStruct s)
Generate a source code file containing all elements of a struct defined in a x-file.- Parameters:
s-Descriptionof XDR struct.
-
dumpUnion
public static void dumpUnion(JrpcgenUnion u)
Generate a source code file containing all elements of a union defined in a x-file.- Parameters:
u-Descriptionof XDR union.
-
dumpTypedef
public static void dumpTypedef(JrpcgenDeclaration d)
Generate a source code file containing a wrapper class for a typedef defined in a x-file.- Parameters:
d-Descriptionof XDR typedef.
-
dumpClasses
public static 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 static void dumpClientStubMethods(java.io.PrintWriter out, JrpcgenVersionInfo versionInfo)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:
out- Printer writer to send source code to.versionInfo- Information about the remote program version for which source code is to be generated.
-
dumpClient
public static void dumpClient(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 static void dumpServerStubMethodCall(java.io.PrintWriter out, JrpcgenProcedureInfo proc)
-
dumpServerStubMethods
public static void dumpServerStubMethods(java.io.PrintWriter out, JrpcgenVersionInfo versionInfo)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 static void dumpServer(JrpcgenProgramInfo programInfo)
-
dumpFiles
public static void dumpFiles()
Create the source code files based on the parsed information from the x-file.
-
main
public static void main(java.lang.String[] args)
The main part of jrpcgen where all things start.
-
doParse
public static void doParse() throws java.io.FileNotFoundException, java.lang.ExceptionThe 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.FileNotFoundExceptionjava.lang.Exception
-
-