Using structures in xfNetLink Java

Repository structures passed as parameters to your Synergy methods are included in your JAR file as classes. There will be a separate class for each structure and for each group. The fields in the repository structure will become properties of the class.

For example, say you have the following repository structure, which is passed to the login() method.

user
    fname      ,a25
    lname      ,a25
    maxrate    ,d18.2
    group  address    ,a
      street   ,a20
      city     ,a20
      state    ,a2
      zip      ,d9
    endgroup

In your JAR file, you’ll see a class named “User” with the properties Fname, Lname, and Maxrate; note that the first letter of each field name is capitalized. There will be a set and get method for each property, named with the property name (e.g., setFname() and getFname()). Use the set and get methods in the class to assign values to the properties and retrieve values from them. (If you specified the -ro option when running genjava, fields that are flagged as read-only in Repository were generated as read-only properties and therefore have a get method but no set method.)

Note

By default, the properties are named with the repository field names. See Passing structures as parameters for details on overriding the default name.

You’ll also see a class named “Address” in the JAR file.This class represents the group within User. (Fields defined as struct data type in the repository are treated the same as group fields.) The group class will also have set and get methods for accessing its properties (e.g., setStreet() and getStreet()). When you instantiate a new User object, the User constructor automatically instantiates a new Address object named Address_str. Consequently, under normal circumstances, you will not need to access the Address class directly.

If the group is defined as an array in the repository, the Address object instantiated by the structure class will be named Address_ary. See the example under step 2 below.

For additional information about structure classes, see Understanding the generated Java classes. For more information on passing structures as parameters, and for details on how overlays are handled, see Passing structures as parameters.

1. To access the properties, instantiate the structure as a new object. For example:
User user1 = new User();

In our example, this will also instantiate a new object named Address_str, which represents the address group.

2. If you’re sending data to Synergy, use the class’s set methods to assign values to the properties. For example:
user1.setFname("Mickey");
user1.setLname("Franklin");
user1.setMaxrate(150.00);

Use the group’s set methods to assign values to the properties of the group class:

user1.Address_str.setStreet("2330 Gold Meadow Way");
user1.Address_str.setCity("Gold River");
user1.Address_str.setState("CA");
user1.Address_str.setZip(956704471)

If the group is an array, use the set methods in the Address_ary object:

user1.Address_ary[0].setStreet("2330 Gold Meadow Way");
user1.Address_ary[1].setStreet("2445 Alpha Lane");
3. Pass the structure object as a parameter when you call the method:
appLog.login(id, password, user1);
4. If data is being returned from Synergy, instantiate new objects to hold the data, and then use the get methods to obtain the data:
String first = new String();
String last = new String();
double rate = new double();
first = user1.getFname();
last = user1.getLname();
rate = user1.getMaxrate();

The procedure for obtaining data from the properties in the group class is similar. For example:

String street = new String();
street = user1.Address_str.getStreet();