1 58 package org.oddjob.arooa; 59 60 import java.util.ArrayList ; 61 import java.util.HashMap ; 62 import java.util.List ; 63 import java.util.Map ; 64 65 import org.xml.sax.Locator ; 66 67 72 public class ArooaContext { 73 74 78 private Locator locator; 79 80 81 private Map prefixMapping = new HashMap (); 82 83 private final Map values = new HashMap (); 84 85 private final ArooaContext parent; 86 87 90 public ArooaContext() { 91 parent = null; 92 } 93 94 public ArooaContext(ArooaContext parent) { 95 this.parent = parent; 96 } 97 98 public void set(String name, Object value) { 99 values.put(name, value); 100 } 101 102 public Object get(String name) { 103 Object value = values.get(name); 104 if (value != null) { 105 return value; 106 } 107 if (parent != null) { 108 return parent.get(name); 109 } 110 return null; 111 } 112 113 public Object getLocal(String name) { 114 return values.get(name); 115 } 116 117 public ArooaContext getParent() { 118 return parent; 119 } 120 121 125 public Locator getLocator() { 126 Locator locator = this.locator; 127 if (locator != null) { 128 return locator; 129 } 130 if (parent != null) { 131 return parent.getLocator(); 132 } 133 return null; 134 } 135 136 140 public void setLocator(Locator locator) { 141 this.locator = locator; 142 } 143 144 150 public void startPrefixMapping(String prefix, String uri) { 151 List list = (List ) prefixMapping.get(prefix); 152 if (list == null) { 153 list = new ArrayList (); 154 prefixMapping.put(prefix, list); 155 } 156 list.add(uri); 157 } 158 159 164 public void endPrefixMapping(String prefix) { 165 List list = (List ) prefixMapping.get(prefix); 166 if (list == null || list.size() == 0) { 167 return; } 169 list.remove(list.size() - 1); 170 } 171 172 178 public String getPrefixMapping(String prefix) { 179 List list = (List ) prefixMapping.get(prefix); 180 if (list == null || list.size() == 0) { 181 return null; 182 } 183 return (String ) list.get(list.size() - 1); 184 } 185 186 } 187 188 189 | Popular Tags |