blob: 194cb5b5fb5c87f419f92f32efe00782fa2e437b [file] [log] [blame]
<?xml version="1.0" encoding="iso-8859-1"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<page>
<content>
<p>
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.
</p>
<h2>Interfaces</h2>
<p>
Here's the interface of the DatabaseFacade class, which is used by our
Flowscript code to "talk" to the Java beans:
<pre class="code">
/** 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();
</pre>
</p>
<p>
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.
<pre class="code">
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);
</pre>
</p>
<p>
Here's the TaskCommentBean interface:
<pre class="code">
public int getId();
public Date getDate();
public void setDate(Date m_date);
public String getComment();
public void setComment(String m_comment);
</pre>
</p>
<h2>Access from Flowscript</h2>
<p>
Here's a code excerpt showing how Flowscript code can access Java classes.
</p>
<pre class="code">
var db = Packages.org.apache.cocoon.samples.tour.beans.DatabaseFacade.getInstance();
...
list = db.getTasks();
</pre>
<p>
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.
</p>
</content>
</page>