project35.io
Class Project35DataFileReader

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by project35.io.Project35DataFileReader
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

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

this reads a project35 data file, whether that file is a final format submission file or whether it is a .pdr file contained in the native .pdz file format. It also can read template files, which is a saved portion of a file that can be used by multiple files. The main distinction between data files and template files is that templates always start with the tag and the data files will start with a top level tag that matches the "topLevelElement" expected by the current schema. (Note that the expected top level record type is defined in the configuration * file.

When the reader reads the file, it verifies that the schema stamp written into the data matches the schema currently being used by Project35. in this case it is sufficient that the schema in the file ends with the same .xsd file used by the tool.

This class is part of the new system for reading the project35 data file format. for more information about this, please check the architecture document that comes with the release.


Copyright (c) 2008 Kevin Garwood for Project35. The original code was developed by Kevin Garwood for the University of Manchester. Revisions have been made for Project35, a project that is independent of that institution. This code is licensed under the Academic Free License version 3.0. The code attribution for the original code is included here:

Copyright (c) Kevin Garwood and University of Manchester 2007. All rights reserved. Licensed under the Academic Free License version 3.0. For more information on the terms and conditions, please see the file "LICENSE" that is included in this distribution.


Version:
1.0
Author:
Kevin Garwood (kgarwood@users.sourceforge.net)

Field Summary
protected  IDGeneratorService idGeneratorService
          used to register id values assigned to xs:id fields in a record model
protected  java.util.Hashtable modelFromID
          this records xs:id identifier --> record model references.
protected  java.io.OutputStreamWriter out
           
 
Constructor Summary
Project35DataFileReader(Project35FormContext project35FormContext, boolean readTemplate)
           
 
Method Summary
 void characters(char[] tagData, int start, int length)
           
protected  void clearRecordIDRegistry()
          clears the registry that associates ID values with model objects
 void endDocument()
           
 void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)
           
 RecordModel getRootModel()
           
 void ignoreTopLevelElementCheck()
           
 void omitModelStamp()
          causes Project35 to ignore whether there is a match between the model stamp in the file and the model stamp used by the application
protected  void populateModelWithAttributeValues(RecordModel recordModel, org.xml.sax.Attributes attributes)
          tries to match the attributes found in the tag of a record model to either edit field values or references
 void registerIDFields(RecordModel recordModel)
          registers the identifiers used by the record's xs:id fields to be excluded as possible values for keys generated by the service in the future.
 void resolveIDREFS(java.lang.Object recordObject)
          recurvisely goes through the model tree and tries to replace the ID value held by each reference with an actual record model.
 void setIDGeneratorService(IDGeneratorService idGeneratorService)
          sets the ID Generator service which picks up identifiers that have already been used in recorded records.
 void startDocument()
           
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes)
           
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

modelFromID

protected java.util.Hashtable modelFromID
this records xs:id identifier --> record model references. when a file is read, it may identify a reference instead of an record. After the file is read, these references have to be converted from simple xml identifiers into pointers that refer to record model objects. This hashtable is used for that conversion process.


idGeneratorService

protected IDGeneratorService idGeneratorService
used to register id values assigned to xs:id fields in a record model


out

protected java.io.OutputStreamWriter out
Constructor Detail

Project35DataFileReader

public Project35DataFileReader(Project35FormContext project35FormContext,
                               boolean readTemplate)
Method Detail

getRootModel

public RecordModel getRootModel()
Returns:
the root record model of the document

ignoreTopLevelElementCheck

public void ignoreTopLevelElementCheck()

omitModelStamp

public void omitModelStamp()
causes Project35 to ignore whether there is a match between the model stamp in the file and the model stamp used by the application


setIDGeneratorService

public void setIDGeneratorService(IDGeneratorService idGeneratorService)
sets the ID Generator service which picks up identifiers that have already been used in recorded records. When new records are produced, the id generator service will exclude identifier values that have already appeared in the file

Parameters:
idGeneratorService - the service that is used to generate values for identifier fields in record model instances.

resolveIDREFS

public void resolveIDREFS(java.lang.Object recordObject)
recurvisely goes through the model tree and tries to replace the ID value held by each reference with an actual record model. It consults the modelFromID registry to do this.


clearRecordIDRegistry

protected void clearRecordIDRegistry()
clears the registry that associates ID values with model objects


registerIDFields

public void registerIDFields(RecordModel recordModel)
registers the identifiers used by the record's xs:id fields to be excluded as possible values for keys generated by the service in the future.


populateModelWithAttributeValues

protected void populateModelWithAttributeValues(RecordModel recordModel,
                                                org.xml.sax.Attributes attributes)
tries to match the attributes found in the tag of a record model to either edit field values or references


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

startElement

public void startElement(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String qName,
                         org.xml.sax.Attributes attributes)
                  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

characters

public void characters(char[] tagData,
                       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

endElement

public void endElement(java.lang.String uri,
                       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

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