Type Cast and Pseudo-components are provided to support type inheritance, help build message structure, and prevent validation errors. Type Casting addresses a problem in which a base complex type does not contain the same elements as the derived type.
For example, a variable may have a base type, containing two attributes and two elements, and a derived type inherited from the base type, containing an additional attribute and element.
When the message is declared in a WSDL for use in BPEL, the base type is used to declare the message. So, in this example, from the Mapper view of the XML structures we see the variable's base type that does not contain the additional element and attribute.
Since the Mapper is designed to allow you to graphically link elements and attributes, these structures need to be available in the mapper view. To allow mapping of derived type attributes and elements, which are implied by the base type, the Mapper enables you to cast an object to another type - in this example, to the derived type.
To cast an object to another type:
From the Mapper view of the project's bpel file, right-click the variable that has the base type and click Cast To in the pop-up menu. The Subtype Chooser appears displaying a tree with the original type as the root and subtypes under the root. If there are no subtypes, only the original type will appear in the box.
To cast the original variable to the derived type, select derivedType in the Subtype Chooser and click OK. The derivedType variable appears in the Mapper.
Expand the derivedType variable in the Mapper and note that the additional attribute and element are now available to use for mapping.
The Type Cast option allows you to explicitly cast an object to another type. This only works for objects that have a schema type.
In the BPEL Mapper the following object can be casted:
Schema Element
Schema Attribute
Variable (except variables of the WSDL Message type)
Message Part
The Pseudo-component feature is similar to Type Cast. The XML Schema introduces xsd:any. It declares that an element can be located in the XML document and have any name and type. The BPEL mapper allows you to add to the tree elements, which correspond to xsd:any. Such elements don't appear in the schema, but they look similar to other elements. That is why they are called pseudo-elements. The user can map from and to a pseudo-element the same way as for an ordinary element. This also applies to the xsd:anyAttribute. The user can create pseudo-attributes to use for mapping and design purposes.
In the Mapper's Input and Output trees, xsd:any appears as an element node with the name "Any Element" and xsd:anyAttribute as an attribute with the name "Any Attribute". Both have the pop-up menu item "Cast To...", which calls the special dialog box used to specify a name, namespace and type for the new pseudo-component. For xsd:any any global type can be chosen. For xsd:anyAttribute only the global simple types are suggested. In both cases the settings allow you to choose global types from several different sources. The completed pseudo-components appear in the tree with the name pattern (castToElementName)Any Element or (castToAttributeName)Any Attribute.
Validation is passive in regard to type casts and pseudo-components, meaning that validation does not object to an unknown component if it is a qualified type cast or it is declared as a pseudo-component.
The type cast is used to avoid runtime errors, but there are several reasonable limitations:
An object of a specific schema type can be cast only to a subtype. This applies to elements, attributes, variables and message parts. The XML Schema has two derivations, extension and restriction, both of which are supported by type cast.
xsd:any contains additional attributes which might restrict the possible element type.
Only global types can be used when you declare a pseudo-component. Global attributes or elements cannot be used. The target of the type must be referencable, and as such should be global.
You cannot nest type casts, pseudo-components, and mixed declarations.
You cannot add a new predicate to a casted component or its part.
You cannot mix two or more type casts or pseudo components in an XPath expression. A type cast cannot be associated with a specific part of an expression, but only with the expression as a whole.