com.miami.romeo.main
Class DataIO

java.lang.Object
  extended bycom.miami.romeo.main.DataIO

public class DataIO
extends java.lang.Object

DataIO.
This class saves, retrieves or modifies the list of games.

Since:
0.1.3pre2
Version:
$Revision: 1.13 $Date: 2003/12/23 18:25:25 $
Author:
$Author: Stefano Bolli

Field Summary
protected  java.sql.Connection conn
           
protected static java.lang.String dbUrl
           
 javax.swing.JDialog dialog
           
static java.lang.String gameDocAvailability
           
static java.lang.String gameDocCategory
           
static java.lang.String gameDocCloneOf
           
static java.lang.String gameDocDescription
           
static java.lang.String gameDocDriver
           
static java.lang.String gameDocEntry
           
static java.lang.String gameDocFavorite
           
static java.lang.String gameDocIcon
           
static java.lang.String gameDocManufacturer
           
static java.lang.String gameDocName
           
static java.lang.String gameDocPath
           
static java.lang.String gameDocPlayed
           
static java.lang.String gameDocProductionYear
           
static java.lang.String gameDocRoot
           
static java.lang.String gameDocSample
           
static java.lang.String gameDocWorkingStatus
           
protected  java.sql.PreparedStatement pstmt
           
protected  java.sql.ResultSet rs
           
protected  java.sql.Statement stmt
           
 
Constructor Summary
DataIO(Romeo romeo)
          The constructor.
 
Method Summary
 int countRoms(java.lang.String xmame_path)
          This method counts how many roms are available.
protected  void createTable(java.lang.String list_name)
          This method creates a table.
 java.util.Vector getAvailableRoms()
          This method retrieves available roms.
protected  java.util.Vector getData(java.lang.String xmame_path, java.lang.String list_name)
          This method returns a vector containing rom data.
 int getDataStoringType()
          This method returns the data storing type: 0 to use xml document (default) 1 to use sql table 2 to use text file
 java.lang.String[] getInfoFromCatver(java.lang.String catverPath)
          This method retrieves data from catver.ini
 java.lang.String[] getListOfAvailableRoms(java.util.Vector rom, java.lang.String[] gameName)
          This method returns an array with the same length of the game names.
 java.util.Vector getListOfGames(java.lang.String xmame_path, java.lang.String list_name)
          This method calls specific data retrieving void.
 java.lang.String[] getMamuIcons(java.lang.String[] gameName, java.lang.String[] clone)
          This method returns an array of strings with the paths to Mamu' s icons.
 java.lang.String[] getRomCategories(java.lang.String[] gameName)
          This method retrieves a list of rom categories from catver.ini.
 java.lang.String[] getRomDirPaths()
          This method gets the paths to the rom directories and then put them into an array of strings.
 java.io.File[] getRomDirs()
          This method puts the rom dirs set by the user into an array of files.
 java.lang.String[] getRomPaths(java.util.Vector rom, java.lang.String[] gameName)
          This method returns the list of absolute paths for each game.
protected  java.util.Vector getSQLData(java.lang.String list_name)
          This method retrieves the list of game from a MySQL' s table.
protected  java.util.Vector getTextData(java.lang.String list_name)
          This method returns a vector containing data taken from a text file.
protected  java.util.Vector getXMLData(java.lang.String list_name)
          This method returns a vector containing data taken from a XML Document
 org.dom4j.Document getXMLDoc(java.net.URL url)
          This method returns the list of games document.
 boolean listOfGamesExists(java.lang.String xmame_path, java.lang.String list_name)
          This method returns true if the list of games exists, false otherwise.
 void listOfGamesWalk(org.dom4j.Document document)
          We have to walk a large XML document tree (the list of games) then for performance we have to use a fast looping method which avoids the cost of creating an Iterator object for each loop.
 void listOfGamesWalk(org.dom4j.Document document, org.dom4j.Element element)
          We have to walk a large XML document tree (the list of games) then for performance we have to use a fast looping method which avoids the cost of creating an Iterator object for each loop.
 java.util.Vector saveListOfGames(java.lang.String xmame_path, java.lang.String list_name)
          This method saves a new list of games and returns it in a Vector.
protected  java.util.Vector saveSQLTable(java.lang.String xmame_path, java.lang.String list_name, java.lang.String list, boolean listExists)
          This method saves rom data into a MySQL' s table and returns a vector.
protected  java.util.Vector saveTextFile(java.lang.String xmame_path, java.lang.String list_name)
          This method saves rom data into a text file.
