1 package jfun.yan.xml; 2 3 import java.util.LinkedHashMap ; 4 import java.util.Set ; 5 6 final class NutsRegistrar { 7 private final LinkedHashMap store = new LinkedHashMap (); 8 static class Entry{ 9 private final boolean overridable; 10 private final Object obj; 11 private final Location location; 12 Location getLocation() { 13 return location; 14 } 15 Object getValue() { 16 return obj; 17 } 18 boolean isOverridable() { 19 return overridable; 20 } 21 Entry(Object obj, boolean overridable, Location location) { 22 this.location = location; 23 this.obj = obj; 24 this.overridable = overridable; 25 } 26 27 } 28 void register(Object key, Object val, boolean overridable, 29 boolean overriding, Location loc){ 30 final Entry old = (Entry)store.get(key); 31 if(old!=null){ 32 if(!overriding){ 33 throw new ConfigurationException("component key duplidate with " 34 + old.getLocation(), loc); 35 } 36 if(!old.isOverridable()){ 37 throw new ConfigurationException("dynamic registration not overridable at " 38 + old.getLocation(), loc); 39 } 40 store.remove(key); 41 } 42 store.put(key, new Entry(val, overridable, loc)); 43 } 44 int size(){ 45 return store.size(); 46 } 47 boolean isEmpty(){ 48 return store.isEmpty(); 49 } 50 Entry getEntry(Object key){ 51 return (Entry)store.get(key); 52 } 53 Set keySet(){ 54 return store.keySet(); 55 } 56 } 57 | Popular Tags |