Example usage for org.springframework.aop.aspectj.annotation AspectJProxyFactory AspectJProxyFactory

List of usage examples for org.springframework.aop.aspectj.annotation AspectJProxyFactory AspectJProxyFactory

Introduction

In this page you can find the example usage for org.springframework.aop.aspectj.annotation AspectJProxyFactory AspectJProxyFactory.

Prototype

public AspectJProxyFactory(Class<?>... interfaces) 

Source Link

Document

Create a new AspectJProxyFactory .

Usage

From source file:org.senro.metadata.aop.AOPMetadataFactory.java

/**
 * Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and
 * ApplicationContextAware). <p>This method allows the bean instance to perform initialization only possible when
 * all bean properties have been set and to throw an exception in the event of misconfiguration.
 *
 * @throws Exception in the event of misconfiguration (such as failure to set an essential property) or if
 *                   initialization fails.
 *//*from  w  ww.j  a  v  a 2  s . com*/
public void afterPropertiesSet() throws Exception {
    // set up proxies
    classFactory = new AspectJProxyFactory(new MetadataClass());
    for (MetadataProvider provider : metadataProviders) {
        Class clazz = provider.getClassClass();
        classFactory.addAspect(clazz);
        for (Class aClass : ClassUtils.getAllInterfaces(clazz.newInstance())) {
            classFactory.addInterface(aClass);
        }
    }

    propertyFactory = new AspectJProxyFactory(new MetadataProperty());
    for (MetadataProvider provider : metadataProviders) {
        propertyFactory.addAspect(provider.getPropertyClass());
    }

    methodFactory = new AspectJProxyFactory(new MetadataMethod());
    for (MetadataProvider provider : metadataProviders) {
        methodFactory.addAspect(provider.getMethodClass());
    }

    packageFactory = new AspectJProxyFactory(new MetadataPackage());
    for (MetadataProvider provider : metadataProviders) {
        packageFactory.addAspect(provider.getPackageClass());
    }

    referenceFactory = new AspectJProxyFactory(new MetadataReference());
    for (MetadataProvider provider : metadataProviders) {
        referenceFactory.addAspect(provider.getReferenceClass());
    }
}

From source file:de.rahn.finances.services.securities.SecuritiesServiceMetricsAspectTest.java

/**
 * @throws Exception//w w w.  j  a v  a  2s . com
 */
@Before
public void setUp() throws Exception {
    counters.clear();
    gauges.clear();

    AspectJProxyFactory factory = new AspectJProxyFactory(service);
    factory.addAspect(classUnderTests);

    serviceProxy = factory.getProxy();

    testSecurity.setId(randomUUID().toString());
    testSecurity.setIsin("DE0000000000");
    testSecurity.setWkn("000000");
    testSecurity.setSymbol("ABC");
    testSecurity.setName("ABC AG");
    testSecurity.setType(stock);

    List<Security> allSecurity = new ArrayList<>();
    allSecurity.add(testSecurity);

    PageImpl<Security> page = new PageImpl<>(allSecurity, new PageRequest(0, 1), allSecurity.size());

    when(service.getSecurities()).thenReturn(allSecurity);
    when(service.getSecurities(any(Pageable.class))).thenReturn(page);
    when(service.save(testSecurity)).thenReturn(testSecurity);
    when(service.save(null)).thenThrow(new SecurityNotFoundException(""));

    doAnswer(invocation -> {
        counters.add((String) invocation.getArguments()[0]);
        return null;

    }).when(counterService).increment(anyString());
    doAnswer(invocation -> {
        gauges.add((String) invocation.getArguments()[0]);
        return null;

    }).when(gaugeService).submit(anyString(), anyDouble());
}

From source file:org.craftercms.commons.security.permissions.HasPermissionAnnotationHandlerTest.java

private void createTestService() throws PermissionException {
    AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new MockSecuredServiceImpl());
    proxyFactory.addAspect(annotationHandler);

    service = proxyFactory.getProxy();/*www. j  av a2 s . co  m*/
}

From source file:org.senro.metadata.aop.AOPMetadataFactory.java

/**
 * Compose an implementation of Metadata for the Class object provided to this method.  The Metadata object that is
 * returned is a proper composition of all the MetadataProviders that were registered in the startup configuration.
 *
 * @param element A Class object that we would like to recover Metadata for
 * @return A Metadata object//from  www . j  a v  a2 s .  c om
 */
public Metadata createClass(Class element) {
    classFactory = new AspectJProxyFactory(new MetadataClass());

    for (MetadataProvider provider : metadataProviders) {
        Class clazz = provider.getClassClass();
        classFactory.addAspect(clazz);
        Class[] allInterfaces;
        try {
            allInterfaces = ClassUtils.getAllInterfaces(clazz.newInstance());
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
        for (Class aClass : allInterfaces) {
            classFactory.addInterface(aClass);
        }
    }
    return classFactory.getProxy();
}

From source file:org.cybercat.automation.core.PageFactoryImpl.java

@SuppressWarnings("unchecked")
public <T extends AbstractPageObject> T createPage(Class<T> page) throws PageObjectException {
    Constructor<T> cons;//from  ww w.j a v  a 2  s  .  co  m
    try {
        cons = page.getConstructor();
        T result = cons.newInstance();
        for (Field field : page.getDeclaredFields()) {
            field.setAccessible(true);
            if (field.getAnnotation(CCProperty.class) != null) {
                AnnotationBuilder.processPropertyField(result, field);
            }
        }
        AspectJProxyFactory proxyFactory = new AspectJProxyFactory(result);
        proxyFactory.addAspect(new PageObjectStateControlAcpect(this));
        result = (T) proxyFactory.getProxy();
        return result;
    } catch (Exception e) {
        throw new PageObjectException("Page object creation problem.", e);
    }
}

From source file:org.cybercat.automation.annotations.AnnotationBuilder.java

@SuppressWarnings("unchecked")
private final static <T extends IFeature> T createFeature(Class<T> eType) throws AutomationFrameworkException {
    try {//from  w  w w  .ja v  a  2s.  c  o m
        Constructor<T> cons = eType.getDeclaredConstructor();
        T result = cons.newInstance();
        AnnotationBuilder.processCCFeature(result);
        AnnotationBuilder.processCCPageObject(result);
        AspectJProxyFactory proxyFactory = new AspectJProxyFactory(result);
        proxyFactory.addAspect(TestStepAspect.class);
        result = (T) proxyFactory.getProxy();
        log.info(eType.getSimpleName() + " feature has been created.");
        return result;
    } catch (Exception e) {
        // handle test fail
        throw new AutomationFrameworkException("Feature factoring exception. ", e);
    }
}

From source file:org.dspace.app.cris.discovery.CrisSearchService.java

@Override
protected void buildDocument(Context context, Item item) throws SQLException, IOException {
    AspectJProxyFactory pf = new AspectJProxyFactory(item);
    pf.setProxyTargetClass(true);/*from ww w.  j av  a 2 s.  com*/
    pf.addAdvice(new CrisItemWrapper());
    // ProxyFactory pf = new ProxyFactory(item);
    super.buildDocument(context, (Item) pf.getProxy());
}

From source file:org.cybercat.automation.annotations.AnnotationBuilder.java

@SuppressWarnings("unchecked")
private static final <T extends IIntegrationService> T createIntegrationService(Class<T> clazz,
        CCIntegrationService aService) throws AutomationFrameworkException {
    Class<T> cService = versionControlPreprocessor(clazz);
    Constructor<T> cons;/*from  www  . ja v  a2  s. c  o  m*/
    try {
        cons = cService.getConstructor();
        T result = cons.newInstance();
        processIntegrationService(result, result.getClass());
        result.setup();
        AspectJProxyFactory proxyFactory = new AspectJProxyFactory(result);
        proxyFactory.addAspect(new IntegrationServiceAspect(aService.hasSession()));
        result = (T) proxyFactory.getProxy();
        log.info(cService.getSimpleName() + " integration Service has been created.");
        return result;
    } catch (Exception e) {
        throw new AutomationFrameworkException("Integration service creation problem.", e);
    }
}

From source file:org.osaf.cosmo.event.aop.EventLogAdviceTest.java

/** */
protected void setUp() throws Exception {
    testHelper = new TestHelper();
    securityManager = new MockSecurityManager();
    storage = new MockDaoStorage();
    calendarDao = new MockCalendarDao(storage);
    contentDao = new MockContentDao(storage);
    eventLogDao = new MockEventLogDao();
    service = new StandardContentService();
    lockManager = new SingleVMLockManager();
    service.setCalendarDao(calendarDao);
    service.setContentDao(contentDao);//from w  w w  .j  a  v a  2s.c om
    service.setLockManager(lockManager);
    service.setTriageStatusQueryProcessor(new StandardTriageStatusQueryProcessor());
    service.init();

    // create a factory that can generate a proxy for the given target object
    AspectJProxyFactory factory = new AspectJProxyFactory(service);

    // add aspect
    EventLogAdvice eva = new EventLogAdvice();
    eva.setEnabled(true);
    eva.setSecurityManager(securityManager);
    eva.setEventLogDao(eventLogDao);
    eva.init();
    factory.addAspect(eva);

    // now get the proxy object...
    proxyService = factory.getProxy();
}

From source file:org.osaf.cosmo.security.aop.SecurityAdviceTest.java

/** */
protected void setUp() throws Exception {
    testHelper = new TestHelper();
    securityManager = new MockSecurityManager();
    storage = new MockDaoStorage();
    calendarDao = new MockCalendarDao(storage);
    contentDao = new MockContentDao(storage);
    userDao = new MockUserDao(storage);
    service = new StandardContentService();
    lockManager = new SingleVMLockManager();
    service.setCalendarDao(calendarDao);
    service.setContentDao(contentDao);/*w ww  .  j ava  2  s . c o  m*/
    service.setLockManager(lockManager);
    service.setTriageStatusQueryProcessor(new StandardTriageStatusQueryProcessor());
    service.init();

    // create a factory that can generate a proxy for the given target object
    AspectJProxyFactory factory = new AspectJProxyFactory(service);

    // add aspect
    SecurityAdvice sa = new SecurityAdvice();
    sa.setEnabled(true);
    sa.setSecurityManager(securityManager);
    sa.setContentDao(contentDao);
    sa.setUserDao(userDao);
    sa.init();
    factory.addAspect(sa);

    // now get the proxy object...
    proxyService = factory.getProxy();
}