July 15, 2003

Java Beans

In Java there is a component model called Java Bean that is used all over the place. They are used in GUIs and in template languages (webmacro and Jakarta Velocity). I'm using the bean model for web applications and web services.

The major features I use are the get and set methods that access properties of an object. For instance, take a Circle object that has the following properties:

  • Color
  • Radius

To make the class a Java Bean, you'd need to have something similar to this:

class Color
{
   String m_color;
   int m_radius;
   public Color() {}
   String getColor() { return m_color; }
   void setColor(String color) { m_color = color; }
   int getRadius() { return m_radius; }
   void setRadius(int radius) { m_radius = radius; }
}

This can get tedious very quickly especially when you have a large number of properties you want to set & get. And if you're doing commenting, it's a real hassle.

So I wrote this quick and dirty Java program that takes a file with the list of variables and their types and names. It then creates a commented class that has all the appropriate get/set methods.

Posted by Sam at July 15, 2003 2:30 PM
Comments
Post a comment









Remember personal info?