Using enumerations in xfNetLink Java

Your Synergy JAR file includes the following as enum type classes:

There will be a separate class, named with the enumeration name, for each enumeration.

The members in the repository enumeration are the values within the enum type. If you assigned numerical values to the members in repository, they are used for the integer equivalents assigned to the values in the generated classes. If not, the integer equivalents are assigned automatically starting with 0 and incrementing by 1. When you create a new instance of an enum type, it has a default value of the enumerator that has been assigned 0, if you do not explicitly assign a value. Consequently, when defining your enumeration in the repository, you should specify as the first member the value you would like to be the default.

Java doesn’t support a holder class for enumerated types, which means they can’t be passed as out or in/out parameters. We have included methods in your generated classes that give you a way to work around this limitation. getIntHolderValue() gets the integer value of an enumeration member and getEnumeration() associates that integer value with the enumeration member. See the examples below.

The following examples use an enumeration named Color, which has members Green, Blue, etc. (Note that the first letter of each member name is capitalized.) In the first example, the enum is passed as an in/out parameter of the EnumTest1() method, so we use the getIntHolderValue() and getEnumeration() methods. In the second example, the enum is a field within the AcmeCustomer structure class.

//  Method call with an in/out enum parameter 
AcmeCompanyComponent acme = new AcmeCompanyComponent();
acme.Color companyHat = acme.Color.Green;
acme.connect(host, port);
// use IntHolder to get integer value
IntHolder hatColor = companyHat.getIntHolderValue();
//pass IntHolder in method call
acme.EnumTest1(hatColor);
// assign returned value to the companyHat
companyHat = acme.Color.getEnumeration(hatColor);
acme.disconnect();

// Enum field within structure example
AcmeCompanyComponent acme = new AcmeCompanyComponent();
AcmeCustomer customer = new AcmeCustomer(); // structure 
Customer.ColorChoice = acme.Color.Blue;     // enum field of acme.Color
acme.connect(host, port);
acme.GetCustomer1(customer);
acme.disconnect();