Package org.acplt.oncrpc.apps.jrpcgen
Class JrpcgenComplexType
java.lang.Object
org.acplt.oncrpc.apps.jrpcgen.JrpcgenDocumentable
org.acplt.oncrpc.apps.jrpcgen.JrpcgenXdrDefinition
org.acplt.oncrpc.apps.jrpcgen.JrpcgenComplexType
- All Implemented Interfaces:
JrpcgenItem,JrpcgenTypeMapping
- Direct Known Subclasses:
JrpcgenEnum,JrpcgenStruct,JrpcgenTypedefinition,JrpcgenUnion
The complex type class is an abstract base class for complex type mappings
such as structs, unions, enumerations and type definitions. At this level
complex types get the following characteristics:
- A complex type cannot be a base type at the same time.
- The definition name in the x-file is used as name of the Java class, which gets generated by jrpcgen.
- The Java class implements the interface
to provide the required coding methods for the mapped complex type.
invalid reference
XdrAble - As a complex type gets mapped by a Java class, concrete complex types
have to implement the method
generateJavaFile(), which will write the implementation of the Java class. - Within an x-file complex types are formed by XDR definitions and therefore
are handled as extension to the class
JrpcgenXdrDefinitionwithin this library.
- Author:
- Harald Wirths <hwirths@nde.ag>
-
Nested Class Summary
Nested classes/interfaces inherited from class org.acplt.oncrpc.apps.jrpcgen.JrpcgenXdrDefinition
JrpcgenXdrDefinition.Table, JrpcgenXdrDefinition.Type -
Field Summary
Fields inherited from class org.acplt.oncrpc.apps.jrpcgen.JrpcgenDocumentable
documentation -
Constructor Summary
ConstructorsConstructorDescriptionJrpcgenComplexType(String identifier, JrpcgenXdrDefinition.Type type) Constructs a complex type with the identifier and the type specifier passed. -
Method Summary
Modifier and TypeMethodDescriptionabstract voidConcrete implementations are asked to generate a Java file containing an implementation of the Java class mapping the complex type.Returns the identifier of the complex type.The complex type is mapped by a Java class.The Java name is equal to the definition name and therefore equal to the identifier of the complex type.The Java class mapping the complex type usually implements the interface.invalid reference
XdrAblefinal booleanA complex type cannot be a base type at the same time.final booleanA complex type is always different from the typeboolean.final booleanA complex type is always different from the typeopaque.final booleanA complex type is always different from the typeString.final booleanisVoid()A complex type is always different from the typevoid.voidwriteEqualsExpression(JrpcgenJavaFile javaFile, String variableLeft, String variableRight, boolean negate) Writes an equals expression to the passed Java file using the passed names of the left hand side and the right hand side variable.voidwriteJavaToXdr(JrpcgenJavaFile javaFile, String variable) At this level of a complex type the passed variable represents both the Java as well as the XDR representation and will be written as is to the passed Java file.voidwriteJavaToXdr(JrpcgenJavaFile javaFile, JrpcgenJavaFile.Expression expression) Wirtes the passed expression to the passed Java file.voidwriteXdrConstructorCall(JrpcgenJavaFile javaFile, String parameter) Writes a default constructor call or a constructor call with one parameter with the XDR class provided by this mapping.voidwriteXdrConstructorCall(JrpcgenJavaFile javaFile, JrpcgenJavaFile.Expression parameterExpression) Writes a constructor call with the XDR class provided by this mapping.voidwriteXdrDecodingCall(JrpcgenJavaFile javaFile, String xdrStream) Writes an XDR encoding call on the result of the passed expression with the passed name of an XDR decoding stream to the passed Java file.voidwriteXdrDynamicVectorDecodingCall(JrpcgenJavaFile javaFile, String xdrStream) Writes an XDR decoding call for a dynamic vector of the mapping type to the passed Java file.voidwriteXdrDynamicVectorEncodingCall(JrpcgenJavaFile javaFile, String xdrStream, String variable) Writes an XDR encoding call for a dynamic vector of the mapping type to the passed Java file.voidwriteXdrEncodingCall(JrpcgenJavaFile javaFile, String xdrStream, String variable) Writes an XDR encoding call on the passed variable with the passed name of an XDR encoding stream to the passed Java file.voidwriteXdrEncodingCall(JrpcgenJavaFile javaFile, String xdrStream, JrpcgenJavaFile.Expression expression) Writes an XDR encoding call on the result of the passed expression with the passed name of an XDR encoding stream to the passed Java file.voidwriteXdrFixedVectorDecodingCall(JrpcgenJavaFile javaFile, String xdrStream, String size) Writes an XDR decoding call for a fixed vector of the mapping type to the passed Java file.voidwriteXdrFixedVectorEncodingCall(JrpcgenJavaFile javaFile, String xdrStream, String variable, String size) Writes an XDR encoding call for a fixed vector of the mapping type to the passed Java file.voidwriteXdrToJava(JrpcgenJavaFile javaFile, String variable) At this level of a complex type the passed variable represents both the Java as well as the XDR representation and will be written as is to the passed Java file.voidwriteXdrVectorCodingMethods(JrpcgenJavaFile javaFile, JrpcgenContext context) Writes static encoding and decoding methods for fixed and dynamic vectors of the mapping to the passed Java file.Methods inherited from class org.acplt.oncrpc.apps.jrpcgen.JrpcgenXdrDefinition
getIdentifier, getXdrType, isConst, isEnum, isStruct, isTypedef, isUnionMethods inherited from class org.acplt.oncrpc.apps.jrpcgen.JrpcgenDocumentable
appendDeprecatedOrNothing, appendDeprecatedOrNothing, documentationIsEmpty, documentationIsProvided, emptyDocumentation, getDocumentation, getIdentedDocu, getIdentedDocu, isDeprecated, writeDocumentation, writeDocumentation
-
Constructor Details
-
JrpcgenComplexType
Constructs a complex type with the identifier and the type specifier passed.- Parameters:
identifier- The identifier of the complex type.type- The type specifier of the complex type, which will be one ofJrpcgenXdrDefinition.Type.ENUMJrpcgenXdrDefinition.Type.STRUCTJrpcgenXdrDefinition.Type.UNIONJrpcgenXdrDefinition.Type.TYPEDEF
-
-
Method Details
-
generateJavaFile
public abstract void generateJavaFile()Concrete implementations are asked to generate a Java file containing an implementation of the Java class mapping the complex type. -
isVoid
public final boolean isVoid()A complex type is always different from the typevoid.- Specified by:
isVoidin interfaceJrpcgenTypeMapping- Returns:
false, always.
-
isBaseType
public final boolean isBaseType()A complex type cannot be a base type at the same time.- Specified by:
isBaseTypein interfaceJrpcgenTypeMapping- Returns:
false, always.
-
isBooleanType
public final boolean isBooleanType()A complex type is always different from the typeboolean.- Specified by:
isBooleanTypein interfaceJrpcgenTypeMapping- Returns:
false, always.
-
isStringType
public final boolean isStringType()A complex type is always different from the typeString.- Specified by:
isStringTypein interfaceJrpcgenTypeMapping- Returns:
false, always.
-
isOpaqueType
public final boolean isOpaqueType()A complex type is always different from the typeopaque.- Specified by:
isOpaqueTypein interfaceJrpcgenTypeMapping- Returns:
false, always.
-
getDefinitionName
Returns the identifier of the complex type.- Specified by:
getDefinitionNamein interfaceJrpcgenTypeMapping- Returns:
- The identifier of the complex type.
-
getJavaName
The Java name is equal to the definition name and therefore equal to the identifier of the complex type.- Specified by:
getJavaNamein interfaceJrpcgenTypeMapping- Returns:
- The identifier of the complex type.
-
getJavaClass
The complex type is mapped by a Java class. The name of the class is equal to teh definition name of the complex type and therefore equal to the identifier of the complex type.- Specified by:
getJavaClassin interfaceJrpcgenTypeMapping- Returns:
- The identifier of the complex type.
-
getXdrClass
The Java class mapping the complex type usually implements the interface. Therefore the name of the XDR class is equal to the definition name and the identifier of the complex type, respectively.invalid reference
XdrAble- Specified by:
getXdrClassin interfaceJrpcgenTypeMapping- Returns:
- The identifier of the complex type.
-
writeXdrConstructorCall
Writes a default constructor call or a constructor call with one parameter with the XDR class provided by this mapping. Passingnullas value of the parameterparameterwill result in a default constructor call written to the passed Java file. Otherwise the value of the parameterparameterwill be written as parameter to the constuctor call.- Specified by:
writeXdrConstructorCallin interfaceJrpcgenTypeMapping- Parameters:
javaFile- The Java file, where the constructor call is going to be placed.parameter-nullto generate a default constructor call, a parameter name to generate a constructor call with one parameter.
-
writeXdrConstructorCall
public void writeXdrConstructorCall(JrpcgenJavaFile javaFile, JrpcgenJavaFile.Expression parameterExpression) Writes a constructor call with the XDR class provided by this mapping. The parameter expression is intended to write an expression, which evaluates to a parameter to the constructor call.- Specified by:
writeXdrConstructorCallin interfaceJrpcgenTypeMapping- Parameters:
javaFile- The Java file, where the constructor call is going to be placed.parameterExpression- An expression to be called with the passed Java file, when the expression is going to be placed in the Java file.
-
writeJavaToXdr
At this level of a complex type the passed variable represents both the Java as well as the XDR representation and will be written as is to the passed Java file. No conversion will take place.- Specified by:
writeJavaToXdrin interfaceJrpcgenTypeMapping- Parameters:
javaFile- The Java file, where the variable is going to be placed.variable- The name of a variable in Java representation.
-
writeJavaToXdr
Wirtes the passed expression to the passed Java file. At this level of a complex type no conversion takes place and therefore the passed expression will be written as is. The expression is expected to result in a value of the mapped type.- Specified by:
writeJavaToXdrin interfaceJrpcgenTypeMapping- Parameters:
javaFile- The Java file, where the passed expression is going to be placed.expression- An expression to be called with the passed Java file.
-
writeXdrToJava
At this level of a complex type the passed variable represents both the Java as well as the XDR representation and will be written as is to the passed Java file. No conversion will take place.- Specified by:
writeXdrToJavain interfaceJrpcgenTypeMapping- Parameters:
javaFile- The Java file, where the result is going to be placed.variable- The name of a variable in XDR representation.
-
writeXdrEncodingCall
Writes an XDR encoding call on the passed variable with the passed name of an XDR encoding stream to the passed Java file. At this level of complex types the mapping type implements the interfaceand therefore the XDR encoding call will be similar toinvalid reference
XdrAblevariable.xdrEncode(xdrStream).- Specified by:
writeXdrEncodingCallin interfaceJrpcgenTypeMapping- Parameters:
javaFile- The Java file, where the XDR encoding call is going to be placed.xdrStream- The name of the XDR encoding stream instance to be used in the statement.variable- The name of the variable to be used in the statement.
-
writeXdrEncodingCall
public void writeXdrEncodingCall(JrpcgenJavaFile javaFile, String xdrStream, JrpcgenJavaFile.Expression expression) Writes an XDR encoding call on the result of the passed expression with the passed name of an XDR encoding stream to the passed Java file. At this level of complex types the result of the expression is expected to be of the mapping type, which implements the interface. Therefore the XDR encoding call will be similar toinvalid reference
XdrAbleexpression.xdrEncode(xdrStream).- Specified by:
writeXdrEncodingCallin interfaceJrpcgenTypeMapping- Parameters:
javaFile- The Java file, where the XDR encoding call is going to be placed.xdrStream- The name of the XDR encoding stream instance to be used in the statement.expression- An expression to be called with the passed Java file, when the expression is going to be placed in the Java file.
-
writeXdrFixedVectorEncodingCall
public void writeXdrFixedVectorEncodingCall(JrpcgenJavaFile javaFile, String xdrStream, String variable, String size) Writes an XDR encoding call for a fixed vector of the mapping type to the passed Java file. The passed name of an XDR encoding stream, the passed name of the vector variable and the passed size string indicating the size of the fixed vector are used to form the XDR encoding call. This method expects the existence of the static methodxdrEncodeFixedVector(XdrEncodingStream, MappingType, int)in the generated code of the mapping typeMappingTypeas done by a call to the methodwriteXdrVectorCodingMethods(JrpcgenJavaFile, JrpcgenContext)within the implementation of the methodgenerateJavaFile(). TherebyMappingTypeis a placeholder for the name of concrete mapping type at this point.- Specified by:
writeXdrFixedVectorEncodingCallin interfaceJrpcgenTypeMapping- Parameters:
javaFile- The Java file, where the XDR encoding call is going to be placed.xdrStream- The name of the XDR encoding instance to be used in the statement.variable- The name of the variable to be used in the statement.size- A string specifying the size of the fixed vector.
-
writeXdrDynamicVectorEncodingCall
public void writeXdrDynamicVectorEncodingCall(JrpcgenJavaFile javaFile, String xdrStream, String variable) Writes an XDR encoding call for a dynamic vector of the mapping type to the passed Java file. The passed name of an XDR encoding stream and the passed name of the vector variable are used to form the XDR encoding call. This method expects the existence of the static methodxdrEncodeDynamicVector(XdrEncodingStream, MappingType)in the generated code of the mapping type as done by a call to the methodwithin the implementation of the methodinvalid reference
#wirteXdrVectorCodingMethods(JrpcgenJavaFile, JrpcgenContext)generateJavaFile(). TherebyMappingTypeis a placeholder for the name of the concrete mapping type at this point.- Specified by:
writeXdrDynamicVectorEncodingCallin interfaceJrpcgenTypeMapping- Parameters:
javaFile- The Java file, where the XDR encoding call is going to be placed.xdrStream- The name of the XDR encoding instance to be used in the statement.variable- The name of the variable to be used in the statement.
-
writeXdrDecodingCall
Writes an XDR encoding call on the result of the passed expression with the passed name of an XDR decoding stream to the passed Java file. At this level of complex types the mapping type implements the interfaceand therefore the XDR decoding call will be similar to an constructor call with the name of the XDR decoding stream as parameter.invalid reference
XdrAble- Specified by:
writeXdrDecodingCallin interfaceJrpcgenTypeMapping- Parameters:
javaFile- The Java file, where the XDR decoding call is going to be placed.xdrStream- The name of the XDR decoding stream instance to be used in the statement.
-
writeXdrFixedVectorDecodingCall
public void writeXdrFixedVectorDecodingCall(JrpcgenJavaFile javaFile, String xdrStream, String size) Writes an XDR decoding call for a fixed vector of the mapping type to the passed Java file. The passed name of an XDR decoding stream and the passed size string indicating the size of fixed vector are used to form the XDR decoding call. This method expects the existence of the static methodxdrDecodeFixedVector(XdrDecodingStream, int)within the implementation of the generated code of the mapping typeMappingTypeas done by a call to the methodwriteXdrVectorCodingMethods(JrpcgenJavaFile, JrpcgenContext)within the implementation of the methodgenerateJavaFile(). TherebyMappingTypeis a placeholder for the name of the concrete mapping type at this point.- Specified by:
writeXdrFixedVectorDecodingCallin interfaceJrpcgenTypeMapping- Parameters:
javaFile- The Java file, where the XDR decoding call is going to be placed.xdrStream- The name of the XDR decoding stream instance to be used in the statement.size- A string specifying the size of the fixed vector.
-
writeXdrDynamicVectorDecodingCall
Writes an XDR decoding call for a dynamic vector of the mapping type to the passed Java file. The passed name of an XDR decoding stream is used to to form the XDR decoding call. This method expects the existence of the static methodxdrDecodeDynamicVector(XdrDecodingStream)in the generated code of the mapping type as done by a call to methodwriteXdrVectorCodingMethods(JrpcgenJavaFile, JrpcgenContext)within the implementation of the methodgenerateJavaFile().- Specified by:
writeXdrDynamicVectorDecodingCallin interfaceJrpcgenTypeMapping- Parameters:
javaFile- The Java file, where the XDR decoding call is going to be placed.xdrStream- The name of the XDR decoding stream instance to be used in the statement.
-
writeEqualsExpression
public void writeEqualsExpression(JrpcgenJavaFile javaFile, String variableLeft, String variableRight, boolean negate) Writes an equals expression to the passed Java file using the passed names of the left hand side and the right hand side variable. The negate parameter controls whether the statement evaluates totrueon equality or on inequality. At this level of complex types the generated code will be similar tojava.utils.Objects.equals(variableLeft, variableRight)
fornegate=falseand! java.utils.Objects.equals(variableLeft, variableRight)
fornegate=true.- Specified by:
writeEqualsExpressionin interfaceJrpcgenTypeMapping- Parameters:
javaFile- The Java file, where the equality expression is going to be placed.variableLeft- The name of the variable to be used as the left hand side in the statement.variableRight- The name of the variable to be used as the right hand side in the statement.negate-falseto let the resulting statement returntrueon equality,trueto let the resulting statement returntrueon inequality.
-
writeXdrVectorCodingMethods
Writes static encoding and decoding methods for fixed and dynamic vectors of the mapping to the passed Java file. A call to this method is intended during the generation of the class file of the mapping type.However, the static encoding and decoding methods for fixed and dynamic vectors of the mapping type will be written only if they are required as a result of the foregoing parsing process. During the parsing phase vector uses of the mapping type are recognized and stored in maps for types in fixed and dynamic vector uses, respectively. The rules of generation are as follows:
- Nothing will be written, if the mapping type is neither listed in the map of types in fixed vector use nor listed in the map of the types in dynamic vector use.
- The static encoding and decoding methods for dynamic vectors of the mapping type will be written, if the mapping type is used at least in one of the both fixed or dynamic vectors.
- The static encoding methods for fixed and dynamic vectors of the mapping type will be written, if the mapping type is used at least in a fixed vector.
- Parameters:
javaFile- The Java file, where the static methods are going to be placed.context- The context of the current jrpcgen run.
-