1 package com.tonbeller.tbutils.res; 2 3 import java.util.ArrayList ; 4 import java.util.Collection ; 5 import java.util.HashSet ; 6 import java.util.Iterator ; 7 import java.util.List ; 8 import java.util.Set ; 9 10 18 19 public class CompositeResourceProvider implements ResourceProvider { 20 List list = new ArrayList (); 21 22 public String getString(String key) { 23 for (Iterator it = list.iterator(); it.hasNext();) { 24 ResourceProvider r = (ResourceProvider) it.next(); 25 String s = r.getString(key); 26 if (s != null) 27 return s; 28 } 29 return null; 30 } 31 32 public void add(ResourceProvider r) { 33 list.add(r); 34 } 35 36 public void add(int index, ResourceProvider r) { 37 list.add(index, r); 38 } 39 40 public List getProviders() { 41 return list; 42 } 43 44 public Collection keySet() { 45 Set set = new HashSet (); 46 for (Iterator it = list.iterator(); it.hasNext();) { 47 ResourceProvider r = (ResourceProvider) it.next(); 48 set.addAll(r.keySet()); 49 } 50 return set; 51 } 52 53 public void close() { 54 for (Iterator it = list.iterator(); it.hasNext();) { 55 ResourceProvider r = (ResourceProvider) it.next(); 56 r.close(); 57 } 58 } 59 60 public void dump(Dumper d) { 61 for (Iterator it = list.iterator(); it.hasNext();) { 62 ResourceProvider r = (ResourceProvider) it.next(); 63 r.dump(d); 64 } 65 } 66 67 public String getName() { 68 return "CompositeResourceProvider"; 69 } 70 } | Popular Tags |