User's Manual

52 Chapter 8. WAF Application Development Tutorial
8.7. Java Domain Objects
Each object type will have a corresponding domain class written in Java. The domain class exists
to provide a Java-native API to your object type’s data and to behaviors that are specific to your
application. Refer to Chapter 2 WAF Component: Persistence.
package com.example.binder;
import com.arsdigita.persistence.DataCollection;
import com.arsdigita.persistence.DataObject;
import com.arsdigita.util.Assert;
import com.arsdigita.web.Application;
import org.apache.log4j.Logger;
/**
* A collection of <code>Note</code>s.
*
* @see com.example.binder.Note
* @author Justin Ross
*/
public class Binder extends Application {
private static final Logger s_log = Logger.getLogger(Binder.class);
public static final String BASE_DATA_OBJECT_TYPE =
"com.example.binder.Binder";
static final String NOTES = "notes";
protected String getBaseDataObjectType() {
return BASE_DATA_OBJECT_TYPE;
}
protected Binder(final DataObject data) {
super(data);
}
/**
* Returns all the Notes associated with this Binder.
*
* @return A <code>NoteCollection</code> of Note objects
*/
public final NoteCollection getNotes() {
return new NoteCollection((DataCollection) get(NOTES));
}
/**
* Adds <code>note</code> to the set of notes tracked by this
* <code>Binder</code>.
*
* @param note The <code>Note</code> to remove
*/
public void addNote(final Note note) {
Assert.exists(note, Note.class);
if (s_log.isDebugEnabled()) {
s_log.debug("Adding note " + note + " to " + this);
}
add(NOTES, note);
}