use of org.apache.tapestry5.commons.AnnotationProvider in project tapestry-5 by apache.
the class FieldTranslatorSourceImplTest method mockAnnotationProvider.
private AnnotationProvider mockAnnotationProvider(String translatorName) {
AnnotationProvider ap = mockAnnotationProvider();
if (translatorName == null) {
train_getAnnotation(ap, Translate.class, null);
} else {
Translate t = newMock(Translate.class);
expect(t.value()).andReturn(translatorName).atLeastOnce();
train_getAnnotation(ap, Translate.class, t);
}
return ap;
}
use of org.apache.tapestry5.commons.AnnotationProvider in project tapestry-5 by apache.
the class BeanFieldValidatorDefaultSource method createDefaultValidator.
@Override
public FieldValidator createDefaultValidator(final Field field, final String overrideId, final Messages overrideMessages, final Locale locale, final Class propertyType, final AnnotationProvider propertyAnnotations) {
FieldValidator validator = fieldValidatorDefaultSource.createDefaultValidator(field, overrideId, overrideMessages, locale, propertyType, propertyAnnotations);
FieldValidator beanValidator = new BeanFieldValidator(field, validatorFactory, beanValidationGroupSource, clientValidatorSource, formSupport, environment);
return new CompositeFieldValidator(Arrays.asList(validator, beanValidator));
}
use of org.apache.tapestry5.commons.AnnotationProvider in project tapestry-5 by apache.
the class TapestryIOCModule method setupObjectProviders.
/**
* <dl>
* <dt>AnnotationBasedContributions</dt>
* <dd>Empty placeholder used to separate annotation-based ObjectProvider contributions (which come before) from
* non-annotation based (such as ServiceOverride) which come after.</dd>
* <dt>Value</dt>
* <dd>Supports the {@link org.apache.tapestry5.ioc.annotations.Value} annotation</dd>
* <dt>Symbol</dt>
* <dd>Supports the {@link org.apache.tapestry5.ioc.annotations.Symbol} annotations</dd>
* <dt>Autobuild</dt>
* <dd>Supports the {@link org.apache.tapestry5.ioc.annotations.Autobuild} annotation</dd>
* <dt>ServiceOverride</dt>
* <dd>Allows simple service overrides via the {@link org.apache.tapestry5.ioc.services.ServiceOverride} service
* (and its configuration)
* </dl>
*/
@Contribute(MasterObjectProvider.class)
public static void setupObjectProviders(OrderedConfiguration<ObjectProvider> configuration, @Local final ServiceOverride serviceOverride) {
configuration.add("AnnotationBasedContributions", null);
configuration.addInstance("Value", ValueObjectProvider.class, before("AnnotationBasedContributions").build());
configuration.addInstance("Symbol", SymbolObjectProvider.class, before("AnnotationBasedContributions").build());
configuration.add("Autobuild", new AutobuildObjectProvider(), before("AnnotationBasedContributions").build());
ObjectProvider wrapper = new ObjectProvider() {
@Override
public <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator) {
return serviceOverride.getServiceOverrideProvider().provide(objectType, annotationProvider, locator);
}
};
configuration.add("ServiceOverride", wrapper, after("AnnotationBasedContributions").build());
}
use of org.apache.tapestry5.commons.AnnotationProvider in project tapestry-5 by apache.
the class AssetObjectProvider method provide.
/**
* Provides the asset. If the expression does not identify an asset domain, with a prefix, it is assumed to be a
* path on the classpath, relative to the root of the classpath.
*
* @param objectType the type of object (which must be Object or Asset)
* @param locator not used
*/
public <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator) {
Path path = annotationProvider.getAnnotation(Path.class);
if (path == null)
return null;
String expanded = symbolSource.expandSymbols(path.value());
Asset asset = source.getAsset(null, expanded, null);
return typeCoercer.coerce(asset, objectType);
}
use of org.apache.tapestry5.commons.AnnotationProvider in project tapestry-5 by apache.
the class SymbolObjectProvider method provide.
@Override
public <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator) {
Symbol annotation = annotationProvider.getAnnotation(Symbol.class);
if (annotation == null)
return null;
Object value = symbolSource.valueForSymbol(annotation.value());
IntermediateType it = annotationProvider.getAnnotation(IntermediateType.class);
if (it != null)
value = typeCoercer.coerce(value, it.value());
return typeCoercer.coerce(value, objectType);
}
Aggregations