protected  java.util.Vector saveXMLDocument(java.lang.String xmame_path, java.lang.String list_name)
          This method saves rom data into a xml document and returns a vector.
 java.lang.String[] scanMamuDir(java.lang.String prefix)
          This method scans Mamu dir and retrieves paths to available icons.
protected  void setUp()
          This method creates resources used by getSQLData() & saveSQLTable()
 void showUpdateDialog()
          This method creates a JDialog to show the saving process.
protected  boolean SQLTableExists(java.lang.String list_name, java.lang.String table_created)
          This method returns true if the SQL table exists, false otherwise.
 void tearDown()
          This method destroys resources created during the I/O operations.
protected  boolean textFileExists(java.lang.String list_name)
          This method returns true if the text file exists, false otherwise.
 void updateListOfGames(java.util.Vector vector, java.lang.String xmame_path, java.lang.String list_name)
          This method updates the list of games.
protected  void updateSQLTable(java.util.Vector vector, java.lang.String xmame_path, java.lang.String list_name)
          This method saves rom data into a MySQL' s table and returns a vector.
protected  void updateTextFile(java.util.Vector vector, java.lang.String xmame_path, java.lang.String list_name)
          This method updates the text file.
protected  void updateXMLDocument(java.util.Vector vector, java.lang.String xmame_path, java.lang.String list_name)
          This method saves rom data into a xml document and returns a vector.
protected  boolean XMLDocumentExists(java.lang.String list_name)
          This method returns true if the XML Document exists, false otherwise.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dialog

public javax.swing.JDialog dialog

gameDocRoot

public static java.lang.String gameDocRoot

gameDocEntry

public static java.lang.String gameDocEntry

gameDocAvailability

public static java.lang.String gameDocAvailability

gameDocDescription

public static java.lang.String gameDocDescription

gameDocName

public static java.lang.String gameDocName

gameDocProductionYear

public static java.lang.String gameDocProductionYear

gameDocManufacturer

public static java.lang.String gameDocManufacturer

gameDocWorkingStatus

public static java.lang.String gameDocWorkingStatus

gameDocCloneOf

public static java.lang.String gameDocCloneOf

gameDocFavorite

public static java.lang.String gameDocFavorite

gameDocDriver

public static java.lang.String gameDocDriver

gameDocCategory

public static java.lang.String gameDocCategory

gameDocSample

public static java.lang.String gameDocSample

gameDocPlayed

public static java.lang.String gameDocPlayed

gameDocPath

public static java.lang.String gameDocPath

gameDocIcon

public static java.lang.String gameDocIcon

conn

protected java.sql.Connection conn

rs

protected java.sql.ResultSet rs

stmt

protected java.sql.Statement stmt

pstmt

protected java.sql.PreparedStatement pstmt

dbUrl

protected static java.lang.String dbUrl
Constructor Detail

DataIO

public DataIO(Romeo romeo)
The constructor.

Parameters:
romeo - The main class
Method Detail

saveListOfGames

public java.util.Vector saveListOfGames(java.lang.String xmame_path,
                                        java.lang.String list_name)
                                 throws java.lang.InterruptedException
This method saves a new list of games and returns it in a Vector.

Parameters:
xmame_path - The path to the xmame executable
list_name - The name of the list
Returns:
The list of games previously saved
Throws:
java.lang.InterruptedException
Since:
0.1.3pre2
See Also:
showUpdateDialog(), getDataStoringType(), saveXMLDocument(String, String), saveSQLTable(String, String, String, boolean), saveTextFile(String, String)

showUpdateDialog

public void showUpdateDialog()
This method creates a JDialog to show the saving process.

See Also:
UpdateDialog.getDialog()

listOfGamesExists

public boolean listOfGamesExists(java.lang.String xmame_path,
                                 java.lang.String list_name)
This method returns true if the list of games exists, false otherwise.

Parameters:
xmame_path - The path to xmame
list_name - The name of the list
Returns:
True if the list of games exists, false otherwise
Since:
0.1.3pre2
See Also:
XMLDocumentExists(String), SQLTableExists(String, String), textFileExists(String)

updateListOfGames

public void updateListOfGames(java.util.Vector vector,
                              java.lang.String xmame_path,
                              java.lang.String list_name)
This method updates the list of games.

