Complex Java class example

A more complex example is given by the class MainClass (Mainclass.java):

public class MainClass
{
    public boolean _booleanField;
    public SubClass _SubClassField;
    public String _StringField;

    public MainClass(int intPar1)
    {
        _booleanField = intPar1 > 0 ? true : false;
        _SubClassField = new SubClass((short)0);
    }
        public MainClass(int intPar1, SubClass SubClassPar2)
    {
        _booleanField = intPar1 > 0 ? true : false;
        _SubClassField=SubClassPar2;
    }
        public int function1()
    {
        if (_SubClassField._byteArrayField == null)
            return 0;
        else
            return _SubClassField._byteArrayField.length;
    }
        public SubClass function2(int intPar1)
    {
        SubClass returnValue = new SubClass(2);
        for (int index = 0; index < 5; index++)
        {
            returnValue._byteArrayField[index] = (byte)intPar1;
        }
        return returnValue;
    }
        public char function2(short[] shortArrayPar1)
    {
        return 'A';
    }
        public void function3(int intPar1)
    {
        _StringField = "Value " + intPar1 + "was passed";
    }
        public byte[] function4(SubClass SubClassPar1, String StringPar2)
    {
        _StringField = StringPar2;
        return SubClassPar1._byteArrayField;
    }
}

Notice that this class has a field, a constructor parameter and a method parameter that are of the type SubClass.

In the schema (install_dir\examples\adapters\javaclas\mainclass.mtt), the following aspects are noteworthy:

  • There is a field of type SubClass, the value of which is a reference. This object must be created in a previous card and its reference mapped to the ref._SubClassField item.
  • The 2 parameter constructor was selected by the user. The second parameter is of type SubClass (item ref._P2_SubClass). Its value is a text item that is the object reference. This object must be created in an earlier card and assigned a reference value that is then mapped into this item.
  • Methods function1, function2, and function3 were selected by the user, function4 was not.
  • All the methods were selected by the user to be invoked by the adapter.
  • function1 has no parameters. Since it is represented as a group, and groups must have components, it has a single component called #NullArgList. This should be assigned NONE in the map.
  • It is possible that two methods with the same name (but different parameter lists) can be invoked within the same card. To facilitate this, the importer will change the names of the groups to unique names by appending .nn, where .nn is a unique number.

    For example, if we wanted to invoke two different methods named function2, they would appear in the schema as function2.1 and function2.2.