1 package com.android.ide.eclipse.adt.internal.wizards.templates; 2 3 import java.util.Locale; 4 5 import org.xml.sax.Attributes; 6 7 public class TypedVariable { 8 public enum Type { 9 STRING, 10 BOOLEAN, 11 INTEGER; 12 get(String name)13 public static Type get(String name) { 14 if (name == null) { 15 return STRING; 16 } 17 try { 18 return valueOf(name.toUpperCase(Locale.US)); 19 } catch (IllegalArgumentException e) { 20 System.err.println("Unexpected global type '" + name + "'"); 21 System.err.println("Expected one of :"); 22 for (Type s : Type.values()) { 23 System.err.println(" " + s.name().toLowerCase(Locale.US)); 24 } 25 } 26 27 return STRING; 28 } 29 } 30 parseGlobal(Attributes attributes)31 public static Object parseGlobal(Attributes attributes) { 32 String value = attributes.getValue(TemplateHandler.ATTR_VALUE); 33 Type type = Type.get(attributes.getValue(TemplateHandler.ATTR_TYPE)); 34 35 switch (type) { 36 case STRING: 37 return value; 38 case BOOLEAN: 39 return Boolean.parseBoolean(value); 40 case INTEGER: 41 try { 42 return Integer.parseInt(value); 43 } catch (NumberFormatException e) { 44 return value; 45 } 46 } 47 48 return value; 49 } 50 } 51