Search in sources :

Example 11 with AnnotationProvider

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;
}
Also used : AnnotationProvider(org.apache.tapestry5.commons.AnnotationProvider) Translate(org.apache.tapestry5.beaneditor.Translate)

Example 12 with AnnotationProvider

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));
}
Also used : CompositeFieldValidator(org.apache.tapestry5.internal.services.CompositeFieldValidator) FieldValidator(org.apache.tapestry5.FieldValidator) CompositeFieldValidator(org.apache.tapestry5.internal.services.CompositeFieldValidator)

Example 13 with AnnotationProvider

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());
}
Also used : AutobuildObjectProvider(org.apache.tapestry5.ioc.internal.services.AutobuildObjectProvider) ValueObjectProvider(org.apache.tapestry5.ioc.internal.services.ValueObjectProvider) MasterObjectProvider(org.apache.tapestry5.ioc.services.MasterObjectProvider) SymbolObjectProvider(org.apache.tapestry5.ioc.internal.services.SymbolObjectProvider) AutobuildObjectProvider(org.apache.tapestry5.ioc.internal.services.AutobuildObjectProvider)

Example 14 with AnnotationProvider

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);
}
Also used : Path(org.apache.tapestry5.annotations.Path) Asset(org.apache.tapestry5.Asset)

Example 15 with AnnotationProvider

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);
}
Also used : IntermediateType(org.apache.tapestry5.ioc.annotations.IntermediateType) Symbol(org.apache.tapestry5.ioc.annotations.Symbol)

Aggregations

AnnotationProvider (org.apache.tapestry5.commons.AnnotationProvider)17 Test (org.testng.annotations.Test)13 Messages (org.apache.tapestry5.commons.Messages)10 Locale (java.util.Locale)9 Field (org.apache.tapestry5.Field)9 Map (java.util.Map)7 FieldValidator (org.apache.tapestry5.FieldValidator)6 FieldTranslatorSource (org.apache.tapestry5.services.FieldTranslatorSource)6 TranslatorSource (org.apache.tapestry5.services.TranslatorSource)6 FieldTranslator (org.apache.tapestry5.FieldTranslator)5 Translator (org.apache.tapestry5.Translator)5 MarkupWriter (org.apache.tapestry5.MarkupWriter)4 MessageFormatter (org.apache.tapestry5.commons.MessageFormatter)4 ObjectLocator (org.apache.tapestry5.commons.ObjectLocator)4 ObjectProvider (org.apache.tapestry5.commons.ObjectProvider)4 FieldValidatorDefaultSource (org.apache.tapestry5.services.FieldValidatorDefaultSource)4 Asset (org.apache.tapestry5.Asset)3 NullAnnotationProvider (org.apache.tapestry5.commons.internal.NullAnnotationProvider)3 MasterObjectProvider (org.apache.tapestry5.ioc.services.MasterObjectProvider)3 FormSupport (org.apache.tapestry5.services.FormSupport)3