/** * A generic method for performing actions on the <code>object</code>'s hierarchy of * attributes. Allows to customize the bindable marker annotation class. For experts * only. */ static void bind(Object object, IAttributeBinderAction [] attributeBinderActions, Predicate<Field> predicate, Class<? extends Annotation> markerAnnotation) throws InstantiationException, AttributeBindingException { bind(new HashSet<Object>(), new BindingTracker(), 0, object, attributeBinderActions, predicate, markerAnnotation); }
throws InstantiationException, AttributeBindingException return set(object, values, true, filteringAnnotations);
/** * Performs all life cycle actions required upon initialization. */ public static void init(IProcessingComponent processingComponent, Map<String, Object> inputAttributes, Map<String, Object> outputAttributes, boolean checkRequiredAttributes, IControllerContext context) throws ComponentInitializationException { try { AttributeBinder.set(processingComponent, inputAttributes, checkRequiredAttributes, Input.class, Init.class); processingComponent.init(context); AttributeBinder.get(processingComponent, outputAttributes, Output.class, Init.class); } catch (final InstantiationException e) { throw new ComponentInitializationException("Attribute binding failed", e); } }
public void activate(IProcessingComponent processingComponent, String parameter) { // Remember values of @Input @Processing attributes final Map<String, Object> originalValues = Maps.newHashMap(); try { AttributeBinder.get(processingComponent, originalValues, Input.class, Processing.class); resetValues.put(new ReferenceEquality(processingComponent), originalValues); } catch (Exception e) { throw new ProcessingException("Could not unbind attribute values", e); } }
/** * Perform all life cycle actions after processing is completed. */ public static void afterProcessing(IProcessingComponent processingComponent, Map<String, Object> attributes) { try { processingComponent.afterProcessing(); final Map<String, Object> outputAttributesWithNulls = Maps.newHashMap(); // Check if we need to do binding. if (processingComponent.getClass().getAnnotation(Bindable.class) != null) { AttributeBinder.get(processingComponent, outputAttributesWithNulls, Output.class, Processing.class); } attributes.putAll(Maps.filterValues(outputAttributesWithNulls, Predicates.notNull())); } catch (final InstantiationException e) { throw new ProcessingException("Attribute binding failed", e); } } }
/** * Performs safety checks aimed at reporting attempts to set non-primitive * non-thread-safe primitive instances during initialization. These may lead to * hard-to-trace bugs. * * @see "https://issues.apache.org/jira/browse/SOLR-2282" */ void checkNonPrimitiveInstances(IProcessingComponent processingComponent, Map<String, Object> inputAttributes, Predicate<Field> predicate) throws InstantiationException { AttributeBinder.bind(processingComponent, new IAttributeBinderAction [] { new NonPrimitiveInputAttributesCheck(inputAttributes) }, predicate); } }
/** * A version of {@link #set(Object, Map, Class...)} that can optionally skip * {@link Required} attribute checking. For experts only. */ @SafeVarargs public static <T> Map<String, Object> set(T object, Map<String, Object> values, boolean checkRequired, Class<? extends Annotation>... filteringAnnotations) throws InstantiationException, AttributeBindingException { return set(object, values, checkRequired, filteringAnnotations.length > 0 ? new AllAnnotationsPresentPredicate( filteringAnnotations) : Predicates.<Field> alwaysTrue()); }
/** * A version of {@link #set(Object, Map, boolean, Class...)} with a {@link Predicate} * instead of filtering annotations. For experts only. */ public static Map<String, Object> set(Object object, Map<String, Object> values, boolean checkRequired, Predicate<Field> predicate) throws InstantiationException, AttributeBindingException { final AttributeBinderActionBind attributeBinderActionBind = new AttributeBinderActionBind( values, checkRequired, AttributeTransformerFromString.INSTANCE, AttributeTransformerFactory.INSTANCE); final IAttributeBinderAction [] actions = new IAttributeBinderAction [] { attributeBinderActionBind, }; bind(object, actions, predicate); return attributeBinderActionBind.remainingValues; }
public void passivate(IProcessingComponent processingComponent, String parameter) { // Reset values of @Input @Processing attributes back to original values try { // Here's a little hack: we need to disable checking // for required attributes, otherwise, we won't be able // to reset @Required input attributes to null final Map<String, Object> originalAttributes = resetValues .get(new ReferenceEquality(processingComponent)); if (originalAttributes != null) { AttributeBinder.set(processingComponent, originalAttributes, false, Input.class, Processing.class); } } catch (Exception e) { throw new ProcessingException("Could not reset attribute values", e); } } }
/** * A generic method for performing actions on the <code>object</code>'s hierarchy of * attributes. For experts only. */ public static void bind(Object object, IAttributeBinderAction [] attributeBinderActions, Predicate<Field> predicate) throws InstantiationException, AttributeBindingException { bind(new HashSet<Object>(), new BindingTracker(), 0, object, attributeBinderActions, Predicates.<Field> and(CONSISTENCY_CHECKS, predicate), Bindable.class); }
/** * 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); } }
/** * A generic method for performing actions on the <code>object</code>'s hierarchy of * attributes. For experts only. */ @SafeVarargs public static void bind(Object object, IAttributeBinderAction [] attributeBinderActions, Class<? extends Annotation>... filteringAnnotations) throws InstantiationException, AttributeBindingException { bind(object, attributeBinderActions, filteringAnnotations.length > 0 ? new AllAnnotationsPresentPredicate( filteringAnnotations) : Predicates.<Field> alwaysTrue()); }
AttributeBinder.set(component, inputAttributes, false, Input.class, Processing.class);
}; bind(object, actions, filteringAnnotations);
if (clazz.isAnnotationPresent(Bindable.class)) set(value, values, false, predicate);
AttributeBinder.bind(o, actions, p, injectableMarker);
AttributeBinder.set(component, initAttrs, false, predicate);
bind(boundObjects, bindingTracker, level + 1, value, attributeBinderActions, predicate, markerAnnotation);