ARTICLE
asXML - Instances of Classes
To transform classes to XML using the
statement CALL TRANSFORMATION ,
or to create classes from XML data, their classes must implement
the interface IF_SERIALIZABLE_OBJECT
. The instance of a class (object) is displayed as a subelement of
heap as follows:
<(><<)>asx:heap xmlns:nspace ...>
<(><<)>class id = "key">
<(><<)>part classVersion = "...">
<(><<)>name>...<(><<)>/name>
...
<(><<)>/part>
...
<(><<)>/class>
/asx:heap
The class element name is the XML schema type name of the
class of the object (or the dynamic type of the reference variables)
from the nspace namespace (see table below) in uppercase letters.
Mandatory attribute id contains unique key key of the
element by means of which it is referenced by the display of the
corresponding reference variables in values . Subelements
part ... /part contain the values of the instance
attributes of individual object parts as subelements <(><<)>name>...
/name . The individual object parts are defined by means of
the serializable classes of the current inheritance hierarchy.
The namespace of the class name indicates where the class is defined.
The table below shows the possible namespaces, whereby in the first
column, classes stands for http://www.sap.com/abapxml/classes
. For identifiers PRG , CPOOL , and FPOOL , the
same substitution rule applies as that for the namespaces for
anonymous data objects .
Namespace Where Defined
classes/global Class Library
classes/program/PRG Program prg
classes/class-pool/CPOOL Class pool cpool
classes/function-pool/FPOOL Function group fpool
The serializable values of an instance of a class (instance attributes
or output parameters of a special helper method) are displayed in the
asXML display for named data objects or for reference variables
as content or attributes of name ... /name whereby
name is the name of an instance attribute or output parameter in
uppercase letters. For interface attributes, the name of the interface
is added before the name, separated by a point (.), to differentiate it
from a class attribute of the same name. For the identifiers, the same
substitution rules apply as for all
elements.
The serializable values of an instance of a class are specified in the
class by implementing the system interface
IF_SERIALIZABLE_OBJECT . The system interface
IF_SERIALIZABLE_OBJECT is a tag
interface . Its implementation shows the runtime environment the
serializability of a class and its subclasses and allows it to declare
certain other components in the class according to fixed syntax rules.
This interface IF_SERIALIZABLE_OBJECT can only be implemented in
one class of a path and is effective for all subclasses from this class.
If the class or one of its superclasses does not implement the interface
IF_SERIALIZABLE_OBJECT , the element class does not
contain any subelements. By default, all instance attributes of a class
in which the interface IF_SERIALIZABLE_OBJECT is implemented
directly or in a superclass are serialized and deserialized to this
class. This behavior can be changed by declaring special help methods.
Static attributes are ignored in
serializations or deserializations (with the exception of special
constant SERIALIZABLE_CLASS_VERSION ).
Standard Behavior
If the class or one of its superclasses implements the interface
IF_SERIALIZABLE_OBJECT , the element class ...
/class contains at least one subelement part ...
/part /class . These subelements correspond to individual
serializable object parts and contain the displays of the instance
attributes of the respective object part in asXML format. An
object part is specified by the class in which instance attributes are
declared or into which an interface that contains instance attributes is
integrated. A serializable class contains an object part for itself as
well as object parts for all superclasses in the current path of the
inheritance tree up to and including the class that implements the
interface IF_SERIALIZABLE_OBJECT . Name part is the name of
the respective class. If the class is a local class, prefix local
is added in front of the name, separated by a point (.), to
differentiate it from a global class of the same name. Object parts of
superclasses in which the interface IF_SERIALIZABLE_OBJECT is not
implemented are not serializable and do not have a corresponding
subelement part . This means that a class in which the interface
IF_SERIALIZABLE_OBJECT is not implemented (neither in the class
itself nor in a superclass) generates an empty XML element
class in serializations.
In serializations, the XML elements part of the object
parts of the superclasses that implemented the interface
IF_SERIALIZABLE_OBJECT are created for the subclasses and by default
the XML elements of the instance attributes are created in the
order in which they are declared in the class.
In deserializations, an object of the respective class is generated,
whereby the instance constructor is not executed. After the object
generation, all instance attributes have their
initial value or the
start value that is specified with
addition VALUE of statement DATA . By default, the instance
attributes are supplied with the values of the corresponding XML
elements. Here the order of the object parts and the attributes is not
important. Instance attributes without a corresponding XML
element retain their value. Unnecessary XML elements are ignored
as long as they do not belong to a namespace; otherwise they raise an
exception that can be handled. In the deserialization of an element that
does not have any subelements part , no object is created but
instead the target reference variable is initialized.
If a class or one of its superclasses implements the interface
IF_SERIALIZABLE_OBJECT , the private
constant SERIALIZABLE_CLASS_VERSION of type i can be
declared in each object part, that is, in each participating class of
the inheritance tree. In serializations, the value of the constant is
assigned to attribute classVersion of XML element part
. By default, an exception that can be handled is raised in
deserializations if the value of the attribute does not match the value
of the constant in the specified class. An object part can only be
deserialized if the values match or if neither the attribute nor the
constant exists. This behavior can be changed by declaring special help
methods.
Note
Using the standard behavior involves a certain security risk, because
all instance attributes of an object can be serialized and can be
manipulated in the XML data that is created (see
example ).
Adjusted Behavior
By default, all instance attributes of an object part are serialized
regardless of their visibility and the version of the class is checked.
To change this behavior, for each object part, instance methods
SERIALIZE_HELPER and DESERIALIZE_HELPER can be declared and
implemented in the respective class. These methods can only be declared
as private instance methods in classes that implement the interface
IF_SERIALIZABLE_OBJECT directly or in one of its superclasses. The
declaration of one of the methods restricts the declaration of the
others, and the interface is predefined by the syntax check as described
below:
Method SERIALIZE_HELPER is only allowed to have output
parameters, and method DESERIALIZE_HELPER is only allowed to have
input parameters with generic typing .
For each output parameter of method SERIALIZE_HELPER , there must
be an input parameter of method DESERIALIZE_HELPER that has the
same name and the same typing. Additional input parameters of method
DESERIALIZE_HELPER have to be optional.
Method SERIALIZE_HELPER is not allowed to have any output
parameters of name SERIALIZABLE_CLASS_VERSION , and method
DESERIALIZE_HELPER is allowed to have this optional input parameter
of type i . In deserializations, this is supplied with the value
of attribute classVersion of element part . This avoids the
standard check made on the version.
If methods SERIALIZE_HELPER and DESERIALIZE_HELPER are
declared in an object part, the instance attributes of the object part
are not serialized and deserialized. Instead, in serializations, method
SERIALIZE_HELPER is executed and the values of all output
parameters are written to the corresponding element part as
subelements in the order specified in asXML format. The name of a
subelement is the name of the corresponding output parameter in
uppercase letters. In deserializations, method DESERIALIZE_HELPER
is called, whereby the values of the subelements of the corresponding
element part are passed to the input parameters of the methods
that have the same name. The order does not matter here and unnecessary
XML elements are ignored.
Example
See Modified Serializations and
Deserializations .
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved