4 IMExample Java Sample Application

This chapter describes the IMExample Java sample application. This chapter assumes you have already installed, compiled, and can run this sample application. See the readme.txt file for requirements and instructions on how to install, compile, and run this sample application. This chapter describes how Oracle interMedia Java Classes is used in creating this sample application.

4.1 Overview

This sample application lets you retrieve multimedia data from the sample schema, save to a file, play, and delete from the sample schema image, audio, video, and testimonial data using the respective interMedia object types, OrdImage, OrdAudio, OrdVideo, and OrdDoc by product ID for rows in the PM.ONLINE_MEDIA table. Section 4.2 briefly describes how to compile and run the IMExample Java sample application. Section 4.3 describes the class files and shows code examples that illustrate how interMedia object types and methods and other Oracle objects are used.

4.2 Compiling and Running the IMExample Application

To compile the IMExample sample application, enter the following at the command line, assuming you are in the directory where the Java source files are located:

javac *.java

To run the IMExample sample application, enter the following at the command line:

java IMExample

4.3 Description of the IMExample Application

The IMExample sample application when compiled creates the following class files:

IMExample -- creates the sample application frame, maintains the only connection to the database, and allows compatibility with future releases of interMedia.

IMExampleFrame -- extends the JFrame class and displays the main frame.

IMLoginDialog -- extends the JDialog class, displays the login dialog box, and creates the connection to the database.

IMExampleQuery -- performs the SQL SELECT statement to retrieve rows of the OE.PRODUCT_INFORMATION table and displays the content of the table by product ID.

IMProductDialog -- extends the JDialog class, shows a dialog box to display detailed information for a particular product, including the product ID, product name, product description, retrieves and displays the product photo, audio, video, and testimonial data within the appropriate panel, and, supports retrieving, saving, deleting, and playing the media data. Allows for applying changes or rolling back changes to the media objects.

IMImagePanel -- extends the IMMediaPanel class, displays the product photo and its attributes: MIME type, image height, image width, and content length, and if it applies, generates and displays the thumbnail image.

IMAudioPanel -- extends the IMMediaPanel class and displays the product audio and its attributes: MIME type, duration of the audio, and content length.

IMDocPanel -- extends the IMMediaPanel class and displays the product testimonials and its attributes: MIME type and content length.

IMLoadFile -- loads a media stream (photo, video, audio, and testimonials), from a file to the PM.ONLINE_MEDIA table in the database, and if necessary, inserts a row and initializes the media objects, then updates the media data, sets the media attributes, and generates and updates the thumbnail image if loading a photo.

IMSaveFile -- saves a media stream from the database to a target file.

IMMediaPanel -- extends the JPanel class, lays out the common components for the photo, audio, video, and doc panel with load, save, delete, and play check boxes, initializes the MIME configuration for the plug-in players for the operating system detected, plays the data stream associated with the MIME type of the media, and allows users to specify their own player to play the media data stream.

The major flow among these class files is: IMExample to IMExampleFrame to IMLoginDialog (login) to IMExampleFrame.showDefaultTable( ) to IMExampleQuery to IMProductDialog to one group of classes (IMImagePanel, IMAudioPanel, IMVideoPanel, IMDocPanel), and finally to the last group of classes (IMLoadFile, IMSaveFile, IMMediaPanel).

The remaining class files in this sample application include:

IMUtil -- includes common utilities such as a method to generate and update thumbnail images, wrapper methods for each setProperties( ) method of each media object type to separate the exceptions caused by unrecognizable formats, and cleanup methods to close the following: resultSet, Statement, input stream and its reader, and output stream and its writer.

IMMIME -- loads and stores the mapping between plug-in players and the MIME type.

IMResultSetTableModel -- extends the AbstractTableModel class and controls the display of the OE.PRODUCT_INFORMATION table.

IMMessage -- displays various messages for the sample application and classifies the message level as error, warning, or suggestion.

IMMessageResource -- extends the java.util.ListResourceBundle class and contains the actual message text for all messages.

