tigase.xml.db
Class XMLDB

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

public class XMLDB
extends java.lang.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: 435 $
Author:
Artur Hefczyc

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

Constructor Detail

XMLDB

public XMLDB(java.lang.String db_file)
      throws java.io.IOException,
             XMLDBException
Throws:
java.io.IOException
XMLDBException
Method Detail

createDB

public static XMLDB createDB(java.lang.String db_file,
                             java.lang.String root_name,
                             java.lang.String node1_name)

getDBFileName

public java.lang.String getDBFileName()

setupNewDB

protected void setupNewDB(java.lang.String db_file,
                          java.lang.String root_name,
                          java.lang.String node1_name)

loadDB

protected void loadDB()
               throws java.io.IOException,
                      XMLDBException
Throws:
java.io.IOException
XMLDBException

saveDB

protected void saveDB()

getAllNode1sCount

public final long getAllNode1sCount()

getAllNode1s

public final java.util.List<java.lang.String> getAllNode1s()

findNode1

public final DBElement findNode1(java.lang.String node1_id)

getNode1

protected final DBElement getNode1(java.lang.String node1_id)
                            throws NodeNotFoundException
Throws:
NodeNotFoundException

addNode1

public void addNode1(java.lang.String node1_id)
              throws NodeExistsException
Throws:
NodeExistsException

removeNode1

public void removeNode1(java.lang.String node1_id)
                 throws NodeNotFoundException
Throws:
NodeNotFoundException

getNode

protected final DBElement getNode(java.lang.String node1_id,
                                  java.lang.String subnode,
                                  boolean auto_create)
                           throws NodeNotFoundException
Throws:
NodeNotFoundException

setData

public void setData(java.lang.String node1_id,
                    java.lang.String subnode,
                    java.lang.String key,
                    java.lang.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(java.lang.String node1_id,
                    java.lang.String key,
                    java.lang.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 java.lang.String[] getDataList(java.lang.String node1_id,
                                      java.lang.String subnode,
                                      java.lang.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(java.lang.String node1_id,
                            java.lang.String subnode,
                            java.lang.String key)
                     throws NodeNotFoundException
Throws:
NodeNotFoundException

getDataDoubleList

public double[] getDataDoubleList(java.lang.String node1_id,
                                  java.lang.String subnode,
                                  java.lang.String key)
                           throws NodeNotFoundException
Throws:
NodeNotFoundException

getData

public java.lang.Object getData(java.lang.String node1_id,
                                java.lang.String subnode,
                                java.lang.String key,
                                java.lang.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(java.lang.String node1_id,
                      java.lang.String subnode,
                      java.lang.String key,
                      int def)
               throws NodeNotFoundException
Throws:
NodeNotFoundException

getDataDouble

public double getDataDouble(java.lang.String node1_id,
                            java.lang.String subnode,
                            java.lang.String key,
                            double def)
                     throws NodeNotFoundException
Throws:
NodeNotFoundException

getData

public java.lang.Object getData(java.lang.String node1_id,
                                java.lang.String subnode,
                                java.lang.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 java.lang.Object getData(java.lang.String node1_id,
                                java.lang.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 java.lang.String[] getSubnodes(java.lang.String node1_id,
                                      java.lang.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 java.lang.String[] getSubnodes(java.lang.String node1_id)
                               throws NodeNotFoundException
Describe getSubnodes method here.

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

getKeys

public java.lang.String[] getKeys(java.lang.String node1_id,
                                  java.lang.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 java.lang.String[] getKeys(java.lang.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(java.lang.String node1_id,
                       java.lang.String subnode,
                       java.lang.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(java.lang.String node1_id,
                       java.lang.String key)
                throws NodeNotFoundException
Describe removeData method here.

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

removeSubnode

public void removeSubnode(java.lang.String node1_id,
                          java.lang.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 java.io.IOException
Throws:
java.io.IOException


Copyright © 2001-2006 Tigase Developers Team. All rights Reserved.