my.package.MyClass class:<types> <objectType name="obj" class="my.package.MyClass" /> </types>
ObjectType type allows to define complex data structures, and you need to use them in several modules, but you don't want to decode the structure for each module.
class should be defined for the default values using the defaultClass attribute. For example this declaration is incorrect because it is not possible to create a List with an empty constructor.<types> <objectType name="obj" class="java.util.List" /> </types>Instead this declaration is valid:
<types> <objectType name="obj" class="java.util.List" defaultClass="java.util.ArrayList" /> </types>
ObjectType contains except if you know its API. For example, if you have a structure type representing a Point, you know though the XML represention of the type what is contained in an element of this type and how to access them:<structType name="point"> <field name="x" type="float" /> <field name="y" type="float" /> </structType>But suppose that now we replace this type by an
ObjectType, backed by a Point class:<types> <objectType name="point" class="my.package.Point" /> </types>and for the Class:
public class Point { private float x; private float y; public Point() { } public void setX(float x) { this.x = x; } public float getX() { return x; } public void setY(float y) { this.y = y; } public float getY() { return y; } }You have no way to know what constitute the
Point just by looking at the XML specification of the type, or even when using the API if you don't know that getX() return the x value and getY() return the y value.
public void subscribe(ServiceInstance service) { Data data = service.getData("point"); ObjectType type = (ObjectType)data.getType(); Object value = data.getValue(); Object graph = type.getDeclaredFieldsValues(value); }In that case the
graph object would be a Map with two elements:ObjectTypeTag annotation on the class. In our case:@ObjectTypeTag public class Point { ... }
ObjectTypeAttrTag annotation on each getter method. In our example:@ObjectTypeTag public class Point { private float x; private float y; public Point() { } public void setX(float x) { this.x = x; } @ObjectTypeAttrTag(name="x") public float getX() { return x; } public void setY(float y) { this.y = y; } @ObjectTypeAttrTag(name="y") public float getY() { return y; } }In our case, we defined the two methods which are the getters for the "x" and "y" parameters.
Copyright 2017-2020 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence