List of usage examples for org.springframework.aop.framework ProxyFactory addAdvice
@Override public void addAdvice(Advice advice) throws AopConfigException
From source file:org.jdal.remoting.rmi.RmiProxyFactoryBean.java
/** * {@inheritDoc}/*from w w w . java 2 s .c o m*/ */ @Override public void afterPropertiesSet() { super.afterPropertiesSet(); if (getServiceInterface() == null) { throw new IllegalArgumentException("Property 'serviceInterface' is required"); } ProxyFactory pf = new ProxyFactory(new Class[] { getServiceInterface(), RemoteClient.class }); pf.addAdvisor(new RemoteClientAdvisor(getRemoteReference())); pf.addAdvice(this); serviceProxy = pf.getProxy(); }
From source file:net.sf.oval.test.integration.spring.SpringAOPAllianceBeanValidationTest.java
public void testCGLIBProxying() { {/*from ww w . j a va 2 s .c om*/ final ProxyFactory prFactory = new ProxyFactory(new TestServiceWithoutInterface()); prFactory.setProxyTargetClass(true); prFactory.addAdvice(new GuardInterceptor(new Guard(new BeanValidationAnnotationsConfigurer()))); final TestServiceWithoutInterface testServiceWithoutInterface = (TestServiceWithoutInterface) prFactory .getProxy(); try { testServiceWithoutInterface.getSomething(null); fail(); } catch (final ConstraintsViolatedException ex) { assertEquals("NOT_NULL", ex.getConstraintViolations()[0].getMessage()); } try { testServiceWithoutInterface.getSomething("123456"); fail(); } catch (final ConstraintsViolatedException ex) { assertEquals("MAX_LENGTH", ex.getConstraintViolations()[0].getMessage()); } } { final ProxyFactory prFactory = new ProxyFactory(new TestServiceWithInterface()); prFactory.setProxyTargetClass(true); prFactory.addAdvice(new GuardInterceptor(new Guard(new BeanValidationAnnotationsConfigurer()))); final TestServiceWithInterface testServiceWithInterface = (TestServiceWithInterface) prFactory .getProxy(); try { testServiceWithInterface.getSomething(null); fail(); } catch (final ConstraintsViolatedException ex) { assertEquals("NOT_NULL", ex.getConstraintViolations()[0].getMessage()); } try { testServiceWithInterface.getSomething("123456"); fail(); } catch (final ConstraintsViolatedException ex) { assertEquals("MAX_LENGTH", ex.getConstraintViolations()[0].getMessage()); } } }
From source file:fr.pilato.spring.elasticsearch.ElasticsearchNodeFactoryBean.java
@Override public void afterPropertiesSet() throws Exception { if (async) {/*from w w w . j a va 2s .co m*/ Assert.notNull(taskExecutor); Future<Node> nodeFuture = taskExecutor.submit(new Callable<Node>() { @Override public Node call() throws Exception { return initialize(); } }); ProxyFactory proxyFactory = new ProxyFactory(); proxyFactory.setProxyTargetClass(true); proxyFactory.setTargetClass(Node.class); proxyFactory.addAdvice(new GenericInvocationHandler(nodeFuture)); proxyfiedNode = (Node) proxyFactory.getProxy(); } else { node = initialize(); } }
From source file:org.jdal.service.PersistentServiceFactory.java
/** * Creates a default transactional proxy for service with default transacction attributes * @param <T>//from w w w. jav a 2s . c o m * @param service * @return a Tx Proxy for service with default tx attributes */ @SuppressWarnings("unchecked") public <T> PersistentManager<T, Serializable> makeTransactionalProxy( PersistentManager<T, Serializable> service) { ProxyFactory factory = new ProxyFactory(service); factory.setInterfaces(new Class[] { Dao.class }); TransactionInterceptor interceptor = new TransactionInterceptor(transactionManager, new MatchAlwaysTransactionAttributeSource()); factory.addAdvice(interceptor); factory.setTarget(service); return (PersistentManager<T, Serializable>) factory.getProxy(); }
From source file:org.LexGrid.LexBIG.caCore.client.proxy.LexEVSProxyHelperImpl.java
@Override protected Object convertObjectToProxy(ApplicationService as, Object obj) { if (null == obj) return null; //Check to see if the returned object is an EVSRemoteExecutionResults. //If so, unwrap it and update the proxy target if (obj instanceof RemoteExecutionResults) { RemoteExecutionResults results = (RemoteExecutionResults) obj; //if the returned results are null, return null if (results.getReturnValue() == null) return null; //Get the current proxy target and update it with the retuned value //from the server Advised advised = (Advised) AopContext.currentProxy(); advised.setTargetSource(new SingletonTargetSource(results.getObj())); obj = results.getReturnValue();//from w ww. j a va2 s .c o m } if (obj instanceof RemoteShell) { Class<?>[] targetInterfaces = ((RemoteShell) obj).getTargetInterfaces(); Class<?> targetClass = ((RemoteShell) obj).getTargetClass(); ProxyFactory pf = new ProxyFactory(targetInterfaces); pf.addAdvice(new LexEVSBeanProxy(as, this)); pf.setProxyTargetClass(true); pf.setTargetClass(targetClass); pf.setTarget(obj); return pf.getProxy(); } if (obj instanceof Integer || obj instanceof Float || obj instanceof Double || obj instanceof Character || obj instanceof Long || obj instanceof Boolean || obj instanceof String || obj instanceof Date || obj instanceof LexEVSBeanProxy || obj instanceof BeanProxy) return obj; if (!LexEVSCaCoreUtils.isLexBigClass(obj.getClass())) { return obj; } // Don't proxy client-safe LexBig objects if (isClientSafe(obj.getClass())) { return obj; } else { return LexEVSCaCoreUtils.createProxy(obj, as, this); } }
From source file:aop.DeclareMixinAspectJAdvisorFactoryTest.java
protected Object createProxy(Object target, List<Advisor> advisors, Class<?>... interfaces) { ProxyFactory pf = new ProxyFactory(target); if (interfaces.length > 1 || interfaces[0].isInterface()) { pf.setInterfaces(interfaces);//from ww w .j a va2 s. co m } else { pf.setProxyTargetClass(true); } // Required everywhere we use AspectJ proxies pf.addAdvice(ExposeInvocationInterceptor.INSTANCE); for (Object a : advisors) { pf.addAdvisor((Advisor) a); } pf.setExposeProxy(true); return pf.getProxy(); }
From source file:org.LexGrid.LexBIG.caCore.client.proxy.DataServiceProxyHelperImpl.java
@Override protected Object convertObjectToProxy(ApplicationService as, Object obj) { if (null == obj) return null; if (obj instanceof Integer || obj instanceof Float || obj instanceof Double || obj instanceof Character || obj instanceof Long || obj instanceof Boolean || obj instanceof String || obj instanceof Date || obj instanceof LexEVSBeanProxy || obj instanceof BeanProxy) return obj; ProxyFactory pf = new ProxyFactory(obj); pf.setProxyTargetClass(true);//from w w w . ja va2 s .c o m pf.addAdvice(new LexEVSBeanProxy(as, this)); pf.setExposeProxy(true); return pf.getProxy(); }
From source file:org.arrow.service.engine.execution.interceptor.impl.MultiInstanceLoopCharacteristicsExecutionInterceptor.java
/** * {@inheritDoc}/*from ww w. j a va 2 s . c o m*/ */ @Override public BpmnNodeEntity beforeExecution(Execution execution, BpmnNodeEntity entity) { Task task = (Task) entity; MultiInstanceLoopCharacteristics characteristics; characteristics = task.getMultiInstanceLoopCharacteristics(); ProxyFactory factory = new ProxyFactory(task); // Loop Cardinality if (characteristics.getLoopCardinality() != null) { Advice advice = new LoopCardinalityAdvice(characteristics); factory.addAdvice(advice); } return (BpmnNodeEntity) factory.getProxy(); }
From source file:ome.testing.InterceptingServiceFactory.java
@SuppressWarnings("unchecked") <T extends ServiceInterface> T wrap(T service) { ProxyFactory factory = new ProxyFactory(); factory.setInterfaces(service.getClass().getInterfaces()); for (MethodInterceptor i : interceptors) { factory.addAdvice(i); }// ww w . j av a2 s. co m factory.setTarget(service); return (T) factory.getProxy(); }
From source file:org.springframework.data.rest.core.projection.ProxyProjectionFactory.java
@Override @SuppressWarnings("unchecked") public <T> T createProjection(Object source, Class<T> projectionType) { Assert.isTrue(projectionType.isInterface(), "Projection type must be an interface!"); if (source == null) { return null; }//from w ww . j a v a 2 s .c o m ProxyFactory factory = new ProxyFactory(); factory.setTarget(source); factory.setOpaque(true); factory.setInterfaces(projectionType, TargetClassAware.class); factory.addAdvice(new TargetClassAwareMethodInterceptor(source.getClass())); factory.addAdvice(getMethodInterceptor(source, projectionType)); return (T) factory.getProxy(); }