Class JrpcgenConst
- All Implemented Interfaces:
JrpcgenItem
- Direct Known Subclasses:
JrpcgenEnum.Element
JrpcgenConst class represents a single constant defined
in an rpcgen "x"-file.- Version:
- $Revision: 1.1 $ $Date: 2003/08/13 12:03:45 $ $State: Exp $ $Locker: $
- Author:
- Harald Albrecht
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classType definition for a table of XDR constants.Nested classes/interfaces inherited from class org.acplt.oncrpc.apps.jrpcgen.JrpcgenXdrDefinition
JrpcgenXdrDefinition.Type -
Field Summary
Fields inherited from class org.acplt.oncrpc.apps.jrpcgen.JrpcgenDocumentable
documentation -
Constructor Summary
ConstructorsConstructorDescriptionJrpcgenConst(JrpcgenContext context, String identifier, String value) Constructs aJrpcgenConstand sets the identifier and the associated value.JrpcgenConst(JrpcgenContext context, String identifier, String value, String enclosure) Constructs aJrpcgenConstand sets the identifier and the associated value of an enumeration etc. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringdetectIdentifier(String expression) Detects a character sequence at the beginning of the passed expression, which holds the definition of an identifier as described in RFC 4506:An identifier is a letter followed by an optional sequence of letters, digits, or underbar ('_').
voiddump()Dumps the constant as well as its value toSystem.out.<T extends Appendable>
Tdump(T appendable) getAsCaseValue(String forEnclosure) Delivers a case value representation of the constant.static StringgetAsCaseValue(String constantExpression, String forEnclosure, JrpcgenContext context) Delivers the passed constant expression as a case value, which is intended to be used within a switch-case-statement.getAsRValue(String forEnclosure) Delivers an r-value representation of the constant.static StringgetAsRValue(String constantExpression, String forEnclosure, JrpcgenContext context) Delivers the passed constant expression as an r-value.static StringgetAsRValue(String constantExpression, JrpcgenContext context) Delivers the passed constant expression as an r-value.final JrpcgenContextDelivers the context the constant definition belongs to.final StringReturns the name of the enclosure the constant lives in.getForEnclosure(String forEnclosure) Delivers the representation of the constant with respect to the passed enclosure name.final StringgetValue()Delivers the value defined for the constant.getValueAsRValue(String forEnclosure) Delivers an r-value representation of the value defined by the constant.Returns the value as integer literal (and thus resolving identifiers recursively, if necessary).final voidsetEnclosure(String enclosure) Sets the name of the enclosure the constant lives in.final voidSets the value represented by the constant.toString()voidwriteDeclaration(JrpcgenJavaFile javaFile) 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
-
JrpcgenConst
Constructs aJrpcgenConstand sets the identifier and the associated value.- Parameters:
context- The context the new contant belongs to.identifier- Constant identifier to define.value- Value assigned to constant.
-
JrpcgenConst
Constructs aJrpcgenConstand sets the identifier and the associated value of an enumeration etc.- Parameters:
context- The context the new contant belongs to.identifier- Constant identifier to define.value- Value assigned to constant.enclosure- Name of enclosing enumeration, etc.
-
-
Method Details
-
getAsRValue
Delivers the passed constant expression as an r-value. The passed constant expression may contain a constant value or an identifier of a constant known to the global table of constants.Passing for example the string literal
"42", the method returns the passed string"42".Passing for example the string literal
"VERSION", the method may return the string"demo.VERSION"in case the global table of constants contains a constant definition with the identifierVERSIONnested in the enclosure (namespace)demo. Otherwise the passed string"VERSION"is returned.Passing for example the string literal
"ENUM_FIRST", the method may return the string"EnumerationValues.ENUM_FIRST.getEncoding()"in case the global table of constants contains a constant definition with the identifierENUM_FIRSTnested in the enclosure (namespace)EnumerationValuesoriginating from an enumeration definition provided that XDR ernumerations are mapped by Java enumerations.- Parameters:
constantExpression- A string containing a constant value or the identifier of a constant definition known to the global table of constant definitions.context- The context of the rpcgen run, providing the table of global constant definitions collected so far.- Returns:
- The passed constant expression or the string representation of the reference to the constant identified by the passed constant expression.
-
getAsRValue
public static String getAsRValue(String constantExpression, String forEnclosure, JrpcgenContext context) Delivers the passed constant expression as an r-value. The passed constant expression may contain a constant value or an identifier of a constant known to the global table of constants.Passing for example the string literal
"42", the method returns the passed string"42".Given a target enclosure (namespace)
elementand a global constant definition with the identifierVERSIONnested in the enclosure (namespace)demo, passing the string literals"VERSION"and"element"results in returning the string"demo.VERSION".Given a target enclosure (namespace)
demoand a global constant definition with the identifierVERSIONnested in the enclosure (namespace)demo, passing the string literals"VERSION"and"demo"results in returning the string"VERSION".Given a target enclosure (namespace)
elementand a global constant definition with the identifierENUM_FIRSTnested in the enclosure (namespace)EnumerationValuesoriginating from an enumeration definition, passing the string literals"ENUM_FIRST"and"element"results in returning the string"EnumerationValues.ENUM_FIRST.getEncoding()"provided that XDR enumerations are mapped by Java enumerations (seeJrpcgenEnum.Element).- Parameters:
constantExpression- A string containing a constant value or the identifier of a constant definition known to the global table of constant definitions.forEnclosure- The target enclosure (namespace), where the r-value is intended to be used.context- The context of the rpcgen run, providing the table of global constant definitions collected so far.- Returns:
- The passed constant expression or the string representation of the reference to the constant identified by the passed constant expression.
-
getAsCaseValue
public static String getAsCaseValue(String constantExpression, String forEnclosure, JrpcgenContext context) Delivers the passed constant expression as a case value, which is intended to be used within a switch-case-statement. The passed constant expression may contain a constant value or an identifier of a constant known to the global table of constants.Passing for example the string literal
"42", the method returns the passed string"42".Given a target enclosure (namespace)
elementand a global constant definition with the identifierVERSIONnested in the enclosure (namespace)demo, passing the string literals"VERSION"and"element"result in returning the string"demo.VERSION".Given a target enclosure (namespace)
elementand a global constant definition with the identifierENUM_FIRSTnested in the enclosure (namespace)EnumerationValuesoriginating from an enumeration definition, passing the string literals"ENUM_FIRST"and"element"results in returning the string"ENUM_FIRST"provided that XDR enumerations are mapped by Java enumerations (seeJrpcgenEnum.Element).- Parameters:
constantExpression- A string containing a constant value or the identifier of a constant definition known to the global table of constant definitions.forEnclosure- The target enclosure (namespace), where the r-value is intended to be used.context- The context of the rpcgen run, providing the table of global constant definitions collected so far.- Returns:
- The passed constant expression or the string representation of the reference to the constant identified by the passed constant expression.
-
getContext
Delivers the context the constant definition belongs to.- Returns:
- The context teh constant definition belongs to.
-
getValue
Delivers the value defined for the constant.- Returns:
- The value of the constant.
-
setValue
Sets the value represented by the constant.- Parameters:
value- The value of the constant in string representation.
-
getEnclosure
Returns the name of the enclosure the constant lives in.- Returns:
- The name of the enclosure.
-
setEnclosure
Sets the name of the enclosure the constant lives in.- Parameters:
enclosure- The name of the enclosure.
-
getForEnclosure
Delivers the representation of the constant with respect to the passed enclosure name.The passed enclosure name identifies the target enclosure (namespace), where the requested constant representation is intended to be used.
- Parameters:
forEnclosure- The name of the target enclosure.- Returns:
- One of the following representations
will be returned:
- The value of the constant, if the constant is a global constant.
- The identifier of the constant, if the constant lives in the target enclosure.
- The joined version of the enclosure the constant lives in and the identifier of the constant, delimited by a dot.
-
getAsRValue
Delivers an r-value representation of the constant.The passed enclosure name identifies the target enclosure (namespace), where the requested constant representation is intended to be used.
- Parameters:
forEnclosure- The name of the target enclosure.- Returns:
- One of the following representations
will be returned:
- The value of the constant, if the constant is a global constant.
- The identifier of the constant, if the constant lives in the target enclosure.
- The joined version of the enclosure the constant lives in and the identifier of the constant, delimited by a dot.
-
getAsCaseValue
Delivers a case value representation of the constant.The passed enclosure name identifies the target enclosure (namespace), where the requested constant representation is intended to be used.
- Parameters:
forEnclosure- The name of the target enclosure.- Returns:
- One of the following representations
will be returned:
- The value of the constant, if the constant is a global constant.
- The identifier of the constant, if the constant lives in the target enclosure.
- The joined version of the enclosure the constant lives in and the identifier of the constant, delimited by a dot.
-
getValueAsRValue
Delivers an r-value representation of the value defined by the constant. This is useful for example writing the declaration of an enumeration element.The passed eclosure name identifies the target enclosure (namespace), where the requested value representation is intended to be used.
- Parameters:
forEnclosure- The name of the target enclosure.- Returns:
- One of the following representations
will be returned:
- The value of the constant, if the constant is a global constant or independent of another constant.
- If the value is dependent on another constant, the r-value representation of that constant with respect to the target enclosure is taken and where applicable joined with the trailing part of the value following the identifier of the other constant.
-
resolveValue
Returns the value as integer literal (and thus resolving identifiers recursively, if necessary). This is only possible for simple subsitutions, that is A is defined as B, B as C, and C as 42, thus A is eventually defined as 42.This simple kind of resolving is necessary when defining a particular version of an ONC/RPC protocol. We need to be able to resolve the version to an integer literal because we need to append the version number to any remote procedure defined to avoid identifier clashes if the same remote procedure is defined for several versions.
- Returns:
- integer literal as
Stringornull, if the identifier could not be resolved to an integer literal.
-
writeDeclaration
-
dump
public void dump()Dumps the constant as well as its value toSystem.out. -
dump
-
toString
-
detectIdentifier
Detects a character sequence at the beginning of the passed expression, which holds the definition of an identifier as described in RFC 4506:An identifier is a letter followed by an optional sequence of letters, digits, or underbar ('_'). The case of identifiers is not ignored.
Letters are defined by the character set ['a'-'z','A'-'Z'] within this implementation.
Digits are defined by the character set ['0'-'9'] within this implementation.
- Parameters:
expression- An expression possibly starting with an identifier like character sequence.- Returns:
- The detected identifier at the beginning of the passed expression or
nullin case the passed expression does not start with a letter.
-