private Object resolveParameter(java.lang.annotation.Annotation[] parmAnnos, Class<?> paramType) { Object val = null; boolean hitResolver = false; Default defAnno = null; for (Annotation anno : parmAnnos) { Class<?> annotype = anno.annotationType(); if (defAnno == null && annotype.equals(Default.class)) { defAnno = (Default) anno; continue; } ParamResolver<Annotation> resolver = _paramResolvers.get(annotype); if (resolver == null) continue; hitResolver = true; val = resolver.resolveParameter(anno, paramType); if (val != null) { break; } // don't break until get a value } if (val == null && defAnno != null) { val = Classes.coerce(paramType, defAnno.value()); } // to compatible to rc2, do we have to? if (_mappingType && val == null && !hitResolver && _types != null) { for (Type type : _types) { if (type != null && paramType.isAssignableFrom(type.clz)) { val = type.value; break; } } } return val; }
private Object evaluate0(Object self, String expr, Class<?> expectedType, Page page) { if (expr == null || expr.length() == 0 || expr.indexOf("${") < 0) { if (expectedType == Object.class || expectedType == String.class) return expr; return Classes.coerce(expectedType, expr); } final Evaluator eval = getEvaluator(page, null); final Expression expression = eval.parseExpression(expr, expectedType); return self instanceof Page ? eval.evaluate((Page) self, expression) : eval.evaluate((Component) self, expression); }
/** Converts the specified object to an character. */ public static char toChar(Object val) { return ((Character) Classes.coerce(char.class, val)).charValue(); }
/** Converts the specified object to a (big) decimal. */ public static BigDecimal toDecimal(Object val) { return (BigDecimal) Classes.coerce(BigDecimal.class, val); }
/** Converts the specified object to an integer. */ public static int toInt(Object val) { return ((Integer) Classes.coerce(int.class, val)).intValue(); }
/** Converts the specified object to a number. */ public static Number toNumber(Object val) { return (Number) Classes.coerce(Number.class, val); }
/** Converts the specified object to a string. */ public static String toString(Object val) { return (String) Classes.coerce(String.class, val); }
/** Converts the specified object to a boolean. */ public static boolean toBoolean(Object val) { return ((Boolean) Classes.coerce(boolean.class, val)).booleanValue(); }
private void myLoadAttribute(Component comp, Object bean) { try { // since 3.1, 20080416, support bindingArgs for non-supported tag // bug #2803575, merge bindingArgs together since a component can have // multiple bindings on different attributes. Map<Object, Object> bindArgs = cast((Map) comp.getAttribute(DataBinder.ARGS)); if (bindArgs == null) { bindArgs = new HashMap<Object, Object>(); comp.setAttribute(DataBinder.ARGS, bindArgs); } if (_args != null) { bindArgs.putAll(_args); comp.setAttribute(_attr + "_" + DataBinder.ARGS, _args); } if (_converter != null) { bean = _converter.coerceToUi(bean, comp); if (bean == TypeConverter.IGNORE) return; // ignore, so don't do Fields.set() } // Bug #1876198 Error msg appears when load page (databind+CustomConstraint) // catching WrongValueException no longer works, check special case and // use setRowValue() method directly if ((comp instanceof InputElement) && "value".equals(_attr)) { Object value = bean; Object oldv = null; try { // Bug 1879389 final Method m = comp.getClass().getMethod("getValue"); oldv = ((InputElement) comp).getRawValue(); value = Classes.coerce(m.getReturnType(), bean); } catch (NoSuchMethodException ex) { // ignore it } // See both Bug 3000305 and 2874098 Fields.set(comp, "rawValue", value, _converter == null); } else { Fields.set(comp, _attr, bean, _converter == null); } } catch (ClassCastException ex) { throw UiException.Aide.wrap(ex); } catch (NoSuchMethodException ex) { // Bug #1813278, Annotations do not work with xhtml tags if (comp instanceof DynamicPropertied) { final DynamicPropertied dpcomp = (DynamicPropertied) comp; if (dpcomp.hasDynamicProperty(_attr)) { // no way to know destination type of the property, use bean as is dpcomp.setDynamicProperty(_attr, bean); } else { throw UiException.Aide.wrap(ex); } } else { // Feature# 2855116. Save into component custom-attribute(also a variable in ZK5). comp.setAttribute(_attr, bean); } // Bug #1876198 Error msg appears when load page (databind+CustomConstraint) // catching WrongValueException no longer works, so mark it out /*} catch (WrongValueException ex) { //Bug #1615371, try to use setRawValue() if ("value".equals(_attr)) { try { Fields.set(comp, "rawValue", bean, _converter == null); } catch (Exception ex1) { //exception throw ex; } } else { throw ex; } */ } }