Using inheritance and polymorphism with attributes
Consider as an example that your data model could contain a Person entity. This business entity has several attributes including Address. This attribute has one main reusable type, AddressType. Talend Studio enables you to create inheritance reusable types that return a collection of new elements while inheriting the attributes from the AddressType in order to return one address format specific to Europe and another specific to the USA. So in this example, the Europe and US address types both extend the generic address type.
Before you begin
You have already created the data model and business entities in the data model. For further information, see Creating a data model and Creating business entities in a data model respectively.
About this task
To create inheritance and polymorphism for attributes, do the following:
Procedure
What to do next
You have achieved inheritance here at the attribute level by extending an existing type (AddressType) to add specific elements to complete the US and EU addresses while inheriting the attributes from the main address type.
Polymorphism is also achieved when, at runtime, the actual address instance of a person can be an EUAddressType or a USAddressType. When authorized business users browse master data records through Talend MDM Web UI, the concrete address type for the open record (person) is automatically selected. Business users will also have in an open record a list for the Address attribute. From this list they can choose any of the complex address types you defined in Talend Studio.
By default, the list displays the code of the types, but Talend Studio also lets you define labels for the complex types so that they can have labels in different languages and become more understandable as displayed in the list.
You can define labels either in the Data Model Types panel or in the source XML schema of the data model.
To define labels for complex types in the Data Model Types panel, proceed as follows:
-
Open the data model where you have defined the complex types.
-
Right-click the complex type for which you want to set labels and then select Set the labels.
-
The Set the Labels dialog box pops up.
From the list to the left, select a language and then enter a label corresponding to the selected language in the field to the right.
-
Click the [+] button in the upper right corner to add the defined label to the Language/Label list.
-
Click OK to validate your changes and close the dialog box.
The labels will be displayed under the Annotations node of the complex type.
When authorized business users browse master data records in the updated data model through Talend MDM Web UI, the list for the Address attribute shows the complex type labels you defined in the annotations.
To define labels for the complex types in the source XML schema of the data model, proceed as follows:
-
Open the data model where you have defined the complex types.
-
Click Schema Source at the bottom of the editor to open the source XML schema of the data model.
-
Browse to the schema corresponding to the extended complex type to which you want to add a label and which you want to display in a certain order for the business user.
-
Inside the root element of the complex type, use the X_Label_<ISO> annotation to add a label for the extended type and the X_Order_Value annotation to define the order of the extended type, as follows:
... <xsd:complexType name="EUAddressType"> <xsd:annotation> <xsd:appinfo source="X_Label_EN">EU address format</xsd:appinfo> <xsd:appinfo source="X_Label_FR">format d'adresse UE</xsd:appinfo> <xsd:appinfo source="X_Order_Value">2</xsd:appinfo> </xsd:annotation> <xsd:complexContent> <xsd:extension base="AddressType"> <xsd:sequence maxOccurs="1" minOccurs="1"> <xsd:element maxOccurs="1" minOccurs="1" name="PostalCode" type="xsd:string"/> <xsd:element maxOccurs="1" minOccurs="1" name="Country" type="xsd:string"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> <xsd:complexType name="USAddressType"> <xsd:annotation> <xsd:appinfo source="X_Label_EN">US address format</xsd:appinfo> <xsd:appinfo source="X_Label_FR">format d'adresse US</xsd:appinfo> <xsd:appinfo source="X_Order_Value">1</xsd:appinfo> </xsd:annotation> <xsd:complexContent> <xsd:extension base="AddressType"> <xsd:sequence maxOccurs="1" minOccurs="1"> <xsd:element maxOccurs="1" minOccurs="1" name="ZipCode" type="xsd:string"/> <xsd:element maxOccurs="1" minOccurs="1" name="State" type="xsd:string"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> ...
In the above schema, you want to name the EUAddressType as EU address format and you want it to be the second in the list of extended types. You want also to name the USAddressType as US address format and you want it to be the first in the list of extended types.
-
Save your modifications in the model editor.
When authorized business users browse master data records in the updated data model through Talend MDM Web UI, the list for the Address attribute shows the complex type labels you defined in the annotations and the extended types are displayed in the order you defined as well.