Monday, February 28, 2005

Playing With OFX Again

During the past few days I played with OFX again, this time with castor. Below are my findings:
  • I was only able to make 'type' method working. The easiest way to make it work (I think) is to create custom binding file with the content below:
    <?xml version="1.0"?>
    <cbf:binding 
      xmlns:cbf="http://www.castor.org/SourceGenerator/Binding"
      defaultBindingType='type'>
    </cbf:binding>
    
  • I had to disable class descriptors generation (-nodesc option). For some reason (parameter mismatch in method signatures), classes generated with class descriptors would not compile.
Apart from the above, castor worked great. It may save you from lots of manual coding. For example, reading a bank transaction list may be as easy as:
public class Demo {
  private static final String FILE_TO_READ =
    "dat/test/download.xml";
  public static void main(String[] args) 
    throws FileNotFoundException,
      MarshalException, ValidationException {
    FileReader fileReader = 
      new FileReader(new File(FILE_TO_READ));
    StatementTransactionResponse sr =
      (StatementTransactionResponse) Unmarshaller.unmarshal(
        StatementTransactionResponse.class, 
        fileReader);
    // Do whatever with your transaction list :-)
  }
}