use of org.apache.tapestry5.ioc.AdvisorDef in project tapestry-5 by apache.
the class DefaultModuleDefImpl method addAdvisorDef.
private void addAdvisorDef(Method method) {
Advise annotation = method.getAnnotation(Advise.class);
Class serviceInterface = annotation == null ? null : annotation.serviceInterface();
// TODO: methods just named "decorate"
String advisorId = annotation == null ? stripMethodPrefix(method, ADVISE_METHOD_NAME_PREFIX) : extractId(serviceInterface, annotation.id());
// TODO: Check for duplicates
Class returnType = method.getReturnType();
if (!returnType.equals(void.class))
throw new RuntimeException(String.format("Advise method %s does not return void.", toString(method)));
boolean found = false;
for (Class pt : method.getParameterTypes()) {
if (pt.equals(MethodAdviceReceiver.class)) {
found = true;
break;
}
}
if (!found)
throw new RuntimeException(String.format("Advise method %s must take a parameter of type %s.", toString(method), MethodAdviceReceiver.class.getName()));
Set<Class> markers = extractMarkers(method, Advise.class);
AdvisorDef def = new AdvisorDefImpl(method, extractPatterns(advisorId, method), extractConstraints(method), proxyFactory, advisorId, serviceInterface, markers);
advisorDefs.put(advisorId, def);
}
use of org.apache.tapestry5.ioc.AdvisorDef 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();
}
Aggregations