Model interaction

This document describes how Bishop converts HTTP request variables into Java object and how to invoke methods on the model (business objects).

WebMacro vs Bishop

If WebMacro transform the java object into html, Bishop does something like the opposite. Bishop converts HTTP request variables into real java object. These object can then be used as arguments to methods on the business model. Thus eliminating the need for the global Hashtable, or the context as it is called in WebMacro.

Parameter conversion

As mentioned elsewhere, Bishop is able to convert HTTP request variables into ordinary Java objects. While this might sound a bit like magic at first, doesn't mean that it is hard to use.

The parameter conversion is primarily used when invoking model methods. If the method setAgeForUser(String name, int age) should be invoked, we need 2 variables. These variables are supplied by the client as HTTP request variables and are accessible via the servlet api as Strings. The user has filled out a form that contained one field with named "name" that contains the name of the user who's age should be changed and one variabled "age" with the value for age.

When invoking the method setAgeForUser, Bishop get the variables "name" and "age" from the HTTP request and converts them into their Java representation. Ie the name is a java.lang.String and the age variable is an int. These new objects are then supplied as arguments when the method is called.

The Bishop code for this conversion and invokation would be:

<bishop>
  <invoke object="users" method="setAgeForUser">
    <in name="name" type="java.lang.String" default-value="john doe"/>
    <in name="age" type="int" default-value="42"/>
  </invoke>
</bishop>
	    

If the client for some reason doesn't provide these request variables, is it possible to defined a default-value for each object. This is shown in the code above.

Objects

A model invokation can take existing objects as arguments as well as HTTP request varibles. For example, the result from one invokation can be used as input to another:

<bishop>
  <invoke object="inventory" method="getItem">
    <in name="itemId" type="java.lang.String"/>
    <out name="itemToAdd"/>
  </invoke>
  <invoke object="shoppingCart" method="addItem">
    <in name="itemToAdd" type="webshop.Item"/>
  </invoke>  
</bishop>
	    


[home] | [introduction] | [webmacro] | [model interaction] | [developer's guide] | [reference] | [terms and definitions]