tigase.xml.db
Class XMLDB

java.lang.Object
  extended by tigase.xml.db.XMLDB

public class XMLDB
extends Object

XMLDB is the main database access class. It allows you to create new database in given file, open database from given file, add, delete and retrieve data and data lists. All data or data lists are stored in database nodes. There are three possible kinds of nodes for each database:

  1. root node - this is top node in each XML hierachy tree. There can be only one root node in database as there can be only one root element in XML file. The element name for root node can be defined by the user when new database is created or defualt element name 'root' is used.
  2. node1 nodes - these are the first level nodes under root node. There can be any number of nodes on this level. All data added for this database are added to first level node unless subnode path is given. User can define element name of node1 when new database is created. If not given default element name 'node' is used.
  3. subnodes - node on any deeper level under node1 level. There can be any number of subnodes on any level. Subnodes have always 'node' element name and this can't be changed.

All node1 nodes and subnodes can contains any number of data associated with keys. With some keys there ca be more than one value assigned. Such kind of data are called data lists.
Although element name for subnode can not be defined it is actually not important. Because user database doesn't use subnode element names. He doesn't even use neiher root node element name nor node1 element name. database user uses node name what is quite different from node element name. Let see example below:

<node name='roster'/>

In this example node element name is node and node name is roster.
database users (actually developers) use only node names.
If you want to access subnode on some level you need to give full path to this subnode. For example, let's assume we have following database:

  <node name='tigase'>
 <node name='server'>
 </node>
 <node name='xmpp'>
 </node>
 </node>

If you need to access 'server' subnode you need to call method with '/tigase/server' as subnode path and for subnode 'xmpp' proper subnode path is of course '/tigase/xmpp'. If you skip subnode path or give null as a parameter you will be accessing data on node1 level. You can not access or save data on root node level.

Created: Tue Oct 26 15:27:33 2004

Version:
$Rev$
Author:
Artur Hefczyc

Constructor Summary
XMLDB(String db_file)
          Constructs ...
 
Method Summary
 void addNode1(String node1_id)
          Method description
static XMLDB createDB(String db_file, String root_name, String node1_name)
          Method description
 DBElement findNode1(String node1_id)
          Method description
 List<String> getAllNode1s()
          Method description
 long getAllNode1sCount()
          Method description
 Object getData(String node1_id, String key)
          Describe getData method here.
 Object getData(String node1_id, String subnode, String key)
          Describe getData method here.
 Object getData(String node1_id, String subnode, String key, Object def)
          Describe getData method here.
 double getDataDouble(String node1_id, String subnode, String key, double def)
          Method description
 double[] getDataDoubleList(String node1_id, String subnode, String key)
          Method description
 int getDataInt(String node1_id, String subnode, String key, int def)
          Method description
 int[] getDataIntList(String node1_id, String subnode, String key)
          Method description
 String[] getDataList(String node1_id, String subnode, String key)
          Describe getDataList method here.
 String getDBFileName()
          Method description
 String[] getKeys(String node1_id)
          Describe getKeys method here.
 String[] getKeys(String node1_id, String subnode)
          Describe getKeys method here.
protected  DBElement getNode(String node1_id, String subnode, boolean auto_create)
          Method description
protected  DBElement getNode1(String node1_id)
          Method description
 String[] getSubnodes(String node1_id)
          Describe getSubnodes method here.
 String[] getSubnodes(String node1_id, String subnode)
          Describe getSubnodes method here.
protected  void loadDB()
          Method description
 void removeData(String node1_id, String key)
          Describe removeData method here.
 void removeData(String node1_id, String subnode, String key)
          Describe removeData method here.
 void removeNode1(String node1_id)
          Method description
 void removeSubnode(String node1_id, String subnode)
          Describe removeSubnode method here.
protected  void saveDB()
          Method description
 void setData(String node1_id, String key, Object value)
          Describe setData method here.
 void setData(String node1_id, String subnode, String key, Object value)
          Describe setData method here.
protected  void setupNewDB(String db_file, String root_name, String node1_name)
          Method description
 void sync()
          Method description
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLDB

public XMLDB(String db_file)
      throws IOException,
             XMLDBException
Constructs ...

Parameters:
db_file -
Throws:
IOException
XMLDBException
Method Detail

createDB

public static XMLDB createDB(String db_file,
                             String root_name,
                             String node1_name)
Method description

Parameters:
db_file -
root_name -
node1_name -
Returns:

getDBFileName

public String getDBFileName()
Method description

Returns:

setupNewDB

protected void setupNewDB(String db_file,
                          String root_name,
                          String node1_name)
Method description

Parameters:
db_file -
root_name -
node1_name -

loadDB

protected void loadDB()
               throws IOException,
                      XMLDBException
Method description

Throws:
IOException
XMLDBException

saveDB

protected void saveDB()
Method description


getAllNode1sCount

public final long getAllNode1sCount()
Method description

Returns:

getAllNode1s

public final List<String> getAllNode1s()
Method description

Returns:

findNode1

public final DBElement findNode1(String node1_id)
Method description

Parameters:
node1_id -
Returns:

getNode1

