use of com.google.gwt.uibinder.client.UiFactory in project gwt-test-utils by gwt-test-utils.
the class UiBinderInstanciator method getObjectFromUiFactory.
private static <U> U getObjectFromUiFactory(Class<U> clazz, Object owner) {
Map<Method, UiFactory> map = GwtReflectionUtils.getAnnotatedMethod(owner.getClass(), UiFactory.class);
List<Method> compatibleFactories = new ArrayList<Method>();
for (Method factoryMethod : map.keySet()) {
if (clazz.isAssignableFrom(factoryMethod.getReturnType())) {
compatibleFactories.add(factoryMethod);
}
}
switch(compatibleFactories.size()) {
case 0:
return null;
case 1:
return (U) GwtReflectionUtils.callPrivateMethod(owner, compatibleFactories.get(0));
default:
throw new GwtTestUiBinderException("Duplicate factory in class '" + owner.getClass().getName() + " for type '" + clazz.getName() + "'");
}
}
Aggregations