Field f = NamePolicy.class.getDeclaredField(policyName.toUpperCase());
policy = (NamePolicy) f.get(null);
} catch (IllegalAccessException e) {
logger.log(TreeLogger.ERROR, "Bad gwt.namePolicy " + policyName, e);
throw new UnableToCompleteException();
} catch (NoSuchFieldException e) {
// This means that the value specified is not a field, but likely
// a class name. Try instantiating one and seeing if it's a
// subclass of NamePolicy.
try {
Class<? extends NamePolicy> clazz = Class.forName(policyName).asSubclass(
NamePolicy.class);
policy = clazz.newInstance();
} catch (ClassCastException ee) {
logger.log(TreeLogger.ERROR,
"@gwt.namePolicy is not an implementation of NamePolicy", null);
throw new UnableToCompleteException();
} catch (ClassNotFoundException ee) {
logger.log(TreeLogger.ERROR, "Bad gwt.namePolicy " + policyName, ee);
throw new UnableToCompleteException();
} catch (IllegalAccessException ee) {
logger.log(TreeLogger.ERROR, "Bad gwt.namePolicy " + policyName, ee);
throw new UnableToCompleteException();
} catch (InstantiationException ee) {
logger.log(TreeLogger.ERROR, "Bad gwt.namePolicy " + policyName, ee);
throw new UnableToCompleteException();
}
}
}
// Execute the conversion