Package org.acplt.oncrpc.apps.jrpcgen

# Class JrpcgenConst

java.lang.Object
org.acplt.oncrpc.apps.jrpcgen.JrpcgenDocumentable
org.acplt.oncrpc.apps.jrpcgen.JrpcgenXdrDefinition
org.acplt.oncrpc.apps.jrpcgen.JrpcgenConst

All Implemented Interfaces:
  `JrpcgenItem`

Direct Known Subclasses:
  `JrpcgenEnum.Element`

public class JrpcgenConst extends JrpcgenXdrDefinition
The `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 Classes
Modifier and Type
Class
Description
`static class`
`JrpcgenConst.Table`
Type 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

Constructors
Constructor
Description
`JrpcgenConst(JrpcgenContext context, String identifier, String value)`
Constructs a `JrpcgenConst` and sets the identifier and the associated value.
`JrpcgenConst(JrpcgenContext context, String identifier, String value, String enclosure)`
Constructs a `JrpcgenConst` and sets the identifier and the associated value of an enumeration etc.

## Method Summary

Modifier and Type
Method
Description
`static String`
`detectIdentifier(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: <quote>An identifier is a letter followed by an optional sequence of letters, digits, or underbar ('_').
`void`
`dump()`
Dumps the constant as well as its value to `System.out`.
`<T extends Appendable>
T`
`dump(T appendable)`
`String`
`getAsCaseValue(String forEnclosure)`
Delivers a case value representation of the constant.
`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.
`String`
`getAsRValue(String forEnclosure)`
Delivers an r-value representation of the constant.
`static String`
`getAsRValue(String constantExpression, String forEnclosure, JrpcgenContext context)`
Delivers the passed constant expression as an r-value.
`static String`
`getAsRValue(String constantExpression, JrpcgenContext context)`
Delivers the passed constant expression as an r-value.
`final JrpcgenContext`
`getContext()`
Delivers the context the constant definition belongs to.
`final String`
`getEnclosure()`
Returns the name of the enclosure the constant lives in.
`String`
`getForEnclosure(String forEnclosure)`
Delivers the representation of the constant with respect to the passed enclosure name.
`final String`
`getValue()`
Delivers the value defined for the constant.
`String`
`getValueAsRValue(String forEnclosure)`
Delivers an r-value representation of the value defined by the constant.
`String`
`resolveValue()`
Returns the value as integer literal (and thus resolving identifiers recursively, if necessary).
`final void`
`setEnclosure(String enclosure)`
Sets the name of the enclosure the constant lives in.
`final void`
`setValue(String value)`
Sets the value represented by the constant.
`String`
`toString()`
`void`
`writeDeclaration(JrpcgenJavaFile javaFile)`

### Methods inherited from class org.acplt.oncrpc.apps.jrpcgen.JrpcgenXdrDefinition

`getIdentifier, getXdrType, isConst, isEnum, isStruct, isTypedef, isUnion`

### Methods inherited from class org.acplt.oncrpc.apps.jrpcgen.JrpcgenDocumentable

`appendDeprecatedOrNothing, appendDeprecatedOrNothing, documentationIsEmpty, documentationIsProvided, emptyDocumentation, getDocumentation, getIdentedDocu, getIdentedDocu, isDeprecated, writeDocumentation, writeDocumentation`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Constructor Details

### JrpcgenConst

public JrpcgenConst(JrpcgenContext context, String identifier, String value)
Constructs a `JrpcgenConst` and 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

public JrpcgenConst(JrpcgenContext context, String identifier, String value, String enclosure)
Constructs a `JrpcgenConst` and 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

public static String getAsRValue(String constantExpression, 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"`.

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 identifier `VERSION` nested 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 identifier `ENUM_FIRST` nested in the enclosure (namespace) `EnumerationValues` originating 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) `element` and a global constant definition with the identifier `VERSION` nested in the enclosure (namespace) `demo`, passing the string literals `"VERSION"` and `"element"` results in returning the string `"demo.VERSION"`.

Given a target enclosure (namespace) `demo` and a global constant definition with the identifier `VERSION` nested in the enclosure (namespace) `demo`, passing the string literals `"VERSION"` and `"demo"` results in returning the string `"VERSION"`.

Given a target enclosure (namespace) `element` and a global constant definition with the identifier `ENUM_FIRST` nested in the enclosure (namespace) `EnumerationValues` originating 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 (see `JrpcgenEnum.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) `element` and a global constant definition with the identifier `VERSION` nested in the enclosure (namespace) `demo`, passing the string literals `"VERSION"` and `"element"` result in returning the string `"demo.VERSION"`.

Given a target enclosure (namespace) `element` and a global constant definition with the identifier `ENUM_FIRST` nested in the enclosure (namespace) `EnumerationValues` originating 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 (see `JrpcgenEnum.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

public final JrpcgenContext getContext()
Delivers the context the constant definition belongs to.

Returns:
  The context teh constant definition belongs to.

### getValue

public final String getValue()
Delivers the value defined for the constant.

Returns:
  The value of the constant.

### setValue

public final void setValue(String value)
Sets the value represented by the constant.

Parameters:
  `value` - The value of the constant in string representation.

### getEnclosure

public final String getEnclosure()
Returns the name of the enclosure the constant lives in.

Returns:
  The name of the enclosure.

### setEnclosure

public final void setEnclosure(String enclosure)
Sets the name of the enclosure the constant lives in.

Parameters:
  `enclosure` - The name of the enclosure.

### getForEnclosure

public String getForEnclosure(String forEnclosure)
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

public String getAsRValue(String forEnclosure)
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

public String getAsCaseValue(String forEnclosure)
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

public String getValueAsRValue(String forEnclosure)
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

public String 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 `String` or `null`, if the identifier could not be resolved to an integer literal.

### writeDeclaration

public void writeDeclaration(JrpcgenJavaFile javaFile)

### dump

public void dump()
Dumps the constant as well as its value to `System.out`.

### dump

public <T extends Appendable> T dump(T appendable)

### toString

public String toString()

Overrides:
  `toString` in class `Object`

### detectIdentifier

public static String detectIdentifier(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: <quote>An identifier is a letter followed by an optional sequence of letters, digits, or underbar ('_'). The case of identifiers is not ignored.</quote>

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 `null` in case the passed expression does not start with a letter.