DataBeans

DataBeans are Java objects used to carry a logical collection of data from one Java or system context to another.  For example, they are frequently used in enterprise architectures to carry data from a servlet or user interface component to an ejb container or back-end processing module.  They may also provide mechanisms for mapping data from one form to another.  For example, mapping between a set of Java variables and a protocol or XML String.


DataBean Inheritance Hierarchy

DataBean
  UIBean
  ObjectBean
    ViewBean
      ViewBeanPerson
      ViewBeanContent
      ViewBeanContent
TransportBean
 

DataBean

  1. Implements Serializable.
  2. Provides superclass for other individual DataBean types.
  3. Provides no actual function.

UIBean

  1. One of two (currently) subtypes of DataBean
  2. Transports data from control segment of servlet to first layer of model (i.e., ProcessUserActiion).
  3. Carries action to be performed.
  4. Carries user data obtained from QueryString (stored as Hashtable, accessed through getUserParam( param_name ) method.
  5. Carries reference to the back-end DataObject the action is directed toward (e.g., DBMS table).
  6. Carries system data obtained from HTTP or other source (stored as Hashtable, accessed through getSysParam( param_name ) method.

Comments:

  1. The consumer of a UIBean must know the particular parameters coming from the user interface in order to get to their associated values (e.g., that a form contains a field with name, name_first).
  2. Parameters are not order in any way.
  3. The object to which the UIBean is directed (i.e., ProcessUserAction) needs no other information from the servlet to carry out its function.

ObjectBean

  1. One of two (currently) subtypes of DataBean
  2. The superclass of ViewBean
  3. Carries content data for carrying out a function on a data object in the back-end (EJB Container) system.
  4. Carries type (currently unused) and target information.
  5. Conceptually, shifts from parameter orientation to a field and value orientation.  Thus, no getUserParam() method, but includes getValue( field_name ), isField( field_name ),  and getFields() methods.
  6. No concept of order for fields or values.

Comments:

  1. Data carried as a values Hashtable.
  2. getFields() and isField() methods based on values Hashtable, rather than separate objects.

ViewBean

  1. Subtype of ObjectBean
  2. The superclass of ViewBeans for individual types of data objects/dbms tables (e.g., Person and Content).  Thus, provides generic function that is supplemented in subclasses for individual types of data objects.
  3. Includes concept of order for values, carried in Vector of field names.
  4. Supports set of labels, each associated with a particular field (e.g., First Name for nameFirst).
  5. Supports a set of Values for Display as a set of Strings used for particular representations of data values (e.g., 3/29/40 for a particular Date, as opposed to March 29, 1940).
  6. Includes, and thereby generalizes, a getXml() method based on the Vector of field names.  Provides "core" xml in the form of a sequence of individual items.  Presumes this core xml will be embedded in other, contextual xml.  
      
      public java.lang.String getXML() {

        String xmlString = new String();

        for ( int i=0; i<this.getNumberOfFields(); i++ ) {

            String currentField = getField(i);
            String label = getLabel( currentField );
            String valueForDisplay = getValueForDisplay ( currentField );

            xmlString += "<field>";

            xmlString += "<label>" + label + "</label>";
            xmlString += "<name>" + currentField + "</name>";
            xmlString += "<value>" + valueForDisplay + "</value>";

            xmlString += "</field>";
        }

        return xmlString;

    }

  7. Individual items marked using the following xml tags:
      <field>
          <label></label>
          <name></name>
          <value></value>
      </field>

ViewBean SubClasses

  1. Subtype of ViewBean
  2. Provide views for specific data objects/tables (e.g., Person and Content).
  3. Implementation is very simple, since most of the function is provided by the ViewBean superclass.
  4. Key function is provided by an init() method, called as part of the subclasses constructor.  This method "localizes" the subclass for the particular data object or table by setting the specific field names of the superclasses  fields Vector, therby fixing its order as well.  Also defines the particular display labels.  See the following code example:

      public void init() {

          setTarget( ObjectBean.PERSON );
          setTargetName( "Person" );

          setField ( "personID" );

          setField ( "nameFirst" );
          setField ( "nameMiddle" );
          setField ( "nameLast" );

          setField ( "address" );
          setField ( "city" );
          setField ( "state" );
          setField ( "zip" ); 

          setField ( "phoneHome" );
          setField ( "phoneWork" );
          setField ( "phoneFax" );
          setField ( "phoneCell" );

          setField ( "email" );
          setField ( "url" );

          setField ( "dateCreated" );
          setField ( "dateModified" );


          setLabel ( "personID", "PersonID" );

          setLabel ( "nameFirst", "First Name" ); 
          setLabel ( "nameMiddle", "Middle Name" ); 
          setLabel ( "nameLast", "Last Name" );

          setLabel ( "address", "Address" );
          setLabel ( "city", "City" ); 
          setLabel ( "state", "State" ); 
          setLabel ( "zip", "Zip Code" );

          setLabel ( "phoneHome", "Home Phone" );
          setLabel ( "phoneWork", "Work Phone" ); 
          setLabel ( "phoneFax", "Fax" ); 
          setLabel ( "phoneCell", "Cell Phone" );

          setLabel ( "email", "Email" );
          setLabel ( "url", "URL" );

          setLabel ( "dateCreated", "Date Created" ); 
          setLabel ( "dateModified", "Date Modified" ); 

      }

TransportBean

  1. Subtype of java.util.Vector
  2. Used to carry multiple objects (e.g., ObjectBeans) from one context to another (e.g., ProcessUserAction <==> EJB Container).
  3. Includes action, response code, response message, and unique identifier.
  4. Supports sequential access: getCurrent, getFirst(), getLast, getNext, getPrevious methods.
  5. Maintains state between accesses.

Example System

An example system that uses the DataBeans discussed here is the  work-in-progress  Object-Oriented Content system.