Example usage for org.springframework.aop.framework Advised getAdvisors

List of usage examples for org.springframework.aop.framework Advised getAdvisors

Introduction

In this page you can find the example usage for org.springframework.aop.framework Advised getAdvisors.

Prototype

Advisor[] getAdvisors();

Source Link

Document

Return the advisors applying to this proxy.

Usage

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

/**
 * This method will remove AuthorizationAdvice from a particular core OpenMRS service.
 *//*from  www. j a  v a 2s .  c om*/
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.springmodules.cache.interceptor.proxy.CacheProxyFactoryBeanTests.java

public void testAfterPropertiesSetWithCacheFlushAttributesNotSet() throws Exception {
    factoryBean = new CacheProxyFactoryBean();
    setUpCachingModels();//from  w  ww .j  a  v  a2s .c o m

    expectAfterPropertiesSetOnCachingInterceptorOnly();
    replay();

    Person targetObject = new PersonImpl("Anakin", "Skywalker");
    factoryBean.setTarget(targetObject);

    factoryBean.afterPropertiesSet();

    // verify that the target is only advised for caching.
    Advised advised = (Advised) factoryBean.getProxy();
    Advisor[] advisors = advised.getAdvisors();
    assertEquals(1, advisors.length);
    assertEquals(CachingModelSourceAdvisor.class, advisors[0].getClass());

    verify();
}

From source file:org.springmodules.cache.interceptor.proxy.CacheProxyFactoryBeanTests.java

public void testAfterPropertiesSetWithProxyInterfacesEqualToNullAndProxyTargetClassEqualToTrue() {
    expectAfterPropertiesSetOnInterceptors();
    replay();/*w w  w .  java  2  s . c  o  m*/

    Person targetObject = new PersonImpl("Darth", "Vader");
    factoryBean.setTarget(targetObject);
    factoryBean.setProxyTargetClass(true);

    factoryBean.afterPropertiesSet();

    Advised advised = (Advised) factoryBean.getProxy();
    Advisor[] advisors = advised.getAdvisors();
    assertEquals(2, advisors.length);
    Advisor advisor1 = advisors[0];
    Advisor advisor2 = advisors[1];

    if (advisor1 instanceof CachingModelSourceAdvisor) {
        assertEquals(FlushingModelSourceAdvisor.class, advisor2.getClass());

    } else if (advisor1 instanceof FlushingModelSourceAdvisor) {
        assertEquals(CachingModelSourceAdvisor.class, advisor2.getClass());

    } else {
        fail("Expected: <" + CachingModelSourceAdvisor.class.getName() + "> or <"
                + FlushingModelSourceAdvisor.class.getName() + "> but was: <" + advisor1.getClass().getName()
                + ">");
    }

    verify();
}

From source file:org.springframework.aop.interceptor.ConcurrencyThrottleInterceptorTests.java

@Test
public void testSerializable() throws Exception {
    DerivedTestBean tb = new DerivedTestBean();
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setInterfaces(new Class[] { ITestBean.class });
    ConcurrencyThrottleInterceptor cti = new ConcurrencyThrottleInterceptor();
    proxyFactory.addAdvice(cti);/*from w  w  w.  j ava  2  s .  com*/
    proxyFactory.setTarget(tb);
    ITestBean proxy = (ITestBean) proxyFactory.getProxy();
    proxy.getAge();

    ITestBean serializedProxy = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy);
    Advised advised = (Advised) serializedProxy;
    ConcurrencyThrottleInterceptor serializedCti = (ConcurrencyThrottleInterceptor) advised.getAdvisors()[0]
            .getAdvice();
    assertEquals(cti.getConcurrencyLimit(), serializedCti.getConcurrencyLimit());
    serializedProxy.getAge();
}