1 21 22 package nu.xom.samples; 23 24 import java.util.ArrayList ; 25 import java.util.HashMap ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 import java.util.Map ; 29 30 import nu.xom.Element; 31 32 33 48 public class Bureau { 49 50 private String code; 53 private String name; 54 private String year; 55 private String agencyCode; 56 57 private List accounts = new ArrayList (); 58 59 private static Map instances = new HashMap (); 60 61 private Bureau(String name, String code, String agencyCode, 64 String year) { 65 66 this.name = name; 67 this.code = code; 68 this.agencyCode = agencyCode; 69 this.year = year; 70 71 } 72 73 public static Bureau getInstance(String name, String code, 74 String agencyCode, String year) { 75 76 String key = agencyCode+" "+code+" "+year; 77 Bureau bureau = (Bureau) instances.get(key); 78 if (bureau == null) { 79 bureau = new Bureau(name, code, agencyCode, year); 80 instances.put(key, bureau); 81 } 82 83 return bureau; 84 85 } 86 87 public void add(Account account) { 88 if (!accounts.contains(account)) accounts.add(account); 89 } 90 91 public Element getXML() { 92 93 Element bureau = new Element("Bureau"); 94 Element name = new Element("Name"); 95 Element code = new Element("Code"); 96 97 name.appendChild(this.name); 98 code.appendChild(this.code); 99 bureau.appendChild(name); 100 bureau.appendChild(code); 101 102 Iterator iterator = accounts.iterator(); 103 while (iterator.hasNext()) { 104 Account account = (Account) iterator.next(); 105 bureau.appendChild(account.getXML()); 106 } 107 return bureau; 108 109 } 110 111 } | Popular Tags |