Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 22nd, 2012  |  syntax: None  |  size: 1.37 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Digester rules for a string list
  2. <response>
  3.   <total>1000</total>
  4.   <warning>warning1</warning>
  5.   <warning>warning2</warning>
  6. </response>
  7.        
  8. public class Response {
  9.     private BigDecimal total;
  10.  
  11.     private List<String> warnings=new ArrayList<String>();
  12.  
  13.     public List<String> getWarnings() {
  14.         return warnings;
  15.     }
  16.  
  17.     public void setWarnings(List<String> warnings) {
  18.         this.warnings = warnings;
  19.     }
  20.  
  21.     public BigDecimal getTotal() {
  22.         return total;
  23.     }
  24.  
  25.     public void setTotal(BigDecimal total) {
  26.         this.total = total;
  27.     }
  28.  
  29.     public void addWarning(String warning) {
  30.         warnings.add(warning);
  31.     }
  32. }
  33.        
  34. Digester digester = new Digester();
  35. digester.setValidating( false );
  36. digester.addObjectCreate( "response", Response.class );
  37. digester.addBeanPropertySetter( "response/total", "total" );
  38. digester.addObjectCreate("response/warning","warnings", ArrayList.class);
  39. digester.addCallMethod("response/warning", "add", 1);
  40. digester.addCallParam("response/warning", 0);
  41. ret = (Rate)digester.parse(new ByteArrayInputStream(xml.getBytes()));
  42.        
  43. Digester digester = new Digester();
  44.     digester.setValidating( false );
  45.     digester.addObjectCreate("response", Response.class );
  46.     digester.addBeanPropertySetter("response/total", "total" );
  47.     digester.addCallMethod("response/warning", "addWarning", 1);
  48.     digester.addCallParam("response/warning", 0);