commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Roll <gr...@ServiceIntelligence.com>
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">
   <ShopRequests>
      <visit>
         <location>
            <hierarchy>
               <name>Retail</name>
               <level num="1">The Retail Store</level>
               <level num="2">MB</level>
               <level num="3">03020015</level>
            </hierarchy>
            <site>03020015</site>
            <address>13 Broadway</address>
            <city>Winnipeg</city>
            <postcode>n0n0n0</postcode>
            <phone>666-1234</phone>
            <landmark>Some where over there</landmark>
         </location>
      </visit>
   </ShopRequests>


I have rules defined as follows:

	dig.addObjectCreate("ShopRequests", "com.xxx.ShopRequests");
        
      dig.addObjectCreate("ShopRequests/visit", "com.xxx.ShopRequest");
      dig.addBeanPropertySetter("ShopRequests/visit/v_request_type",
"requestType");
                
      dig.addObjectCreate("ShopRequests/visit/location",
"com.xxx.Location");
      dig.addBeanPropertySetter("ShopRequests/visit/location/site",
"siteNum");
      dig.addBeanPropertySetter("ShopRequests/visit/location/address",
"address1");
      dig.addBeanPropertySetter("ShopRequests/visit/location/city", "city");
      dig.addBeanPropertySetter("ShopRequests/visit/location/postcode",
"postalCode");
      dig.addBeanPropertySetter("ShopRequests/visit/location/phone",
"phone");
      dig.addBeanPropertySetter("ShopRequests/visit/location/landmark",
"landmark1");
        
      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
the 
	// ShopRequests object for every instance of <level>?
      String[] ctypes = {"java.lang.Integer", "java.lang.String"};
      dig.addCallMethod("ShopRequests/visit", "addHierarchyNode", 2,
ctypes);
      dig.addCallParam("ShopRequests/visit/location/hierarchy/level", 0,
"num");
      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

Mime
View raw message