use of com.vaadin.flow.templatemodel.InvalidTemplateModelException in project flow by vaadin.
the class BeanModelType method getListModelType.
private static ModelType getListModelType(Type propertyType, PropertyFilter propertyFilter, String propertyName, Class<?> declaringClass) {
assert ListModelType.isList(propertyType);
ParameterizedType pt = (ParameterizedType) propertyType;
Type itemType = pt.getActualTypeArguments()[0];
if (itemType instanceof ParameterizedType) {
return new ListModelType<>((ComplexModelType<?>) getModelType(itemType, propertyFilter, propertyName, declaringClass));
} else {
if (!(itemType instanceof Class<?>)) {
throw new InvalidTemplateModelException("Element type " + itemType.getTypeName() + " is not a valid Bean type. Used in class " + declaringClass.getSimpleName() + " with property named " + propertyName + " with list type " + propertyType.getTypeName());
}
Class<?> beansListItemType = (Class<?>) itemType;
return new ListModelType<>(new BeanModelType<>(beansListItemType, propertyFilter));
}
}
use of com.vaadin.flow.templatemodel.InvalidTemplateModelException in project flow by vaadin.
the class TemplateModelProxyHandler method intercept.
/**
* Processes a method invocation on a Byte buddy proxy instance and returns
* the result. This method will be invoked on an invocation handler when a
* method is invoked on a proxy instance that it is associated with.
*
* @param target
* the proxy instance
* @param method
* the {@code Method} instance corresponding to the proxied
* method invoked on the proxy instance.
*
* @param args
* an array of objects containing the values of the arguments
* passed in the method invocation on the proxy instance.
* @return the value to return from the method invocation on the proxy
* instance.
*/
@RuntimeType
@SuppressWarnings("static-method")
public Object intercept(@This Object target, @Origin Method method, @AllArguments Object[] args) {
String propertyName = ReflectTools.getPropertyName(method);
BeanModelType<?> modelType = getModelTypeForProxy(target);
if (!modelType.hasProperty(propertyName)) {
throw new InvalidTemplateModelException(modelType.getProxyType().getName() + " has no property named " + propertyName + " (or it has been excluded)");
}
ModelType propertyType = modelType.getPropertyType(propertyName);
ModelMap modelMap = ModelMap.get(getStateNodeForProxy(target));
if (ReflectTools.isGetter(method)) {
return handleGetter(modelMap, propertyName, propertyType);
} else if (ReflectTools.isSetter(method)) {
Object value = args[0];
handleSetter(modelMap, propertyName, propertyType, value);
return null;
}
throw new InvalidTemplateModelException(getUnsupportedMethodMessage(method, args));
}
Aggregations