public final class Layout extends Object implements Serializable
LayoutMessage
.
After creating a layout, its name must be defined using the setName
method. Then, the addField
method
must be called for each field. Finally, the complete
method
must be called to complete the definition of the layout.
Constructor and Description |
---|
Layout()
Creates a new
Layout instance for the default JVM locale. |
Layout(Locale locale)
Creates a new
Layout instance for the given locale. |
Modifier and Type | Method and Description |
---|---|
LayoutField |
addField(FieldType type,
String name,
int length,
int scale,
String defval)
Appends a new field to the collection of fields of this layout.
|
static Layout |
compile(String specification,
boolean verifySignature)
Compiles the given
specification into a layout. |
void |
complete(String signature)
Completes the definition of the collection of fields of this layout.
|
static LayoutField |
createField(FieldType type,
String name,
int length,
int scale,
String defval,
int offset,
int occurs)
Creates a new field without a
layout . |
static LayoutField |
createField(FieldType type,
String name,
int length,
int scale,
String defval,
int offset,
int occurs,
Locale locale)
Creates a new field without a
layout . |
boolean |
exists(String name)
Returns
true if the layout field indexed by the supplied name exists in this layout. |
Collection<LayoutField> |
fields()
Returns an unmodifiable collection with the fields contained 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.
|
Locale |
getLocale()
Returns the locale 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. |
static String |
normalizeName(String name)
Converts supplied name to upper case and replaces "-" by "_".
|
void |
setLocale(Locale locale)
Changes the locale of this layout and all of it's fields.
|
void |
setName(String name)
Changes the name of this layout.
|
String |
toString()
Creates and returns a string serialization of this layout.
|
public Layout()
Layout
instance for the default JVM locale. Once
the layout isComplete
, the locale can be changed
using setLocale
.public Layout(Locale locale)
Layout
instance for the given locale. If supplied
locale
is null
, the default JVM locale is used. Once the
layout isComplete
, the locale can be changed using
setLocale
.locale
- the initial locale of the layout (can be null).public String getName()
null
if this layout
is not complete
.null
.public void setName(String name)
complete
.name
- the name of this layout.NullPointerException
- if name
is null
.IllegalStateException
- if the layout definition is complete.public int getLength()
0
if this layout is not complete
.public String getSignature()
null
if this layout is not complete
.public Locale getLocale()
null
for default locale.public void setLocale(Locale locale)
locale
is null
, the default JVM locale is used.locale
- the locale of the layout (can be null).IllegalStateException
- if the layout is not complete.public LayoutField getField(String name)
name
. Returns
null
if the field is not defined in the layout, or if the layout
is not complete
.name
- the name of the required field.name
or null
.NullPointerException
- if name
is null
.public boolean exists(String name)
true
if the layout field indexed by the supplied name
exists in this layout. It returns false
if this layout is
not complete
.name
- the name of the layout field.true
if the field is defined in this layout.NullPointerException
- if name
is null
.public Collection<LayoutField> fields()
addField
method. It returns an empty
collection if this layout is not complete
.public LayoutField addField(FieldType type, String name, int length, int scale, String defval)
LayoutField
.
Certain calls to this method must be made in pairs. In particular, if a
field of type LIST
is added, then this list
must be closed (or terminated) adding a field of type 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.length
- total length of the new field.scale
- numeric scale of the new field.defval
- default value of the new field.null
if type
is
LISTEND
.NullPointerException
- if an argument is null
.IllegalArgumentException
- if an argument is invalid.IllegalStateException
- if the layout definition is complete.public static LayoutField createField(FieldType type, String name, int length, int scale, String defval, int offset, int occurs)
layout
. The properties of
the new field are specified by the supplied arguments, whose legal values
and restrictions are all explained in LayoutField
. Fields created
with this method can only be used to retrieve/store values in messages
. The returned field uses the default JVM locale.type
- type of the new field.name
- name of the new field.length
- total length of the new field.scale
- numeric scale of the new field.defval
- default value of the new field.offset
- the offset position of the field.occurs
- the occurrences of the field.layout
.NullPointerException
- if an argument is null
.IllegalArgumentException
- if type
is invalid.public static LayoutField createField(FieldType type, String name, int length, int scale, String defval, int offset, int occurs, Locale locale)
layout
. The properties of
the new field are specified by the supplied arguments, whose legal values
and restrictions are all explained in LayoutField
. Fields created
with this method can only be used to retrieve/store values in messages
. If supplied locale
is null
, the
default JVM locale is used.type
- type of the new field.name
- name of the new field.length
- total length of the new field.scale
- numeric scale of the new field.defval
- default value of the new field.offset
- the offset position of the field.occurs
- the occurrences of the field.locale
- the locale of the field (can be null).layout
.NullPointerException
- if an argument is null
.IllegalArgumentException
- if type
is invalid.public boolean isComplete()
true
if this layout is complete. A layout is complete
when it's name, fields and signature have all been defined. A complete
layout is immutable, so none of its properties can be changed.true
if this layout is complete.public void complete(String signature)
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 (can be null).IllegalStateException
- if the layout definition is complete.public String toString()
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
IllegalStateException
- if the layout is not complete.public static String normalizeName(String name)
name
- the name to be normalized (can be null).name
.public static Layout compile(String specification, boolean verifySignature)
specification
into a layout. The first line of
the specification
provides the name of the layout, and the
last line provides it's signature. The lines between the first and
the last define the fields of the layout. The following is a
sample layout specification
:
VR:1.0:FMPRA_ING:2021-08-01:18:22:50 N:5:CODIGO X:1:TIPO:M N:11.2:VALOR X:1:ESTADO:A D:8:FECHAING:* X:30:DESCRIP D:8:FECACT:* CS:64:FMPRA_ING:ONHP2hI8ptNvgfYJSErLqa
specification
- the specification of the layout.verifySignature
- if true
verify the layout signature.specification
.NullPointerException
- if specification
is null
.IllegalArgumentException
- if specification
is invalid.Copyright © OBCOM INGENIERIA S.A. (Chile). All Rights Reserved.