IMJOptionPane -- extends and puts into subclasses the JOptionPane class in order to add an accessible description message to the displayed dialog box.

IMFileChooser -- extends the JFileChooser class, and inherits from the JFileChooser class in order to add the button mnemonic and accessible description.

IMAttrTableModel -- extends and puts into subclasses the DefaultTableModel class in order to provide the table model for displaying media attributes, and overwrites the isCellEditable( ) method to make the cells uneditable.

FocusedJTextField -- extends and puts into subclasses the JTextField class and overwrites the isFocusTraversable( ) method to allow it to gain focus when it is set to uneditable.

FocusedJTextArea -- extends and puts into subclasses the JTextArea class and overwrites the isFocusTraversable( ) method to allow it to gain focus when it is set to uneditable; also overrides the isManagingFocus( ) method to force the JTextArea class not to handle a TAB key operation.

FocusedJPanel -- extends and puts into subclasses the JPanel class and overwrites the isFocusTraversable( ) method to allow it to gain focus.

FocusedJLabel -- extends and puts into subclasses the JLabel class, overwrites the isFocusTraversable( ) method, and adds a focus listener to allow it to gain focus.

BooleanRenderer -- extends the JCheckBox class and renders Boolean objects as JCheckBox (a checkbox) in a JTable (two-dimensional table format). This class also sets the AccessibleName and AccessibleDescription properties by setting the tooltip to support accessibility.

IMStreamAbsorber -- extends the Thread class and runs as a separate thread to consume an input stream. This is useful when a plug-in application is loaded and it writes something out to, for example, a standard error, without consuming the application's output, the application may be unable to continue.

IMTable -- extends and puts into subclasses the JTable class and overwrites the isManagingFocus( ) method to avoid letting the table handle a TAB key operation.

IMTableRenderer -- extends the DefaultTableCellRenderer class and renders the PRODUCT_ID, PRODUCT_NAME, and PRODUCT_DESCRIPTION columns to add accessibility information, and sets the customized display.

IMUIUtil -- includes common GUI utilities.

IMExample Class

This class makes a call to the interMedia OrdMediaUtil.imCompatibilityInit( ) method (see the bolded line in the code example) to allow compatibility with future releases of interMedia in case a database upgrade includes evolved object types, as follows:

Calling the OrdMediaUtil.imCompatibilityInit( ) method is a recommended practice to help ensure client-side applications can maintain compatibility with the current release of the interMedia object types (OrdAudio, OrdImage, OrdVideo, OrdDoc, and OrdSource), in the event that there is a database upgrade that includes evolved object types.

IMProductDialog Class

This class defines the following methods followed by a description of what each does:

The loadMedia( ) method to retrieve the media objects from the database. This method performs a SQL SELECT...FOR UPDATE statement on the PM.ONLINE_MEDIA table where the PRODUCT_ID column is a parameter marker; then this class uses the getORAData and getORADataFactory interfaces supplied by Oracle to get the media data objects from the result set.

The displayImage( ) method calls the IMImagePanel.display( ) method to display the image data attributes, display the thumbnail image, and display the full sized image using a media player that supports this MIME type.

The displayAudio( ) method calls the IMAudioPanel.display( ) method to display the audio data attributes and play the audio stream using a media player that supports this MIME type.

The displayVideo( ) method calls the IMVideoPanel.display( ) method to display the video data attributes and play the video stream using a media player that supports this MIME type.

The displayDoc( ) method calls the IMDocPanel.display( ) method to display the testimonial data attributes and play the testimonial data using a media player that supports this MIME type.

The following code example shows the loadMedia( ), displayMedia( ), displayImage( ), displayAudio( ), displayVideo( ), and displayDoc( ) methods, and highlights in bold the SQL query statements and areas in the code where interMedia and other Oracle object types and methods are used. See the IMImagePanel Class, IMAudioPanel Class, IMVideoPanel Class, and IMDocPanel Class sections for code examples of the corresponding m_jXxxPanel.display( ) methods, where Xxx represents the particular media data type, Img, Aud, Vid, or Doc.