Parameters:
vector - The Vector containing rom data
xmame_path - The path to the xmame executable
list_name - The name of the list
Since:
0.1.3pre2
See Also:
getDataStoringType(), updateXMLDocument(Vector, String, String), updateSQLTable(Vector, String, String), updateTextFile(Vector, String, String)

getListOfGames

public java.util.Vector getListOfGames(java.lang.String xmame_path,
                                       java.lang.String list_name)
This method calls specific data retrieving void.

Parameters:
xmame_path - The path to xmame
list_name - The list name
Returns:
A Vector containing rom data
Since:
0.1.3pre2
See Also:
getXMLData(String), getSQLData(String), getTextData(String)

getDataStoringType

public int getDataStoringType()
This method returns the data storing type: 0 to use xml document (default) 1 to use sql table 2 to use text file

Returns:
Data storing type
Since:
0.1.3pre2

XMLDocumentExists

protected boolean XMLDocumentExists(java.lang.String list_name)
This method returns true if the XML Document exists, false otherwise.

Parameters:
list_name - The list name
Returns:
True if the XML Document exists, false otherwise
Since:
0.1.3pre2

saveXMLDocument

protected java.util.Vector saveXMLDocument(java.lang.String xmame_path,
                                           java.lang.String list_name)
This method saves rom data into a xml document and returns a vector.

Parameters:
xmame_path - The path to xmame
list_name - The name of the list
Returns:
A vector containing rom data
Since:
0.1.3pre2
See Also:
getData(String, String)

updateXMLDocument

protected void updateXMLDocument(java.util.Vector vector,
                                 java.lang.String xmame_path,
                                 java.lang.String list_name)
This method saves rom data into a xml document and returns a vector.

Parameters:
vector - The Vector containing rom data
xmame_path - The path to xmame
list_name - The name of the list
Returns:
A vector containing rom data
Since:
0.1.3pre2

getXMLData

protected java.util.Vector getXMLData(java.lang.String list_name)
This method returns a vector containing data taken from a XML Document

Parameters:
list_name - The name of the list of games
Returns:
A vector containing rom data
Since:
0.1.3pre2

getXMLDoc

public org.dom4j.Document getXMLDoc(java.net.URL url)
                             throws org.dom4j.DocumentException
This method returns the list of games document.

Parameters:
url - The list of games
Returns:
Document
Throws:
org.dom4j.DocumentException

listOfGamesWalk

public void listOfGamesWalk(org.dom4j.Document document)
We have to walk a large XML document tree (the list of games) then for performance we have to use a fast looping method which avoids the cost of creating an Iterator object for each loop.

Parameters:
document - The document we want to walk
See Also:
listOfGamesWalk(Document, Element)

listOfGamesWalk

public void listOfGamesWalk(org.dom4j.Document document,
                            org.dom4j.Element element)
We have to walk a large XML document tree (the list of games) then for performance we have to use a fast looping method which avoids the cost of creating an Iterator object for each loop.

Parameters:
document - The document we want to walk
element - The element to find

SQLTableExists

protected boolean SQLTableExists(java.lang.String list_name,
                                 java.lang.String table_created)
This method returns true if the SQL table exists, false otherwise.

Parameters:
list_name - The list name
table_created - This String contains the names of the tables created
Returns:
True if the SQL table exists, false otherwise
Since:
0.1.3pre2

saveSQLTable

protected java.util.Vector saveSQLTable(java.lang.String xmame_path,
                                        java.lang.String list_name,
                                        java.lang.String list,
                                        boolean listExists)
This method saves rom data into a MySQL' s table and returns a vector.

Parameters:
xmame_path - The path to xmame
list_name - The list name used by other data storing types
list - The list name
listExists - True if the list exists, false otherwise
Returns:
A vector containing rom data
Since:
0.1.3pre2
See Also:
setUp(), tearDown()

updateSQLTable

protected void updateSQLTable(java.util.Vector vector,
                              java.lang.String xmame_path,
                              java.lang.String list_name)
This method saves rom data into a MySQL' s table and returns a vector.

Parameters:
vector - The vector conatining the data to save
xmame_path - The path to xmame
list_name - The list name
Returns:
A vector containing rom data
Since:
0.1.3pre2
See Also:
setUp(), tearDown()

getSQLData

protected java.util.Vector getSQLData(java.lang.String list_name)
This method retrieves the list of game from a MySQL' s table.

Parameters:
list_name - The list name
Returns:
A vector containing game data
Since:
0.1.3pre2
See Also:
setUp(), tearDown()

setUp

protected void setUp()
              throws java.lang.Exception
