Search in sources :

Example 1 with AdvisorDef

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);
}
Also used : MethodAdviceReceiver(org.apache.tapestry5.ioc.MethodAdviceReceiver) Advise(org.apache.tapestry5.ioc.annotations.Advise) AdvisorDef(org.apache.tapestry5.ioc.AdvisorDef)

Example 2 with AdvisorDef

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();
}
Also used : ServiceResources(org.apache.tapestry5.ioc.ServiceResources) Logger(org.slf4j.Logger) TapestryIOCModule(org.apache.tapestry5.ioc.modules.TapestryIOCModule) ServiceAdvisor(org.apache.tapestry5.ioc.ServiceAdvisor) AdvisorDef(org.apache.tapestry5.ioc.AdvisorDef) Orderer(org.apache.tapestry5.ioc.internal.util.Orderer)

Aggregations

AdvisorDef (org.apache.tapestry5.ioc.AdvisorDef)2 MethodAdviceReceiver (org.apache.tapestry5.ioc.MethodAdviceReceiver)1 ServiceAdvisor (org.apache.tapestry5.ioc.ServiceAdvisor)1 ServiceResources (org.apache.tapestry5.ioc.ServiceResources)1 Advise (org.apache.tapestry5.ioc.annotations.Advise)1 Orderer (org.apache.tapestry5.ioc.internal.util.Orderer)1 TapestryIOCModule (org.apache.tapestry5.ioc.modules.TapestryIOCModule)1 Logger (org.slf4j.Logger)1