Example usage for org.springframework.aop Advisor getAdvice

List of usage examples for org.springframework.aop Advisor getAdvice

Introduction

In this page you can find the example usage for org.springframework.aop Advisor getAdvice.

Prototype

Advice getAdvice();

Source Link

Document

Return the advice part of this aspect.

Usage

From source file:cn.guoyukun.spring.utils.AopProxyUtils.java

private static void removeAdvisor(Object proxy, Class<? extends Advice> adviceClass) {
    if (!AopUtils.isAopProxy(proxy)) {
        return;// w  w w.jav  a  2  s.com
    }
    ProxyFactory proxyFactory = null;
    if (AopUtils.isJdkDynamicProxy(proxy)) {
        proxyFactory = findJdkDynamicProxyFactory(proxy);
    }
    if (AopUtils.isCglibProxy(proxy)) {
        proxyFactory = findCglibProxyFactory(proxy);
    }

    Advisor[] advisors = proxyFactory.getAdvisors();

    if (advisors == null || advisors.length == 0) {
        return;
    }

    for (Advisor advisor : advisors) {
        if (adviceClass.isAssignableFrom(advisor.getAdvice().getClass())) {
            proxyFactory.removeAdvisor(advisor);
            break;
        }
    }
}

From source file:cn.guoyukun.spring.utils.AopProxyUtils.java

private static boolean hasAdvice(Object proxy, Class<? extends Advice> adviceClass) {
    if (!AopUtils.isAopProxy(proxy)) {
        return false;
    }//from www  .j  a v  a2  s .c  o m
    ProxyFactory proxyFactory = null;
    if (AopUtils.isJdkDynamicProxy(proxy)) {
        proxyFactory = findJdkDynamicProxyFactory(proxy);
    }
    if (AopUtils.isCglibProxy(proxy)) {
        proxyFactory = findCglibProxyFactory(proxy);
    }

    Advisor[] advisors = proxyFactory.getAdvisors();

    if (advisors == null || advisors.length == 0) {
        return false;
    }

    for (Advisor advisor : advisors) {
        if (adviceClass.isAssignableFrom(advisor.getAdvice().getClass())) {
            return true;
        }
    }
    return false;
}

From source file:org.mule.providers.soap.axis.wsdl.wsrf.util.AdviceAdderHelper.java

/**
 * addAdvisors to ProxyfactoryBean given using reflection to find Advices class
 * end with "Advice" suffix. All advisors are mapped on "extend*" pattern string
 * method refer to Target bean./*from   www  . j  a  v  a  2 s  . c o m*/
 * 
 * @param targetImpl Target Object
 * @return new Proxy
 */
public static IExtendCall addAdvisorsTo(IExtendCall targetImpl) {
    ProxyFactory factory = new ProxyFactory(targetImpl);

    List l = getListAdvisorClass();
    ListIterator li = l.listIterator();
    Advisor advisor = null;

    if (order.size() == 0) {

        while (li.hasNext()) {
            advisor = (Advisor) li.next();
            order.add(advisor);
        }
    }
    Iterator it = order.iterator();

    while (it.hasNext()) {
        advisor = (Advisor) it.next();
        factory.addAdvisor(countAdvice, advisor);
        Logger.getLogger(factory.getClass()).log(Level.DEBUG, factory.getClass().getName() + " : added "
                + advisor.getAdvice().getClass().getName() + " at index position " + countAdvice);
        countAdvice++;
    }

    countAdvice = 0;
    return (IExtendCall) factory.getProxy();
}

From source file:org.openmrs.module.trumpmodule.TrumpModuleActivator.java

/**
 * This method will remove AuthorizationAdvice from a particular core OpenMRS service.
 *//* ww w. j  a v a  2 s  .  c o m*/
