use of org.apache.tapestry5.ioc.def.ServiceDef in project tapestry-5 by apache.
the class InterceptorStackBuilder method createObject.
@Override
public Object createObject() {
Object current = delegate.createObject();
List<ServiceDecorator> decorators = registry.findDecoratorsForService(serviceDef);
// We get the decorators ordered according to their dependencies. However, we want to
// process from the last interceptor to the first, so we reverse the list.
Collections.reverse(decorators);
for (final ServiceDecorator decorator : decorators) {
final Object delegate = current;
Object interceptor = registry.invoke("Invoking " + decorator, new Invokable<Object>() {
@Override
public Object invoke() {
return decorator.createInterceptor(delegate);
}
});
if (interceptor != null)
current = interceptor;
}
return current;
}
use of org.apache.tapestry5.ioc.def.ServiceDef 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.def.ServiceDef 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