edu.ucsb.nceas.metacat
Class DocumentImpl

java.lang.Object
  |
  +--edu.ucsb.nceas.metacat.DocumentImpl

public class DocumentImpl
extends java.lang.Object

A class that represents an XML document. It can be created with a simple document identifier from a database connection. It also will write an XML text document to a database connection using SAX.


Constructor Summary
DocumentImpl(java.sql.Connection conn, long rootnodeid, java.lang.String docname, java.lang.String doctype, java.lang.String docid, java.lang.String action, java.lang.String user, java.lang.String pub, java.lang.String catalogid, int serverCode)
          Construct a new document instance, writing the contents to the database.
DocumentImpl(java.sql.Connection conn, long rootNodeId, java.lang.String docName, java.lang.String docType, java.lang.String docId, java.lang.String newRevision, java.lang.String action, java.lang.String user, java.lang.String pub, java.lang.String catalogId, int serverCode)
          Construct a new document instance, writing the contents to the database.
DocumentImpl(java.sql.Connection conn, java.lang.String docid)
          Constructor, creates document from database connection, used for reading the document
DocumentImpl(java.sql.Connection conn, java.lang.String docid, boolean readNodes)
          Constructor used to create a document and read the document information from the database.
 
Method Summary
static void delete(java.sql.Connection conn, java.lang.String accnum, java.lang.String user, java.lang.String[] groups)
          Delete an XML file from the database (actually, just make it a revision in the xml_revisions table)
 java.lang.String getCreateDate()
          get the creation date
 java.lang.String getDocID()
          Get the document identifier (docid)
 java.lang.String getDocname()
          get the document name
 java.lang.String getDoctype()
          get the document type (which is the PublicID)
 java.lang.String getPublicaccess()
           
 int getRev()
           
 long getRootNodeID()
          get the root node identifier
 int getServerlocation()
           
 java.lang.String getSystemID()
          get the system identifier
 java.lang.String getUpdateDate()
          get the update date
 java.lang.String getUserowner()
           
 java.lang.String getUserupdated()
           
 boolean hasReadPermission(java.sql.Connection conn, java.lang.String user, java.lang.String[] groups, java.lang.String docId)
          Check for "READ" permission base on docid, user and group
static void main(java.lang.String[] args)
          the main routine used to test the DBWriter utility.
 java.lang.String readUsingSlowAlgorithm()
          Get a text representation of the XML document as a string This older algorithm uses a recursive tree of Objects to represent the nodes of the tree.
static void registerDocument(java.lang.String docname, java.lang.String doctype, java.lang.String accnum, java.lang.String user, int serverCode)
          Register a document that resides on the filesystem with the database.
 java.lang.String toString()
          Print a string representation of the XML document
 void toXml(java.io.Writer pw)
          Print a text representation of the XML document to a Writer
static java.lang.String write(java.sql.Connection conn, java.io.Reader xml, java.lang.String pub, java.io.Reader dtd, java.lang.String action, java.lang.String docid, java.lang.String user, java.lang.String[] groups, boolean validate)
           
static java.lang.String write(java.sql.Connection conn, java.io.Reader xml, java.lang.String pub, java.io.Reader dtd, java.lang.String action, java.lang.String accnum, java.lang.String user, java.lang.String[] groups, int serverCode, boolean override, boolean validate)
          Write an XML file to the database, given a Reader
static java.lang.String write(java.sql.Connection conn, java.io.Reader xml, java.lang.String action, java.lang.String docid, java.lang.String user, java.lang.String[] groups, int serverCode)
           
static java.lang.String write(java.sql.Connection conn, java.io.Reader xml, java.lang.String pub, java.lang.String action, java.lang.String docid, java.lang.String user, java.lang.String[] groups)
           
static java.lang.String write(java.sql.Connection conn, java.io.Reader xml, java.lang.String pub, java.lang.String action, java.lang.String docid, java.lang.String user, java.lang.String[] groups, int serverCode)
           
static java.lang.String write(java.sql.Connection conn, java.io.Reader xml, java.lang.String pub, java.lang.String action, java.lang.String docid, java.lang.String user, java.lang.String[] groups, int serverCode, boolean override)
           
static java.lang.String write(java.sql.Connection conn, java.lang.String filename, java.lang.String pub, java.lang.String dtdfilename, java.lang.String action, java.lang.String docid, java.lang.String user, java.lang.String[] groups)
          Write an XML file to the database, given a filename
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DocumentImpl

public DocumentImpl(java.sql.Connection conn,
                    java.lang.String docid,
                    boolean readNodes)
             throws McdbException
Constructor used to create a document and read the document information from the database. If readNodes is false, then the node data is not read at this time, but is deferred until it is needed (such as when a call to toXml() is made).
Parameters:
conn - the database connection from which to read the document
docid - the identifier of the document to be created
readNodes - flag indicating whether the xmlnodes should be read

DocumentImpl

public DocumentImpl(java.sql.Connection conn,
                    java.lang.String docid)
             throws McdbException
