Description
Once a class instance is declared in a program through the REF_CLASS instruction, a special syntax needs to be used to gain access to its attributes, for both reading and writing.
This syntax is based on the principle of Getters and Setters of object languages.
Getting the value of a class attribute
To retrieve the value of an attribute of a REF_CLASS type variable, the following syntax must be used:
MyVariableResult = MyInstance.getNameAttribute()
or
MyVariableResult = MyInstance.getNameAttributeArray()(index[,index2])
Example:
Adelia class CAR whose 4GL source is:
*attributes
{
ALPHA(15) Make;
ALPHA(250) Model;
NUM_BIN_2 NumHp;
DATE DatePurch;
ALPHA(50) Options(30)
}
Then in the Visual Adelia Batch program:
* Declaring a REF_CLASS variable:
REF_CLASS(CAR) iCar
NUM_BIN_2 MyBin2
DATE MyDate
ALPHA(50) TabOptions(30)
ALPHA(50) option;
* Getting the value of the attribute 'NumHp' of the iCar class:
MyBin2 = iCar.getNumHp()
* Getting the value of the attribute 'NumHp' of the iCar class:
MyDate = iCar.getDatePurch()
* Get the value of the first element of the attribute 'Options' from the iCar class:
Option = iCar.getOptions()(1)
Note:
It is assumed here that the iCar variable is already instantiated (e.g. it is one of the parameters of the input to the program or procedure), or that it has been instantiated in the program via the 4GL instruction NEW:
iCar = new CAR()
It is possible to test whether the iCar variable is instantiated with the reserved word *NULL:
If iCar = *NULL
Retrieving all the array attribute elements
The following syntax must be used to get all the values from a one-dimensional, two-dimensional or dynamic array attribute:
MyArrayVariable = MyInstance.getArrayAttributeName()
NewArray must be an array variable with an Adelia type and dimensions which are compatible with those of the relevant array attribute.
If the number of NewArray entries is different from the number of entries of the array attribute, only the common entries are retrieved.
Example:
REF_CLASS(CAR) iCar
ALPHA(50) TabOptions(30)
iCar = new CAR()
* .... instance attribute value allocation...
* Retrieval of the 'Options' 1D array attribute value from the CAR class instance in the "tabOptions" array variable
tabOptions = iCar.getOptions()
Changing the value of a class attribute
To fix the value of an attribute of a REF_CLASS type variable, the following syntax must be used:
XXX.setYYY(ZZZ)
XXX being a variable of the REF_CLASS type
YYY being an attribute of this class
ZZZ being the value to be fixed to this attribute
When the attribute is a class
REF_CLASS(PERSON) iFather
REF_CLASS(FAMILY) iFamily
Father = new PERSON()
iFamily.setFather(iFather)
When the attribute is a simple standard Adelia type (ALPHA, NUM_BIN_2, ..) or an overall array:
MyInstance.setNameAttribute(NewValue)
NewValue may be an alphanumeric or numeric constant, or a variable, with an Adelia type compatible with that of the attribute concerned.
Warning: In the case of a numerical constant with decimals, the dot is the only decimal separator allowed.
Example:
REF_CLASS(PERSON) iFather
ALPHA(33) MyAlpha33
iFather.setFirstname('John')
iFather.setName(MyAlpha33)
↑ Top of pageiFather.setSize(1.78)
To update an element of an array attribute
MyInstance.setNameAttribute(NewValue, Index1[, Index2])
NewValue may be an alphanumeric or numeric constant, or a variable, with an Adelia type compatible with that of the attribute concerned.
Index1 and Index2 may be a numeric constant or numeric variable.
Example:
REF_CLASS(PERSON) iFather
REF_CLASS(CAR) iCar
NUM_BIN_4 MyBin4
NUM_BIN_2 Index1
NUM_BIN_2 Index2
Index = 5
iFather.setArray1DFirstnamesChildren('nicholas', Index1)
iFather.setArray1DFirstnamesChildren('virginia', 4)
iCar.setOptions('peugeot', 4)
iFather.setArrayBin4_2D (MyBin4, 6, 11)
↑ Top of pageiFather.setTArrayBin4_2D (444, Index1, Index2)
To update all elements of an array attribute
MyInstance.setNameAttributeArray(NewArray | NewValue)
NewArray must be an array variable with an Adelia type and dimensions compatible with those of the array attribute concerned. If the number of NewArray
entries is different from the number of entries of the array attribute, the update only involves the number of common entries.
NewValue may b an alphanumeric or numeric constant, or a simple variable, with an Adelia type compatible with that of the array attribute concerned. The reserved words *TRUE and *FALSE for the BOOL type and *NULL for the IMAGE type are also permitted. More generally, the reserved words with an Adelia type which is compatible with that of the relevant array attribute are allowed.
Example:
REF_CLASS(PERSON) iFather
REF_CLASS(CAR) iCar
NUM_BIN_4 MyBin4
NUM_BIN_2 MyArrayBin4(2,2)
ALPHA(20) MyAlpha
MyBin4 = 5865
MyAlpha = 'ABS'
MyArrayBin4(1,1) = 20
MyArrayBin4(1,2) = 40
MyArrayBin4(2,1) = 60
MyArrayBin4(2,2) = 80
iCar.setOptions('GPS')
iCar.setOptions(MonAlpha)
iFather.setArrayBin4_2D (444)
iFather.setArrayBin4_2D (MyBin4)
iFather.setArrayBin4_2D (MyArrayBin4)
To update an element of a dynamic array type attribute
Example:
Adelia class TICKET whose 4GL source is:
*attributes
{
ALPHA(15) Id;
ALPHA(250) Comments();
DATE Updates();
REF_CLASS(SOURCE) Sources()
}
Example:
REF_CLASS(TICKET) itick
REF_CLASS(SOURCE) iSrc
DATE currDate
iTick = new TICKET()
iTick.Comments = new ALPHA(250)()(10)
iTick.Updates = new DATE()(10)
iTick.Sources = new SOURCE()(10)
TIME currDate
iTick.setId('1')
iTick.setComments('Creation of the ticket', 1)
iTick.setUpdates(currDate, 1)
iSrc = new SOURCE()
iTick.setSources(iSrc, 1)
Note:
During serialization, only the elements actually added to the dynamic array are taken into account.
This assertion is always true for the order CONV_DATA.
In the case of the serialization of a class of a REST web service, it is necessary to declare the correct JacksonJaxbJsonProvider (the one from the package com.fasterxml.jackson.jaxrs.json) in the configuration file beans.xml.
Extract from the file beans.xml [JacksonJaxbJsonProvider]:
<?xml version="1.0" encoding="UTF-8"?> <cxf:bus> <cxf:properties> <entry key="skip.default.json.provider.registration" value="true"/> </cxf:properties> </cxf:bus> <!-- remplace le org.apache.cxf.jaxrs.provider.json.JSONProvider ou org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider --> <bean class="com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider"/>
To update all the elements of a dynamic array attribute
MyInstance.setArrayAttributeName(NewArray | NewValue)
NewArray
must be a one-dimensional array variable with an Adelia type which is compatible with that of the relevant dynamic array attribute.
When the number of entries of the NewArray
is different from the number of current elements of the dynamic array attribute, the update involves the number of NewArray
entries, and the number of entries and elements of the dynamic array attribute after assignment is the same as the number of "NewArray
" entries/elements.
NewValue
can be an alphanumeric or numeric constant, or a simple variable, with an Adelia type which is compatible with that of the relevant array attribute. The reserved words *TRUE and *FALSE for the BOOL type, as well as *NULL for the IMAGE type, are also allowed. More generally, the reserved words with an Adelia type which is compatible with that of the relevant array attribute are allowed. NewValue is assigned to all the relevant allocated entries of the attribute.
Example:
REF_CLASS(TICKET) itick
REF_CLASS(SOURCE) iSrc
DATE tabDates(10)
ALPHA(250) myComment
myComment = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'
* ... "tabDates" 1D array occurrences value allocation...
* Dynamic array and class instantiation
iTick = new TICKET()
iTick.Comments = new ALPHA(250)()(10)
iTick.Updates = new DATE()(10)
iTick.Sources = new SOURCE()(10)
* Updating of the "Updates" dynamic array attribute from the whole "tabDates" array variable
iTick.setUpdates(tabDates)
* Updating of the "Comments" dynamic array attribute from the "myComment" simple variable
iTick.setComments(myComment)
To add an element at the end of an attribute of type dynamic array
Also from the TICKET class, it is possible to add a value at the end of the dynamic arrays 'Comments', 'Updates' or 'Sources' regardless of the initial size allocated for the array.
Example:
REF_CLASS(TICKET) itick
REF_CLASS(SOURCE) iSrc
DATE currDate
iTick = new TICKET()
iTick.Comments = new ALPHA(250)()(1)
iTick.Updates = new DATE()(5)
iTick.Sources = new SOURCE()(2)
TIME currDate
iTick.setId('1')
iTick.setComments('Creation of the ticket', 1)
iTick.setComments('Ticket creation', *END)
iTick.setUpdates(currDate, 1)
iSrc = new SOURCE()
iTick.setSources(iSrc, 1)
iSrc = new SOURCE()
iTick.setSources(iSrc, *END)
iSrc = new SOURCE()
iTick.setSources(iSrc, *END)
Note:
During serialization, only the elements actually added to the dynamic array are taken into account.
This assertion is always true for the order CONV_DATA.
In the case of the serialization of a class of a REST web service, it is necessary to declare the correct JacksonJaxbJsonProvider (the one from the package com.fasterxml.jackson.jaxrs.json) in the configuration file beans.xml.
Extract from the file beans.xml [JacksonJaxbJsonProvider]:
<?xml version="1.0" encoding="UTF-8"?> <cxf:bus> <cxf:properties> <entry key="skip.default.json.provider.registration" value="true"/> </cxf:properties> </cxf:bus> <!-- remplace le org.apache.cxf.jaxrs.provider.json.JSONProvider ou org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider --> <bean class="com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider"/>
Retrieving the number of elements of an attribute of type dynamic array
The predefined function &NBR_ELT is used to retrieve the number of elements of an attribute of type dynamic array.
Example:
REF_CLASS(TICKET) itick
NUM_BIN_2 nbComments
iTick = new TICKET()
iTick.Comments = new ALPHA(250)()(1)
iTick.setComments('Comment 1', 1)
iTick.setComments('Comment 2', *END)
iTick.setComments('Comment 3', *END)
↑ Top of pagenbComments = &NBR_ELT(iTick.getComments())