use of org.apache.tapestry5.ioc.internal.util.Orderer in project tapestry-5 by apache.
the class RegistryImpl method addToOrderedConfiguration.
private <T> void addToOrderedConfiguration(Orderer<T> orderer, Map<String, OrderedConfigurationOverride<T>> overrides, Class<T> valueType, ServiceDef3 serviceDef, final Module module) {
String serviceId = serviceDef.getServiceId();
Set<ContributionDef2> contributions = module.getContributorDefsForService(serviceDef);
if (contributions.isEmpty())
return;
Logger logger = getServiceLogger(serviceId);
final ServiceResources resources = new ServiceResourcesImpl(this, module, serviceDef, proxyFactory, logger);
for (final ContributionDef def : contributions) {
final OrderedConfiguration<T> validating = new ValidatingOrderedConfigurationWrapper<T>(valueType, resources, typeCoercerProxy, orderer, overrides, def);
String description = "Invoking " + def;
logger.debug(description);
operationTracker.run(description, new Runnable() {
@Override
public void run() {
def.contribute(module, resources, validating);
}
});
}
}
use of org.apache.tapestry5.ioc.internal.util.Orderer in project tapestry-5 by apache.
the class RegistryImpl method findDecoratorsForService.
@Override
public List<ServiceDecorator> findDecoratorsForService(ServiceDef3 serviceDef) {
lock.check();
assert serviceDef != null;
Logger logger = getServiceLogger(serviceDef.getServiceId());
Orderer<ServiceDecorator> orderer = new Orderer<ServiceDecorator>(logger, true);
for (Module module : moduleToServiceDefs.keySet()) {
Set<DecoratorDef> decoratorDefs = module.findMatchingDecoratorDefs(serviceDef);
if (decoratorDefs.isEmpty())
continue;
ServiceResources resources = new ServiceResourcesImpl(this, module, serviceDef, proxyFactory, logger);
for (DecoratorDef decoratorDef : decoratorDefs) {
ServiceDecorator decorator = decoratorDef.createDecorator(module, resources);
try {
orderer.add(decoratorDef.getDecoratorId(), decorator, decoratorDef.getConstraints());
} catch (IllegalArgumentException e) {
throw new RuntimeException(String.format("Service %s has two different decorators methods named decorate%s in different module classes. " + "You can solve this by renaming one of them and annotating it with @Match(\"%2$s\").", serviceDef.getServiceId(), decoratorDef.getDecoratorId()));
}
}
}
return orderer.getOrdered();
}
use of org.apache.tapestry5.ioc.internal.util.Orderer in project tapestry-5 by apache.
the class RegistryImpl method findAdvisorsForService.
@Override
public List<ServiceAdvisor> findAdvisorsForService(ServiceDef3 serviceDef) {
lock.check();
assert serviceDef != null;
Logger logger = getServiceLogger(serviceDef.getServiceId());
Orderer<ServiceAdvisor> orderer = new Orderer<ServiceAdvisor>(logger, true);
for (Module module : moduleToServiceDefs.keySet()) {
Set<AdvisorDef> advisorDefs = module.findMatchingServiceAdvisors(serviceDef);
if (advisorDefs.isEmpty())
continue;
ServiceResources resources = new ServiceResourcesImpl(this, module, serviceDef, proxyFactory, logger);
for (AdvisorDef advisorDef : advisorDefs) {
ServiceAdvisor advisor = advisorDef.createAdvisor(module, resources);
orderer.add(advisorDef.getAdvisorId(), advisor, advisorDef.getConstraints());
}
}
return orderer.getOrdered();
}
use of org.apache.tapestry5.ioc.internal.util.Orderer 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;
}
Aggregations