public class RecordFormatDocument
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable
java com.ibm.as400.data.RecordFormatDocument -serialize RFML document nameOptions:
.rfml.ser
(lowercase).
Serialized RFML files
To increase run-time performance, you can use a serialized RFML file.
A serialized RFML file contains serialized Java objects representing the RFML.
The objects that are serialized are the same objects that are created when you
construct the RecordFormatDocument object from a RFML source file.
Using serialized RFML files gives you better performance because the IBM
XML parser is not needed at run-time to interpret and validate the RFML tags.
For usage examples, refer to the PCML section of the Toolbox Programmer's
Guide. The behavior of RecordFormatDocument matches that of
ProgramCallDocument
for methods that have the same name, such as setIntValue() and getIntValue().
Note: This class requires Java 2 (v1.2.2) or later.
Constructor and Description |
---|
RecordFormatDocument()
Constructs a RecordFormatDocument.
|
RecordFormatDocument(Record record)
Constructs a RecordFormatDocument from a Record object.
|
RecordFormatDocument(RecordFormat recordFormat)
Constructs a RecordFormatDocument from a RecordFormat object.
|
RecordFormatDocument(java.lang.String documentName)
Constructs a RecordFormatDocument.
|
RecordFormatDocument(java.lang.String documentName,
java.lang.ClassLoader loader)
Constructs a RecordFormatDocument.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone()
Creates and returns a copy of this object.
|
Descriptor |
getDescriptor()
Returns a Descriptor representing the current RFML document.
|
static Descriptor |
getDescriptor(java.lang.String documentName)
Returns a Descriptor for the specified RFML document.
|
static Descriptor |
getDescriptor(java.lang.String documentName,
java.lang.ClassLoader loader)
Returns a Descriptor representing the specified RFML document.
|
double |
getDoubleValue(java.lang.String name)
Returns a
double value for the named element. |
double |
getDoubleValue(java.lang.String name,
int[] indices)
Returns a
double value for the named element given indices to the data element. |
int |
getIntValue(java.lang.String name)
Returns an
int value for the named element. |
int |
getIntValue(java.lang.String name,
int[] indices)
Returns an
int value for the named element given indices to the data element. |
java.lang.String |
getStringValue(java.lang.String name)
Returns a
String value for the named <data type="char"> element. |
java.lang.String |
getStringValue(java.lang.String name,
int type)
Returns a
String value for the named <data type="char"> element. |
java.lang.String |
getStringValue(java.lang.String name,
int[] indices,
int type)
Returns a
String value for the named <data type="char"> element, given indices to the data element. |
java.lang.Object |
getValue(java.lang.String name)
Returns the Java object value for the named element.
|
java.lang.Object |
getValue(java.lang.String name,
int[] indices)
Returns the Java object value for the named element given indices to the data element.
|
static void |
main(java.lang.String[] args)
Provides a command line interface to RecordFormatDocument.
|
void |
serialize(java.io.File file)
Serializes the RecordFormatDocument.
|
void |
serialize(java.io.OutputStream outputStream)
Serializes the RecordFormatDocument.
|
void |
serialize(java.lang.String fileName)
Serializes the RecordFormatDocument.
|
void |
setDocument(java.lang.String documentName)
Sets the RFML document resource.
|
void |
setDocument(java.lang.String documentName,
java.lang.ClassLoader loader)
Sets the RFML document resource.
|
void |
setIntValue(java.lang.String name,
int value)
Sets the Java object value for the named element using an int input value.
|
void |
setIntValue(java.lang.String name,
int[] indices,
int value)
Sets the Java object value for the named element using an int input value
given indices to the data element.
|
void |
setStringValue(java.lang.String name,
int[] indices,
java.lang.String value,
int type)
Sets the Java object value for the named <data type="char"> element using a String input value, given indices to the data element.
|
void |
setStringValue(java.lang.String name,
java.lang.String value)
Sets the Java object value for the named <data type="char"> element using a String input.
|
void |
setStringValue(java.lang.String name,
java.lang.String value,
int type)
Sets the Java object value for the named <data type="char"> element using a String input.
|
void |
setValue(java.lang.String name,
int[] indices,
java.lang.Object value)
Sets the Java object value for the named element
given indices to the data element.
|
void |
setValue(java.lang.String name,
java.lang.Object value)
Sets the Java object value for the named element.
|
void |
setValues(java.lang.String formatName,
byte[] values)
Sets the data represented by the specified
<recordformat> element. |
void |
setValues(java.lang.String formatName,
Record record)
Sets the Java object values for the specified
<recordformat> element, based on the values stored in the record object passed into the method. |
byte[] |
toByteArray(java.lang.String formatName)
Returns the data contained by the specified
<recordformat> element, as a byte array. |
Record |
toRecord(java.lang.String formatName)
Returns a Record object with the same structure and data as the specified
<recordformat> element. |
RecordFormat |
toRecordFormat(java.lang.String formatName)
Returns a RecordFormat object with the same structure as the specified
<recordformat> element. |
void |
toXml(java.io.File file)
Generates XML (RFML) representing the data contained in this object.
|
void |
toXml(java.io.OutputStream outputStream)
Generates XML (RFML) representing the data contained in this object.
|
void |
toXml(java.lang.String fileName)
Generates XML (RFML) representing the data contained in this object.
|
public RecordFormatDocument()
Prior to using an object constructed with this method,
either setDocument
or setValues
must be called.
public RecordFormatDocument(java.lang.String documentName) throws XmlException
documentName
- The document resource name of the RFML document for the record formats to be referenced.
All RFML-related file extensions are assumed to be lowercase (for example, .rfml or .rfml.ser).
The resource name can be a package qualified name. For example, "com.myCompany.myPackage.myRfml"XmlException
- when the specified RFML document cannot be found.public RecordFormatDocument(java.lang.String documentName, java.lang.ClassLoader loader) throws XmlException
documentName
- The document resource name of the RFML document for the record formats to be referenced.
All RFML-related file extensions are assumed to be lowercase (for example, .rfml or .rfml.ser).
The resource name can be a package qualified name. For example, "com.myCompany.myPackage.myRfml"loader
- The ClassLoader that will be used when loading the specified document resource.XmlException
- when the specified RFML document cannot be found.public RecordFormatDocument(Record record) throws XmlException
AS400Structure
AS400Array
with elements of type AS400Array (multidimensional array)
record
- The Record object.XmlException
public RecordFormatDocument(RecordFormat recordFormat) throws XmlException
AS400Structure
AS400Array
with elements of type AS400Array (multidimensional array)
recordFormat
- The RecordFormat object.XmlException
public java.lang.Object clone()
clone
in class java.lang.Object
public static Descriptor getDescriptor(java.lang.String documentName) throws XmlException
documentName
- The document resource name of the RFML document for which the Descriptor is returned.
The resource name can be a package qualified name. For example, "com.myCompany.myPackage.myRfml"XmlException
- when the specified RFML document cannot be found.public static Descriptor getDescriptor(java.lang.String documentName, java.lang.ClassLoader loader) throws XmlException
documentName
- The document resource name of the RFML document for which the Descriptor is returned.
The resource name can be a package qualified name. For example, "com.myCompany.myPackage.myRfml"loader
- The ClassLoader that will be used when loading the specified document resource.XmlException
- when the specified RFML document cannot be found.public Descriptor getDescriptor()
public double getDoubleValue(java.lang.String name) throws XmlException
double
value for the named element.name
- The name of the <data> element in the PCML document.XmlException
- If an error occurs while processing RFML.public double getDoubleValue(java.lang.String name, int[] indices) throws XmlException
double
value for the named element given indices to the data element.
If the data element is an array or is an element in a structure array, an index
must be specified for each dimension of the data.name
- The name of the <data> element in the PCML document.indices
- An array of indices for accessing the value of an element in an array.XmlException
- If an error occurs while processing RFML.public int getIntValue(java.lang.String name) throws XmlException
int
value for the named element.name
- The name of the <data> element in the PCML document.XmlException
- If an error occurs while processing RFML.public int getIntValue(java.lang.String name, int[] indices) throws XmlException
int
value for the named element given indices to the data element.
If the data element is an array or is an element in a structure array, an index
must be specified for each dimension of the data.name
- The name of the <data> element in the PCML document.indices
- An array of indices for accessing the value of an element in an array.XmlException
- If an error occurs while processing RFML.public java.lang.String getStringValue(java.lang.String name) throws XmlException
String
value for the named <data type="char"> element.
The default bidi string type is assumed (BidiStringType.DEFAULT
).name
- The name of the <data>
element in the RFML document.XmlException
- If an error occurs while processing RFML.public java.lang.String getStringValue(java.lang.String name, int type) throws XmlException
String
value for the named <data type="char"> element.
This method should be used when the string type cannot be determined until run-time. In those cases, the RFML document cannot be used to indicate the string type so this method can be used to get the value using the string type that is specified.
name
- The name of the <data>
element in the RFML document.type
- The bidi string type, as defined by the CDRA (Character
Data Representation Architecture).XmlException
- If an error occurs while processing RFML.public java.lang.String getStringValue(java.lang.String name, int[] indices, int type) throws XmlException
String
value for the named <data type="char"> element, given indices to the data element.
If the data element is an array or is an element in a structure array, an index
must be specified for each dimension of the data.
This method should be used when the string type cannot be determined until run-time. In those cases, the RFML document cannot be used to indicate the string type so this method can be used to get the value using the string type that is specified.
name
- The name of the <data>
element in the RFML document.indices
- An array of indices for setting the value of an element in an array.type
- The bidi string type, as defined by the CDRA (Character
Data Representation Architecture).XmlException
- If an error occurs while processing RFML.public java.lang.Object getValue(java.lang.String name) throws XmlException
The type of object returned depends on the description in the RFML document.
RFML Description | Object Returned |
---|---|
type=char | String |
type=byte | byte[] |
type=int length=2 precision=15 | Short |
type=int length=2 precision=16 | Integer |
type=int length=4 precision=31 | Integer |
type=int length=4 precision=32 | Long |
type=int length=8 precision=63 | Long |
type=int length=8 precision=64 | Double |
type=packed | BigDecimal |
type=zoned | BigDecimal |
type=float length=4 | Float |
type=float length=8 | Double |
type=struct | null |
name
- The name of the <data>
element in the RFML document.<data>
element in the RFML document.XmlException
- If an error occurs while processing RFML.public java.lang.Object getValue(java.lang.String name, int[] indices) throws XmlException
The type of object returned depends on the description in the RFML document.
name
- The name of the <data>
element in the RFML document.indices
- An array of indices for accessing the value of an element in an array.<data>
element in the RFML document.XmlException
- If an error occurs while processing RFML.public static void main(java.lang.String[] args)
args
- The arguments.public void serialize(java.io.OutputStream outputStream) throws java.io.IOException, XmlException
outputStream
- The output stream to which to serialize the object.java.io.IOException
- If an error occurs while writing to the stream.XmlException
- If an error occurs while processing RFML.public void serialize(java.io.File file) throws java.io.IOException, XmlException
file
- The file to which to serialize the object.java.io.IOException
- If an error occurs while writing to the file.XmlException
- If an error occurs while processing RFML.public void serialize(java.lang.String fileName) throws java.io.IOException, XmlException
fileName
- The name of the file to which to serialize the object.java.io.IOException
- If an error occurs while writing to the file.XmlException
- If an error occurs while processing RFML.public void setIntValue(java.lang.String name, int value) throws XmlException
The named element must be able to be set using a Integer object.
name
- The name of the <data>
element in the RFML document.value
- The int value for the named element.XmlException
- If an error occurs while processing RFML.public void setIntValue(java.lang.String name, int[] indices, int value) throws XmlException
The named element must be able to be set using a Integer object.
name
- The name of the <data>
element in the RFML document.indices
- An array of indices for setting the value of an element in an array.value
- The int value for the named element.XmlException
- If an error occurs while processing RFML.public void setStringValue(java.lang.String name, java.lang.String value) throws XmlException
BidiStringType.DEFAULT
).name
- The name of the <data>
element in the RFML document.value
- The string value for the named element.XmlException
- If an error occurs while processing RFML.public void setStringValue(java.lang.String name, java.lang.String value, int type) throws XmlException
This method should be used when the string type cannot be determined until run-time. In those cases, the RFML document cannot be used to indicate the string type so this method can be used to set the value and the string type of the input value.
name
- The name of the <data>
element in the RFML document.value
- The string value for the named element.type
- The bidi string type, as defined by the CDRA (Character
Data Representation Architecture).XmlException
- If an error occurs while processing RFML.BidiStringType
public void setStringValue(java.lang.String name, int[] indices, java.lang.String value, int type) throws XmlException
This method should be used when the string type cannot be determined until run-time. In those cases, the RFML document cannot be used to indicate the string type so this method can be used to set the value and the string type of the input value.
name
- The name of the <data>
element in the RFML document.indices
- An array of indices for setting the value of an element in an array.value
- The string value for the named element.type
- The bidi string type, as defined by the CDRA (Character
Data Representation Architecture).XmlException
- If an error occurs while processing RFML.public void setDocument(java.lang.String documentName) throws XmlException
documentName
- The document resource name of the RFML document for the record formats to be referenced.
All RFML-related file extensions are assumed to be lowercase (for example, .rfml or .rfml.ser).
The resource name can be a package qualified name. For example, "com.myCompany.myPackage.myRfml"XmlException
- when the specified RFML document cannot be found.public void setDocument(java.lang.String documentName, java.lang.ClassLoader loader) throws XmlException
documentName
- The document resource name of the RFML document for the record formats to be referenced.
All RFML-related file extensions are assumed to be lowercase (for example, .rfml or .rfml.ser).
The resource name can be a package qualified name. For example, "com.myCompany.myPackage.myRfml"loader
- The ClassLoader that will be used when loading the specified document resource.XmlException
- when the specified RFML document cannot be found.public void setValue(java.lang.String name, java.lang.Object value) throws XmlException
If the input value provided is not an instance of the
correct Java class for the defined data type, it will be converted
to the correct Java class.
For example, if an element is defined as
"type=int length=2 precision=15
",
it will automatically be converted to a Java Short object, if the value specified is an instance of Number or String.
name
- The name of the <data>
element in the RFML document.value
- The Java object value for the named element. The type of Object passed must be
the correct type for the element definition or a String that can be converted to the correct type. Null values are not allowed.XmlException
- If an error occurs while processing RFML.public void setValue(java.lang.String name, int[] indices, java.lang.Object value) throws XmlException
If the input value provided is not an instance of the
correct Java class for the defined data type, it will be converted
to the correct Java class.
For example, if an element is defined as
"type=int length=2 precision=15
",
it will automatically be converted to a Java Short object, if the value specified is an instance of Number or String.
name
- The name of the <data>
element in the RFML document.indices
- An array of indices for setting the value of an element in an array.value
- The Java object value for the named element. The type of Object passed must be
the correct type for the element definition or a String that can be converted to the correct type. Null values are not allowed.XmlException
- If an error occurs while processing RFML.public void setValues(java.lang.String formatName, Record record) throws XmlException
<recordformat>
element, based on the values stored in the record object passed into the method.
type=int length=2 precision=15
",
it will automatically be converted to a Java Short object, if the value specified is an instance of Number or String. If any field in the Record is null-valued, a warning is issued.
AS400Structure
AS400Array
with elements of type AS400Array (multidimensional array)
formatName
- The name of the <recordformat>
element in the RFML document.record
- The record object containing the data.XmlException
- If an error occurs while processing RFML, or if an encoding specified by the Record is unsupported.public void setValues(java.lang.String formatName, byte[] values) throws XmlException
<recordformat>
element.formatName
- The name of the <recordformat>
element in the RFML document.values
- The byte values for all the fields in the the named element. The length of the byte array must exactly match the length of data required, otherwise an XmlException is thrown.XmlException
- If an error occurs while processing RFML.public byte[] toByteArray(java.lang.String formatName) throws XmlException
<recordformat>
element, as a byte array.formatName
- The name of the <recordformat>
element in the RFML document.XmlException
public Record toRecord(java.lang.String formatName) throws XmlException
<recordformat>
element.
Before this method is called, all <data> elements must either have their values set, or have 'init' values.
formatName
- The name of the <recordformat>
element in the RFML document.<recordformat>
element.XmlException
- If an error occurs while processing RFML.public RecordFormat toRecordFormat(java.lang.String formatName) throws XmlException
<recordformat>
element.
Note: For <data> elements, the 'count' attribute is disregarded.formatName
- The name of the <recordformat>
element in the RFML document.<recordformat>
element.XmlException
public void toXml(java.io.OutputStream outputStream) throws java.io.IOException, XmlException
outputStream
- The output stream to which to write the text.java.io.IOException
- If an error occurs while writing the data.XmlException
- If an error occurs while processing RFML.public void toXml(java.io.File file) throws java.io.IOException, XmlException
file
- The file to which to write the text.java.io.IOException
- If an error occurs while writing the data.XmlException
- If an error occurs while processing RFML.public void toXml(java.lang.String fileName) throws java.io.IOException, XmlException
fileName
- The pathname of the file to which to write the text.java.io.IOException
- If an error occurs while writing the data.XmlException
- If an error occurs while processing RFML.