1 21 22 package nu.xom.samples; 23 24 import java.util.ArrayList ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import java.util.Map ; 28 29 import nu.xom.Attribute; 30 import nu.xom.Element; 31 32 33 48 public class Budget { 49 50 private List agencies = new ArrayList (); 51 private String year; 52 53 public Budget(String year) { 54 this.year = year; 55 } 56 57 public void add(Agency agency) { 59 if (!agencies.contains(agency)) agencies.add(agency); 60 } 61 62 public void add(Map lineItem) { 63 64 String agencyName = (String ) lineItem.get("AgencyName"); 65 String agencyCode = (String ) lineItem.get("AgencyCode"); 66 String treasuryAgencyCode 67 = (String ) lineItem.get("TreasuryAgencyCode"); 68 Agency agency = Agency.getInstance(agencyName, agencyCode, 69 treasuryAgencyCode, year); 70 this.add(agency); 71 72 String bureauName = (String ) lineItem.get("BureauName"); 73 String bureauCode = (String ) lineItem.get("BureauCode"); 74 Bureau bureau = Bureau.getInstance(bureauName, bureauCode, 75 agencyCode, year); 76 agency.add(bureau); 77 78 String accountName = (String ) lineItem.get("AccountName"); 81 String accountCode = (String ) lineItem.get("AccountCode"); 82 String category = (String ) lineItem.get("BEACategory"); 83 Account account = Account.getInstance(accountName, 84 accountCode, category, bureauCode, agencyCode, year); 85 bureau.add(account); 86 87 String subfunctionTitle = (String ) lineItem.get("SubfunctionTitle"); 90 String subfunctionCode 91 = (String ) lineItem.get("SubfunctionCode"); 92 String yearKey = year; 93 if (!yearKey.equals("TransitionalQuarter")) { 94 yearKey = "Y" + year; 95 } 96 long amount 97 = 1000L * Long.parseLong((String ) lineItem.get(yearKey)); 98 Subfunction subfunction = new Subfunction(subfunctionTitle, 99 subfunctionCode, amount); 100 account.add(subfunction); 101 102 } 103 104 public Element getXML() { 105 106 Element budget = new Element("Budget"); 107 budget.addAttribute(new Attribute("year", String.valueOf(year))); 108 Iterator iterator = agencies.iterator(); 109 while (iterator.hasNext()) { 110 Agency agency = (Agency) iterator.next(); 111 budget.appendChild(agency.getXML()); 112 } 113 return budget; 114 115 } 116 117 } | Popular Tags |