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 Account { 49 50 private String code; 53 private String name; 54 private String BEACategory; 55 private String bureauCode; 56 private String agencyCode; 57 private String year; 58 59 private List subfunctions = new ArrayList (); 60 61 private static Map instances = new HashMap (); 62 63 private Account(String name, String code, String BEACategory, 66 String bureauCode, String agencyCode, String year) { 67 68 this.name = name; 69 this.code = code; 70 this.BEACategory = BEACategory; 71 this.bureauCode = bureauCode; 72 this.agencyCode = agencyCode; 73 this.year = year; 74 75 } 76 77 public static Account getInstance(String name, String code, 78 String BEACategory, String bureauCode, String agencyCode, 79 String year) { 80 81 String key = code + " " + BEACategory + " " + bureauCode 82 + " " + agencyCode + " " + year; 83 Account account = (Account) instances.get(key); 84 if (account == null) { 85 account = new Account(name, code, BEACategory, bureauCode, 86 agencyCode, year); 87 instances.put(key, account); 88 } 89 90 return account; 91 92 } 93 94 public void add(Subfunction sfx) { 95 if (!subfunctions.contains(sfx)) subfunctions.add(sfx); 96 } 97 98 public Element getXML() { 99 100 Element account = new Element("Account"); 101 Element name = new Element("Name"); 102 Element code = new Element("Code"); 103 Element BEACategory = new Element("BEACategory"); 104 name.appendChild(this.name); 105 code.appendChild(this.code); 106 BEACategory.appendChild(this.BEACategory); 107 account.appendChild(name); 108 account.appendChild(code); 109 account.appendChild(BEACategory); 110 111 Iterator iterator = subfunctions.iterator(); 112 while (iterator.hasNext()) { 113 Subfunction subfunction = (Subfunction) iterator.next(); 114 account.appendChild(subfunction.getXML()); 115 } 116 return account; 117 118 } 119 120 } 121 | Popular Tags |