[Batchserver-cvs] Batch_IO_1.1/src/org/jmonks/batch/io/ofx package.html, NONE, 1.1 OFXFileReader.ja
Brought to you by:
suresh_pragada
Update of /cvsroot/batchserver/Batch_IO_1.1/src/org/jmonks/batch/io/ofx In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv5459 Modified Files: OFXFileReader.java OFXFileSpec.java OFXFileWriter.java OFXHeaderRecord.java OFXVersion.java Added Files: package.html Log Message: no message Index: OFXFileReader.java =================================================================== RCS file: /cvsroot/batchserver/Batch_IO_1.1/src/org/jmonks/batch/io/ofx/OFXFileReader.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** OFXFileReader.java 18 Oct 2006 03:19:16 -0000 1.1.1.1 --- OFXFileReader.java 18 Oct 2006 23:04:01 -0000 1.2 *************** *** 34,41 **** /** * <p> ! * OFXFileReader reads the file in the OFX format and returns ! * the message sets as objects. It supports the new set of ! * methods to return the message sets and doesnt support the ! * <i>getNextRecord</i> method from FileReader. * </p> * --- 34,47 ---- /** * <p> ! * OFXFileReader reads the specified OFX file using the given file spec ! * and returns the records on the needed basis. ! * It reads the message sets and messages lazily to support reading ! * of the large files. It doesnt support the <i>getNextRecord</i> method ! * inherited from the FileReader and supports a new method <i>getNextMessageSet</i> to ! * read the message sets on needed basis. It guesses the OFXVersion from the given ! * file stream and ofx headers. So, OFXFileSpec doesnt need version to read the files. ! * To find out how to read ! * each record from the file and to read the each field from the record, refer to the ! * package javadoc. * </p> * *************** *** 53,61 **** * Holds the reference of the file. */ ! protected BufferedReader reader=null; /** * Holds the OFXHeaderRecord. */ ! protected OFXHeaderRecord headerRecord=null; /** * Holds the OFXParser refernece. --- 59,67 ---- * Holds the reference of the file. */ ! private BufferedReader reader=null; /** * Holds the OFXHeaderRecord. */ ! private OFXHeaderRecord headerRecord=null; /** * Holds the OFXParser refernece. *************** *** 104,107 **** --- 110,114 ---- this.reader=new BufferedReader(reader); OFXVersion version=this.guessAndCreateOFXHeaderRecord(); + logger.debug("Successuflly read the header record and the version guessed = " + version.toString()); try { *************** *** 115,132 **** OFXEvent event=null; while((event=parser.getNextEvent())!=null) - { if(event.getEventType()==OFXEvent.START_DOCUMENT) break; ! } } catch(OFXStreamException exception) { exception.printStackTrace(); ! logger.fatal("OFXParseException while trying to create the OFXParser. Message = " + exception.getMessage(), exception); throw new OFXStreamException("Unable to create the OFXParser. Message = " + exception.getMessage()); } logger.trace("Exiting OFXFileReader constructor"); } ! public OFXHeaderRecord getOFXHeaderRecord() { --- 122,144 ---- OFXEvent event=null; while((event=parser.getNextEvent())!=null) if(event.getEventType()==OFXEvent.START_DOCUMENT) break; ! logger.debug("Reader initialization has been done."); } catch(OFXStreamException exception) { exception.printStackTrace(); ! logger.fatal("OFXStreamException while trying to create the OFXParser. Message = " + exception.getMessage(), exception); throw new OFXStreamException("Unable to create the OFXParser. Message = " + exception.getMessage()); } logger.trace("Exiting OFXFileReader constructor"); } ! ! /** ! * Returns the OFX Headers as OFXHeaderRecord. This header record is constructed ! * at the time of initialization and can be called at any time. ! * ! * @return Returns the OFXHeaderRecord. ! */ public OFXHeaderRecord getOFXHeaderRecord() { *************** *** 134,144 **** } public ReaderRecord getNextRecord() { ! throw new UnsupportedOperationException("OFXFileReader not supports getNextRecord method. Use getNextMessageSet method."); } public void close() { if(this.reader!=null) { --- 146,170 ---- } + /** + * OFXFileReader does not support this method and provide an alternative + * <i>getNextMessageSet</i> method to read the message sets. + * + * @throws java.lang.UnsupportedOperationException If this method is called to + * read the message sets. + */ public ReaderRecord getNextRecord() { ! throw new UnsupportedOperationException("OFXFileReader does not supports " + ! "getNextRecord method. Use getNextMessageSet method."); } + /** + * Closes the OFXFileReader. Any attempt to read the message sets on the reader + * after calling this method yeilds null. Any attempt to read + * read the messages from the message sets yields null. + */ public void close() { + logger.trace("Entering OFXFileReader close"); if(this.reader!=null) { *************** *** 146,149 **** --- 172,176 ---- { this.reader.close(); + logger.debug("OFXFileReader has been closed."); } catch(IOException exception) *************** *** 156,161 **** --- 183,192 ---- } } + logger.trace("Exiting OFXFileReader close"); } + /** + * Gets the version of the stream this reader is reading. + */ public OFXVersion getOFXVersion() { *************** *** 163,168 **** --- 194,211 ---- } + /** + * Gets the next message set available from the stream. If reader is closed + * or no more message sets available, it return null. Once message set is obtained + * all the message to be retrieved, before calling this method for the next + * message sets. If fail to read all the messages, it skips all the messages + * in the previous message set. + * + * @return Returns the next message set available. Null, if none is available or reader is closed. + * + * @throws OFXStreamException If any problem while reading the next message set. + */ public MessageSet getNextMessageSet() { + logger.trace("Entering getNextMessageSet"); if(this.reader!=null) { *************** *** 185,189 **** this.currentMessageSet=(MessageSet)messageSet; ((MessageSetReader)messageSet).initializeReader(this.currentMessageSet.getMessageSetType(), this.parser); - return this.currentMessageSet; } catch(Exception exception) --- 228,231 ---- *************** *** 208,213 **** else { this.close(); - return null; } } --- 250,256 ---- else { + logger.debug("Reader encountered the end of document event. Closing the reader."); + this.currentMessageSet=null; this.close(); } } *************** *** 215,230 **** { exception.printStackTrace(); ! logger.fatal("OFXParseException while trying to read the next message set. Message = " + exception.getMessage(), exception); throw new OFXStreamException("Unable to read the next message set. Message = " + exception.getMessage()); } } else ! return null; } private OFXVersion guessAndCreateOFXHeaderRecord() { OFXVersion version=OFXVersion.OFX_1_6; ! while(true) { --- 258,285 ---- { exception.printStackTrace(); ! logger.fatal("OFXStreamException while trying to read the next message set. Message = " + exception.getMessage(), exception); throw new OFXStreamException("Unable to read the next message set. Message = " + exception.getMessage()); } } else ! this.currentMessageSet=null; ! ! logger.trace("Entering getNextMessageSet"); ! return this.currentMessageSet; } + /** + * Guesses the version of the ofx stream and creates the ofx header record. + * + * @return Returns the version of the ofx stream. + */ private OFXVersion guessAndCreateOFXHeaderRecord() { + logger.trace("Entering guessAndCreateOFXHeaderRecord"); OFXVersion version=OFXVersion.OFX_1_6; ! /** ! * Keep on reading the stream until receive the non space character. Check ! * the non space chacter for the ofx block type. ! */ while(true) { *************** *** 269,280 **** } } return version; } private OFXVersion createXMLOFXHeaderRecord() { try { - OFXVersion version=OFXVersion.OFX_2_0_2; this.headerRecord=new OFXHeaderRecord(); boolean endOfHeaders=false; --- 324,340 ---- } } + logger.trace("Entering guessAndCreateOFXHeaderRecord"); return version; } + /** + * Creates the OFXHeaderRecord from the OFX Headers in the form of XML. + */ private OFXVersion createXMLOFXHeaderRecord() { + logger.trace("Entering createXMLOFXHeaderRecord"); + OFXVersion version=OFXVersion.OFX_2_0_2; try { this.headerRecord=new OFXHeaderRecord(); boolean endOfHeaders=false; *************** *** 327,331 **** } - return version; } catch(IOException exception) --- 387,390 ---- *************** *** 335,345 **** throw new OFXStreamException(exception.getMessage()); } } ! private OFXVersion createSGMLOFXHeaderRecord() { try { - OFXVersion version=OFXVersion.OFX_1_6; this.headerRecord=new OFXHeaderRecord(); boolean endOfHeaders=false; --- 394,410 ---- throw new OFXStreamException(exception.getMessage()); } + logger.trace("Exiting createXMLOFXHeaderRecord"); + return version; } ! ! /** ! * Creates the OFXHeaderRecord from the OFX Headers in the form of SGML. ! */ private OFXVersion createSGMLOFXHeaderRecord() { + logger.trace("Entering createSGMLOFXHeaderRecord"); + OFXVersion version=OFXVersion.OFX_1_6; try { this.headerRecord=new OFXHeaderRecord(); boolean endOfHeaders=false; *************** *** 381,385 **** endOfHeaders=true; } - return version; } catch(IOException exception) --- 446,449 ---- *************** *** 389,392 **** --- 453,458 ---- throw new OFXStreamException(exception.getMessage()); } + logger.trace("Exiting createSGMLOFXHeaderRecord"); + return version; } Index: OFXVersion.java =================================================================== RCS file: /cvsroot/batchserver/Batch_IO_1.1/src/org/jmonks/batch/io/ofx/OFXVersion.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** OFXVersion.java 18 Oct 2006 03:19:16 -0000 1.1.1.1 --- OFXVersion.java 18 Oct 2006 23:04:01 -0000 1.2 *************** *** 12,27 **** /** * ! * @author Suresh Pragada */ public class OFXVersion { ! String versionId=null; ! /** Creates a new instance of OFXVersion */ private OFXVersion(String versionId) { this.versionId=versionId; } ! public static OFXVersion createOFXVersion(String versionId) { --- 12,46 ---- /** + * <p> + * OFXVersion is an enum class provides the OFX Version list. + * </p> * ! * @author Suresh Pragada ! * @version 1.1 ! * @since 1.1 */ public class OFXVersion { ! /** ! * Holds the version ID. ! */ ! private String versionId=null; ! ! /** ! * Creates a new instance of OFXVersion ! */ private OFXVersion(String versionId) { this.versionId=versionId; } ! ! /** ! * Returns the matching OFXVersion reference to the input value. If doesnt ! * matches with any existing versions, it returns null. ! * ! * @param versionId Version id to be matched. ! * ! * @return Returns OFXVersion reference, null, if none is matched with the given value. ! */ public static OFXVersion createOFXVersion(String versionId) { *************** *** 38,41 **** --- 57,63 ---- } + /** + * Returns the versionId. + */ public String toString() { *************** *** 43,49 **** --- 65,83 ---- } + /** + * Represents the OFX version 1.0.2 and the value in the file spec should be "102". + */ public static final OFXVersion OFX_1_0_2 = new OFXVersion("102"); + /** + * Represents the OFX version 1.5.1 and the value in the file spec should be "151". + */ public static final OFXVersion OFX_1_5_1 = new OFXVersion("151"); + /** + * Represents the OFX version 1.6 and the value in the file spec should be "16". + */ public static final OFXVersion OFX_1_6 = new OFXVersion("16"); + /** + * Represents the OFX version 2.0.2 and the value in the file spec should be "202". + */ public static final OFXVersion OFX_2_0_2 = new OFXVersion("202"); } Index: OFXFileSpec.java =================================================================== RCS file: /cvsroot/batchserver/Batch_IO_1.1/src/org/jmonks/batch/io/ofx/OFXFileSpec.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** OFXFileSpec.java 18 Oct 2006 03:19:16 -0000 1.1.1.1 --- OFXFileSpec.java 18 Oct 2006 23:04:01 -0000 1.2 *************** *** 19,25 **** /** * <p> ! * OFXFileSpec provides the details about the OFX version number. It doesnt ! * any record specs, since the OFX file formats are predefined in the format ! * of specification. * </p> * --- 19,38 ---- /** * <p> ! * OFXFileSpec represents the file spec defines the OFX file. ! * Since the format of the OFX files are defined in the form of ! * a specification, this file spec doesnt require any record specs. ! * It follows the defined specification to read the message sets and ! * messages. The file-type attribute should be "ofx" and it requires one ! * more additional attribute "version" to identify the version of the file. ! * The values here should be one of the valid versions from ! * {@link org.jmonks.batch.io.ofx.OFXVersion} class. ! * class. ! * ! * </p> ! * <p> ! * <pre> ! * <file-spec file-type="ofx" version="151"> ! * </file-spec> ! * </pre> * </p> * *************** *** 30,39 **** public class OFXFileSpec extends FileSpec { public static final String VERSION_ATTRIB_NAME = "version"; ! protected String version=null; private static Logger logger=Logger.getLogger(OFXFileSpec.class); ! protected OFXFileSpec() { --- 43,60 ---- public class OFXFileSpec extends FileSpec { + /** + * Constant defines the version attribute name. + */ public static final String VERSION_ATTRIB_NAME = "version"; ! /** ! * Holds the given version identifier. ! */ protected String version=null; private static Logger logger=Logger.getLogger(OFXFileSpec.class); ! ! /** ! * Constructs the OFXFileSpec instance. ! */ protected OFXFileSpec() { *************** *** 41,44 **** --- 62,68 ---- } + /** + * Gets the defined version in the file spec. + */ public String getVersion() { *************** *** 46,51 **** --- 70,84 ---- } + /** + * Factory method to create the ofx file spec object from the given + * DOM Element representing the file-spec element. + * + * @param fileSpecElement DOM Element representing the file-spec element. + * + * @return Returns the instance of OFXFileSpec. + */ public static FileSpec createOFXFileSpec(final Element fileSpecElement) { + logger.trace("Entering createOFXFileSpec"); OFXFileSpec fileSpec=new OFXFileSpec(); *************** *** 55,60 **** else fileSpec.version=null; ! return fileSpec; } } --- 88,107 ---- else fileSpec.version=null; ! ! logger.trace("Exiting createOFXFileSpec"); return fileSpec; } + + /** + * Returns the string representation of OFXFileSpec. + */ + public String toString() + { + StringBuffer stringValue=new StringBuffer("{OFXFileSpec "); + stringValue.append("[fileType = " + super.fileType.toString() + "]"); + stringValue.append("[version = " + this.version + "]"); + stringValue.append("}"); + return stringValue.toString(); + } + } --- NEW FILE: package.html --- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>OFX Implementation Overview</title> </head> <body> OFX implementation for the IO API. <p> </p> </body> </html> Index: OFXHeaderRecord.java =================================================================== RCS file: /cvsroot/batchserver/Batch_IO_1.1/src/org/jmonks/batch/io/ofx/OFXHeaderRecord.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** OFXHeaderRecord.java 18 Oct 2006 03:19:16 -0000 1.1.1.1 --- OFXHeaderRecord.java 18 Oct 2006 23:04:01 -0000 1.2 *************** *** 12,36 **** /** * ! * @author Suresh Pragada */ public class OFXHeaderRecord { ! private String ofxHeader=null; private String data=null; private String version=null; private String security=null; private String encoding=null; private String charSet=null; private String compression=null; private String oldFileUID=null; private String newFileUID=null; ! /** Creates a new instance of OFXHeaderRecord */ public OFXHeaderRecord() { } ! public void setOfxHeader(String ofxHeader) { --- 12,73 ---- /** + * <p> + * OFXHeaderRecord holds the OFX headers read from the OFXFileReader or + * OFX header to be written to the OFXFileWriter. + * </p> * ! * @author Suresh Pragada ! * @version 1.1 ! * @since 1.1 */ public class OFXHeaderRecord { ! /** ! * Holds the OFXHEADER header ! */ private String ofxHeader=null; + /** + * Holds the DATA header + */ private String data=null; + /** + * Holds the VERSION header + */ private String version=null; + /** + * Holds the SECURITY header + */ private String security=null; + /** + * Holds the ENCODING header + */ private String encoding=null; + /** + * Holds the CHARSET header + */ private String charSet=null; + /** + * Holds the COMPRESSION header + */ private String compression=null; + /** + * Holds the OLDFILEUID header + */ private String oldFileUID=null; + /** + * Holds the NEWFILEUID header + */ private String newFileUID=null; ! /** ! * Creates a new instance of OFXHeaderRecord ! */ public OFXHeaderRecord() { } ! ! /** ! * Sets OFXHEADER header. ! */ public void setOfxHeader(String ofxHeader) { *************** *** 38,41 **** --- 75,81 ---- } + /** + * Sets DATA header. + */ public void setData(String data) { *************** *** 43,46 **** --- 83,89 ---- } + /** + * Sets VERSION header. + */ public void setVersion(String version) { *************** *** 48,51 **** --- 91,97 ---- } + /** + * Sets SECURITY header. + */ public void setSecurity(String security) { *************** *** 53,56 **** --- 99,105 ---- } + /** + * Sets ENCODING header. + */ public void setEncoding(String encoding) { *************** *** 58,61 **** --- 107,113 ---- } + /** + * Sets CHARSET header. + */ public void setCharSet(String charSet) { *************** *** 63,66 **** --- 115,121 ---- } + /** + * Sets COMPRESSION header. + */ public void setCompression(String compression) { *************** *** 68,71 **** --- 123,129 ---- } + /** + * Sets OLDFILEUID header. + */ public void setOldFileUID(String oldFileUID) { *************** *** 73,76 **** --- 131,137 ---- } + /** + * Sets NEWFILEUID header. + */ public void setNewFileUID(String newFileUID) { *************** *** 78,86 **** } public String getOfxHeader() { return this.ofxHeader; } ! public String getData() { --- 139,153 ---- } + /** + * Gets OFXHEADER header. + */ public String getOfxHeader() { return this.ofxHeader; } ! ! /** ! * Gets DATA header. ! */ public String getData() { *************** *** 88,91 **** --- 155,161 ---- } + /** + * Gets VERSION header. + */ public String getVersion() { *************** *** 93,96 **** --- 163,169 ---- } + /** + * Gets SECURITY header. + */ public String getSecurity() { *************** *** 98,101 **** --- 171,177 ---- } + /** + * Gets ENCODING header. + */ public String getEncoding() { *************** *** 103,106 **** --- 179,185 ---- } + /** + * Gets CHARSET header. + */ public String getCharSet() { *************** *** 108,111 **** --- 187,193 ---- } + /** + * Gets COMPRESSION header. + */ public String getCompression() { *************** *** 113,116 **** --- 195,201 ---- } + /** + * Gets OLDFILEUID header. + */ public String getOldFileUID() { *************** *** 118,121 **** --- 203,209 ---- } + /** + * Gets NEWFILEUID header. + */ public String getNewFileUID() { Index: OFXFileWriter.java =================================================================== RCS file: /cvsroot/batchserver/Batch_IO_1.1/src/org/jmonks/batch/io/ofx/OFXFileWriter.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** OFXFileWriter.java 18 Oct 2006 03:19:16 -0000 1.1.1.1 --- OFXFileWriter.java 18 Oct 2006 23:04:01 -0000 1.2 *************** *** 29,49 **** /** * ! * @author Suresh Pragada */ public class OFXFileWriter extends FileWriter { protected OFXFileSpec fileSpec=null; private OFXWriterHelper writerHelper=null; private MessageSet currentMessageSet=null; private boolean writtenHeaderRecord=false; private static Logger logger=Logger.getLogger(OFXFileWriter.class); public OFXFileWriter(OutputStream fileOutputStream,FileSpec fileSpec) { this(new OutputStreamWriter(fileOutputStream), fileSpec); } ! public OFXFileWriter(Writer writer,FileSpec fileSpec) { --- 29,88 ---- /** + * <p> + * OFXFileWriter writes the ofx file using the submmited message sets + * and following the given file spec. It looks for the version of the OFX + * data block in needs to generate from the "version" attribute in the file spec. + * It none is mentioned it uses the default "1.6" OFX version. It does not supports + * the <i>createNextRecord</i> and <i>writeRecord</i> methods inherited from + * the FileWriter. It provides a method <i>createNextMessageSet</i> to create the + * message sets that can be written to the stream. It writes the message sets and + * messages immediately to the output stream to support the writing of large files. + * OFXHeaderRecord needs to be written before creating any message sets. + * </p> * ! * @author Suresh Pragada ! * @version 1.0 ! * @since 1.0 */ public class OFXFileWriter extends FileWriter { + /** + * Holds the OFX FileSpec. + */ protected OFXFileSpec fileSpec=null; + /** + * Holds the OFX Writer helper. + */ private OFXWriterHelper writerHelper=null; + /** + * Holds the recent message set reference. + */ private MessageSet currentMessageSet=null; + /** + * Flag tells whether header has been written to the stream or not. + */ private boolean writtenHeaderRecord=false; private static Logger logger=Logger.getLogger(OFXFileWriter.class); + /** + * Constructs the OFXFileWriter by accepting the outputStream + * and file spec. + * + * @param fileOutputStream Reference to the outputstream. + * @param fileSpec Reference to the file spec. + */ public OFXFileWriter(OutputStream fileOutputStream,FileSpec fileSpec) { this(new OutputStreamWriter(fileOutputStream), fileSpec); } ! ! /** ! * Constructs the OFXFileWriter by accepting the outputStream ! * and file spec. ! * ! * @param writer Reference to the writer. ! * @param fileSpec Reference to the file spec. ! */ public OFXFileWriter(Writer writer,FileSpec fileSpec) { *************** *** 55,61 **** } ! public void writeOFXHeaderRecord(OFXHeaderRecord headerRecord) { if(this.writtenHeaderRecord) throw new IllegalStateException("OFXHeaderRecord should be written only once."); --- 94,107 ---- } ! /** ! * Writes the OFX Headers represented by OFXHeaderRecord to the stream. ! * ! * @param headerRecord OFXHeaderRecord which holds ofx headers. ! * ! * @throws IllegalStateException If header is written already. ! */ public void writeOFXHeaderRecord(OFXHeaderRecord headerRecord) { + logger.trace("Entering writeOFXHeaderRecord = " + this.writtenHeaderRecord); if(this.writtenHeaderRecord) throw new IllegalStateException("OFXHeaderRecord should be written only once."); *************** *** 65,103 **** this.writtenHeaderRecord=true; } } public MessageSet createNextMessageSet(MessageSetType messageSetType) { if(!this.writtenHeaderRecord) throw new IllegalStateException("Header record should be written before creating any message sets."); ! if(this.currentMessageSet!=null) ! ((MessageSetWriter)this.currentMessageSet).finishedWritingMessages(); ! ! String messageSetImplClassName=(String)MessageSetDefinitions.getDefinitions().getMessageSetImpl(messageSetType); ! if(messageSetImplClassName!=null) { ! try { ! Object messageSet=Class.forName(messageSetImplClassName).newInstance(); ! ((MessageSetWriter)messageSet).initializeWriter(messageSetType, this.writerHelper); ! this.currentMessageSet=(MessageSet)messageSet; ! return this.currentMessageSet; } ! catch(Exception exception) ! { ! exception.printStackTrace(); ! logger.error("Unable to instantiate the configured messageset implementation " + messageSetImplClassName + ". Message =" + exception.getMessage()); ! throw new OFXStreamException("Unable to instantiate the configured messageset implementation " + messageSetImplClassName + ". Message =" + exception.getMessage()); } } else ! { ! logger.error("Unsupported MessageSet " + messageSetType.toString() + " has been requested."); ! throw new OFXStreamException("Unsupported MessageSet " + messageSetType.toString() + " has been requested."); ! } } ! public WriterRecord createWriterRecord(RecordType recordType) { --- 111,176 ---- this.writtenHeaderRecord=true; } + logger.trace("Exiting writeOFXHeaderRecord"); } + /** + * Creates the next message set to be written to the stream. Writer immediately + * start writing the message set and messages added to the message set there after + * to the stream. + * + * @param messageSetType Type of the message set to be created. + * + * @return Returns the requested message set, null, if writer is already closed. + * + * @throws OFXStreamException If there is any problem creating the message set. + */ public MessageSet createNextMessageSet(MessageSetType messageSetType) { + logger.trace("Entering createNextMessageSet"); if(!this.writtenHeaderRecord) throw new IllegalStateException("Header record should be written before creating any message sets."); ! if(this.writerHelper!=null) { ! if(this.currentMessageSet!=null) ! ((MessageSetWriter)this.currentMessageSet).finishedWritingMessages(); ! ! String messageSetImplClassName=(String)MessageSetDefinitions.getDefinitions().getMessageSetImpl(messageSetType); ! if(messageSetImplClassName!=null) { ! try ! { ! Object messageSet=Class.forName(messageSetImplClassName).newInstance(); ! ((MessageSetWriter)messageSet).initializeWriter(messageSetType, this.writerHelper); ! this.currentMessageSet=(MessageSet)messageSet; ! } ! catch(Exception exception) ! { ! exception.printStackTrace(); ! logger.error("Unable to instantiate the configured messageset implementation " + messageSetImplClassName + ". Message =" + exception.getMessage()); ! throw new OFXStreamException("Unable to instantiate the configured messageset implementation " + messageSetImplClassName + ". Message =" + exception.getMessage()); ! } } ! else ! { ! logger.error("Unsupported MessageSet " + messageSetType.toString() + " has been requested."); ! throw new OFXStreamException("Unsupported MessageSet " + messageSetType.toString() + " has been requested."); } } else ! this.currentMessageSet=null; ! ! logger.trace("Entering createNextMessageSet"); ! return this.currentMessageSet; } ! ! /** ! * This methos is not supported by OFXFileWriter. Use <i>createNextMessageSet</i> ! * to create the message sets. ! * ! * @throws java.lang.UnsupportedOperationException Thrown if there is any attempt to ! * call this method. ! */ public WriterRecord createWriterRecord(RecordType recordType) { *************** *** 105,113 **** } public void writeRecord(WriterRecord record) { ! throw new UnsupportedOperationException("OFXFileWriter not supports writeRecord method. Messages written into the messageset will be written to the file."); } public void close() { --- 178,196 ---- } + /** + * This methos is not supported by OFXFileWriter. Messages will be immediately + * written to the stream, when they are being added to the message sets. + * + * @throws java.lang.UnsupportedOperationException Thrown if there is any attempt to + * call this method. + */ public void writeRecord(WriterRecord record) { ! throw new UnsupportedOperationException("OFXFileWriter not supports writeRecord method. Messages written into the messageset will be written to the file immediately."); } + /** + * Closes the OFXFileWriter. + */ public void close() { *************** *** 126,135 **** --- 209,234 ---- + /** + * Helper class for the OFXFileWriter to write OFX Content based on the differnt + * parameters like version and special characters. + */ public class OFXWriterHelper { + /** + * Holds the writer. + */ private BufferedWriter writer=null; + /** + * Holds the version number. + */ private OFXVersion version=null; + /** + * Tells whether this writer have to write end tags or not. + */ private boolean needEndTag=true; + /** + * Constructs the OFXWriterHelper using given writer and version. + */ private OFXWriterHelper(BufferedWriter writer, OFXVersion version) { *************** *** 140,143 **** --- 239,245 ---- } + /** + * Write the start element. It adds the angle brackets to the given element name. + */ public void writeStartElement(String elementName) { *************** *** 153,156 **** --- 255,261 ---- } + /** + * Writes the given element name and value to the stream. + */ public void writeElement(String name, String value) { *************** *** 174,178 **** } } ! public void writeEndElement(String elementName) { --- 279,287 ---- } } ! ! /** ! * Writes the end element to the stream. Before writing it escapses the special ! * characters. ! */ public void writeEndElement(String elementName) { *************** *** 188,191 **** --- 297,303 ---- } + /** + * Writes the OFXHeaderRecord to the stream. + */ private void writeOFXHeaderRecord(OFXHeaderRecord headerRecord) { *************** *** 245,248 **** --- 357,363 ---- } + /** + * Closes the writer. + */ private void close(boolean writeEndDocumentTag) { |