KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > xml > Import


1 package jfun.yan.xml;
2
3
4
5 import java.util.ArrayList JavaDoc;
6 import java.util.Set JavaDoc;
7
8 final class Import implements LocationAware{
9   private final Filter filter;
10   private final Module importee;
11   private final String JavaDoc prefix;
12   private final Location loc;
13   private final String JavaDoc[] keys;
14   Import(String JavaDoc 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 JavaDoc[] getKeys(){
23     return keys;
24   }
25   Module getImported(){
26     return importee;
27   }
28   private String JavaDoc[] findKeys(){
29     final String JavaDoc[] exported = importee.getExports();
30     final StringPredicate pred = filter.getPredicate();
31     final ArrayList JavaDoc buf = new ArrayList JavaDoc(exported.length);
32     for(int i=0; i<exported.length; i++){
33       final String JavaDoc key = exported[i];
34       if(pred.isString(key)){
35         buf.add(key);
36       }
37     }
38     final String JavaDoc[] ret = new String JavaDoc[buf.size()];
39     buf.toArray(ret);
40     return ret;
41   }
42   Filter getFilter() {
43     return filter;
44   }
45
46   String JavaDoc getPrefix(){
47     return prefix;
48   }
49   public Location getLocation(){
50     return loc;
51   }
52   private Registry filter(final Registry reg){
53     //final StringPredicate pred = filter.getPredicate();
54
final Set JavaDoc set = MyUtil.getNameSet(keys);
55     return new Registry(){
56       public void put(String JavaDoc key, Object JavaDoc 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