use of org.apache.tapestry5.commons.AnnotationProvider in project tapestry-5 by apache.
the class ValueObjectProvider method provide.
@Override
public <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator) {
Value annotation = annotationProvider.getAnnotation(Value.class);
if (annotation == null)
return null;
String value = annotation.value();
Object expanded = symbolSource.expandSymbols(value);
IntermediateType intermediate = annotationProvider.getAnnotation(IntermediateType.class);
if (intermediate != null)
expanded = typeCoercer.coerce(expanded, intermediate.value());
return typeCoercer.coerce(expanded, objectType);
}
use of org.apache.tapestry5.commons.AnnotationProvider in project tapestry-5 by apache.
the class FieldValidatorDefaultSourceImpl method createDefaultValidator.
public FieldValidator createDefaultValidator(Field field, String overrideId, Messages overrideMessages, Locale locale, Class propertyType, AnnotationProvider propertyAnnotations) {
List<FieldValidator> validators = newList();
for (String constraint : validationConstraintGenerator.buildConstraints(propertyType, propertyAnnotations)) {
int equalsx = constraint.indexOf('=');
String validatorType = equalsx > 0 ? constraint.substring(0, equalsx) : constraint;
String constraintValue = equalsx > 0 ? constraint.substring(equalsx + 1) : null;
FieldValidator validator = fieldValidatorSource.createValidator(field, validatorType, constraintValue, overrideId, overrideMessages, locale);
validators.add(validator);
}
return validators.size() == 1 ? validators.get(0) : new CompositeFieldValidator(validators);
}
use of org.apache.tapestry5.commons.AnnotationProvider in project tapestry-5 by apache.
the class FieldTranslatorSourceImplTest method create_default_translator_with_per_form_override_message.
@Test
public void create_default_translator_with_per_form_override_message() {
Field field = mockField();
Messages messages = mockMessages();
Locale locale = Locale.ENGLISH;
Class propertyType = Map.class;
TranslatorSource ts = mockTranslatorSource();
FormSupport fs = mockFormSupport();
Translator translator = mockTranslator("maptrans", Map.class);
MessageFormatter formatter = mockMessageFormatter();
MarkupWriter writer = mockMarkupWriter();
String label = "My Label";
String message = "Formatted Message";
AnnotationProvider ap = mockAnnotationProvider(null);
train_findByType(ts, propertyType, translator);
train_getFormValidationId(fs, "myform");
train_contains(messages, "myform-myfield-maptrans-message", true);
train_getMessageFormatter(messages, "myform-myfield-maptrans-message", formatter);
train_getLabel(field, label);
train_format(formatter, message, label);
translator.render(field, message, writer, fs);
replay();
FieldTranslatorSource source = new FieldTranslatorSourceImpl(ts, null, fs);
FieldTranslator ft = source.createDefaultTranslator(field, "myfield", messages, locale, propertyType, ap);
assertEquals(ft.getType(), Map.class);
ft.render(writer);
verify();
}
use of org.apache.tapestry5.commons.AnnotationProvider in project tapestry-5 by apache.
the class FieldValidatorDefaultSourceImplTest method no_validators_at_all.
@SuppressWarnings("unchecked")
@Test
public void no_validators_at_all() throws Exception {
ValidationConstraintGenerator gen = mockValidationConstraintGenerator();
FieldValidatorSource source = mockFieldValidatorSource();
Class propertyType = Integer.class;
AnnotationProvider provider = mockAnnotationProvider();
String overrideId = "overrideId";
Messages overrideMessages = mockMessages();
Field field = mockField();
Locale locale = Locale.ENGLISH;
String value = "*VALUE*";
train_buildConstraints(gen, propertyType, provider);
replay();
FieldValidatorDefaultSource fieldValidatorSource = new FieldValidatorDefaultSourceImpl(gen, source);
FieldValidator composite = fieldValidatorSource.createDefaultValidator(field, overrideId, overrideMessages, locale, propertyType, provider);
composite.validate(value);
verify();
}
use of org.apache.tapestry5.commons.AnnotationProvider in project tapestry-5 by apache.
the class FieldTranslatorSourceImplTest method create_default_translator_with_annotation.
@Test
public void create_default_translator_with_annotation() {
TranslatorSource ts = mockTranslatorSource();
AnnotationProvider ap = mockAnnotationProvider("fred");
Translator t = mockTranslator();
expect(ts.get("fred")).andReturn(t);
replay();
FieldTranslatorSourceImpl source = new FieldTranslatorSourceImpl(ts, null, null);
assertSame(source.findTranslator(Map.class, ap), t);
verify();
}
Aggregations