Search in sources :

Example 21 with AnnotationProvider

use of org.apache.tapestry5.commons.AnnotationProvider in project tapestry-5 by apache.

the class MessagesConstraintGenerator method buildConstraints.

public List<String> buildConstraints(Class propertyType, AnnotationProvider annotationProvider) {
    EnvironmentMessages environmentMessages = environment.peek(EnvironmentMessages.class);
    if (environmentMessages == null) {
        return null;
    }
    String key = environmentMessages.getOverrideId() + "-validate";
    Messages m = environmentMessages.getMessages();
    if (!m.contains(key)) {
        return null;
    }
    String result = m.get(key);
    if (InternalUtils.isBlank(result)) {
        return null;
    }
    return Arrays.asList(splitPattern.split(result));
}
Also used : Messages(org.apache.tapestry5.commons.Messages)

Example 22 with AnnotationProvider

use of org.apache.tapestry5.commons.AnnotationProvider in project tapestry-5 by apache.

the class RegistryImpl method getServiceByTypeAndMarkers.

private <T> T getServiceByTypeAndMarkers(Class<T> serviceInterface, Class<? extends Annotation>... markerTypes) {
    if (markerTypes.length == 0) {
        return getServiceByTypeAlone(serviceInterface);
    }
    AnnotationProvider provider = createAnnotationProvider(markerTypes);
    Set<ServiceDef2> matches = CollectionFactory.newSet();
    List<Class> markers = CollectionFactory.newList();
    findServiceDefsMatchingMarkerAndType(serviceInterface, provider, null, markers, matches);
    return extractServiceFromMatches(serviceInterface, markers, matches);
}
Also used : NullAnnotationProvider(org.apache.tapestry5.commons.internal.NullAnnotationProvider)

Example 23 with AnnotationProvider

use of org.apache.tapestry5.commons.AnnotationProvider in project tapestry-5 by apache.

the class RegistryImpl method getOrderedConfiguration.

@Override
@SuppressWarnings("unchecked")
public <T> List<T> getOrderedConfiguration(ServiceDef3 serviceDef, Class<T> objectType) {
    lock.check();
    String serviceId = serviceDef.getServiceId();
    Logger logger = getServiceLogger(serviceId);
    Orderer<T> orderer = new Orderer<T>(logger);
    Map<String, OrderedConfigurationOverride<T>> overrides = CollectionFactory.newCaseInsensitiveMap();
    // TAP5-2129. NOTICE: if someday an ordering between modules is added, this should be reverted
    // or a notice added to the documentation.
    List<Module> modules = new ArrayList<Module>(moduleToServiceDefs.keySet());
    Collections.sort(modules, new ModuleComparator());
    for (Module m : modules) addToOrderedConfiguration(orderer, overrides, objectType, serviceDef, m);
    if (serviceId.equals("MasterObjectProvider")) {
        ObjectProvider contribution = new ObjectProvider() {

            @Override
            public <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator) {
                return findServiceByMarkerAndType(objectType, annotationProvider, null);
            }
        };
        orderer.add("ServiceByMarker", (T) contribution);
    }
    for (OrderedConfigurationOverride<T> override : overrides.values()) override.apply();
    final List<T> result = orderer.getOrdered();
    if (!isServiceConfigurationListenerServiceDef(serviceDef)) {
        serviceConfigurationListener.onOrderedConfiguration(serviceDef, result);
    }
    return result;
}
Also used : NullAnnotationProvider(org.apache.tapestry5.commons.internal.NullAnnotationProvider) Logger(org.slf4j.Logger) MasterObjectProvider(org.apache.tapestry5.ioc.services.MasterObjectProvider) TapestryIOCModule(org.apache.tapestry5.ioc.modules.TapestryIOCModule) Orderer(org.apache.tapestry5.ioc.internal.util.Orderer)

Example 24 with AnnotationProvider

use of org.apache.tapestry5.commons.AnnotationProvider in project tapestry-5 by apache.

the class ServiceAnnotationObjectProviderTest method annotation_present.

@SuppressWarnings("unchecked")
@Test
public void annotation_present() {
    Class objectType = Runnable.class;
    AnnotationProvider provider = mockAnnotationProvider();
    ObjectLocator locator = mockObjectLocator();
    Service service = newMock(Service.class);
    String serviceId = "JiffyPop";
    Runnable instance = mockRunnable();
    train_getAnnotation(provider, Service.class, service);
    expect(service.value()).andReturn(serviceId);
    train_getService(locator, serviceId, objectType, instance);
    replay();
    ObjectProvider objectProvider = new ServiceAnnotationObjectProvider();
    assertSame(objectProvider.provide(objectType, provider, locator), instance);
    verify();
}
Also used : AnnotationProvider(org.apache.tapestry5.commons.AnnotationProvider) ObjectLocator(org.apache.tapestry5.commons.ObjectLocator) Service(org.apache.tapestry5.annotations.Service) ObjectProvider(org.apache.tapestry5.commons.ObjectProvider) Test(org.testng.annotations.Test)

Example 25 with AnnotationProvider

use of org.apache.tapestry5.commons.AnnotationProvider in project tapestry-5 by apache.

the class ServiceAnnotationObjectProviderTest method no_annotation.

@SuppressWarnings("unchecked")
@Test
public void no_annotation() {
    Class objectType = Runnable.class;
    AnnotationProvider provider = mockAnnotationProvider();
    ObjectLocator locator = mockObjectLocator();
    train_getAnnotation(provider, Service.class, null);
    replay();
    ObjectProvider objectProvider = new ServiceAnnotationObjectProvider();
    assertNull(objectProvider.provide(objectType, provider, locator));
    verify();
}
Also used : AnnotationProvider(org.apache.tapestry5.commons.AnnotationProvider) ObjectLocator(org.apache.tapestry5.commons.ObjectLocator) ObjectProvider(org.apache.tapestry5.commons.ObjectProvider) Test(org.testng.annotations.Test)

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