| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
package org.apache.tapestry5.internal.bindings; |
| 16 | |
|
| 17 | |
import org.apache.tapestry5.Binding; |
| 18 | |
import org.apache.tapestry5.ComponentResources; |
| 19 | |
import org.apache.tapestry5.Field; |
| 20 | |
import org.apache.tapestry5.FieldValidator; |
| 21 | |
import org.apache.tapestry5.internal.services.StringInterner; |
| 22 | |
import org.apache.tapestry5.ioc.Location; |
| 23 | |
import org.apache.tapestry5.ioc.internal.util.TapestryException; |
| 24 | |
import org.apache.tapestry5.services.BindingFactory; |
| 25 | |
import org.apache.tapestry5.services.FieldValidatorSource; |
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | 16 | public class ValidateBindingFactory implements BindingFactory |
| 33 | |
{ |
| 34 | |
private final FieldValidatorSource fieldValidatorSource; |
| 35 | |
|
| 36 | |
private final StringInterner interner; |
| 37 | |
|
| 38 | |
public ValidateBindingFactory(FieldValidatorSource fieldValidatorSource, StringInterner interner) |
| 39 | 6 | { |
| 40 | 6 | this.fieldValidatorSource = fieldValidatorSource; |
| 41 | 6 | this.interner = interner; |
| 42 | 6 | } |
| 43 | |
|
| 44 | |
public Binding newBinding(String description, ComponentResources container, |
| 45 | |
ComponentResources component, final String expression, Location location) |
| 46 | |
{ |
| 47 | 18 | Object fieldAsObject = component.getComponent(); |
| 48 | |
|
| 49 | 18 | if (!Field.class.isInstance(fieldAsObject)) |
| 50 | 2 | throw new TapestryException(BindingsMessages.validateBindingForFieldsOnly(component), |
| 51 | |
location, null); |
| 52 | |
|
| 53 | 16 | final Field field = (Field) fieldAsObject; |
| 54 | |
|
| 55 | 16 | return new InvariantBinding(location, FieldValidator.class, interner.intern(description + ": " + expression)) |
| 56 | |
{ |
| 57 | 16 | public Object get() |
| 58 | |
{ |
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | 16 | return fieldValidatorSource.createValidators(field, expression); |
| 65 | |
} |
| 66 | |
}; |
| 67 | |
} |
| 68 | |
} |