public void reInitialServiceAdvices() {

    ArrayList<OpenmrsService> services = new ArrayList<OpenmrsService>();

    // painstakingly add all the services to a list, because reflection is dangerous
    // not the tidiest way, but hey...
    services.add(Context.getPatientService());
    services.add(Context.getAdministrationService());
    services.add(Context.getAlertService());
    services.add(Context.getCohortService());
    services.add(Context.getConceptService());
    services.add(Context.getEncounterService());
    services.add(Context.getFormService());
    services.add(Context.getHL7Service());
    services.add(Context.getLocationService());
    services.add(Context.getObsService());
    services.add(Context.getOrderService());
    services.add(Context.getPatientService());
    services.add(Context.getProgramWorkflowService());
    services.add(Context.getReportObjectService());
    services.add(Context.getSchedulerService());
    services.add(Context.getSerializationService());

    for (OpenmrsService service : services) {

        Advised advisedService = (Advised) service;
        Advisor[] advisors = advisedService.getAdvisors();
        for (Advisor a : advisors) {
            if (a.getAdvice() instanceof AuthorizationAdvice) {
                advisedService.removeAdvice(a.getAdvice());
            }
        }
    }
}

From source file:org.springframework.aop.framework.AdvisedSupport.java

public int indexOf(Advice advice) {
    for (int i = 0; i < this.advisors.size(); i++) {
        Advisor advisor = (Advisor) this.advisors.get(i);
        if (advisor.getAdvice() == advice) {
            return i;
        }// w ww.  ja va  2  s  .c  om
    }
    return -1;
}

From source file:org.springframework.aop.framework.AdvisedSupport.java

/**
 * Is the given advice included in any advisor within this proxy configuration?
 * @param advice the advice to check inclusion of
 * @return whether this advice instance is included
 *///from   ww  w  . j  a v  a 2 s  . com
public boolean adviceIncluded(Advice advice) {
    for (int i = 0; i < this.advisors.size(); i++) {
        Advisor advisor = (Advisor) this.advisors.get(i);
        if (advisor.getAdvice() == advice) {
            return true;
        }
    }
    return false;
}

From source file:org.springframework.aop.framework.AdvisedSupport.java

/**
 * Count advices of the given class./*w  w  w .  j a  va  2s.c  o  m*/
 * @param adviceClass the advice class to check
 * @return the count of the interceptors of this class or subclasses
 */
public int countAdvicesOfType(Class adviceClass) {
    Assert.notNull(adviceClass, "Advice class must not be null");
    int count = 0;
    for (int i = 0; i < this.advisors.size(); i++) {
        Advisor advisor = (Advisor) this.advisors.get(i);
        if (advisor.getAdvice() != null && adviceClass.isAssignableFrom(advisor.getAdvice().getClass())) {
            count++;
        }
    }
    return count;
}

From source file:org.springframework.integration.monitor.IntegrationMBeanExporter.java

public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {

    if (bean instanceof Advised) {
        for (Advisor advisor : ((Advised) bean).getAdvisors()) {
            Advice advice = advisor.getAdvice();
            if (advice instanceof MessageHandlerMetrics || advice instanceof MessageSourceMetrics
                    || advice instanceof MessageChannelMetrics) {
                // Already advised - so probably a factory bean product
                return bean;
            }/*from w ww .  j av  a 2  s  .c o m*/
        }
    }

    if (bean instanceof MessageHandler) {
        SimpleMessageHandlerMetrics monitor = new SimpleMessageHandlerMetrics((MessageHandler) bean);
        Object advised = applyHandlerInterceptor(bean, monitor, beanClassLoader);
        handlers.add(monitor);
        bean = advised;
    }

    if (bean instanceof MessageSource<?>) {
        SimpleMessageSourceMetrics monitor = new SimpleMessageSourceMetrics((MessageSource<?>) bean);
        Object advised = applySourceInterceptor(bean, monitor, beanClassLoader);
        sources.add(monitor);
        bean = advised;
    }

    if (bean instanceof MessageChannel) {
        DirectChannelMetrics monitor;
        MessageChannel target = (MessageChannel) extractTarget(bean);
        if (bean instanceof PollableChannel) {
            if (target instanceof QueueChannel) {
                monitor = new QueueChannelMetrics((QueueChannel) target, beanName);
            } else {
                monitor = new PollableChannelMetrics(target, beanName);
            }
        } else {
            monitor = new DirectChannelMetrics(target, beanName);
        }
        Object advised = applyChannelInterceptor(bean, monitor, beanClassLoader);
        channels.add(monitor);
        bean = advised;
    }

    return bean;

}