Providing access to generated files

The generateBinFiles() method does not return the actual generated business object definitions. For Business Object Wizard to be able to access the generated content, the ODA class must implement the content-retrieval method for files. Business Object Wizard uses the information in the content-metadata object (which generateBinFiles() does return) to determine which content-retrieval method to call. For file content, Business Object Wizard calls the getBinFile() method to retrieve the generated business object definitions.

Note:
Business Object Wizard calls the generateBinFile() method for generation of files if the ODA supports the on-request content protocol. If the ODA supports the callback content protocol for generation of files, a user-defined method actually generates the files. However, this method does not return the actual generated content either. Therefore, Business Object Wizard still requires the getBinFile() method to access the generated files.

Regardless of the content protocol your ODA supports for generation of files, the ODA class must implement the getBinFile() method. This method is defined as part of the IGeneratesBinFiles interface. The method accepts as an argument an index, which identifies the number of files to return. It accesses these files in the generated-content structure and returns an array of the retrieved file (File) objects. The number of files in this array depends on the value of the index argument, as Table 48 shows.

Table 48. Retrieving files

Value of index Description Number of elements in array that getBinFile() returns
In the range 0 to count - 1, where count is the total number of files in the generated-content structure Specifies the index position into the generated-content structure of the file to retrieve One file object

 ODKConstant.GET_ALL_OBJECTS
 
Special constant to indicate the return of all files in the generated-content structure All file objects in the generated-content structure (count)

For the sample Roman Army ODA, the FileCreator.run() method (defined in the ArmyAgent5 class) populates the m_files array with the generated files. Therefore, the getBinFile() method (also defined in ArmyAgent5) retrieves the specified number of files from this array. The following code shows the getBinFile() method for the sample Roman Army ODA:

public File[] getBinFile(long index) throws ODKException
 {
    if (index == ODKConstant.GET_ALL_OBJECTS)
       return m_files;
    else
       return new File[] {m_files[(int)index]};
 }
 

Copyright IBM Corp. 1997, 2004