As already mentioned, our Java beans are dead simple and not very robust. The "database" is simply held in memory, loaded with simulated data at startup.
Here's the interface of the DatabaseFacade class, which is used by our Flowscript code to "talk" to the Java beans:
/** access the Database */ public static DatabaseFacade getInstance(); /** get our list of tasks * @return a List of TaskBean objects */ public List getTasks(); /** get a single TaskBean */ public TaskBean getTaskBeanById(int id) throws Exception; /** get this object's version */ public String getVersion();
Here's the interface of the TaskBean class, our main "task" object. It is basically a Java Bean with one read-only and three read-write properties.
public int getId(); public String getTaskName(); public void setTaskName(String m_taskName); public String getAssignedTo(); public void setAssignedTo(String m_assignedTo); /** @return a List of TaskCommentBean objects */ public List getComments(); /** @param c a List of TaskCommentBean objects */ public void setComments(List c);
Here's the TaskCommentBean interface:
public int getId(); public Date getDate(); public void setDate(Date m_date); public String getComment(); public void setComment(String m_comment);
Here's a code excerpt showing how Flowscript code can access Java classes.
var db = Packages.org.apache.cocoon.samples.tour.beans.DatabaseFacade.getInstance(); ... list = db.getTasks();
Simple enough. The "official" way of accessing Java components in a Cocoon application would be to use the Avalon lookup mechanisms, but this wouldn't add much to our example so we took the easy way here.