You create a data model class in your extension to describe the information needed from the Data Acess Manager.

When you create a data model class, you specify the type of vSphere or custom object to which the request pertains, and the specific properties of that object that you need to retrieve. For example, you can create a data model class to request information on a Virtual Machine object and include the name and powerState properties in the data request.

The data model class must extend the DataObject class and use the [Model] annotation tag. Typically, you create the data model class as a separate class or package in your plug-in module. This package must import the package com.vmware.core.model.DataObject from the vSphere Web Client SDK.

The type tag in the [Model] annotation is optional. If you specify the type tag in the annotation, the data model class can retrieve properties only for objects of the specified type. You can create a data model class to request common properties for multiple object types, or you can use the type tag in the [Model] annotation to make the data model class specific to a particular vSphere object type.

In the data model class, you must specify a class property for each data property to retrieve through DAM. When you declare each property, you must include a [Model] annotation with a property tag. The [Model] annotation on a property differs from the [Model] annotation on the class.

The [Model] annotation on a property associates the property with a data property belonging to a vSphere object. The property tag of the annotation specifies the name of the property to retrieve from the vSphere object. When you use the data model class in a data request, DAM retrieves the property specified in the annotation from the vSphere environment, and assigns the value to the associated class property.

When you use the data model class in a data request, the DAM returns values only for class properties that have the [Model] annotation. Class properties without the annotation are ignored.

The following example shows a data model class. The class MyVmData has a [Model] annotation and extends DataObject. In the example, the object type VirtualMachine is specified, indicating that the data model retrieves information on Virtual Machine objects. The class MyVmData includes the myVmName and myVmPowerState annotated properties. Each property includes an annotation that specifies to the DAM the vSphere property to associate with the class property.

package com.myExtension.model {
  import com.vmware.core.model.DataObject
 
  // data model class annotation and declaration
  [Model(type="VirtualMachine")]
  public class MyVmData extends DataObject {
 
    //properties to retrieve, specified by annotation
    [Model(property="name")]
    public var myVmName:String;
 
    [Model(property="runtime.powerState")]
    public var myVmPowerState:String;
  }
}

You can specify and annotate class properties to retrieve data on related objects, such as the host associated with a given virtual machine object. You use the relation tag in the [Model] annotation for the class property to specify that the property requested from the DAM is for a related object.

The following data model class is with a property annotated for the DAM to retrieve data from a related object. In the example, the class property myVmHostName is annotated for the DAM to retrieve the name property of the vSphere host object related to the target virtual machine object.

  [Model(type="VirtualMachine")]
  public class MyVmData extends DataObject {
      [Model(relation="runtime.host", property="name")]
      public var myVmHostName:String;
  }

You can retrieve properties over multi-hop relationships by specifying each hop separated by a comma. The following example shows a property annotated to retrieve data over a multi-hop relationship. In the example, the myDatacenterName property is annotated to retrieve the name property for a datacenter object associated with the host for a given virtual machine.

  [Model(type="VirtualMachine")]
  public class MyVmData extends DataObject{
      [Model(relation="runtime.host,cluster", property="name")]
      public var myDatacenterName:String;
  }

You can also retrieve properties for an object relationship with multiple cardinality, where the relationship is one-to-many. For example, one such relationship is that of a virtual machine object to multiple related network objects. When you retrieve a related property of this type, the associated class property in the data model class must be of type Array or ArrayCollection.

The annotated properties in a data model class can be single properties, or they can be nested data model classes. To specify a class property as a nested data model class, as opposed to a single property, you omit the property tag from the [Model] annotation when declaring the class property.

Omitting the property tag implicitly declares that the class member variable is a data model of the same object type as the parent data model. If the relation tag is specified, however, the class property is assumed to be a data model for the object type specified in the relation tag.

The following example data model class is with two class properties that are nested data models. The first property, myVmHardwareData, is another data model for Virtual Machine objects, the same as the parent data model. The second property, myHostDetails, is a data model for Host objects.

  [Model(type="VirtualMachine")]
  public class MyVmData extends DataObject{
      [Model]
      public var myVmHardwareData:VmHardwareData; // VmHardwareData is a VM data model
      [Model(relation="runtime.host")]
      public var myHostDetails:HostData; // HostData is a Host data model
  }

You can use a nested data model to create an array of data model objects. The following example shows a data model class that uses a nested data model to create an array of objects based on the Host data model.

  [Model(relation="runtime.host")]
  public var HostList:Array; // array of Host objects using the HostData model

If the related object for which you want to retrieve data is a user-defined custom object, you must use a different syntax in your [Model(relation="..."] annotation. Your [Model] annotation must explicitly specify both the custom object type, and the nested data model that you use to define that type. The following example shows a data model class that uses a nested data model for a user-defined custom Chassis object.

[Model(relation="Chassis as comexample:Chassis", nestedModel="com.example.ChassisModelData"]
public var myChassisDetails:ChassisModelData; // Chassis object using the ChassisModelData model

In the example, the [Model(relation="..."] annotation specifies the exact object type for Chassis as comexample:Chassis. The annotation also includes an explicit nestedModel attribute that specifies the fully-qualified class name for the Chassis data model. Use this syntax for any custom object type that you include in a data model class.