next up previous contents
Next: Storing in the Database Up: In the Beginning Previous: MapToJava aka Dave Knull   Contents

Basic Class Description

Our example will walk through creation of a Class User, and building upon each step we can go from a simple class description to generating a complex data storage persistence layer. The first entry to create a user goes as follows
  <class name="org.ephman.examples.user.generated.User">
    <description>This class represents a User</description>
    <field name="userId" type="string" required="true"/>
    <field name="userName" type="string"/>
  </class>
This describes a class and it's fields3.5. Running MapToJava on this XML file will produce a java file in org/ephman/examples/user/generated/ called User.java.3.6 This class will have two protected member variables _userId and _userName, both of type java.lang.String3.7. Also public routines
  public String getUserId ()
  public void setUserId (String foo)
  public String getUserName ()
  public void setUserName (String foo)
will be generated for get/set operations on these fields.

Also note the 'description' tag this text is placed at the top of the class (good for Javadoc), and required="true" was placed on the userId field. This won't generate any extra Java code but is a directive to the XML Marshaller (and SQL, Validation) that this field must exist.



2002-03-05