use of org.apache.tapestry5.ioc.def.ServiceDef in project tapestry-5 by apache.
the class RegistryImpl method getMappedConfiguration.
@Override
public <K, V> Map<K, V> getMappedConfiguration(ServiceDef3 serviceDef, Class<K> keyType, Class<V> objectType) {
lock.check();
// When the key type is String, then a case insensitive map is used.
Map<K, V> result = newConfigurationMap(keyType);
Map<K, ContributionDef> keyToContribution = newConfigurationMap(keyType);
Map<K, MappedConfigurationOverride<K, V>> overrides = newConfigurationMap(keyType);
for (Module m : moduleToServiceDefs.keySet()) addToMappedConfiguration(result, overrides, keyToContribution, keyType, objectType, serviceDef, m);
for (MappedConfigurationOverride<K, V> override : overrides.values()) {
override.apply();
}
if (!isServiceConfigurationListenerServiceDef(serviceDef)) {
serviceConfigurationListener.onMappedConfiguration(serviceDef, result);
}
return result;
}
use of org.apache.tapestry5.ioc.def.ServiceDef in project tapestry-5 by apache.
the class RegistryImpl method addToMappedConfiguration.
private <K, V> void addToMappedConfiguration(Map<K, V> map, Map<K, MappedConfigurationOverride<K, V>> overrides, Map<K, ContributionDef> keyToContribution, Class<K> keyClass, Class<V> 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 MappedConfiguration<K, V> validating = new ValidatingMappedConfigurationWrapper<K, V>(valueType, resources, typeCoercerProxy, map, overrides, serviceId, def, keyClass, keyToContribution);
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.def.ServiceDef in project tapestry-5 by apache.
the class DefaultModuleDefImpl method addServiceDef.
@Override
public void addServiceDef(ServiceDef serviceDef) {
String serviceId = serviceDef.getServiceId();
ServiceDef existing = serviceDefs.get(serviceId);
if (existing != null)
throw new RuntimeException(IOCMessages.buildMethodConflict(serviceId, serviceDef.toString(), existing.toString()));
serviceDefs.put(serviceId, serviceDef);
}
use of org.apache.tapestry5.ioc.def.ServiceDef 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.def.ServiceDef 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();
}
Aggregations