1 19 package org.netbeans.modules.xml.tools.generator; 20 21 import java.util.*; 22 23 24 36 public class ElementBindings extends HashMap { 37 38 39 private static final long serialVersionUID =-1529089675411853246L; 40 41 43 public static final String DELIMITER_HANDLING = 44 Util.THIS.getString ("DELIMITER_HANDLING"); 45 public static final String DATA_HANDLING = 46 Util.THIS.getString ("DATA_HANDLING"); 47 public static final String IGNORE_HANDLING = 48 Util.THIS.getString ("IGNORE_HANDLING"); 49 public static final String MIXED_HANDLING = 50 Util.THIS.getString ("MIXED_HANDLING"); 51 public static final String EMPTY_HANDLING = 52 Util.THIS.getString ("EMPTY_HANDLING"); 53 54 55 public ElementBindings() { 56 } 57 58 62 public Entry put(String element, Entry entry) { 63 if (element == null) return null; 64 if (element.equals(entry.getElement()) == false) return null; 65 return (Entry) super.put(element, entry); 66 } 67 68 71 public Entry put(String element, String method, String parslet, String type) { 72 return (Entry) super.put(element, new Entry(element, method, parslet, type)); 73 } 74 75 78 public String getMethod(String element) { 79 Entry entry = getEntry(element); 80 if (entry == null) { 81 return null; 82 } else { 83 return entry.getMethod(); 84 } 85 } 86 87 90 public String getParslet(String element) { 91 Entry entry = getEntry(element); 92 if (entry == null) { 93 return null; 94 } else { 95 return entry.getParslet(); 96 } 97 } 98 99 102 public boolean containsParslet(String name) { 103 104 if (name == null) return false; 105 106 Iterator it = values().iterator(); 107 while (it.hasNext()) { 108 Entry next = (Entry) it.next(); 109 if (name.equals(next.parslet)) return true; 110 } 111 112 return false; 113 } 114 115 118 public int getParsletUsageCount(String parslet) { 119 int toret = 0; 120 Iterator it = values().iterator(); 121 122 while (it.hasNext()) { 123 Entry next = (Entry) it.next(); 124 if (parslet != null && parslet.equals(next.parslet)) { 125 toret++; 126 } 127 } 128 129 return toret; 130 } 131 132 135 public final Entry getEntry(String element) { 136 return (Entry) get(element); 137 } 138 139 143 public final Entry getEntry(final int index) { 144 int myindex = index; 145 Iterator it = values().iterator(); 146 while (it.hasNext()) { 147 Entry next = (Entry) it.next(); 148 if (myindex-- == 0) 149 return next; 150 } 151 return null; 152 } 153 154 public String toString() { 155 Iterator it = values().iterator(); 156 StringBuffer sb = new StringBuffer (); 157 sb.append("{"); while (it.hasNext()) { 159 sb.append(it.next()); 160 } 161 sb.append("}"); return sb.toString(); 163 } 164 165 168 public static final class Entry { 169 170 172 public static final String EMPTY = "EMPTY"; public static final String CONTAINER = "CONTAINER"; public static final String DATA = "DATA"; public static final String MIXED = "MIXED"; public static final String IGNORE = "IGNORE"; 178 private String type; 179 180 182 private String method; 183 184 private String element; 185 186 private String parslet; 187 188 189 190 public Entry(String element, String method, String parslet, String type) { 191 this.method = method; 192 this.element = element; 193 this.parslet = parslet; 194 this.type = type; 195 } 196 197 201 public String getMethod() { 202 return method; 203 } 204 205 209 public String getElement() { 210 return element; 211 } 212 213 217 public String getParslet() { 218 return parslet; 219 } 220 221 224 public String getType() { 225 return type; 226 } 227 228 public String toString() { 229 return element + " => (" + method + ", " + parslet + ", " + type + ")"; } 231 232 void setType(String type) { 233 this.type = type; 234 } 235 236 void setMethod(String method) { 237 this.method = method; 238 } 239 240 void setParslet(String parslet) { 241 this.parslet = parslet; 242 } 243 244 247 public static final String displayTypeFor(String type) { 248 249 if (ElementBindings.Entry.CONTAINER.equals(type)) { 250 return DELIMITER_HANDLING; 251 } else if (ElementBindings.Entry.DATA.equals(type)) { 252 return DATA_HANDLING; 253 } else if (ElementBindings.Entry.MIXED.equals(type)) { 254 return MIXED_HANDLING; 255 } else if (ElementBindings.Entry.IGNORE.equals(type)) { 256 return IGNORE_HANDLING; 257 } else if (ElementBindings.Entry.EMPTY.equals(type)) { 258 return EMPTY_HANDLING; 259 } else { 260 return IGNORE_HANDLING; 261 } 262 } 263 264 267 public static final String typeFor(String type) { 268 if (DELIMITER_HANDLING.equals(type)) { 269 return ElementBindings.Entry.CONTAINER; 270 } else if (DATA_HANDLING.equals(type)) { 271 return ElementBindings.Entry.DATA; 272 } else if (MIXED_HANDLING.equals(type)) { 273 return ElementBindings.Entry.MIXED; 274 } else if (EMPTY_HANDLING.equals(type)) { 275 return ElementBindings.Entry.EMPTY; 276 } else { 277 return ElementBindings.Entry.IGNORE; 278 } 279 } 280 281 284 public static final Vector displayTypesFor(ElementDeclarations.Entry entry) { 285 Vector list = new Vector(4); 286 list.add(IGNORE_HANDLING); 287 if ((entry.getType() & ElementDeclarations.Entry.DATA) == 1) 288 list.add(DATA_HANDLING); 289 if ((entry.getType() & ElementDeclarations.Entry.CONTAINER) == 2) 290 list.add(DELIMITER_HANDLING); 291 if (entry.getType() == ElementDeclarations.Entry.MIXED) 292 list.add(MIXED_HANDLING); 293 if (entry.getType() == ElementDeclarations.Entry.EMPTY) 294 list.add(EMPTY_HANDLING); 295 return list; 296 } 297 } 298 } 299 | Popular Tags |