/** * Sets a property value or defers that operation if the property is marked as such. * * @param instance Instance containing the property or attribute map. * @param name Name of property or attribute. If prefixed with "@", is interpreted as an * attribute name; otherwise as a property name. * @param value The value to set. * @return Null if the operation occurred, or a DeferredSetter object if deferred. */ public DeferredSetter setProperty(BaseComponent instance, String name, Object value) { if (name.startsWith("@")) { instance.setAttribute(name.substring(1), value); return null; } Method method = setters.get(name); if (method == null) { if (parameters.containsKey(name)) { return null; } String message = getters.containsKey(name) ? "Property is read-only" : "Property is not recognized"; throw new ComponentException(message + ": " + name); } if (deferred.contains(name)) { return new DeferredSetter(instance, method, value); } ConvertUtil.invokeSetter(instance, method, value); return null; }
/** * Materializes this page definition under the given parent component. * * @param parent The parent component for all top level components produced. This may be null. * @param args A map of arguments that will be copied into the attribute maps of all top level * components. This may be null. * @return A list of all top level components produced. */ public List<BaseComponent> materialize(BaseComponent parent, Map<String, Object> args) { try { List<DeferredSetter> deferrals = new ArrayList<>(); List<BaseComponent> created = new ArrayList<>(); materialize(root.getChildren(), parent, deferrals, args, created); for (DeferredSetter deferral : deferrals) { deferral.execute(); } return created; } catch (Exception e) { throw new ComponentException(e, "Exception materializing page definition '%s'", source); } }