Bean Builder II: Modeling Java Beans

On a previous entry the requirements for BeanBuilder were sketched. The basic idea is to use a configuration file as a poor-man way to model a hierarchy of JavaBeans, and then generate Java source code from that.
So, what format should I use for this configuration file? Mmmm... there're lots of options. Let me review some of them.
XDoclet...
A simple approach could be to use plain Java files annotated with Xdoclet tags. The problem is that XDoclet seems to be dead (version 1.2.2 was released in 2004!), and I won't resurrect it just to build some plain POJOS, right?
... or Eclipse EMF...
Another option would be, of course, to use the Eclipse Modeling Framework. Eclipse's EMF seems appealing, but too heavy for just building some JavaBeans, right?. A quick look at Eclipse EMF reveals:
While EMF uses XMI (XML Metadata Interchange) as its canonical form of a model definition[1] , you have several ways of getting your model into that form:
- Create the XMI document directly, using an XML or text editor
- Export the XMI document from a modeling tool such as Rational Rose
- Annotate Java interfaces with model properties
- Use XML Schema to describe the form of a serialization of the model Eclipse EMF Overview
Wait, wait. I have to model my JavaBeans using Rational Rose? No way, dude!
... or Java annotations...
Someone suggested using Java annotations for describing what my JavaBeans should look like. I could use @JavaBean and @Property and @BoundProperty or whatever.
That's an interesting approach, but if I annotate Java source code with annotations I would depend on the annotations, right? And that violates one of my requirements: have as little dependencies as possible. Can we make any better?
... or a Domain Specific Language...
Another approach would be creating a Domain Specific Language for building JavaBeans.
I could do that quickly with, say, Scheme or Lisp.
But, you know, I think there's a better approach:
... or XML Schemas (and or Relax NG)
Another approach is using XML Schema files. These seem to be quite popular. Some benefits I can think of:
- Good XML Schema editors out there. NetBeans' is terrific!.
- Lots of existing public repositories of XML Schemas that I can use to model my JavaBeans. From "Bookmarks" to "VectorImages", lots of stuff out there just ready to use.
- No dependencies at all. I mean, just download the XML Schema (or create a new one) and I'm all set.
- JAXB code generation. Of course. I can use XML Schemas or Relax NG to define how my JavaBeans are going to look like.
So, unless you have a better alternative, I think I'll choose XML Schemas for defining the structure of the generated JavaBeans.
Happy bean-building!
Antonio





as I understand you correctly you would like to simply enchance the jaxb resulting classes with the propertysupport, etc. ?
In respect to Java annotations, you could have a compile time dependency, but not a runtime dependency. Lombok (http://projectlombok.org/index.html) might be worth looking at.
I think you can use castor API with a few velocity code to transform just an xml description to JavaBean.
I use to do this to generate EJB3 components form just an XML description.
NetBeans does not support Relax NG...
@psychollek
Yes, I'd like to enhance resulting classes with propertysupport or with any other stuff I may consider appropriate (more on this later on).
@Simon
I know about Lombok, but I'm not very keen on annotations. I may give it a second try later on.
@Arist
I know of castor. I'll explore castor in the next entry.
@hantsy
I know. I'm not too worried about Relax NG support...yet. More on this later on.
Thanks all for your hints!!
Cheers, Antonio