it.mokabyte.pattern.dao
Class MyDaoXmlImpl

java.lang.Object
  |
  +--it.mokabyte.pattern.dao.MyDaoXmlImpl
All Implemented Interfaces:
MyDao

public class MyDaoXmlImpl
extends java.lang.Object
implements MyDao

Title:MyDaoXmlImpl

MyDaoXmlImpl makes an access to XML repository file whit this format:

Lucky

Fortune 13
13456.67

This file is in /temp/xml_src directory an the name is reposiroty.xml<\b>

Author:
S.Rossini, L.Dozio

Field Summary
private  java.lang.String ATTRIBUTE_PK
          tag primary key
private  org.w3c.dom.Document doc
          the DOM document
private  java.io.File fileRepository
          the repository file
private  java.lang.String TAG_ACCOUNT
          tag account
private  java.lang.String TAG_ADDRESS
          tag address
private  java.lang.String TAG_BALANCE
          tag balance
private  java.lang.String TAG_NAME
          tag name
 
Constructor Summary
MyDaoXmlImpl()
          Constructor for the MyDaoXmlImpl object
 
Method Summary
 boolean accountExists(AccountPK key)
           
private  void addNode(AccountOM accOm)
          Add an account to the DOM document
 int deleteAccount(AccountPK pk)
          the Method deletes an exist account
private  org.w3c.dom.Node getNode(java.lang.String pkValue)
          Gets the node attribute of the DOM repository object
private  AccountOM getValueObject(org.w3c.dom.Node node, java.lang.String pkValue)
          Get the valueObject attribute of the DOM repository
private  void initResourceFile(java.lang.String dataSourceName)
          init the XML reposistory
 int insertAccount(AccountPK pk, java.lang.String name, java.lang.String address, double balance)
          the Method inserts a new AccountOM in the repository
private  void openDocument()
          the method inti the DOM document
 AccountOM readAccount(AccountPK pk)
          the Method read an exist account
private  void saveDocument()
          the method save the values in an XML file repository
 int updateAccount(AccountPK key, java.lang.String name, java.lang.String address, double balance)
          the Method update an exist account
private  void updateDocument(AccountOM ao)
          the method update the value in the repository DOM obejct
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

doc

private org.w3c.dom.Document doc
the DOM document

fileRepository

private java.io.File fileRepository
the repository file

TAG_NAME

private java.lang.String TAG_NAME
tag name

TAG_ADDRESS

private java.lang.String TAG_ADDRESS
tag address

TAG_BALANCE

private java.lang.String TAG_BALANCE
tag balance

TAG_ACCOUNT

private java.lang.String TAG_ACCOUNT
tag account

ATTRIBUTE_PK

private java.lang.String ATTRIBUTE_PK
tag primary key
Constructor Detail

MyDaoXmlImpl

public MyDaoXmlImpl()
             throws DAOException
Constructor for the MyDaoXmlImpl object
Throws:
DAOException - there is not name file repository
Method Detail

insertAccount

public int insertAccount(AccountPK pk,
                         java.lang.String name,
                         java.lang.String address,
                         double balance)
                  throws DAOException
the Method inserts a new AccountOM in the repository
Specified by:
insertAccount in interface MyDao
Parameters:
pk - the account primary key
name - the account name
address - the account email address
balance - the account balance
Returns:
the number of value inserted in the repository
Throws:
DAOException - Object already exist, or problem with insert

deleteAccount

public int deleteAccount(AccountPK pk)
                  throws DAOException
the Method deletes an exist account
Specified by:
deleteAccount in interface MyDao
Parameters:
pk - the account primary key
Returns:
the number of element deleted
Throws:
DAOException - the account element not exist or problem with delete

readAccount

public AccountOM readAccount(AccountPK pk)
                      throws DAOException
the Method read an exist account
Specified by:
readAccount in interface MyDao
Parameters:
pk - the account primary key
Returns:
Account value or an exception if value not exist
Throws:
DAOException - the account not exist, or problem whit select

updateAccount

public int updateAccount(AccountPK key,
                         java.lang.String name,
                         java.lang.String address,
                         double balance)
                  throws DAOException
the Method update an exist account
Specified by:
updateAccount in interface MyDao
Parameters:
key - the account primary key
name - the account name value
address - the account address value
balance - the account balance value
Returns:
the number of element updated
Throws:
DAOException - account not exist or problem with update

accountExists

public boolean accountExists(AccountPK key)
                      throws DAOException
Specified by:
accountExists in interface MyDao
Parameters:
key - the Primary Key for this account
Returns:
Whether the indicated account exists
Throws:
DAOException - thrown if an object not exist

initResourceFile

private void initResourceFile(java.lang.String dataSourceName)
                       throws java.lang.Exception
init the XML reposistory
Parameters:
dataSourceName - the fiel name repository
Throws:
java.lang.Exception - not found the file in the specify path

addNode

private void addNode(AccountOM accOm)
              throws DAOException
Add an account to the DOM document
Parameters:
accOm - the account value
Throws:
DAOException - object already exist or problem with insert

getValueObject

private AccountOM getValueObject(org.w3c.dom.Node node,
                                 java.lang.String pkValue)
Get the valueObject attribute of the DOM repository
Parameters:
node - the node value
pkValue - the primary key value
Returns:
The valueObject value

getNode

private org.w3c.dom.Node getNode(java.lang.String pkValue)
                          throws DAOException
Gets the node attribute of the DOM repository object
Parameters:
pkValue - the primary key
Returns:
The node value or null if NOT exist
Throws:
DAOException - problem with DOM select

updateDocument

private void updateDocument(AccountOM ao)
                     throws DAOException
the method update the value in the repository DOM obejct
Parameters:
ao - the account object to update
Throws:
DAOException - the object not exist or problem with update

openDocument

private void openDocument()
                   throws DAOException
the method inti the DOM document
Throws:
DAOException - problem with init DOM

saveDocument

private void saveDocument()
                   throws DAOException
the method save the values in an XML file repository
Throws:
DAOException - problem with saving