Ancient Programming

What I encounter in my software part of life is in danger of being commented upon here

  • Jacob von Eyben

    MeAfter finishing my education in 2002 I have been working as a Systems Architect for the danish consulting company Nordija. My primary area is the Java platform with particular interest for what could be called lightweight architecture. That includes technologies like Spring, EJB 3, Hibernate, JPA, Acegi etc. Besides the Java platform I have interest in other languages like Ruby, Actionscript 3 (for flex development) and others.

Fixedformat4j 1.2.0 released

Posted by jeyben on June 12th, 2008

This evening I released a new version of fixedformat4j containing improved error reporting when failing to parse data using the FixedFormatManager.

The lack of good error reporting was a bit of a pain. It was not easy to see where in the parsing failed and it was not possible to get a complete list of format instructions.

A new ParseException is now thrown which contains the nessesary information.

See example of the new and improved stacktrace:

com.ancientprogramming.fixedformat4j.format.ParseException: failed to parse 'barfooba' at offset 16 as java.util.Date from 'foobarfoobarfoobarfoobar'. Got format instructions from com.ancientprogramming.fixedformat4j.format.impl.MyRecord.getDateData. See details{FormatContext{offset=16, dataType=java.util.Date, formatter=com.ancientprogramming.fixedformat4j.format.impl.ByTypeFormatter}, FormatInstructions{length=8, alignment=LEFT, paddingChar=' ', fixedFormatPatternData=FixedFormatPatternData{pattern='yyyyMMdd'}, fixedFormatBooleanData=FixedFormatBooleanData{trueValue='T', falseValue='F'}, fixedFormatNumberData=FixedFormatNumberData{signing=NOSIGN, positiveSign='+', negativeSign='-'}, fixedFormatDecimalData=FixedFormatDecimalData{decimals=2, useDecimalDelimiter=false, decimalDelimiter='.'}}}
 at com.ancientprogramming.fixedformat4j.format.impl.FixedFormatManagerImpl.readDataAccordingFieldAnnotation(FixedFormatManagerImpl.java:179)
 at com.ancientprogramming.fixedformat4j.format.impl.FixedFormatManagerImpl.load(FixedFormatManagerImpl.java:70)

Feel free to download the latest version and take a look at the changelist.

2 Responses to “Fixedformat4j 1.2.0 released”

  1. Daniele Says:

    Hi. I have found and tried Fixedformat4j 1.1.1 today (no 1.2.0 on maven2 repo to date…)

    I really like the api and I would like to integrate in the simple mechanism it provides to read field, also my custom validation.

    To say: I would like to have a string validator that check that the strings does not contains character like points and such. Or, that a Date is valid and a day 99 is not accepted (while JDK DateFormatter accept it and just updates the month).

    I would Like to write my custom annotation, or use FixedFormatPattern that could accept a regex and validate it in the StringFormatter implementation.

    What I am asking are not new features but if there is a way to add a custom Formatter. Here we have tried to find some entry point without any success. You have any advice?

    Thanks and congratulation for nice work.

  2. jeyben Says:

    @Daniele: I have requested the 1.2.0 to be uploaded to ibiblio two days ago. It usually takes a week for them to process the jira upload request.
    In the meantime you can download the jar manually and put it in your project repository.

    About your custom formatter request it is already possible. I just haven’t made thorough documentation on this topic yet.

    But what you have to do is implement the FixedFormatter interface (you could extend the StringFormatter and override the asString asObject methods with your validation code). Each formatter will have all the annotated data available through a FormatInstructions object.

    The current StringFormatter implementation looks like this and you can access the pattern through the FormatInstructions object:

    public String asString(String string, FormatInstructions instructions) {
      String result = null;
      if (string != null) {
        result = string;
      }
      return result;
    }
    

    You can use your custom formatter by adding it to the Field annotation like this:

    @Field(offset = 50, length = 10, align = Align.RIGHT, paddingChar = '0', formatter = CustomFormatter.class)
    

    I hope that helped you.

    Your validation idea is good. I will find a way to implement it in the 1.3.0 release. Feel free to send me your implementation thoughts.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>