I thought the following translator for Java 1.5 Enum might find a place
in either the framework or library. The only catch is that it must be
complied with a 1.5 jdk (calls java.lang.Enum.valueOf), although it will
work with -source 1.1. Is HiveMind is required to compile with a 1.4/3/2
jkd? Anyway, do with what you will.
--Ryan Slack
import org.apache.hivemind.schema.Translator;
import org.apache.hivemind.internal.Module;
import org.apache.hivemind.Location;
import org.apache.hivemind.ApplicationRuntimeException;
public class EnumTranslator implements Translator{
public java.lang.Object translate(Module contributingModule,
java.lang.Class propertyType,
java.lang.String inputValue,
Location location){
try{
return java.lang.Enum.valueOf(propertyType,inputValue);
}catch(IllegalArgumentException ex){
throw new ApplicationRuntimeException(ex.getMessage(),location,ex);
}catch(NullPointerException ex){
if(propertyType==null){
throw new ApplicationRuntimeException("no Enum type
provied",location,ex);
}else if(inputValue==null){
throw new ApplicationRuntimeException("null is not an
Enum",location,ex);
}
}
return null; //should not be reachable. Maybe throw a RuntimeException?
}
}