この章では、Oracle Multimedia IMExampleサンプル・アプリケーションについて説明し、Oracle Multimedia Java Classesを使用してこのJavaサンプル・アプリケーションを作成する方法を示します。
この章では、次のことを想定しています。
Oracle Multimedia Java Classesを使用したJavaアプリケーションの開発に精通している。
Oracle Multimedia IMExampleサンプル・アプリケーションをインストールおよび構成している。
サンプル・アプリケーション・ファイルおよびREADME.txt
ファイルは次のディレクトリにあります。
<ORACLE_HOME>
/ord/im/demo/java
(LinuxおよびUNIXの場合)
<ORACLE_HOME>
\ord\im\demo\java
(Windowsの場合)
次の項では、IMExampleアプリケーションの実行方法について説明します。このサンプル・アプリケーションをインストール、コンパイルおよび実行する場合の追加要件および手順については、README.txt
ファイルを参照してください。
次のフォト・アルバム・サンプル・アプリケーションの詳細は、第3章を参照してください。
Oracle Multimedia PL/SQL Web Toolkitフォト・アルバム・アプリケーション
Oracle Multimedia Javaサーブレット・フォト・アルバム・アプリケーション
Oracle Multimedia JSPフォト・アルバム・アプリケーション
Oracle Multimedia ASP/VBScriptフォト・アルバム・アプリケーション
この一連のWebアプリケーションでは、PL/SQLスクリプト、Javaサーブレット・ファイル、JSPファイルおよびASP/VBScriptファイルを使用して、Oracle Multimediaオブジェクト型でメディアをアップロードおよび取得する様々な方法を示します。
メディアをアップロードおよび取得するPL/SQL GatewayのWebアプリケーションであるOracle Multimedia Code Wizardサンプル・アプリケーションの詳細は、第4章を参照してください。
IMExampleアプリケーションでは、Oracle Databaseのサンプル・スキーマからマルチメディア・データを取得することができます。また、サンプル・スキーマのイメージ、オーディオ、ビデオおよび使用レポートのデータをファイルに保存、再生、削除することもできます。これらの操作は、PM.ONLINE_MEDIA
表の行の製品IDごとに、それぞれOracle Multimediaオブジェクト型のORDImage、ORDAudio、ORDVideoおよびORDDocを使用して実行します。5.2項では、クラス・ファイルについて説明し、コード例でOracle Multimediaオブジェクト型、メソッドおよびその他のOracleオブジェクトの使用方法を示します。
IMExampleサンプル・アプリケーションをコンパイルすると、次のクラス・ファイルが作成されます。
IMExample
: サンプル・アプリケーションのフレームを作成し、データベースへの接続のみを保持します。このクラスは、サンプル・アプリケーションへのエントリ・ポイントです。
IMExampleFrame
: JFrame
クラスを拡張し、メイン・フレームを表示します。
IMLoginDialog
: JDialog
クラスを拡張し、ログイン・ダイアログ・ボックスを表示し、データベースへの接続を確立します。
IMExampleQuery
: SQL SELECT文を実行してOE.PRODUCT_INFORMATION
表の行を検索し、製品IDごとに表のコンテンツを表示します。
IMProductDialog
: JDialog
クラスを拡張し、ダイアログ・ボックスで特定の製品の詳細情報(製品ID、製品名、製品の説明など)を表示します。また、IMProductDialogクラスは、適切なパネル内で製品の写真、オーディオ、ビデオおよび使用レポートのデータを検索および表示します。メディア・データの検索、保存、削除および再生もサポートします。さらに、メディア・オブジェクトへの変更の適用またはロールバックを実行可能にします。
IMImagePanel
: IMMediaPanel
クラスを拡張し、製品の写真とその属性(MIMEタイプ、イメージの高さ、イメージの幅およびコンテンツ長)を表示し、必要に応じてメタデータの読取りまたは書込み用縮小イメージを生成および表示します。
IMAudioPanel
: IMMediaPanel
クラスを拡張し、製品のオーディオとその属性(MIMEタイプ、オーディオの再生時間およびコンテンツ長)を表示します。
IMVideoPanel
: IMMediaPanel
クラスを拡張し、製品のビデオとその属性(MIMEタイプ、フレームの高さ、フレームの幅、ビデオの再生時間およびコンテンツ長)を表示します。
IMDocPanel
: IMMediaPanel
クラスを拡張し、製品の使用レポートとその属性(MIMEタイプおよびコンテンツ長)を表示します。
IMLoadFile
: ファイルからデータベース内のPM.ONLINE_MEDIA
表にメディア・ストリーム(写真、ビデオ、オーディオおよび使用レポート)をロードします。また、必要に応じて行の挿入およびメディア・オブジェクトの初期化を実行し、メディア・データを更新して、メディア属性を設定し、写真をロードする場合は縮小イメージを生成および更新します。
IMSaveFile
: データベースのメディア・ストリームをファイルに保存します。
IMMediaPanel
: JPanel
クラスを拡張し、写真、オーディオ、ビデオおよびドキュメント用パネルの共通コンポーネントをロード、保存、削除および再生のチェック・ボックスとともに配置して、検出されたオペレーティング・システムのプラグイン・プレーヤのMIME構成を初期化します。また、メディアのMIMEタイプに関連付けられたデータ・ストリームを再生し、ユーザーが独自のプレーヤを指定してメディア・データ・ストリームを再生することを許可します。
これらのクラス・ファイル間の主なフローは、IMExample
、IMExampleFrame
、IMLoginDialog
(ログイン)、IMExampleFrame
.showDefaultTable( )
、IMExampleQuery
、IMProductDialog
、いずれかのクラスのグループ(IMImagePanel
、IMAudioPanel
、IMVideoPanel
またはIMDocPanel
)と続き、最後にクラスの最終グループ(IMLoadFile
、IMSaveFile
またはIMMediaPanel
)となります。
このサンプル・アプリケーションの残りのクラス・ファイルには、次のものが含まれます。
IMUtil
: 縮小イメージを生成および更新するメソッド、フォーマットを認識できないために発生した例外を分離する各メディア・オブジェクト型の各setProperties( )メソッドのラッパー・メソッド、resultSet、Statement、入力ストリームとそのリーダー、および出力ストリームとそのライターをクローズするクリーンアップ・メソッドなどの共通ユーティリティが含まれます。
IMMIME
: プラグイン・プレーヤとMIMEタイプ間のマッピングをロードおよび格納します。
IMResultSetTableModel
: AbstractTableModel
クラスを拡張し、OE.PRODUCT_INFORMATION
表の表示を制御します。
IMMessage
: サンプル・アプリケーションの様々なメッセージを表示し、メッセージ・レベルをエラー、警告または提案に分類します。
IMMessageResource
: java.util.ListResourceBundle
クラスを拡張し、すべてのメッセージの実際のメッセージ・テキストが含まれます。
IMJOptionPane
: JOptionPane
クラスを拡張およびサブクラス化し、表示されるダイアログ・ボックスにアクセス可能な説明メッセージを追加します。
IMGetMetadataDialog
:JDialog
クラスを拡張し、イメージからXML文書にメタデータを検索し、それをJTree形式で表示します。
IMPutMetadataDialog
:JDialog
クラスを拡張し、ユーザーが入力するイメージを書き込むためのXMPパケットを構成します。
XMLTreeNode
:DefaultMutableTreeNode
クラスを拡張し、XMLノードのツリー表現を作成します。
XMLTreeView
:JPanel
クラスを拡張し、XML文書をツリーとして表示します。
IMFileChooser
: JFileChooser
クラスを拡張し、JFileChooser
クラスから継承して、ボタンのニーモニックおよびアクセス可能な説明を追加します。
IMConstants
: 列名、メディア・タイプ、メッセージ・タイプおよびメッセージ・ダイアログのタイトルのすべての定数を含むIMConstantsインタフェースを記述します。
IMAttrTableModel
: DefaultTableModel
クラスを拡張およびサブクラス化し、メディア属性を表示するための表モデルを提供し、isCellEditable( )メソッドを上書きしてセルを編集不可にします。
FocusedJTextField
: JTextField
クラスを拡張およびサブクラス化し、isFocusTraversable( )メソッドを上書きして、編集不可に設定された場合にフォーカスが当たるように指定できます。
FocusedJTextArea
: JTextArea
クラスを拡張およびサブクラス化し、isFocusTraversable( )メソッドを上書きして、編集不可に設定された場合にフォーカスが当たるようにできます。また、isManagingFocus( )メソッドを上書きして、JTextArea
クラスが[Tab]キー操作を処理しないように指定できます。
FocusedJPanel
: JPanel
クラスを拡張およびサブクラス化し、isFocusTraversable( )メソッドを上書きしてフォーカスが当たるように指定できます。
FocusedJLabel
: JLabel
クラスを拡張およびサブクラス化し、isFocusTraversable( )メソッドを上書きし、フォーカス・リスナーを追加してフォーカスが当たるように指定できます。
BooleanRenderer
: JCheckBox
クラスを拡張し、ブール・オブジェクトをJCheckBox(チェック・ボックス)としてJTable(2次元表フォーマット)でレンダリングします。また、このクラスは、ツールチップを設定してアクセシビリティをサポートすることで、AccessibleNameおよびAccessibleDescriptionプロパティを設定します。
IMStreamAbsorber
: Thread
クラスを拡張し、個別のスレッドとして実行して入力ストリームをコンシュームします。これは、プラグイン・アプリケーションがロードされ、たとえばアプリケーションの出力をコンシュームせずに標準エラーが発生したためにアプリケーションを続行できなくなった場合に有効です。
IMTable
: JTable
クラスを拡張およびサブクラス化し、isManagingFocus( )メソッドを上書きして表が[Tab]キー操作を処理しないように指定します。
IMTableRenderer
: DefaultTableCellRenderer
クラスを拡張し、PRODUCT_ID
、PRODUCT_NAME
およびPRODUCT_DESCRIPTION
列をレンダリングして、アクセシビリティ情報を追加し、カスタマイズされた表示を設定します。
IMUIUtil
: 共通GUIユーティリティが含まれます。
このクラスが定義するメソッドおよびその機能の説明を次に示します。
loadMedia( )メソッド: データベースからメディア・オブジェクトを取得します。このメソッドは、PRODUCT_ID
列がパラメータ・マーカーであるPM.ONLINE_MEDIA
表にSQL SELECT...FOR UPDATE文を実行します。このクラスは次に、getORADataおよびgetORADataFactoryインタフェースを使用して、結果セットからメディア・データ・オブジェクトを取得します。
displayMedia( )メソッド: メディア・データを表示します。これによって、対応するメディア表示メソッド(displayImage( )、displayAudio( )、displayVideo( )およびdisplayDoc( ))がコールされます。
displayImage( )メソッド: IMImagePanel.display( )メソッドをコールし、このMIMEタイプをサポートするメディア・プレーヤを使用して、イメージ・データ属性、縮小イメージおよび原寸イメージを表示します。
displayAudio( )メソッド: IMAudioPanel.display( )メソッドをコールし、このMIMEタイプをサポートするメディア・プレーヤを使用して、オーディオ・データ属性を表示し、オーディオ・ストリームを再生します。
displayVideo( )メソッド: IMVideoPanel.display( )メソッドをコールし、このMIMEタイプをサポートするメディア・プレーヤを使用して、ビデオ・データ属性を表示し、ビデオ・ストリームを再生します。
displayDoc( )メソッド: IMDocPanel.display( )メソッドをコールし、このMIMEタイプをサポートするメディア・プレーヤを使用して、使用レポート・データ属性を表示し、使用レポート・データを再生します。
次のコード例に、loadMedia( )、displayMedia( )、displayImage( )、displayAudio( )、displayVideo( )およびdisplayDoc( )メソッドを示します。SQL問合せ文、およびOracle MultimediaとOracleの他のオブジェクト型およびメソッドが使用されているコード部分は、太字で強調表示しています。
private void loadMedia() throws SQLException, IOException { String sQuery ="select product_photo, product_thumbnail, product_audio, product_video, " +
"product_testimonials from pm.online_media where product_id = ? for update";
OracleConnection conn = null; OracleResultSet rs = null; OraclePreparedStatement pstmt = null; boolean isInsertNeeded = false; byte[] ctx[] = new byte[1][64]; try { conn = IMExample.getDBConnection(); pstmt = (OraclePreparedStatement)conn.prepareStatement(sQuery); pstmt.setInt(1, m_iProdId); rs = (OracleResultSet)pstmt.executeQuery(); if (rs.next() == true) {m_img = (OrdImage)rs.getORAData(1, OrdImage.getORADataFactory());
m_imgThumb = (OrdImage)rs.getORAData(2, OrdImage.getORADataFactory());
m_aud = (OrdAudio)rs.getORAData(3, OrdAudio.getORADataFactory());
m_vid = (OrdVideo)rs.getORAData(4, OrdVideo.getORADataFactory());
m_doc = (OrdDoc)rs.getORAData(5, OrdDoc.getORADataFactory());
} displayMedia(); rs.close(); pstmt.close(); } finally { IMUtil.cleanup(rs, pstmt); } } private void displayMedia() throws SQLException, IOException { displayImage(); displayAudio(); displayVideo(); displayDoc(); } /** * Add the product photo panel. */ private void displayImage() throws SQLException, IOException {m_jImgPanel = new IMImagePanel(this,
m_img, m_imgThumb, m_iProdId, m_colorFieldBg);
m_jImgPanel.display(); m_jImgPanel.getAccessibleContext().setAccessibleName ("Product photo panel"); m_jImgPanel.getAccessibleContext().setAccessibleDescription ("Product photo panel with an image icon on the left, " + "image attribute panel in the middle and image control" + "panel on the right."); m_jMediaPanel.add(m_jImgPanel); Component jImgFocus = m_jImgPanel.getFirstFocusComponent(); } /** * Add the product audio panel. */ private void displayAudio() throws SQLException, IOException { m_jAudPanel = new IMAudioPanel(this, m_aud, m_iProdId, m_colorFieldBg); m_jAudPanel.display(); m_jAudPanel.getAccessibleContext().setAccessibleName ("Product audio panel"); m_jAudPanel.getAccessibleContext().setAccessibleDescription( "Product audio panel with an audio icon at the left, " + "audio attribute panel in the middle and audio control" + "panel at the right."); m_jMediaPanel.add(m_jAudPanel); } /** * Add the product video panel. */ private void displayVideo() throws SQLException, IOException {m_jVidPanel = new IMVideoPanel(this, m_vid, m_iProdId, m_colorFieldBg);
m_jVidPanel.display(); m_jVidPanel.getAccessibleContext().setAccessibleName ("Product audio panel"); m_jVidPanel.getAccessibleContext().setAccessibleDescription( "Product audio panel with an video icon at the left, " + "video attribute panel in the middle and video control" + "panel at the right."); m_jMediaPanel.add(m_jVidPanel); } /** * Add the product testimonials panel. */ private void displayDoc() throws SQLException, IOException {m_jDocPanel = new IMDocPanel(this, m _doc, m_iProdId, m_colorFieldBg);
m_jDocPanel.display(); m_jDocPanel.getAccessibleContext().setAccessibleName ("Product testimonials panel"); m_jDocPanel.getAccessibleContext().setAccessibleDescription( "Product testimonials panel with an document icon at the left, " + "testimonials attribute panel in the middle and testimonials control" + "panel at the right."); m_jMediaPanel.add(m_jDocPanel); }
対応するm_jXxxPanel.display( )メソッドのコード例は、IMImagePanelクラス、IMAudioPanelクラス、IMVideoPanelクラスおよびIMDocPanelクラスを参照してください。Xxxは、特定のメディア・データ型(Img、Aud、VidまたはDoc)を表します。
このクラスは、イメージ・パネル、製品の写真とその属性および縮小イメージを表示します。メタデータの読取りおよび書込み用の一覧も表示します。このクラスで定義される各メソッドおよびその機能の詳細を次に示します。
display( )メソッドは、 最初にinsertProperty( )メソッドをコールします。insertProperty( )メソッドは、Oracle Multimedia Imageのオブジェクト型メソッド(getMimeType( )、getHeight( )、getWidth( )およびgetContentlength( ))をコールし、イメージの属性を取得して表に表示します。また、display( )メソッドは、イメージ・メタデータの読取りおよび書込み用にユーザー・インタフェースのコンポーネントを配置します。
このクラスは、縮小イメージがサポートされているフォーマットでは、製品の写真の縮小イメージを表示します。これは、IMUtil.generateThumbnail( )メソッドをコールして製品の写真から縮小イメージを作成することで生成されます。
addThumbnail( )メソッド: 新しい縮小イメージを表示します。
changeThumbnail( )メソッド: 縮小イメージを変更します。
saveToFile( )メソッド: 写真をファイルに保存します。
deleteMedia( )メソッド: OrdImage.init( )メソッドを使用してイメージのオブジェクト型の列を空に設定して、製品の写真イメージおよびその縮小イメージをデータベースから削除します。
play( )メディア・メソッド: メディア・プレーヤを使用してイメージを表示します。
setMedia( )メソッド: 写真および縮小オブジェクトを設定します。
notExist( )メソッド: イメージ・データが存在するかどうかを確認し、BLOBが空であるか、既存のBFILEと関連付けられていない場合はtrueを戻し、それ以外の場合はfalseを戻します。
getDataInByteArray( )メソッド: 最初にBFILEに対してOracle MultimediaのimportData( )メソッドをコールして、バイト配列にイメージ・データを取得し、Oracle MultimediaのgetDataInByteArray( )メソッドをコールした結果を戻します。
refreshPanel( )メソッド: 写真イメージ、属性および縮小イメージの更新時に、表示をリフレッシュします。
getFirstFocusComponent( )メソッド: 正しい順序でフォーカスを当てます。
emptyPanel( )メソッド: アイコンおよび属性パネルを消去します。
showMetadata( )メソッド:選択された型のメタデータを表示するためのウィンドウを表示します。
writeMetadata( )メソッド:メタデータの書込みダイアログ・ボックスを表示します。
次のコード例に、display( )、insertProperty( )、notExist( )、getDataInByteArray( )およびrefreshPanel( )メソッドを示します。SQL問合せ文、およびOracle MultimediaとOracleの他のオブジェクト型およびメソッドが使用されているコード部分は、太字で強調表示しています。
void display() throws IOException, SQLException { addControlPane();if (notExist(m_img))
{ // The image does not exist. m_hasMedia = false; layoutEmpty(s_sNotExist); } else { m_hasMedia = true; // If image exists, try to show the attributes. if (insertProperty()) { // Show the thumbnail image. // If the thumbnail image does not exist, generate it first.if (m_imgThumb != null)
{String sFormat = m_imgThumb.getFormat();
if (notExist(m_imgThumb) ||
( !("JFIF".equalsIgnoreCase(sFormat)) && !("GIFF".equalsIgnoreCase(sFormat)) )) {m_imgThumb = IMUtil.generateThumbnail(m_iProdId, m_img, m_imgThumb);
}byte[] thumbnail = getDataInByteArray(m_imgThumb);
addThumbnail(thumbnail); } else {m_imgThumb = IMUtil.generateThumbnail(m_iProdId, m_img, m_imgThumb);
byte[] thumbnail = getDataInByteArray(m_imgThumb);
addThumbnail(thumbnail); } } } } . . . boolean insertProperty() throws SQLException { boolean isFormatSupported = false;String sMimeType = m_img.getMimeType();
if (sMimeType == null)isFormatSupported = IMUtil.setProperties(m_img);
else isFormatSupported = true; if (!isFormatSupported) { layoutEmpty(s_sNotSupported); } else { Object[][] data = {{"MIME Type", m_img.getMimeType()},
{"Height", new Integer(m_img.getHeight()).toString()},
{"Width", new Integer(m_img.getWidth()).toString()},
{"Content Length", new Integer(m_img.getContentLength()).toString()}
}; . . . } return isFormatSupported; } . . . static boolean notExist(OrdImage img) throws SQLException, IOException {if (img == null)
return true; else {if (img.isLocal() && (img.getDataInByteArray() == null))
return true;else if (!img.isLocal() && (":///".equals(img.getSource())))
return true; else {if (!img.isLocal())
{BFILE bfile = img.getBFILE();
if (!bfile.fileExists())
return true; else return false; } else return false; } } } . . .static byte[] getDataInByteArray(OrdImage img) throws SQLException, IOException
{if (notExist(img))
return null; else {if (!img.isLocal())
{ byte[] ctx[] = new byte[1][4000]; try {img.importData(ctx);
} catch (SQLException e) { new IMMessage(IMConstants.ERROR, "MEDIA_SOURCE_ERR", e); return null; } }return img.getDataInByteArray();
} } . . . void refreshPanel(boolean isFormatSupported) throws SQLException, IOException { m_hasMedia = true; if (isFormatSupported) { if (m_jAttrTbl == null) { m_jAttrPane.remove(m_jEmpty); m_jIconPane.remove(m_jIcon);byte[] thumbnail = getDataInByteArray(m_imgThumb);
addThumbnail(thumbnail); insertProperty(); } else {byte[] thumbnail = getDataInByteArray(m_imgThumb);
changThumbnail(thumbnail);m_jAttrTbl.setValueAt(m_img.getMimeType(), 0, 1);
m_jAttrTbl.setValueAt(new Integer(m_img.getHeight()).toString(), 1, 1);
m_jAttrTbl.setValueAt(new Integer(m_img.getWidth()).toString(), 2, 1);
m_jAttrTbl.setValueAt(new Integer(m_img.getContentLength()).toString(),3, 1);
} } . . . }
このクラスは、製品の写真にメタデータの詳細情報を表示するためのダイアログ・ボックスを表示します。このクラスでは、displayMetadata( )メソッドを定義し、その動作も説明します。
displayMetadata( )メソッドは、Oracle Multimedia OrdImage getMetadata( )メソッドを使用してイメージ・メタデータを検索し、表示します。
次のコード例に、displayMetadata( )メソッドを示します。SQL問合せ文、およびOracle Multimediaと他のOracleのオブジェクト型およびメソッドが使用されているコード部分は、太字で強調表示しています。
private void displayMetadata(String sMetaType)
{
XMLDocument doc = null;
try
{
//
// Retrieves the metadata into an XMLType array
//
XMLType xmlList[] = m_img.getMetadata(sMetaType);
if (xmlList.length == 1)
{
DOMParser parser = new DOMParser();
parser.setValidationMode(XMLConstants.NONVALIDATING);
parser.setPreserveWhitespace(false);
parser.parse(new StringReader(XMLType.createXML(xmlList[0]).getStringVal()));
doc = parser.getDocument();
}
}
.
.
.
}
このクラスは、製品の写真にメタデータを書き込むためのダイアログ・ボックスを表示します。このクラスでは、writeMetadata( )メソッドを定義し、その動作も説明します。
writeMetadata( )メソッドは、Oracle Multimedia OrdImage putMetadata( )メソッドを使用してXMPメタデータをイメージ・メタデータに書き込みます。
次のコード例に、writeMetadata( )メソッドを示します。SQL問合せ文、およびOracle Multimediaと他のOracleのオブジェクト型およびメソッドが使用されているコード部分は、太字で強調表示しています。
void writeMetadata() { try { // // Let the StringBuffer to hold the XMP packet // StringBuffer sb = new StringBuffer( "<xmpMetadata xmlns=\"http://xmlns.oracle.com/ord/meta/xmp\" " + " xsi:schemaLocation=\"http://xmlns.oracle.com/ord/meta/xmp " + " http://xmlns.oracle.com/ord/meta/xmp\" " + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" > " + " <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"> " + " <rdf:Description about=\"\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"> " ); String str = null; if ( (str=m_jTitleField.getText()) != null) sb.append("<dc:title>" + str + "</dc:title>"); if ( (str=m_jCreatorField.getText()) !=null) sb.append("<dc:creator>" + str + "</dc:creator>"); if ( (str=m_jDateField.getText()) !=null) sb.append("<dc:date>" + str + "</dc:date>"); if ( (str=m_jDescriptionField.getText()) !=null) sb.append("<dc:description>" + str + "</dc:description>"); if ( (str=m_jCopyrightField.getText()) !=null) sb.append("<dc:rights>" + str + "</dc:rights>"); sb.append("</rdf:Description></rdf:RDF></xmpMetadata>"); XMLType xmp = XMLType.createXML(IMExample.getDBConnection(), sb.toString(), "http://xmlns.oracle.com/ord/meta/xmp", true, true); // // Make sure the image data is local // if (!m_img.isLocal()) { byte[] ctx[] = new byte[1][4000]; m_img.importData(ctx); } // // Call Ordimage.putMetadata // m_img.putMetadata(xmp, "XMP", "utf-8"); this.dispose(); } . . . }
このクラスは、ビデオ・パネル、製品のビデオおよびその属性を表示します。このクラスの構造および機能は、IMImagePanel
クラスと同じです。メソッドの説明は、IMImage Panelクラスを参照してください。
次のコード例に、display( )、insertProperty( )、notExist( )、getDataInByteArray( )およびrefreshPanel( )メソッドを示します。SQL問合せ文、およびOracle MultimediaとOracleの他のオブジェクト型およびメソッドが使用されているコード部分は、太字で強調表示しています。
void display() throws IOException, SQLException { addControlPane(); // Set the video icon. m_jIcon = new JLabel(new ImageIcon(IMExampleFrame.class.getResource("OrdVideo.gif"))); m_jIcon.setLabelFor(m_jAttrPane); m_jIconPane.add(m_jIcon, BorderLayout.CENTER); if (notExist()) { // The video does not exist. m_hasMedia = false; layoutEmpty(s_sNotExist); } else { m_hasMedia = true; // If the video exists, try to show the attributes. insertProperty(); } } . . . boolean insertProperty() throws SQLException { boolean isFormatSupported = false;String sMimeType = m_vid.getMimeType();
if (sMimeType == null)isFormatSupported = IMUtil.setProperties(m_vid);
else isFormatSupported = true; if (!isFormatSupported) { layoutEmpty(s_sNotSupported); } else { Object[][] data = {{"MIME Type", m_vid.getMimeType()},
{"Height", new Integer(m_vid.getHeight()).toString()},
{"Width", new Integer(m_vid.getWidth()).toString()},
{"Duration", new Integer(m_vid.getVideoDuration()).toString()},
{"Content Length", new Integer(m_vid.getContentLength()).toString()}
}; . . . } return isFormatSupported; } . . . boolean notExist() throws SQLException, IOException {if (m_vid == null)
return true; else {if (m_vid.isLocal() && (m_vid.getDataInByteArray() == null))
return true;else if (!m_vid.isLocal() && (":///".equals(m_vid.getSource())))
return true; else {if (!m_vid.isLocal())
{BFILE bfile = m_vid.getBFILE();
if (!bfile.fileExists())
return true; else return false; } else return false; } } } . . .byte[] getDataInByteArray(OrdVideo vid) throws SQLException, IOException
{ if (!m_hasMedia) return null; else {if (!vid.isLocal())
{ byte[] ctx[] = new byte[1][4000]; try {vid.importData(ctx);
} catch (SQLException e) { new IMMessage(IMConstants.ERROR, "MEDIA_SOURCE_ERR", e); return null; } }return vid.getDataInByteArray();
} } . . . void refreshPanel(boolean isFormatSupported) throws SQLException, IOException { m_hasMedia = true; if (isFormatSupported) { if (m_jAttrTbl == null) { m_jAttrPane.remove(m_jEmpty); insertProperty(); } else {m_jAttrTbl.setValueAt(m_vid.getMimeType(), 0, 1);
m_jAttrTbl.setValueAt(new Integer(m_vid.getHeight()).toString(), 1, 1);
m_jAttrTbl.setValueAt(new Integer(m_vid.getWidth()).toString(), 2, 1);
m_jAttrTbl.setValueAt(new Integer(m_vid.getVideoDuration()).toString(), 3, 1);
m_jAttrTbl.setValueAt(new Integer(m_vid.getContentLength()).toString(), 4, 1);
} } . . . }
このクラスは、オーディオ・パネル、製品のオーディオおよびその属性を表示します。このクラスの構造および機能は、IMImagePanel
クラスと同じです。メソッドの説明は、IMImage Panelクラスを参照してください。
次のコード例に、display( )、insertProperty( )、notExist( )、getDataInByteArray( )およびrefreshPanel( )メソッドを示します。SQL問合せ文、およびOracle MultimediaとOracleの他のオブジェクト型およびメソッドが使用されているコード部分は、太字で強調表示しています。
void display() throws IOException, SQLException { addControlPane(); // Set the audio icon. m_jIcon = new JLabel(new ImageIcon(IMExampleFrame.class.getResource("OrdAudio.gif"))); m_jIcon.setLabelFor(m_jAttrPane); m_jIconPane.add(m_jIcon, BorderLayout.CENTER); if (notExist()) { // The audio does not exist. m_hasMedia = false; layoutEmpty(s_sNotExist); } else { m_hasMedia = true; // If the audio exists, try to show the attributes. insertProperty(); } } . . . boolean insertProperty() throws SQLException { boolean isFormatSupported = false;String sMimeType = m_aud.getMimeType();
if (sMimeType == null)isFormatSupported = IMUtil.setProperties(m_aud);
else isFormatSupported = true; if (!isFormatSupported) { layoutEmpty(s_sNotSupported); } else { Object[][] data = {{"MIME Type", m_aud.getMimeType()},
{"Duration", new Integer(m_aud.getAudioDuration()).toString()},
{"Content Length", new Integer(m_aud.getContentLength()).toString()}
}; . . . } return isFormatSupported; } . . . boolean notExist() throws SQLException, IOException {if (m_aud == null)
return true; else {if (m_aud.isLocal() && (m_aud.getDataInByteArray() == null))
return true;else if (!m_aud.isLocal() && (":///".equals(m_aud.getSource())))
return true; else {if (!m_aud.isLocal())
{BFILE bfile = m_aud.getBFILE();
if (!bfile.fileExists())
return true; else return false; } else return false; } } } . . .byte[] getDataInByteArray(OrdAudio aud) throws SQLException, IOException
{ if (!m_hasMedia) return null; else {if (!aud.isLocal())
{ byte[] ctx[] = new byte[1][4000]; try {aud.importData(ctx);
} catch (SQLException e) { new IMMessage(IMConstants.ERROR, "MEDIA_SOURCE_ERR", e); return null; } }return aud.getDataInByteArray();
} } . . . void refreshPanel(boolean isFormatSupported) throws SQLException, IOException { m_hasMedia = true; if (isFormatSupported) { if (m_jAttrTbl == null) { m_jAttrPane.remove(m_jEmpty); insertProperty(); } else {m_jAttrTbl.setValueAt(m_aud.getMimeType(), 0, 1);
m_jAttrTbl.setValueAt(new Integer(m_aud.getAudioDuration()).toString(), 1, 1);
m_jAttrTbl.setValueAt(new Integer(m_aud.getContentLength()).toString(), 2, 1);
} } . . . }
このクラスは、ドキュメント・パネル、製品の使用レポートおよびその属性を表示します。このクラスの構造および機能は、IMImagePanel
クラスと同じです。メソッドの説明は、IMImage Panelクラスを参照してください。
次のコード例に、display( )、insertProperty( )、notExist( )、getDataInByteArray( )およびrefreshPanel( )メソッドを示します。SQL問合せ文、およびOracle MultimediaとOracleの他のオブジェクト型およびメソッドが使用されているコード部分は、太字で強調表示しています。
void display() throws IOException, SQLException { addControlPane(); // Set the icon. m_jIcon = new JLabel(new ImageIcon( IMExampleFrame.class.getResource("OrdDoc.gif") )); m_jIcon.setLabelFor(m_jAttrPane); m_jIconPane.add(m_jIcon, BorderLayout.CENTER); if (notExist()) { // The doc does not exist. m_hasMedia = false; layoutEmpty(s_sNotExist); } else { // If the doc exists, show the attribute table. m_hasMedia = true; insertProperty(); } } . . . boolean insertProperty() throws SQLException { boolean isFormatSupported = false;String sMimeType = m_doc.getMimeType();
if (sMimeType == null)isFormatSupported = IMUtil.setProperties(m_doc);
else isFormatSupported = true; if (!isFormatSupported) { layoutEmpty(s_sNotSupported); } else { Object[][] data = {{"MIME Type", m_doc.getMimeType()},
{"Content Length", new Integer(m_doc.getContentLength()).toString()}
}; . . . } return isFormatSupported; } . . . boolean notExist() throws SQLException, IOException {if (m_doc == null)
return true; else {if (m_doc.isLocal() && (m_doc.getDataInByteArray() == null))
return true;else if (!m_doc.isLocal() && (":///".equals(m_doc.getSource())))
return true; else {if (!m_doc.isLocal())
{BFILE bfile = m_doc.getBFILE();
if (!bfile.fileExists())
return true; else return false; } else return false; } } } . . .byte[] getDataInByteArray(OrdDoc doc) throws SQLException, IOException
{ if (!m_hasMedia) return null; else {if (!doc.isLocal())
{ byte[] ctx[] = new byte[1][4000]; try {doc.importData(ctx, false);
} catch (SQLException e) { new IMMessage(IMConstants.ERROR, "MEDIA_SOURCE_ERR", e); return null; } }return doc.getDataInByteArray();
} } . . . void refreshPanel(boolean isFormatSupported) throws SQLException, IOException { m_hasMedia = true; if (isFormatSupported) { if (m_jAttrTbl == null) { m_jAttrPane.remove(m_jEmpty); insertProperty(); } else {m_jAttrTbl.setValueAt(m_doc.getMimeType(), 0, 1);
m_jAttrTbl.setValueAt(new Integer(m_doc.getContentLength()).toString(), 1, 1);
} } . . . }
このクラスは、各メディア・オブジェクト型のメディア・ストリームを、ファイルからデータベースにロードします。このクラスは、最初にこのPRODUCT_ID
列がPM.ONLINE_MEDIA
表に存在するかどうかを確認し、存在しない場合は、その表に新しい行を挿入します。次に、各メディア・オブジェクト型の新しいメディア・オブジェクトを作成および初期化し、メディア・データを更新し(メディア・データがデータベースに格納されていない場合は、データベースにロードします)、最後に、各メディア・データ・オブジェクトのメディア属性を設定します。
このクラスでは、IMFileLoad( )メソッドがinitFileChooser( )メソッドをコールし、次にinitFileChooser( )メソッドがloadNewMedia( )メソッドをコールして行の挿入およびメディア・オブジェクト型の列の初期化を実行し、updateMedia( )メソッドをコールしてメディアの更新およびメディア属性の設定を実行します。
次のコード例に、loadNewMedia( )およびUpdateMedia( )メソッドを示します。前述したとおり、SQL問合せ文、およびOracle MultimediaとOracleの他のオブジェクト型およびメソッドが使用されているコード部分は、太字で強調表示しています。
private void loadNewMedia() throws SQLException, FileNotFoundException, SecurityException, IOException { boolean isInsertNeeded = false; String sQuery = null; OracleConnection conn = null; OracleResultSet rs = null; OraclePreparedStatement pstmt = null; try { conn = IMExample.getDBConnection(); if (m_obj == null) { // First, check whether or not this product exists in the // pm.online_media table. If it exists, isInsertNeeded is set to false; // or else, isInsertNeeded is set to true. sQuery = new String("select product_id from pm.online_media where product_id = ?");
pstmt = (OraclePreparedStatement) conn.prepareStatement(sQuery); pstmt.setInt(1, m_iProdId); rs = (OracleResultSet)pstmt.executeQuery(); if (rs.next() == false) isInsertNeeded = true; else isInsertNeeded = false; rs.close(); pstmt.close(); if (isInsertNeeded) { // If this product is not in the pm.online_media table, // insert a row in pm.online_media for this product, // and initialize the media object at the same time. sQuery = new String("insert into pm.online_media (product_id, product_photo, " +
"product_photo_signature, product_thumbnail, product_video, " +
"product_audio, product_text, product_testimonials) values (" +
"?, ORDSYS.ORDImage.init(), ORDSYS.ORDImageSignature.init(), " +
"ORDSYS.ORDImage.init(), ORDSYS.ORDVideo.init(), " +
"ORDSYS.ORDAudio.init(), null, ORDSYS.ORDDoc.init())");
pstmt = (OraclePreparedStatement) conn.prepareCall(sQuery); pstmt.setInt(1, m_iProdId); pstmt.execute(); pstmt.close(); } } if (!isInsertNeeded) { // Create a new media object. switch (m_iTypeIdentifier) { case IMG_TYPE: sQuery = new String("update pm.online_media set " + m_sColName +
" = ORDSYS.ORDImage.init() where product_id = ?");
break; case AUD_TYPE: sQuery = new String("update pm.online_media set " + m_sColName +
" = ORDSYS.ORDAudio.init() where product_id = ?");
break; case VID_TYPE: sQuery = new String("update pm.online_media set " + m_sColName +
" = ORDSYS.ORDVideo.init() where product_id = ?");
break; case DOC_TYPE: sQuery = new String("update pm.online_media set " + m_sColName +
" = ORDSYS.ORDDoc.init() where product_id = ?");
break; default: new IMMessage(IMConstants.ERROR, "UNKNOWN_TYPE"); break; } pstmt = (OraclePreparedStatement) conn.prepareCall(sQuery); pstmt.setInt(1, m_iProdId); pstmt.execute(); pstmt.close(); } // At this point, there is a row in the online_media table // for this product and the desired media object is initialized. // In the following, we update the media object pointer and // acquire the right to modify it by selecting again from the // database. // sQuery = new String( "select " + m_sColName +
"from pm.online_media where product_id = ? for update");
pstmt = (OraclePreparedStatement) conn.prepareStatement(sQuery); pstmt.setInt(1, m_iProdId); rs = (OracleResultSet)pstmt.executeQuery(); if (rs.next() == false) throw new SQLException(); else { switch (m_iTypeIdentifier) { case IMG_TYPE:m_img = (OrdImage)rs.getORAData(1, OrdImage.getORADataFactory());
break; case AUD_TYPE:m_aud = (OrdAudio)rs.getORAData(1, OrdAudio.getORADataFactory());
break; case VID_TYPE:m_vid = (OrdVideo)rs.getORAData(1, OrdVideo.getORADataFactory());
break; case DOC_TYPE:m_doc = (OrdDoc)rs.getORAData(1, OrdDoc.getORADataFactory());
break; default: new IMMessage(IMConstants.ERROR, "UNKNOWN_TYPE"); break; } // Update the media object. updateMedia(); } rs.close(); pstmt.close(); } finally { IMUtil.cleanup(rs, pstmt); } } /** * Update the media and also set the media properties. */ private void updateMedia() throws SQLException, FileNotFoundException, SecurityException, IOException { String sQuery = null; OracleConnection conn = null; byte[] ctx[] = new byte[1][64]; OraclePreparedStatement pstmt = null; boolean isFormatSupported = false; try { conn = IMExample.getDBConnection(); sQuery = new String("update pm.online_media set " + m_sColName +
" = ? where product_id = ?");
pstmt = (OraclePreparedStatement) conn.prepareCall(sQuery); pstmt.setInt(2, m_iProdId); switch (m_iTypeIdentifier) { case IMG_TYPE:m_img.loadDataFromFile(m_jFileChooser.getText());
isFormatSupported = IMUtil.setProperties(m_img);
m_img.setLocal();
pstmt.setORAData(1, m_img);
break; case AUD_TYPE:m_aud.loadDataFromFile(m_jFileChooser.getText());
isFormatSupported = IMUtil.setProperties(m_aud);
m_aud.setLocal();
pstmt.setORAData(1, m_aud);
// We need to update the media pointer for display, // because the input media pointer may be null.((IMAudioPanel)m_parent).setMedia(m_aud);
((IMAudioPanel)m_parent).refreshPanel(isFormatSupported); break; case VID_TYPE:m_vid.loadDataFromFile(m_jFileChooser.getText());
isFormatSupported = IMUtil.setProperties(m_vid);
m_vid.setLocal();
pstmt.setORAData(1, m_vid);
((IMVideoPanel)m_parent).setMedia(m_vid);
((IMVideoPanel)m_parent).refreshPanel(isFormatSupported); break; case DOC_TYPE:m_doc.loadDataFromFile(m_jFileChooser.getText());
isFormatSupported = IMUtil.setProperties(m_doc);
m_doc.setLocal();
pstmt.setORAData(1, m_doc);
((IMDocPanel)m_parent).setMedia(m_doc);
((IMDocPanel)m_parent).refreshPanel(isFormatSupported); break; default: new IMMessage(IMConstants.ERROR, "UNKNOWN_TYPE"); break; } pstmt.execute(); pstmt.close(); // Update the thumbnail image. if (m_iTypeIdentifier == IMG_TYPE) { if (isFormatSupported)m_imgThumb = IMUtil.generateThumbnail(m_iProdId, m_img, m_imgThumb);
((IMImagePanel)m_parent).setMedia(m_img, m_imgThumb);
((IMImagePanel)m_parent).refreshPanel(isFormatSupported); } } finally { IMUtil.cleanup(pstmt); } }
このクラスには、generateThumbnail( )スタティック・メソッド、フォーマットを認識できないために発生した例外を分離する各メディア・オブジェクト型のsetProperties( )メソッドのラッパー・メソッド、多くのクリーンアップ・メソッドなどの共通ユーティリティが含まれます。
次のコード例に、generateThumbnail( )メソッドを示します。SQL問合せ文、およびOracle Multimediaと他のOracleのオブジェクト型およびメソッドが使用されているコード部分は、太字で強調表示しています。
static OrdImage generateThumbnail(int iProdId, OrdImage img, OrdImage imgThumb)
throws SQLException { String sQuery = null; OracleConnection conn = null; OracleResultSet rs = null; OraclePreparedStatement pstmt = null; try { conn = IMExample.getDBConnection(); if (imgThumb == null) { // The thumbnail media pointer is not initialized. // Initialize it first. sQuery = new String("update pm.online_media set product_thumbnail = " +
"ORDSYS.ORDImage.init() where product_id = ?");
pstmt = (OraclePreparedStatement) conn.prepareCall(sQuery); pstmt.setInt(1, iProdId); pstmt.execute(); pstmt.close(); // Acquire the new pointer and the permission to update. sQuery = new String("select product_thumbnail from pm.online_media " +
"where product_id = ? for update");
pstmt = (OraclePreparedStatement) conn.prepareStatement(sQuery); pstmt.setInt(1, iProdId); rs = (OracleResultSet)pstmt.executeQuery(); if (rs.next() == false) throw new SQLException(); elseimgThumb = (OrdImage)rs.getORAData(1, OrdImage.getORADataFactory());
rs.close(); pstmt.close(); } // Generate the thumbnail image.img.processCopy("maxScale=64 64, fileFormat=GIFF", imgThumb);
// Update the thumbnail image in the database. sQuery = new String("update pm.online_media set product_thumbnail = ? where product_id = ?");
pstmt = (OraclePreparedStatement) conn.prepareCall(sQuery); pstmt.setORAData(1, imgThumb);
pstmt.setInt(2, iProdId); pstmt.execute(); pstmt.close(); return imgThumb; } finally { IMUtil.cleanup(rs, pstmt); } }