Products Downloads


French version


 



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()


* Getting the value of the attribute 'Options' of the iCar class:

tabOptions = iCar.getOptions()


* 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


↑ Top of page


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.


Example:

REF_CLASS(PERSON)      iFather

ALPHA(33)              MyAlpha33


iFather.setFirstname('John')

iFather.setName(MyAlpha33)

↑ Top of page



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)

iFather.setTArrayBin4_2D (444, Index1, Index2)

↑ Top of page



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]:

Beans.xml
<?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"/>

↑ Top of page



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 tables 'Comments', 'Updates' or 'Sources' regardless of the initial size allocated for the table.


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]:

Beans.xml
<?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"/>


↑ Top of page



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)


nbComments = &NBR_ELT(iTick.getComments())

↑ Top of page

  • Aucune étiquette