This class displays the image panel, the product photo and its attributes, and the thumbnail image. What follows is a more detailed description of each of the methods that are defined and what each does:

The display( ) method, which first calls the insertProperty( ) method, which calls the interMedia image object type methods getMimeType( ), getHeight( ), getWidth( ), and getContentlength( ) to get the attributes of the image to display in a table.

For supported formats, the class displays the product photo thumbnail image, which is generated by calling the IMUtil.generateThumbnail( )method to create the thumbnail image from the product photo.

The addThumbnail( ) method to show the new thumbnail image.

The changeThumbnail( ) method to change the thumbnail image.

The saveToFile( ) method to save the photo to a file.

The deleteMedia( ) method to delete the product photo image and its thumbnail image from the database by setting the image object type columns to empty using the OrdImage.init( ) method.

The play( ) media method to show the image using a media player.

The setMedia( ) method to set the photo and thumbnail object.

The notExist( ) method checks to see if the image data exists and returns true if the BLOB is empty or is not associated with an existing BFILE; otherwise, it returns false.

The getDataInByteArray( ) method retrieves image data into a byte array by calling the interMedia importData( ) method first for the BFILE and returns the results of calling the interMedia getDataInByteArray( ) method.

The refreshPanel( ) method refreshes the display when updating the photo image, attributes, and thumbnail image.

The following code example includes the display( ), insertProperty( ), notExist( ), getDataInByteArray( ), and refreshPanel( ) methods, and highlights in bold any SQL query statements and areas in the code where interMedia and other Oracle object types and methods are used:

This class displays the video panel, the product video, and its attributes. This class is identical in structure and functions similarly to the IMImagePanel class. See the IMImagePanel Class section for descriptions of methods. The following code example includes the display( ), insertProperty( ), notExist( ), getDataInByteArray( ), and refreshPanel( ) methods, and highlights in bold any SQL query statements and areas in the code where interMedia and other Oracle object types and methods are used:

This class displays the audio panel, the product audio, and its attributes. This class is identical in structure and functions similarly to the IMImagePanel class. See the IMImagePanel Class section for descriptions of methods. The following code example includes the display( ), insertProperty( ), notExist( ), getDataInByteArray( ), and refreshPanel( ) methods, and highlights in bold any SQL query statements and areas in the code where interMedia and other Oracle object types and methods are used:

This class displays the doc panel, the product testimonials, and its attributes. This class is identical in structure and functions similarly to the IMImagePanel class. See the IMImagePanel Class section for descriptions of methods. The following code example includes the display( ), insertProperty( ), notExist( ), getDataInByteArray( ), and refreshPanel( ) methods, and highlights in bold any SQL query statements and areas in the code where interMedia and other Oracle object types and methods are used:

This class loads a media stream from a file to a database for each of the media object types. First, it checks to see if this PRODUCT_ID column exists in the PM.ONLINE_MEDIA table and if not, it inserts a new row into the table. Then, it creates and initializes a new media object for each media object type, updates the media data, that is, loads it into the database if it is not already stored there, and finally, sets the media attributes for each media data object.

In this class, the IMFileLoad( ) method calls the initFileChooser( ) method, then the initFileChooser( ) method calls the loadNewMedia( ) method, which does the row insertion and initializing of the media object type columns, and then calls the updateMedia( ) method to update the media and to set the media attributes.

The following code example includes the loadNewMedia( ) and UpdateMedia( ) methods, and highlights in bold any SQL query statements and areas in the code where interMedia and other Oracle object types and methods are used as previously described:

This class contains common utilities, such as a generateThumbnail( ) static method, wrapper methods for the setProperties( ) methods for each media object type to separate the exceptions caused by unrecognizable formats, and finally, a number of cleanup methods. The following code example includes the generateThumbnail( ) method, and highlights in bold any SQL query statements and areas in the code where interMedia and other Oracle object types and methods are used: