Jan 15

Okay, so its not the highlight of the framework, but its something. Just an example to show that it’s working, both for you and for myself.

You can download the source, and I’ll post here the Recipe and Step classes (the only classes in the application except the Form). There was no XSD needed to read or write the XML document, and as you can see, it’s perfectly readable by any application.

X2J in action


// lang java
@Name("three-step-recipe")
@Root
public class Recipe {
    private int prepTime;
    private String name;
    private Step[] steps;

    @Attribute
    public int getPreparationTime() {
        return prepTime;
    }

    @Attribute
    @Mandatory
    public String getName() {
        return name;
    }

    @FixedSequence(3)
    @Element
    public Step[] getSteps() {
        return steps;
    }
  }
}

@ComplexType
public class Step {
    private String title;

    @Attribute
    @Mandatory
    public String getTitle() {
        return title;
    }
}

Obviously there are setters to complement the getters. I removed them so that the page won’t be too stuffed with code.

And again, you can find the X2J project here.

PS until I manage to instsall this code highlighter, the code text might appear dull and small. Apologies ahead.

Related Posts with Thumbnails
Share

2 Responses to “X2J in action”

  1. Contest coming up at Chaotic Java Says:

    [...] As an attempt to promote X2J, my XML easy binding framework, I might start up a fun contest soon. The contest would be about finding bugs and solutions to bugs (not really hard to find Bugs, but looking into a code I’ve written is not considered as fun), and about suggesting features and feature implementation suggestions. [...]

  2. Ophir Radnitz Says:

    I really enjoy reading your blog, keep up the good work!

    As for the syntax highlighter plugin, I’d like to recommend (as an alternative, should you choose to consider one) GeSHi. It is well supported, very active and supports a lot of language syntaxes. I use it happily on a Drupal installation, but I see there’s a WordPress plugin for it too.

    http://qbnz.com/highlighter/
    http://www.thedevproject.com/projects/wordpress-geshi-plugin/