1 16 package com.google.gwt.dev.util.xml; 17 18 import com.google.gwt.core.ext.UnableToCompleteException; 19 20 24 public class HandlerArgs { 25 26 private final String [] attrNames; 28 29 private final String [] argValues; 30 31 private final HandlerParam[] handlerParams; 32 33 private final int lineNumber; 34 35 private final Schema schema; 36 37 private final String elemName; 38 39 public HandlerArgs(Schema schema, int lineNumber, String elemName, 40 HandlerParam[] handlerParams) { 41 this.schema = schema; 42 this.lineNumber = lineNumber; 43 this.elemName = elemName; 44 this.handlerParams = handlerParams; 45 attrNames = new String [handlerParams.length]; 46 argValues = new String [handlerParams.length]; 47 48 for (int i = 0, n = handlerParams.length; i < n; ++i) { 51 argValues[i] = this.handlerParams[i].getDefaultValue(schema); 52 } 53 } 54 55 60 public Object convertToArg(int i) throws UnableToCompleteException { 61 String value = argValues[i]; 62 if (value != null) { 63 AttributeConverter converter = schema.getAttributeConverter(handlerParams[i].getParamType()); 64 return converter.convertToArg(schema, lineNumber, elemName, attrNames[i], 65 value); 66 } else { 67 return new NullPointerException ("Argument " + i + " was null"); 68 } 69 } 70 71 public int getArgCount() { 72 return handlerParams.length; 73 } 74 75 public String getArgName(int i) { 76 return handlerParams[i].getNormalizedName(); 77 } 78 79 public boolean isArgSet(int i) { 80 if (argValues[i] != null) { 81 return true; 82 } else { 83 return false; 84 } 85 } 86 87 91 public boolean setArg(String attrName, String attrValue) { 92 String normalizedAttrName = normalizeAttrName(attrName); 93 for (int i = 0, n = handlerParams.length; i < n; ++i) { 94 Object testParamName = handlerParams[i].getNormalizedName(); 95 if (testParamName.equals(normalizedAttrName)) { 96 attrNames[i] = attrName; 98 argValues[i] = attrValue; 99 return true; 100 } 101 } 102 return false; 103 } 104 105 private String normalizeAttrName(String attrName) { 106 return attrName.replace('-', '_'); 108 } 109 } 110 | Popular Tags |