protected final DBElement getNode1(String node1_id)
                            throws NodeNotFoundException
Method description

Parameters:
node1_id -
Returns:
Throws:
NodeNotFoundException

addNode1

public void addNode1(String node1_id)
              throws NodeExistsException
Method description

Parameters:
node1_id -
Throws:
NodeExistsException

removeNode1

public void removeNode1(String node1_id)
                 throws NodeNotFoundException
Method description

Parameters:
node1_id -
Throws:
NodeNotFoundException

getNode

protected final DBElement getNode(String node1_id,
                                  String subnode,
                                  boolean auto_create)
                           throws NodeNotFoundException
Method description

Parameters:
node1_id -
subnode -
auto_create -
Returns:
Throws:
NodeNotFoundException

setData

public void setData(String node1_id,
                    String subnode,
                    String key,
                    Object value)
             throws NodeNotFoundException
Describe setData method here.

Parameters:
node1_id - a String value
subnode - a String value
key - a String value
value - a String value
Throws:
NodeNotFoundException

setData

public void setData(String node1_id,
                    String key,
                    Object value)
             throws NodeNotFoundException
Describe setData method here.

Parameters:
node1_id - a String value
key - a String value
value - a String value
Throws:
NodeNotFoundException

getDataList

public String[] getDataList(String node1_id,
                            String subnode,
                            String key)
                     throws NodeNotFoundException
Describe getDataList method here.

Parameters:
node1_id - a String value
subnode - a String value
key - a String value
Returns:
a String[] value
Throws:
NodeNotFoundException - if an error occurs

getDataIntList

public int[] getDataIntList(String node1_id,
                            String subnode,
                            String key)
                     throws NodeNotFoundException
Method description

Parameters:
node1_id -
subnode -
key -
Returns:
Throws:
NodeNotFoundException

getDataDoubleList

public double[] getDataDoubleList(String node1_id,
                                  String subnode,
                                  String key)
                           throws NodeNotFoundException
Method description

Parameters:
node1_id -
subnode -
key -
Returns:
Throws:
NodeNotFoundException

getData

public Object getData(String node1_id,
                      String subnode,
                      String key,
                      Object def)
               throws NodeNotFoundException
Describe getData method here.

Parameters:
node1_id - a String value
subnode - a String value
key - a String value
def - a String value
Returns:
a String value
Throws:
NodeNotFoundException

getDataInt

public int getDataInt(String node1_id,
                      String subnode,
                      String key,
                      int def)
               throws NodeNotFoundException
Method description

Parameters:
node1_id -
subnode -
key -
def -
Returns:
Throws:
NodeNotFoundException

getDataDouble

public double getDataDouble(String node1_id,
                            String subnode,
                            String key,
                            double def)
                     throws NodeNotFoundException
Method description

Parameters:
node1_id -
subnode -
key -
def -
Returns:
Throws:
NodeNotFoundException

getData

public Object getData(String node1_id,
                      String subnode,
                      String key)
               throws NodeNotFoundException
Describe getData method here.

Parameters:
node1_id - a String value
subnode - a String value
key - a String value
Returns:
a String value
Throws:
NodeNotFoundException

getData

public Object getData(String node1_id,
                      String key)
               throws NodeNotFoundException
Describe getData method here.

Parameters:
node1_id - a String value
key - a String value
Returns:
a String value
Throws:
NodeNotFoundException

getSubnodes

public String[] getSubnodes(String node1_id,
                            String subnode)
                     throws NodeNotFoundException
Describe getSubnodes method here.

Parameters:
node1_id - a String value
subnode - a String value
Returns:
a String[] value
Throws:
NodeNotFoundException

getSubnodes

public String[] getSubnodes(String node1_id)
                     throws NodeNotFoundException
Describe getSubnodes method here.

Parameters:
node1_id - a String value
Returns:
a String[] value
Throws:
NodeNotFoundException

getKeys

public String[] getKeys(String node1_id,
                        String subnode)
                 throws NodeNotFoundException
Describe getKeys method here.

Parameters:
node1_id - a String value
subnode - a String value
Returns:
a String[] value
Throws:
NodeNotFoundException

getKeys

public String[] getKeys(String node1_id)
                 throws NodeNotFoundException
Describe getKeys method here.

Parameters:
node1_id - a String value
Returns:
a String[] value
Throws:
NodeNotFoundException

removeData

public void removeData(String node1_id,
                       String subnode,
                       String key)
                throws NodeNotFoundException
Describe removeData method here.

Parameters:
node1_id - a String value
subnode - a String value
key - a String value
Throws:
NodeNotFoundException

removeData

public void removeData(String node1_id,
                       String key)
                throws NodeNotFoundException
Describe removeData method here.

Parameters:
node1_id - a String value
key - a String value
Throws:
NodeNotFoundException

removeSubnode

public void removeSubnode(String node1_id,
                          String subnode)
                   throws NodeNotFoundException
Describe removeSubnode method here.

Parameters:
node1_id - a String value
subnode - a String value
Throws:
NodeNotFoundException

sync

public void sync()
          throws IOException
Method description

Throws:
IOException


Copyright © 2013 Tigase. All Rights Reserved.