public final class Layout extends Object implements Serializable
Message
.
The collection of fields of a Layout
is defined using a specific
sequence of method calls. First, a Layout
is created, and its name
defined, using the Layout(String)
constructor. Then, the addField
method must be called for each Layout
field.
Finally, the complete
method must be called to complete the
definition of the collection.
Alternatively, a Layout
can be created using the Layout()
constructor and its other properties can be defined using the compile
method.
LayoutField
,
Message
,
Serialized FormConstructor and Description |
---|
Layout()
Creates a new
Layout instance. |
Layout(String name)
Creates a new
Layout with the given name . |
Modifier and Type | Method and Description |
---|---|
LayoutField |
addField(int type,
String name,
int size,
int scale,
String defval)
Appends a new field to the collection of fields of this
Layout . |
void |
compile(String specification)
Compiles the given
specification into a Layout . |
void |
compileEcu(String specification)
Compiles an ECUSER
specification into a Layout . |
void |
complete(String signature)
Completes the definition of the collection of fields of this
Layout . |
boolean |
exists(String name)
Returns
true if the layout field indexed by the supplied name exists in this Layout . |
LayoutField |
getField(String name)
Returns the layout field indexed by the supplied
name . |
int |
getLength()
Returns the sum of the sizes of all the fields of this
Layout . |
String |
getName()
Returns the name of this
Layout . |
String |
getSignature()
Returns the signature (or checksum) of this
Layout . |
boolean |
isComplete()
Returns
true if this Layout is complete. |
Iterator<LayoutField> |
iterator()
Returns a "read-only" iterator over the collection of fields in this
Layout . |
String |
toString()
Creates and returns a string serialization of this
Layout . |
public Layout()
Layout
instance. The remaining properties of this
Layout
must be defined using the compile
method.compile(String)
public Layout(String name)
Layout
with the given name
. The remaining
properties of this Layout
must be defined using the addField
and the complete
methods.name
- the name of this Layout
.addField(int, String, int, int, String)
,
complete(String)
public String getName()
Layout
.Layout
.IllegalStateException
- if the Layout
is not complete.public String getSignature()
Layout
.Layout
.IllegalStateException
- if the Layout
is not complete.public int getLength()
Layout
.
This value can be used to allocate a Message
or a char[]
with enough capacity to store the values of all the fields defined by
this Layout
.Layout
.IllegalStateException
- if the Layout
is not complete.public LayoutField getField(String name)
name
. Returns
null
if the field is not defined in this Layout
.name
- the name of the required field.name
or null
.IllegalStateException
- if the Layout
is not complete.LayoutField
public boolean exists(String name)
true
if the layout field indexed by the supplied name
exists in this Layout
.name
- the name of the layout field.true
if the field is defined in this Layout
.IllegalStateException
- if the Layout
is not complete.public Iterator<LayoutField> iterator()
Layout
. Each object returned by the Iterator.next()
method
corresponds to a LayoutField
. These objects are returned in the
order they were added to the collection by the addField
method.Layout
.IllegalStateException
- if the Layout
is not complete.addField(int, String, int, int, String)
,
Iterator.hasNext()
,
Iterator.next()
public boolean isComplete()
true
if this Layout
is complete. A layout is
complete when it's name, fields and signature have all been properly
defined. A complete Layout
is immutable, hence none of its
properties can be changed.true
if this Layout
is complete.complete(String)
public void compile(String specification)
specification
into a Layout
. The
specification
is composed of a sequence of three or more lines
separeted by a new-line character. The first of these lines specifies the
name of the Layout
. The last line specifies the
signature of the Layout
. The lines between the first and
the last specify the fields of the Layout
.specification
- the specification of the Layout
.NullPointerException
- if the specification is null
.IllegalArgumentException
- if the specification is invalid.public void compileEcu(String specification)
specification
into a Layout
. The
specification
is composed of a sequence of three or more lines
separeted by a new-line character. The first of these lines specifies the
name of the Layout
. The last line specifies the
signature of the Layout
. The lines between the first and
the last specify the fields of the Layout
.specification
- the ECUSER specification of the Layout
.NullPointerException
- if specification
is null
.IllegalArgumentException
- if the specification is invalid.public LayoutField addField(int type, String name, int size, int scale, String defval)
Layout
.
The properties of this new field are specified in the supplied arguments.
Their legal values and restrictions are all explained in LayoutField
. Certain calls to this method must be made in pairs. In
particular, if a field of type LayoutField.LIST
is added, then
this list must be closed (or terminated) adding a field of type
LayoutField.LISTEND
. This last call does not actually add a
LayoutField
; it just completes the definition of the list
field.type
- type of the new field.name
- name of the new field.size
- total size of the new field.scale
- numeric scale of the new field.defval
- default value of the new field.null
if type
is
LayoutField.LISTEND
.NullPointerException
- if the name is null or empty.IllegalArgumentException
- if the name is invalid.IllegalStateException
- if the layout definition is incomplete.public void complete(String signature)
Layout
. The supplied signature
is stored so it can later be
retrieved using the getSignature()
method. Once this method is
called, no other calls to the addField
method are
allowed. In other words, this Layout
becomes immutable after this
method is used.signature
- the signature of this Layout
.IllegalStateException
- if an invalid call sequence is executed.public String toString()
Creates and returns a string serialization of this Layout
. The
serialization consists of a sequence of three or more text lines. The
first line is called the version and starts with the sequence "
VR:
". The last line is called the checksum and starts with
the sequence "CS:
". The lines between the version and the
checksum lines represent layout fields in the following
format:
type:length[.scale]:name[:default]
toString
in class Object
Layout
.IllegalStateException
- if the Layout
is not complete.Copyright © OBCOM INGENIERIA S.A. (Chile). All Rights Reserved.