1 package jfun.yan.xml; 2 3 4 5 import java.util.ArrayList ; 6 import java.util.Set ; 7 8 final class Import implements LocationAware{ 9 private final Filter filter; 10 private final Module importee; 11 private final String prefix; 12 private final Location loc; 13 private final String [] keys; 14 Import(String prefix, Filter filter, Module parent, 15 final Location loc) { 16 this.prefix = prefix; 17 this.filter = filter; 18 this.importee = parent; 19 this.loc = loc; 20 this.keys = findKeys(); 21 } 22 String [] getKeys(){ 23 return keys; 24 } 25 Module getImported(){ 26 return importee; 27 } 28 private String [] findKeys(){ 29 final String [] exported = importee.getExports(); 30 final StringPredicate pred = filter.getPredicate(); 31 final ArrayList buf = new ArrayList (exported.length); 32 for(int i=0; i<exported.length; i++){ 33 final String key = exported[i]; 34 if(pred.isString(key)){ 35 buf.add(key); 36 } 37 } 38 final String [] ret = new String [buf.size()]; 39 buf.toArray(ret); 40 return ret; 41 } 42 Filter getFilter() { 43 return filter; 44 } 45 46 String getPrefix(){ 47 return prefix; 48 } 49 public Location getLocation(){ 50 return loc; 51 } 52 private Registry filter(final Registry reg){ 53 final Set set = MyUtil.getNameSet(keys); 55 return new Registry(){ 56 public void put(String key, Object obj, Location loc){ 57 if(set.contains(key)){ 58 reg.put(prefix+key, obj, loc); 59 } 60 } 61 }; 62 } 63 void register(Registry reg){ 64 importee.register(filter(reg)); 65 } 66 } 67 | Popular Tags |