@Override public Type getGenericType() { if (genericType == null) { if (getter != null) { genericType = getter.getGenericReturnType(); } else if (field != null) { genericType = field.getGenericType(); } else { throw new BindingException("no getter or field for " + camelName); } } return genericType; }
/** * Gets the value of the field to be set into the component. * * @param parentObject the parent object * @return the field's value */ protected Object getModelValue(Object parentObject) { try { Object modelValue = parentObject == null ? null : member.getObject(parentObject); LOGGER.fine(() -> viewComponentToString() + " <- " + member + " = " + StringHelper.objectToLoggableString(modelValue) + (parentObject == null ? "\n(some) object reference was null, " + viewComponentToString() + " not changed" : "")); return modelValue; } catch (BindingException ex) { // improve exception message throw new BindingException(member + ": " + ex.getLocalizedMessage(), ex); } }
throw new BindingException(veto.getLocalizedMessage(), veto); throw new BindingException(member + ": " + ex.getLocalizedMessage(), ex);
@Override public Class<?> getType() { if (type == null) { if (getter != null) { type = getter.getReturnType(); } else if (field != null) { type = field.getType(); } else { throw new BindingException("no getter or field for " + camelName); } if (type.equals(Void.TYPE)) { throw new BindingException("void type is not allowed"); } } return type; }
/** * Gets the the object (FormField or FormContainer) associated with the declared field * in a container. * * @param container the container declaring the field * @param formField the form field declared in the container * @return the form component or container, null if field is not a form object */ private Object getFormObject(Container container, Field formField) { try { if (!formField.isAccessible()) { formField.setAccessible(true); } return formField.get(container); } catch (Exception ex) { throw new BindingException("cannot access " + formField, ex); } }
@Override public void assertAllBound() { Collection<String> unboundColumns = getUnboundColumns(); if (!unboundColumns.isEmpty()) { StringBuilder buf = new StringBuilder(); for (String columnName: unboundColumns) { if (buf.length() > 0) { buf.append(", "); } buf.append(columnName); } throw new BindingException("unbound columns in " + tableConfig + ": " + buf); } }
/** * Gets the the component associated with the declared field in a controller. * * @param controller the controller declaring the field * @param field the form field declared in the controller * @return the component, null if field is not an FxComponent */ private FxComponent getFxComponent(FxController controller, Field field) { FxComponent component = null; try { if (FxComponent.class.isAssignableFrom(field.getType())) { try { component = (FxComponent) field.get(controller); } catch (IllegalAccessException ex) { field.setAccessible(true); component = (FxComponent) field.get(controller); } if (component == null) { throw new BindingException(field + " is null"); } } } catch (IllegalAccessException | IllegalArgumentException ex) { throw new BindingException("cannot access " + field, ex); } return component; }
/** * Programmatically removes a binding from this form. * * @param bindingPath the object's binding path * * @return the removed binding, null if no such binding found */ @Override public FormTableBinding removeBinding(String bindingPath) { FormTableBinding binding = boundPaths.remove(bindingPath); if (binding != null) { if (boundColumns.remove(binding.getColumn()) != binding) { throw new BindingException("Binding " + binding + " missing in component map"); } } return binding; }
@Override public Object getObject(Object parent) { try { // getter takes precedence over field if (getter != null) { try { return getter.invoke(parent); } catch (IllegalAccessException ex) { getter.setAccessible(true); return getter.invoke(parent); } } else { try { return field.get(parent); } catch (IllegalAccessException ex) { field.setAccessible(true); return field.get(parent); } } } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { throw new BindingException("cannot get " + camelName, ex); } }
@Override public FormTableBinding removeBinding(int mColumn) { FormTableBinding binding = boundColumns.remove(mColumn); if (binding != null) { if (boundPaths.remove(binding.getMember().getMemberPath()) != binding) { throw new BindingException("Binding " + binding + " missing in path map"); } } return binding; }
private void applyBindingOptions(FxTextComponent comp, TableColumnConfiguration columnConfiguration, BindingMember member, String options) { if (options != null) { StringTokenizer stok = new StringTokenizer(options.toUpperCase(), ","); while (stok.hasMoreTokens()) { String token = stok.nextToken().trim(); boolean processed; if (comp != null) { processed = applyBindingOption(comp, member, token); } else if (columnConfiguration != null) { processed = applyBindingOption(columnConfiguration, member, token); } else { throw new BindingException("unsupported @Bindable target " + member); } if (!processed) { throw new BindingException("unsupported @Bindable option \"" + token + "\") in " + member); } } } }
throw new BindingException("cannot determine component's type", ex);
/** * Process the component options. * * @param columnOptions the options from the annotation */ protected void processOptions(String columnOptions) { if (columnOptions != null) { StringTokenizer stok = new StringTokenizer(columnOptions.toUpperCase(), ","); while (stok.hasMoreTokens()) { String token = stok.nextToken(); if (!processOption(token)) { throw new BindingException("unsupported @Bindable option \"" + token + "\") in " + getMember()); } } } }
@Override public FormComponentBinding removeBinding(String bindingPath) { FormComponentBinding binding = boundPaths.remove(bindingPath); if (binding != null) { if (boundComponents.remove(binding.getComponent()) != binding) { throw new BindingException("Binding " + binding + " missing in component map"); } binding.getComponent().setBinding(null); } return binding; }
@Override public FxComponentBinding removeBinding(String bindingPath) { FxComponentBinding binding = boundPaths.remove(bindingPath); if (binding != null) { if (boundComponents.remove(binding.getComponent()) != binding) { throw new BindingException("Binding " + binding + " missing in component map"); } binding.getComponent().setBinding(null); } return binding; }
@Override public void assertAllBound() throws BindingException { if (isUnboundPending()) { for (FormComponent comp: eligibleComponents.values()) { // sorted by bindingPath if (comp.getBinding() == null) { LOGGER.severe("unbound component " + comp.getComponentPath()); } } throw new BindingException("unbound components in " + form.getClass().getName()); } }
throw new BindingException("cannot set " + camelName, ex);
@Override public void assertAllBound() { if (isUnboundPending()) { StringBuilder buf = new StringBuilder(); for (FxComponent comp : eligibleComponents.values()) { // sorted by bindingPath if (comp.getBinding() == null) { if (buf.length() > 0) { buf.append(", "); } buf.append(comp.getComponentPath()); } } throw new BindingException("unbound components in " + ReflectionHelper.getClassBaseName(controller.getClass()) + ": " + buf); } }
@Override public BindableElement createBindableElement(Class<?> modelClass, String camelName) { BindableElement element; Class<? extends BindableElement> elementClass = getBindableElementClass(modelClass); if (elementClass != null) { try { Constructor<? extends BindableElement> con = elementClass.getConstructor(String.class); element = con.newInstance(camelName); } catch (IllegalAccessException | IllegalArgumentException | InstantiationException | NoSuchMethodException | SecurityException | InvocationTargetException ex) { throw new BindingException("could not instantiate bindable element " + elementClass.getName(), ex); } } else { // if all else fails: createBinding a default binding element = new DefaultBindableElement(camelName); } LOGGER.fine("created binding {0}", element); return element; }
throw new BindingException("invalid " + Constants.BIND_MAXCOL + " @Bindable option \"" + option + "\") in " + getMember(), ex); throw new BindingException("invalid " + Constants.BIND_SCALE + " @Bindable option \"" + option + "\") in " + getMember(), ex);