static AttributeBindingException createWithNoKey(String message, Throwable cause) { return new AttributeBindingException(null, message, cause); } }
@Override public void performAction(BindingTracker bindingTracker, int level, Object object, Field field, Object value, Predicate<Field> predicate) throws InstantiationException { if (!Modifier.isStatic(field.getModifiers()) && values.containsKey(field.getType())) { if (!Modifier.isPublic(field.getModifiers())) { throw AttributeBindingException.createWithNoKey("Could not assign to non-public field " + object.getClass().getName() + "#" + field.getName() + ", value " + value); } try { field.set(object, values.get(field.getType())); } catch (final Exception e) { throw AttributeBindingException.createWithNoKey("Could not assign field " + object.getClass().getName() + "#" + field.getName() + " with value " + value, e); } } } }
/** * Performs all life cycle actions required before processing starts. */ public static void beforeProcessing(IProcessingComponent processingComponent, Map<String, Object> attributes) throws ProcessingException { try { // Check if we need to do binding. if (processingComponent.getClass().getAnnotation(Bindable.class) != null) { AttributeBinder.set(processingComponent, attributes, Input.class, Processing.class); } processingComponent.beforeProcessing(); } catch (final InstantiationException e) { throw new ProcessingException("Attribute binding failed: " + e.getMessage(), e); } catch (final AttributeBindingException e) { throw new ProcessingException("Attribute binding failed: " + e.getMessage(), e); } }
boolean canBind(Object instance, String key, int level) { final Pair<Object, String> pair = new Pair<Object, String>(instance, key); if (boundInstances.contains(pair)) { throw AttributeBindingException.createWithNoKey( "Collecting values of multiple attributes with the same key (" + key + ") in the same instance of class (" + instance.getClass().getName() + ") is not allowed"); } boundInstances.add(pair); // We can collect this attribute if: // 1) it has not yet been collected or // 2) it has been collected at a deeper level of the nesting hierarchy // but we found another value for it found closer to the root object for // which binding is performed. final Integer boundAtLevel = bindingLevel.get(key); final boolean canBind = boundAtLevel == null || (boundAtLevel != null && boundAtLevel > level); if (canBind) { bindingLevel.put(key, level); } return canBind; } }
static AttributeBindingException createWithNoKey(String message) { return new AttributeBindingException(null, message); }
throw AttributeBindingException.createWithNoKey("Non-public attribute fields are no longer supported: " + field.getDeclaringClass().getName() + "#" + field.getName()); throw AttributeBindingException.createWithNoKey("Non-public fields are no longer supported: " + field.getDeclaringClass().getName() + "#" + field.getName()); throw AttributeBindingException.createWithNoKey("Non-accessible field: " + object.getClass().getName() + "#" + field.getName(), e); throw AttributeBindingException.createWithNoKey("Could not get field value " + object.getClass().getName() + "#" + field.getName()); throw AttributeBindingException.createWithNoKey(e.getMessage(), e); throw AttributeBindingException.createWithNoKey( "Could not get field value " + object.getClass().getName() + "#" + field.getName(), e);
public void performAction(BindingTracker bindingTracker, int level, Object object, Field field, Object value, Predicate<Field> predicate) throws InstantiationException { final String key = BindableUtils.getKey(field); try { // Apply transforms for (IAttributeTransformer transformer : transformers) { value = transformer.transform(value, key, field); } if (bindingTracker.canBind(object, key, level)) { values.put(key, value); } } catch (final Exception e) { throw new AttributeBindingException(key, "Could not get field value " + object.getClass().getName() + "#" + field.getName(), e); } } }
throw new AttributeBindingException(key, "No value for required attribute: " + key + " (" + field.getDeclaringClass().getName() + "#" + field.getName() throw new AttributeBindingException(key, "Not allowed to set required attribute to null: " + key); throw new AttributeBindingException(key, "Could not assign field " + object.getClass().getName() + "#" + field.getName() + " with value " + value, e);