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));
}
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);
}
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;
}
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();
}
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();
}
Aggregations