fedora.client.batch
Class BatchModifyParser

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by fedora.client.batch.BatchModifyParser
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class BatchModifyParser
extends org.xml.sax.helpers.DefaultHandler

Title: BatchModifyParser.java

Description: A class for parsing the xml modify directives in the Batch Modify input file. The parsing is configured to parse directives in the file sequentially. Logs are written for each successful and failed directive that is processed. Recoverable(non-fatal) errors are written to the log file and processing continues. Catastrophic errors will cause parsing to halt and set the count of failed directives to -1 indicating that parsing was halted prior to the end of the file. In this case the logs will contain all directives processed up to the point of failure.

Version:
$Id: BatchModifyParser.java 6306 2007-11-27 14:45:15Z rwayland3 $
Author:
rlw@virginia.edu

Constructor Summary
BatchModifyParser(Uploader UPLOADER, FedoraAPIM APIM, FedoraAPIA APIA, java.io.InputStream in, java.io.PrintStream out)
          Constructor allows this class to initiate the parsing.
 
Method Summary
 void characters(char[] ch, int start, int length)
           
 void endDocument()
           
 void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)
           
static java.util.Map getBDefLabelMap()
           
static java.util.Map getBMechLabelMap(java.lang.String bDefPID)
          Get a map of pid-to-label of behavior mechanisms that implement the behavior defined by the indicated bdef.
 int getFailedCount()
          Get the count of failed directives.
 int getSucceededCount()
          Get the count of successful directives.
static void main(java.lang.String[] args)
           Main method for testing only.
 void skippedEntity(java.lang.String name)
           
 void startDocument()
           
 void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attrs)
           
 void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
           
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BatchModifyParser

public BatchModifyParser(Uploader UPLOADER,
                         FedoraAPIM APIM,
                         FedoraAPIA APIA,
                         java.io.InputStream in,
                         java.io.PrintStream out)

Constructor allows this class to initiate the parsing.

Parameters:
UPLOADER - - An instance of Uploader.
APIM - - An instance of FedoraAPIM.
APIA - - An instance of Fedora APIA.
in - - An input stream containing the xml to be parsed.
out - - A print stream used for writing log info.
Method Detail

getFailedCount

public int getFailedCount()

Get the count of failed directives. Note that a failed count value of -1 indicates that a fatal parsing error occurred before all directives could be parsed and the number of unprocessed directives is indeterminate. The log file will contain details on how many directives were successfully processed before the fatal error was encountered.

Returns:
The count of failed directives.

getSucceededCount

public int getSucceededCount()

Get the count of successful directives.

Returns:
The count of successful directives.

startDocument

public void startDocument()
                   throws org.xml.sax.SAXException
Specified by:
startDocument in interface org.xml.sax.ContentHandler
Overrides:
startDocument in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

endDocument

public void endDocument()
                 throws org.xml.sax.SAXException
Specified by:
endDocument in interface org.xml.sax.ContentHandler
Overrides:
endDocument in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

startPrefixMapping

public void startPrefixMapping(java.lang.String prefix,
                               java.lang.String uri)
                        throws org.xml.sax.SAXException
Specified by:
startPrefixMapping in interface org.xml.sax.ContentHandler
Overrides:
startPrefixMapping in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

skippedEntity

public void skippedEntity(java.lang.String name)
                   throws org.xml.sax.SAXException
Specified by:
skippedEntity in interface org.xml.sax.ContentHandler
Overrides:
skippedEntity in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

startElement

public void startElement(java.lang.String namespaceURI,
                         java.lang.String localName,
                         java.lang.String qName,
                         org.xml.sax.Attributes attrs)
                  throws org.xml.sax.SAXException
Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String namespaceURI,
                       java.lang.String localName,
                       java.lang.String qName)
                throws org.xml.sax.SAXException
Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

getBDefLabelMap

public static java.util.Map getBDefLabelMap()
                                     throws java.io.IOException
Throws:
java.io.IOException

getBMechLabelMap

public static java.util.Map getBMechLabelMap(java.lang.String bDefPID)
                                      throws java.io.IOException
Get a map of pid-to-label of behavior mechanisms that implement the behavior defined by the indicated bdef.

Parameters:
bDefPID - PID of the associated behavior defintion object.
Returns:
A list of the behavior mechanism labels.
Throws:
java.io.IOException - If an error occurs in retrieving the list of labels.

main

public static void main(java.lang.String[] args)

Main method for testing only.

Parameters:
args - Array of input parms consisting of hostname, port, username, password, protocol, directives, log.