Initializing the ODA start

After Business Object Wizard calls the ODA's getMetaData() method, it calls the init() method to begin initialization of the ODAstart. The init() method is part of the low-level ODA base class, ODKAgentBase. It is inherited by the ODA base class, ODKAgentBase2, then inherited in turn by your ODA class. This method performs initialization steps for the ODA.

Important:
The init() method is an abstract method. As part of the implementation of your ODA class, you must implement an init() method.

The main tasks of the init() method include:

Retrieving ODA configuration properties

The init() method can retrieve any of the user-initialized configuration properties it needs to complete the initialization of the ODA. The ODA initializes its configuration properties in its getAgentProperties() method. Users can update these properties as needed in the Configure Agent dialog box of Business Object Wizard. After configuration properties are updated, Business Object Wizard writes them to the memory of the ODA runtime.

The ODK API provides the methods in Table 30 for retrieving the value of an ODA configuration property from the ODA runtime memory.

Table 30. Methods to retrieve the value of an ODA configuration property

ODK library method Description
getAgentProperty()
Retrieves the value of a specified ODA configuration property
getAllAgentProperties()
Retrieves the values of all ODA configuration properties as a Java Hashtable object

All methods in Table 30 are defined in the ODKUtility class. Therefore, you must obtain a handle to the singleton object of this class before you can access any configuration properties. For more information, see Obtaining the handle to the ODKUtility object.

Figure 57 shows the implementation of the init() method (defined in the ArmyAgent3 class from the sample Roman Army ODA).

Figure 57. Initializing the ODA

public void init() throws com.crossworlds.ODK.ODKException
 {
    Hashtable h = m_utility.getAllAgentProperties();
 
// Obtain values of ODA configuration properties
    AgentProperty property = (AgentProperty) h.get("Army general");
    m_general = property.allValues[0].toString();
 
   property = (AgentProperty) h.get("Minimum age for drafting");
    m_minAge = Integer.parseInt(property.allValues[0].toString());
 
   property = (AgentProperty) h.get("Maximum age for drafting");
    m_maxAge = Integer.parseInt(property.allValues[0].toString());
 
   property = (AgentProperty) h.get("Allow adoption");
    m_allowAdoption = new Boolean(
       property.allValues[0].toString()).booleanValue();
 
// Clear the generated-content structure
    m_generatedBOs.clear();
 }
 

In Figure 57, the init() method uses the following to obtain configuration-property values:

The configuration properties that this init() method obtains are all single-cardinality properties. Therefore, the allValues member variable contains only one value. For an example of using multiple-cardinality properties, see Creating the business-property array. This init() method also initializes the ODA's generated-content structure, a vector called m_generatedBOs. This vector will hold the generated business object definitions.

Establishing a connection

The main task of the init() initialization method is usually to establish a connection to the data source. The ODA searches the data source to "discover" objects for potential conversion to business object definitions. To establish the connection, the init() method can perform the following tasks:

The init() method runs successfully if the ODA succeeds in opening a connection and the ODA is ready to begin processing data in the data source. If the ODA cannot open a connection, the init() method should throw an ODKException exception to indicate the cause of the failure.

Checking the ODA version

The getVersion() method returns the version of the ODA runtime. This method is part of the low-level ODA base class, ODKAgentBase. It is inherited by the ODA base class, ODKAgentBase2, then inherited by your ODA class. It is called in both of the following contexts:

Note:
The getVersion() method returns the version of the ODA runtime, not the version of the ODA (which is stored as part of the ODA's metadata).

Copyright IBM Corp. 1997, 2003