public String value() { // make 'LIST_AUTO' into 'list.auto' return name().replace('_','.').toLowerCase(); }
public static Type get(String type) { if (type == null || type.length() == 0) { return CUSTOM; } // make 'list.auto' eq 'LIST_AUTO' return valueOf(type.replace('.','_').toUpperCase()); } }
public Object convert(String value) { // check if this looks like a typical boolean type if (value.matches("true|false|yes|no|y|n|on|off")) { return Type.BOOLEAN.getConverter().convert(Boolean.class, value); } // check if this looks like a typical number else if (value.matches("-?[0-9]+(\\.[0-9]+)?")) { return Type.NUMBER.getConverter().convert(Number.class, value); } // check if this looks like a typical field else if (value.matches("(\\w+\\.)+\\w+")) { return Type.FIELD.getConverter().convert(Object.class, value); } return value; } }
public void setType(String t) { // save the set type value (good for error feedback and whatnot) this.typeValue = t; // and try to convert it to a Type Type type = Type.get(this.typeValue); if (type != null) { setType(type); } }
protected void setType(Type type) { this.isList = type.isList(); // make sure we don't override a custom target or converter if (!type.isCustom()) { this.typeValue = type.value(); this.target = type.getTarget(); this.converter = type.getConverter(); } }