This method creates resources used by getSQLData() & saveSQLTable()

Throws:
Exception - if an error occurs
java.lang.Exception

createTable

protected void createTable(java.lang.String list_name)
                    throws java.lang.Exception
This method creates a table.

Parameters:
list_name - The list name
Throws:
Exception - if an error occurs
java.lang.Exception
Since:
0.1.3pre2

tearDown

public void tearDown()
              throws java.lang.Exception
This method destroys resources created during the I/O operations.

Throws:
Exception - DOCUMENT ME!
java.lang.Exception

textFileExists

protected boolean textFileExists(java.lang.String list_name)
This method returns true if the text file exists, false otherwise.

Parameters:
list_name - The list name
Returns:
True if the text file exists, false otherwise
Since:
0.1.3pre2

saveTextFile

protected java.util.Vector saveTextFile(java.lang.String xmame_path,
                                        java.lang.String list_name)
This method saves rom data into a text file.

Parameters:
xmame_path - The path to xmame
list_name - The name of the list
Returns:
A vector containing game data
Since:
0.1.3pre2

updateTextFile

protected void updateTextFile(java.util.Vector vector,
                              java.lang.String xmame_path,
                              java.lang.String list_name)
This method updates the text file.

Parameters:
vector - The vector conatining the data to save
xmame_path - The path to xmame
list_name - The name of the list
Returns:
A vector containing game data
Since:
0.1.3pre2

getTextData

protected java.util.Vector getTextData(java.lang.String list_name)
This method returns a vector containing data taken from a text file.

Parameters:
list_name - The name of the list of games
Returns:
Vector
Since:
0.1.3pre2

getData

protected java.util.Vector getData(java.lang.String xmame_path,
                                   java.lang.String list_name)
This method returns a vector containing rom data.

Parameters:
xmame_path - The path to the xmame executable
list_name - The path to the list of games
Returns:
Vector of rom data

getMamuIcons

public java.lang.String[] getMamuIcons(java.lang.String[] gameName,
                                       java.lang.String[] clone)
This method returns an array of strings with the paths to Mamu' s icons.

Parameters:
gameName - The game names
clone - The list of clones
Returns:
Paths to Mamu' s icons

scanMamuDir

public java.lang.String[] scanMamuDir(java.lang.String prefix)
This method scans Mamu dir and retrieves paths to available icons.


countRoms

public int countRoms(java.lang.String xmame_path)
This method counts how many roms are available.

Returns:
The number (int) of available roms
Since:
0.1.3pre2
See Also:
getAvailableRoms()

getListOfAvailableRoms

public java.lang.String[] getListOfAvailableRoms(java.util.Vector rom,
                                                 java.lang.String[] gameName)
This method returns an array with the same length of the game names. It' s filled with a "No" if a game is not available, with "Yes" otherwise.

Parameters:
rom - A Vector filled with the available games and their absolute path
gameName - The list of game names
Returns:
The list of game availability
Since:
0.1.3pre2

getRomPaths

public java.lang.String[] getRomPaths(java.util.Vector rom,
                                      java.lang.String[] gameName)
This method returns the list of absolute paths for each game.

Parameters:
rom - A Vector filled with the available games and their absolute path
gameName - The list of game names
Returns:
The list of absolute path for the each game
Since:
0.1.3pre2

getAvailableRoms

public java.util.Vector getAvailableRoms()
This method retrieves available roms.

Returns:
The list of available games
See Also:
getRomDirs()

getRomDirs

public java.io.File[] getRomDirs()
This method puts the rom dirs set by the user into an array of files.

Returns:
The list of rom directories
Since:
0.1.3pre2
See Also:
getRomDirPaths()

getRomDirPaths

public java.lang.String[] getRomDirPaths()
This method gets the paths to the rom directories and then put them into an array of strings.

Returns:
The list of rom dir paths
Since:
0.1.3pre2
See Also:
Utils.parseValues(String, char)

getRomCategories

public java.lang.String[] getRomCategories(java.lang.String[] gameName)
This method retrieves a list of rom categories from catver.ini.

Parameters:
gameName - The games
Returns:
The list of categories
Since:
0.1.3pre1
See Also:
Xmame.getRomNames(String[]), getInfoFromCatver(String)

getInfoFromCatver

public java.lang.String[] getInfoFromCatver(java.lang.String catverPath)
This method retrieves data from catver.ini

Parameters:
catverPath - The path to catver.ini
Returns:
An array of data strings from catver.ini