Constructor, creates document from database connection, used for reading the document
Parameters:
conn - the database connection from which to read the document
docid - the identifier of the document to be created

DocumentImpl

public DocumentImpl(java.sql.Connection conn,
                    long rootnodeid,
                    java.lang.String docname,
                    java.lang.String doctype,
                    java.lang.String docid,
                    java.lang.String action,
                    java.lang.String user,
                    java.lang.String pub,
                    java.lang.String catalogid,
                    int serverCode)
             throws java.sql.SQLException,
                    java.lang.Exception
Construct a new document instance, writing the contents to the database. This method is called from DBSAXHandler because we need to know the root element name for documents without a DOCTYPE before creating it.
Parameters:
conn - the JDBC Connection to which all information is written
rootnodeid - - sequence id of the root node in the document
docname - - the name of DTD, i.e. the name immediately following the DOCTYPE keyword ( should be the root element name ) or the root element name if no DOCTYPE declaration provided (Oracle's and IBM parsers are not aware if it is not the root element name)
doctype - - Public ID of the DTD, i.e. the name immediately following the PUBLIC keyword in DOCTYPE declaration or the docname if no Public ID provided or null if no DOCTYPE declaration provided
docid - the docid to use for the INSERT OR UPDATE
action - the action to be performed (INSERT OR UPDATE)
user - the user that owns the document
pub - flag for public "read" access on document
serverCode - the serverid from xml_replication on which this document resides.

DocumentImpl

public DocumentImpl(java.sql.Connection conn,
                    long rootNodeId,
                    java.lang.String docName,
                    java.lang.String docType,
                    java.lang.String docId,
                    java.lang.String newRevision,
                    java.lang.String action,
                    java.lang.String user,
                    java.lang.String pub,
                    java.lang.String catalogId,
                    int serverCode)
             throws java.sql.SQLException,
                    java.lang.Exception
Construct a new document instance, writing the contents to the database. This method is called from DBSAXHandler because we need to know the root element name for documents without a DOCTYPE before creating it. In this constructor, the docid is without rev. There is a string rev to specify the revision user want to upadate. The revion is only need to be greater than current one. It is not need to be sequent number just after current one. So it is only used in update action
Parameters:
conn - the JDBC Connection to which all information is written
rootnodeid - - sequence id of the root node in the document
docname - - the name of DTD, i.e. the name immediately following the DOCTYPE keyword ( should be the root element name ) or the root element name if no DOCTYPE declaration provided (Oracle's and IBM parsers are not aware if it is not the root element name)
doctype - - Public ID of the DTD, i.e. the name immediately following the PUBLIC keyword in DOCTYPE declaration or the docname if no Public ID provided or null if no DOCTYPE declaration provided
docid - the docid to use for the UPDATE, no version number
version, - need to be update
action - the action to be performed (INSERT OR UPDATE)
user - the user that owns the document
pub - flag for public "read" access on document
serverCode - the serverid from xml_replication on which this document resides.
Method Detail

registerDocument

public static void registerDocument(java.lang.String docname,
                                    java.lang.String doctype,
                                    java.lang.String accnum,
                                    java.lang.String user,
                                    int serverCode)
                             throws java.sql.SQLException,
                                    AccessionNumberException,
                                    java.lang.Exception
Register a document that resides on the filesystem with the database. (ie, just an entry in xml_documents, nothing in xml_nodes). Creates a reference to a filesystem document (used for non-xml data files).
Parameters:
conn - the JDBC Connection to which all information is written
docname - - the name of DTD, i.e. the name immediately following the DOCTYPE keyword ( should be the root element name ) or the root element name if no DOCTYPE declaration provided (Oracle's and IBM parsers are not aware if it is not the root element name)
doctype - - Public ID of the DTD, i.e. the name immediately following the PUBLIC keyword in DOCTYPE declaration or the docname if no Public ID provided or null if no DOCTYPE declaration provided
accnum - the accession number to use for the INSERT OR UPDATE, which includes a revision number for this revision of the document (e.g., knb.1.1)
user - the user that owns the document
serverCode - the serverid from xml_replication on which this document resides.

getDocname

public java.lang.String getDocname()
get the document name

getDoctype

public java.lang.String getDoctype()
get the document type (which is the PublicID)

getSystemID

public java.lang.String getSystemID()
get the system identifier

getRootNodeID

public long getRootNodeID()
get the root node identifier

getCreateDate

public java.lang.String getCreateDate()
get the creation date

getUpdateDate

public java.lang.String getUpdateDate()
get the update date

getDocID

public java.lang.String getDocID()
Get the document identifier (docid)

getUserowner

public java.lang.String getUserowner()

getUserupdated

public java.lang.String getUserupdated()

getServerlocation

public int getServerlocation()

getPublicaccess

public java.lang.String getPublicaccess()

getRev

public int getRev()

toString

public java.lang.String toString()
Print a string representation of the XML document
Overrides:
toString in class java.lang.Object

readUsingSlowAlgorithm

public java.lang.String readUsingSlowAlgorithm()
                                        throws McdbException
Get a text representation of the XML document as a string This older algorithm uses a recursive tree of Objects to represent the nodes of the tree. Each object is passed the data for the document and searches all of the document data to find its children nodes and recursively build. Thus, because each node reads the whole document, this algorithm is extremely slow for larger documents, and the time to completion is O(N^N) wrt the number of nodes. See toXml() for a better algorithm.

toXml

public void toXml(java.io.Writer pw)
           throws McdbException
Print a text representation of the XML document to a Writer
Parameters:
pw - the Writer to which we print the document

write

public static java.lang.String write(java.sql.Connection conn,
                                     java.lang.String filename,
                                     java.lang.String pub,
                                     java.lang.String dtdfilename,
                                     java.lang.String action,
                                     java.lang.String docid,
                                     java.lang.String user,
                                     java.lang.String[] groups)
                              throws java.lang.Exception
Write an XML file to the database, given a filename
Parameters:
conn - the JDBC connection to the database
filename - the filename to be loaded into the database
pub - flag for public "read" access on document
dtdfilename - the dtd to be uploaded on server's file system
action - the action to be performed (INSERT OR UPDATE)
docid - the docid to use for the INSERT OR UPDATE
user - the user that owns the document
groups - the groups to which user belongs

write

public static java.lang.String write(java.sql.Connection conn,
                                     java.io.Reader xml,
                                     java.lang.String pub,
                                     java.io.Reader dtd,
                                     java.lang.String action,
                                     java.lang.String docid,
                                     java.lang.String user,
                                     java.lang.String[] groups,
                                     boolean validate)
                              throws java.lang.Exception

write

public static java.lang.String write(java.sql.Connection conn,
                                     java.io.Reader xml,
                                     java.lang.String pub,
                                     java.lang.String action,
                                     java.lang.String docid,
                                     java.lang.String user,
                                     java.lang.String[] groups)
                              throws java.lang.Exception

write

public static java.lang.String write(java.sql.Connection conn,
                                     java.io.Reader xml,
                                     java.lang.String action,
                                     java.lang.String docid,
                                     java.lang.String user,
                                     java.lang.String[] groups,
                                     int serverCode)
                              throws java.lang.Exception

write

public static java.lang.String write(java.sql.Connection conn,
                                     java.io.Reader xml,
                                     java.lang.String pub,
                                     java.lang.String action,
                                     java.lang.String docid,
                                     java.lang.String user,
                                     java.lang.String[] groups,
                                     int serverCode)
                              throws java.lang.Exception

write

public static java.lang.String write(java.sql.Connection conn,
                                     java.io.Reader xml,
                                     java.lang.String pub,
                                     java.lang.String action,
                                     java.lang.String docid,
                                     java.lang.String user,
                                     java.lang.String[] groups,
                                     int serverCode,
                                     boolean override)
                              throws java.lang.Exception

write

public static java.lang.String write(java.sql.Connection conn,
                                     java.io.Reader xml,
                                     java.lang.String pub,
                                     java.io.Reader dtd,
                                     java.lang.String action,
                                     java.lang.String accnum,
                                     java.lang.String user,
                                     java.lang.String[] groups,
                                     int serverCode,
                                     boolean override,
                                     boolean validate)
                              throws java.lang.Exception
Write an XML file to the database, given a Reader
Parameters:
conn - the JDBC connection to the database
xml - the xml stream to be loaded into the database
pub - flag for public "read" access on xml document
dtd - the dtd to be uploaded on server's file system
action - the action to be performed (INSERT or UPDATE)
accnum - the docid + rev# to use on INSERT or UPDATE
user - the user that owns the document
groups - the groups to which user belongs
serverCode - the serverid from xml_replication on which this document resides.
override - flag to stop insert replication checking. if override = true then a document not belonging to the local server will not be checked upon update for a file lock. if override = false then a document not from this server, upon update will be locked and version checked.

delete

public static void delete(java.sql.Connection conn,
                          java.lang.String accnum,
                          java.lang.String user,
                          java.lang.String[] groups)
                   throws java.lang.Exception
Delete an XML file from the database (actually, just make it a revision in the xml_revisions table)
Parameters:
docid - the ID of the document to be deleted from the database

hasReadPermission

public boolean hasReadPermission(java.sql.Connection conn,
                                 java.lang.String user,
                                 java.lang.String[] groups,
                                 java.lang.String docId)
                          throws java.sql.SQLException,
                                 java.lang.Exception
Check for "READ" permission base on docid, user and group

main

public static void main(java.lang.String[] args)
the main routine used to test the DBWriter utility.

Usage: java DocumentImpl <-f filename -a action -d docid>

Parameters:
filename - the filename to be loaded into the database
action - the action to perform (READ, INSERT, UPDATE, DELETE)
docid - the id of the document to process


Copyright © 2000 National Center for Ecological Analysis and Synthesis. All Rights Reserved.