net.sf.fikin.sql.core
Class SimpleXmlFile

java.lang.Object
  extended by net.sf.fikin.sql.SQLPipeElement
      extended by net.sf.fikin.sql.core.SimpleXmlFile
Direct Known Subclasses:
MultipleXmlFiles

public class SimpleXmlFile
extends SQLPipeElement

Read an XML file and executes the sql statements inside.

It recognizes one tag only which by default is set to uri="http://fikin-ant-tasks.sf.net/sql/simple-input.xsd" and localName="stmt"

One can modify this via object's setter methods.

It treats the text inside the tags as an executable sql statement and does not recognize nested xml tags. In such case an SQXException exception is raisen.

This object accepts file, file name or input stream as input source.

File parsing is based on SAX.

created on Dec 17, 2006

Since:
Version:
$Revision: 1.6 $
Author:
fiykov

Nested Class Summary
 class SimpleXmlFile.SimpleSAXParser
          recognizes only getTag() tag and extract its characters if any nested tags would cause SAXException created on Dec 17, 2006
 
Field Summary
static java.lang.String DEFAULT_TAG
          default tag local name, this parser is configured with
static java.lang.String DEFAULT_URI
          default URI this XML parser is configured with
 
Constructor Summary
SimpleXmlFile()
          default constructs
 
Method Summary
protected  SimpleXmlFile.SimpleSAXParser createParser()
          instantiate new SAX parser object template method
protected  org.xml.sax.XMLReader createReader()
          create XML reader
 void execute(java.lang.String cmd)
          start the XML processing and execute sql statements by delegating them to the next in the pipe
 java.lang.String getFileName()
          get input's file name if given via File-complient set input methods
 org.xml.sax.InputSource getInputSource()
          get the assigned input source
 SimpleXmlFile.SimpleSAXParser getSAXParser()
          get SimpleSAXParser
 java.lang.String getTag()
          what is the tag's name, recognized by the XML parser
 java.lang.String getURI()
          what is the tag's URI, recognized by the XML parser
 org.xml.sax.XMLReader getXMLReader()
          get XMLReader
 void setInputSource(java.io.File input)
          set the input to parse
 void setInputSource(org.xml.sax.InputSource input)
          set the input to parse
 void setInputSource(java.io.InputStream input)
          set the input to parse
 void setInputSource(java.io.Reader input)
          set the input to parse
 void setInputSource(java.lang.String systemId)
          set the input to parse
 void setInputSourceFileName(java.lang.String file)
          set the input to parse
 void setSAXParser(SimpleXmlFile.SimpleSAXParser parser)
          setter for SimpleSAXParser used to parse the input source
 void setTag(java.lang.String tag)
          assign custom defined tag's name the XML is to use
 void setURI(java.lang.String uri)
          assign custom defined tag's URI the XML is to use
 void setXMLReader(org.xml.sax.XMLReader reader)
          setter for XMLReader used to parse the input source
 
Methods inherited from class net.sf.fikin.sql.SQLPipeElement
getBaseClassName, getId, getNext, getPipe, setNext, setPipe
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_URI

public static final java.lang.String DEFAULT_URI
default URI this XML parser is configured with

See Also:
Constant Field Values

DEFAULT_TAG

public static final java.lang.String DEFAULT_TAG
default tag local name, this parser is configured with

See Also:
Constant Field Values
Constructor Detail

SimpleXmlFile

public SimpleXmlFile()
              throws org.xml.sax.SAXException
default constructs

Throws:
org.xml.sax.SAXException
Method Detail

getURI

public java.lang.String getURI()
what is the tag's URI, recognized by the XML parser

Returns:
the uri, by default is DEFAULT_URI

setURI

public void setURI(java.lang.String uri)
assign custom defined tag's URI the XML is to use

Parameters:
uri -

getTag

public java.lang.String getTag()
what is the tag's name, recognized by the XML parser

Returns:
the uri, by default is DEFAULT_TAG

setTag

public void setTag(java.lang.String tag)
assign custom defined tag's name the XML is to use

Parameters:
tag -

getFileName

public java.lang.String getFileName()
get input's file name if given via File-complient set input methods

Returns:
file name of null if ready made input stream has been provided

setSAXParser

public void setSAXParser(SimpleXmlFile.SimpleSAXParser parser)
setter for SimpleSAXParser used to parse the input source

Parameters:
parser -

getSAXParser

public SimpleXmlFile.SimpleSAXParser getSAXParser()
get SimpleSAXParser

Returns:
assigned SAX parser or null

setXMLReader

public void setXMLReader(org.xml.sax.XMLReader reader)
setter for XMLReader used to parse the input source

Parameters:
reader -

getXMLReader

public org.xml.sax.XMLReader getXMLReader()
get XMLReader

Returns:
assigned XML reader or null

getInputSource

public org.xml.sax.InputSource getInputSource()
get the assigned input source

Returns:
the source to parse

setInputSource

public void setInputSource(org.xml.sax.InputSource input)
set the input to parse

Parameters:
input - source

setInputSource

public void setInputSource(java.io.InputStream input)
set the input to parse

Parameters:
input - stream

setInputSource

public void setInputSource(java.io.Reader input)
set the input to parse

Parameters:
input - reader

setInputSource

public void setInputSource(java.io.File input)
                    throws java.io.FileNotFoundException
set the input to parse

Parameters:
input - file
Throws:
java.io.FileNotFoundException

setInputSource

public void setInputSource(java.lang.String systemId)
set the input to parse

Parameters:
systemId -

setInputSourceFileName

public void setInputSourceFileName(java.lang.String file)
                            throws java.io.FileNotFoundException
set the input to parse

Parameters:
file - to use as input
Throws:
java.io.FileNotFoundException

execute

public void execute(java.lang.String cmd)
             throws java.sql.SQLException
start the XML processing and execute sql statements by delegating them to the next in the pipe

Specified by:
execute in class SQLPipeElement
Parameters:
cmd - does not matter at all
Throws:
java.sql.SQLException - in case of error

createParser

protected SimpleXmlFile.SimpleSAXParser createParser()
instantiate new SAX parser object template method


createReader

protected org.xml.sax.XMLReader createReader()
                                      throws org.xml.sax.SAXException
create XML reader

Returns:
xml reader
Throws:
org.xml.sax.SAXException


Copyright © 2003-2007 Nikolay Fiykov. All Rights Reserved.