1616package org .ocpsoft .rewrite .bind ;
1717
1818import java .util .ArrayList ;
19- import java .util .ConcurrentModificationException ;
2019import java .util .LinkedHashMap ;
2120import java .util .List ;
2221import java .util .Map ;
23- import java .util .Map .Entry ;
2422
2523import org .ocpsoft .rewrite .config .Condition ;
2624import org .ocpsoft .rewrite .config .DefaultConditionBuilder ;
3129
3230/**
3331 * Utility class for interacting with {@link Bindable} instances.
34- *
32+ *
3533 * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
36- *
34+ *
3735 */
3836public abstract class Bindings
3937{
@@ -44,69 +42,50 @@ public abstract class Bindings
4442 public static boolean enqueueSubmission (final Rewrite event , final EvaluationContext context ,
4543 final HasBindings bindable , final Object value )
4644 {
45+ if (value == null )
46+ return true ;
47+
4748 Map <HasBindings , Object > map = new LinkedHashMap <HasBindings , Object >();
4849 map .put (bindable , value );
49- return enqueueSubmissions (event , context , map );
50- }
5150
52- /**
53- * Submit the given value to all registered {@link Binding} instances of all given {@link HasBindings} instances.
54- * Perform this by adding individual {@link BindingOperation} instances via
55- * {@link EvaluationContext#addPreOperation(org.ocpsoft.rewrite.config.Operation)}
56- *
57- * @return false if validation fails.
58- */
59- public static boolean enqueueSubmissions (final Rewrite event , final EvaluationContext context ,
60- final Map <? extends HasBindings , ? extends Object > map )
61- {
6251 List <Operation > operations = new ArrayList <Operation >();
63- for (Entry <? extends HasBindings , ? extends Object > entry : map .entrySet ()) {
64-
65- HasBindings parameter = entry .getKey ();
66- Object value = entry .getValue ();
67-
68- List <Binding > bindings = parameter .getBindings ();
52+ List <Binding > bindings = bindable .getBindings ();
53+ for (Binding binding : bindings ) {
6954 try {
70- for (Binding binding : bindings ) {
71- try {
72- if (binding instanceof Evaluation )
73- {
74- /*
75- * Binding to the EvaluationContext is available immediately.
76- */
77- Object convertedValue = binding .convert (event , context , value );
78- if (binding .validate (event , context , convertedValue ))
79- {
80- binding .submit (event , context , value );
81- }
82- else
83- return false ;
84- }
85- else
86- {
87- Object convertedValue = binding .convert (event , context , value );
88- if (binding .validate (event , context , convertedValue ))
89- {
90- convertedValue = binding .convert (event , context , convertedValue );
91- operations .add (new BindingOperation (binding , convertedValue ));
92- }
93- else
94- return false ;
95- }
55+ if (binding instanceof Evaluation )
56+ {
57+ /*
58+ * Binding to the EvaluationContext is available immediately.
59+ */
60+ Object convertedValue = binding .convert (event , context , value );
61+ if (binding .validate (event , context , convertedValue ))
62+ {
63+ binding .submit (event , context , value );
9664 }
97- catch (Exception e ) {
98- throw new RewriteException ("Failed to bind value [" + value + "] to binding [" + binding + "]" , e );
65+ else
66+ return false ;
67+ }
68+ else
69+ {
70+ Object convertedValue = binding .convert (event , context , value );
71+ if (binding .validate (event , context , convertedValue ))
72+ {
73+ convertedValue = binding .convert (event , context , convertedValue );
74+ operations .add (new BindingOperation (binding , convertedValue ));
9975 }
76+ else
77+ return false ;
10078 }
10179 }
102- catch (ConcurrentModificationException e ) {
103- e . printStackTrace ( );
80+ catch (Exception e ) {
81+ throw new RewriteException ( "Failed to bind value [" + value + "] to binding [" + binding + "]" , e );
10482 }
10583 }
10684
10785 for (Operation operation : operations ) {
10886 context .addPreOperation (operation );
10987 }
88+
11089 return true ;
11190 }
11291
@@ -303,7 +282,7 @@ else if ((expected != null) && expected.equals(actual))
303282
304283 /**
305284 * Used to store bindings until all conditions have been met.
306- *
285+ *
307286 * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
308287 */
309288 private static class BindingOperation implements Operation
0 commit comments