After you have created a Domain Object, you can use it as a data type for an attribute. For example, you could create a domain named SSNumberDomain, and write validation code for it that ensures that the resulting data type is a string of nine characters. You could then edit the Emp Entity Object and use SSNumberDomain as the data type for the Essnum attribute, as shown in the following steps.
In the Navigation pane, right-click the Emp Entity Object, then choose Edit to display the Entity Object Wizard.
Click the Attribute Settings tab to display the Attribute Settings panel. Open the Select Attribute drop-down list and select the attribute to which you want to assign to a domain type (Essnum in this example).
Open the Type dropdown list to display a list of available data types. Choose the domain you want to use (SSNumberDomain in this example).
Click Finish to close the wizard. JDeveloper generates code to apply the domain to the attribute.
The following code, which would be used in the Entity Object's .java file, shows how domains enforce validation rules. This code, contrived for the sake of simplicity, takes a string as an argument and tries to create a Social Security number. If the string violates the validation logic defined in SSNumberDomain, an exception is thrown.
public void createSSNumber (String newNumber) { try {
SSNumberDomain SSNumber = new SSNumberDomain(newNumber);// The new number is OK. Continue.
...
} catch (Exception e) {
// The new number is invalid. Handle the error.
...
}
}