For example, the following figure shows a UML class diagram of the VirtualMachine managed object, which has a
runtime property that is defined as an
xsd:dateTime data type.
VirtualMachine also has a
summary property that is a
VirtualMachineSummary data object. The
VirtualMachineSummary data object contains a
config property that is a
VirtualMachineConfigSummary data object.
For example, you can compare the property referenced by the path summary.config.guestId (a string value) to the property referenced in the path
summary.config (the complete
VirtualMachineSummary data object).
Nested Properties and Data Types shows examples of property references and the corresponding data types for some of the properties of the
VirtualMachine managed object shown in
VirtualMachine Managed Object and Nested Properties.
The vSphere API uses xsd:anyType unconstrained type declarations. A vSphere client must map values of
xsd:anyType to explicit data types. An
xsd:anyType value can represent a single data value or it can represent an array. The WSDL for the vSphere API defines array types for all of the data values that a vSphere client can send or receive as arrays. The array types use the prefix “Array Of”. An example of an array type is
ArrayOfString for string values.
When a client sends data to a vSphere Server, the client must use explicit datatypes. For example, a client can define a MethodAction for a
ScheduledTask. The vSphere API defines arguments to the action (the
MethodActionArgument.value property) as type
xsd:anyType. If the action takes an array argument, the client must set the corresponding
MethodAction.argument[].value to the appropriate ArrayOf... type.
When a client receives xsd:anyType data from a vSphere Server, it must cast the data to an explicit type. For example, the
PropertyCollector method
RetrievePropertiesEx returns a set of
ObjectContent data objects. The
ObjectContent.propSet property is a list of
DynamicProperty objects that contains the requested property values. Each
DynamicProperty object contains a name-value pair. The value property (
DynamicProperty.val) is of type
xsd:anyType. It can represent a single object or an array of objects.
When the returned value is a single object such as an Event,
ManagedObjectReference, or
String, you can cast it directly to a variable of the appropriate type. However, when the value is an array of objects you cannot cast the
anyType value directly to an array variable.
When the PropertyCollector returns array data, it sends it as an
xsd:anyType value. The language-specific bindings contain definitions for array objects such as
ArrayOfEvent,
ArrayOfManagedObjectReference, and
ArrayOfString, and corresponding “get” methods. To extract the actual array from a property of type
xsd:anyType, cast
DynamicProperty.val to the appropriate array type and use the matching get method – for example,
getEvent(),
getManagedObjectReference(), or
getString().The following sections provide examples of how to cast returned values for a few of the array types. The code uses the JAX-WS-generated Java bindings for the VMware vSphere Web Services SDK WSDL. Each of the code fragments uses this logic:
Data Object - HostFirewallInfo Properties shows part of the Properties table for the HostFirewallInfo Data Object in the
vSphere Web Services SDK API Reference. When you look at properties in the
vSphere Web Services SDK API Reference, you can see that optional properties are marked with a red asterisk.
In this example, that the defaultPolicy property is always returned, but the
ruleset property will be returned as a null value if it has not been set.