1 16 package com.google.gwt.dev.util.xml; 17 18 import com.google.gwt.core.ext.UnableToCompleteException; 19 20 import java.lang.reflect.Method ; 21 import java.util.HashMap ; 22 import java.util.Map ; 23 24 27 public abstract class Schema { 28 29 private final Map convertersByType = new HashMap (); 30 31 private Schema parent; 32 33 private int lineNumber; 34 35 39 public AttributeConverter getAttributeConverter(Class type) { 40 AttributeConverter converter = (AttributeConverter) convertersByType.get(type); 41 if (converter != null) { 42 return converter; 43 } else if (parent != null) { 44 return parent.getAttributeConverter(type); 45 } 46 47 throw new IllegalStateException ( 48 "Unable to find an attribute converter for type " + type.getName()); 49 } 50 51 public int getLineNumber() { 52 return lineNumber; 53 } 54 55 public void onBadAttributeValue(int line, String elem, String attr, 56 String value, Class paramType) throws UnableToCompleteException { 57 if (parent != null) { 58 parent.onBadAttributeValue(line, elem, attr, value, paramType); 59 } 60 } 61 62 public void onHandlerException(int line, String elem, Method method, 63 Throwable e) throws UnableToCompleteException { 64 if (parent != null) { 65 parent.onHandlerException(line, elem, method, e); 66 } 67 } 68 69 public void onMissingAttribute(int line, String elem, String attr) 70 throws UnableToCompleteException { 71 if (parent != null) { 72 parent.onMissingAttribute(line, elem, attr); 73 } 74 } 75 76 public void onUnexpectedAttribute(int line, String elem, String attr, 77 String value) throws UnableToCompleteException { 78 if (parent != null) { 79 parent.onUnexpectedAttribute(line, elem, attr, value); 80 } 81 } 82 83 public void onUnexpectedChild(int line, String elem) 84 throws UnableToCompleteException { 85 if (parent != null) { 86 parent.onUnexpectedChild(line, elem); 87 } 88 } 89 90 public void onUnexpectedElement(int line, String elem) 91 throws UnableToCompleteException { 92 if (parent != null) { 93 parent.onUnexpectedElement(line, elem); 94 } 95 } 96 97 public void registerAttributeConverter(Class type, 98 AttributeConverter converter) { 99 convertersByType.put(type, converter); 100 } 101 102 public void setLineNumber(int lineNumber) { 103 this.lineNumber = lineNumber; 104 } 105 106 public void setParent(Schema parent) { 107 this.parent = parent; 108 } 109 } 110 | Popular Tags |