Joda - Next Generation Beans

Project
   Home
   SourceForge
   News
   FAQs
   Licence

Joda Time
   Time home

Joda Primitives
   Primitives home

Joda Beans
   Beans home
   Problem statement
   Design overview
   Getting started
   Swing binding
   XML input/output
   XPath access
   API Javadoc

Download
   Source
   CVS

Contributing
   Feedback
   Volunteer
   Contributors

 

 

 

 

 

 

 

 

Design overview

The design

The Joda framework's public API is defined principally as interfaces. These are modelled around the concepts of JavaBeans, but with enhanced capabilities.

Bean

Bean is the main interface extended by domain model interfaces. Bean holds a Map of Property objects which can be queried by generic frameworks without reflection. Each property will have a get and set methods as with a normal JavaBean plus the third method which accesses the Property object for that property. PropertyFactory is used to create the application's object from the interface. For example:

public interface Person extends Bean {
  StringProperty surname();
  String getSurname();
  void setSurname(String surname);
}

Note that for simple beans, there is no need to write a class, just the interface. The class is generated at runtime using the Java 1.3 Proxy class. In the future, Apache BCEL could be used to provide even better runtime code generation.

Property

Property is the superinterface for properties on a Bean. A property has a name and type. It also supports the basic event listener behaviour and the ability to dynamically set the property as unmodifiable. Subinterfaces are defined for the common types in Java, such as String, Boolean, List and Map.

External functions

Building upon the Bean and Property classes are external functional classes. Currently these have been developed in the areas of SAX reading and writing, Swing bindings and XPath access. For example, to output the Person defined above as XML use:

Person person = (Person) JodaFactory.create(Person.class);
person.setSurname("Colebourne");
new XMLOutputter().output(person);
This will produce the XML:
<Person type="org.joda.Person">
  <surname>Colebourne</surname>
</Person>

The XML handling will cope with beans linked to other beans, including recursive setups, where the XML ID/IDREF functionality is used. A SAXHandler also exists, that can read in the XML document and recreate the Bean. In particular, the XML handling will manage numbers, booleans and dates, converting to and from strings.

Other features

  • Each Property and Bean has an attribute Map. This is particularly useful for GUI error handling, as it allows an error to be associated with the property that caused it.
  • The Map of Property objects is also dynamic. This allows a program to add properties to an object at runtime if it needs to even if they weren't defined in the original interface. This has great potential to add to the flexibility of an interface, by allowing extra parameters to be passed in that weren't envisaged when the system was first designed.
  • The Joda system is defined by interfaces, thus it picks up the ability to support multiple inheritance. This can improve other parts of the system by encouraging tight interfaces to be specified as the input parameters.