Extracting data from IterativeModels indirectly

Bensch Jeroen <[email protected]>
Newsgroups gmane.comp.java.enhydra.barracuda.general
Message-ID <F471DF278BF9D4119F5700508BB3647A0421AEBF@beannts01.bean.capco.com>
I just finished typing this mail when I saw Diez' answer coming in.
...


Hi,

I figured my previous question could have been done quite a bit more
descriptive...

Hereby you should find a simplified class-model of how our current
applications looks like,
part of the application at least. Where CarModel just extends VehicleModel,
VehicleModel has a PassengerModel that can be iterated (more than 1
passenger possible). And finally CarModel has a SupplierModel with a single
attribute, the supplier's name.

Whenever we need, for instance, the supplier's name of a car, this is how we
write the directive:

Dir:Get_Data.Car.supplier$name

(CarModel's getName() returns "Car")

And the relevant part of the getItem-method in CarModel goes somewhat like
this:

public Object getItem(String key) {
  if (key.startsWitch("supplier")) {
    key = key.substring(key.indexOf("supplier$") + ("supplier$").length());
    if (suppliermodel == null) {
      return "";
    } else {
      return suppliermodel.getItem(key);
    }
  }
}

This way we can redirect Get_Data directives for models attached to the
actual queried model.
If the item you want to get starts with "supplier" (now we know we have to
redirect to the suppliermodel, and fetch the data there rather than in the
current model), strip "supplier$" off of the key, and execute the
getItem-method in our suppliermodel.

This works. That is to say, it works if our SupplierModel doesn't implement
IterativeModel.

Now, the problem is, what if I wanted to iterate over the PassengerModel of
our car, I wouldn't know how to do it.

CarModel has, as it extends VehicleModel, an attribute passengermodel.

But Dir::Iterate_Start.Car$Passenger (or anything like it) won't work
because Barracuda expects a String returned by one of the Models' getName()
methods.

I can hear you ask yourself, why such a big fuzz over something that is
perfectly possible by just adding the SupplierModel straight to, for
instance, a BTemplate and let Barracuda render it the way it's used to.
Instead of trying to access it via the model that delegates it, in HTML.

The reason is that we're trying to write a code-generator for our value
objects, forms, models and mapping, based on one XML file.
Short extract:

<CLASS name="Vehicle">
  <FIELD multiple="true" name="passenger" type="Passenger"/>
</CLASS>
<CLASS extends="Vehicle" name="Car">
  <FIELD multiple="false" name="supplier" type="Supplier"/>
</CLASS>

We notice that there can only be one supplier for a Car (multiple="false")
and add the according Model in to our CarModel knowing that we can access it
in HTML by using '$'.
Vehicle however can contain multiple passengers, so the PassengerModel will
implement IterativeModel, we add it to VehicleModel but until now can't find
a way to iterate it in our HTML.

Note: Because we include the SupplierModel in CarModel there's no need to
add SupplierModel to the BTemplate, because we can redirect Get_Data's.
Iterated Models pose the difficulty.
diagram.gif (image/gif, 6 KB) - not displayed
InterScan_Disclaimer.txt (text/plain, 631 B)
************************************************************************
The information in this email is confidential and is intended solely
for the addressee(s).
Access to this email by anyone else is unauthorised. If you are not
an intended recipient, please notify the sender of this email 
immediately. You should not copy, use or disseminate the 
information contained in the email.
Any views expressed in this message are those of the individual
sender, except where the sender specifically states them to be
the views of Capco.

http://www.capco.com
***********************************************************************
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.