commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Roll <>
Subject digester - How do I call methods on objects further up the stack
Date Tue, 15 Apr 2003 21:45:07 GMT
I am struggling with trying to figure out how to get the digester class
working with a particular XML file.  The problem I have is that the XML
format does not readily support our bean structure.  Without having to
create custom beans to support this, I don't think the default digester
rules will allow me to accomplish my goal.  So... I'm thinking I need a
custom RULE that will do what I want, but I'm not sure how to go about it...

My beans are structured as follows:
ShopRequests contains ArrayList of ShopRequest
	ShopRequest contains a Location 
	ShopRequest contains an ArrayList of HierarchyLevels

I can create the shoprequest and the location just fine, but now I want to
call a method from ShopRequest to add a HierarchyLevel object to the list
everytime the <level> tag is encountered.  As the hierarchy levels are not
part of the Location bean, I cannot call the addSetNext method as you
typically would.  Also, I cannot figure out how to call the method in
ShopRequest for each level that is found.. In the sample I provided, it is
only called once.  Any gurus out there I could sure use a point in the right
direction!..   I have added comments around the problem code.

The XML File I have is in the following format:

   <?xml version="1.0" encoding="UTF-8"?>
   <!DOCTYPE ShopRequests SYSTEM "ShopRequests.dtd">
               <level num="1">The Retail Store</level>
               <level num="2">MB</level>
               <level num="3">03020015</level>
            <address>13 Broadway</address>
            <landmark>Some where over there</landmark>

I have rules defined as follows:

	dig.addObjectCreate("ShopRequests", "");
      dig.addObjectCreate("ShopRequests/visit", "");
      dig.addBeanPropertySetter("ShopRequests/visit/location/city", "city");
      dig.addCallMethod("ShopRequests/visit", "setHierarchyName", 1);
      dig.addCallParam("ShopRequests/visit/location/hierarchy/name", 0);
	// This is the problem section.  How can I call addHierarchyNode in
	// ShopRequests object for every instance of <level>?
      String[] ctypes = {"java.lang.Integer", "java.lang.String"};
      dig.addCallMethod("ShopRequests/visit", "addHierarchyNode", 2,
      dig.addCallParam("ShopRequests/visit/location/hierarchy/level", 0,
      dig.addCallParam("ShopRequests/visit/location/hierarchy/level", 1);

	// End of problem section
      dig.addSetNext("ShopRequests/visit/location", "setLocation");
	dig.addSetNext( "ShopRequests/visit", "addShopRequest" );

Greg Roll

View raw message