List of usage examples for org.springframework.aop.support DefaultPointcutAdvisor DefaultPointcutAdvisor
public DefaultPointcutAdvisor(Advice advice)
From source file:org.alfresco.repo.lotus.ws.impl.auth.ChainingAuthProxyFactory.java
/** * Instantiates a new chaining subsystem proxy factory. *///from ww w .jav a 2 s . c om public ChainingAuthProxyFactory() { addAdvisor(new DefaultPointcutAdvisor(new MethodInterceptor() { public Object invoke(MethodInvocation mi) throws Throwable { Method method = mi.getMethod(); boolean authenticated = false; try { for (String sourceBeanName : sourceBeanNames) { try { Object bean = beanFactory.getBean(sourceBeanName); // Ignore inactive beans if ((bean instanceof Authenticator) && ((Authenticator) bean).isActive()) { authenticated = (Boolean) method.invoke(bean, mi.getArguments()); if (authenticated) { return authenticated; } } } catch (BeansException e) { // Ignore and continue } } // Fall back to the default object if we have one if (!authenticated && defaultTarget != null && method.getDeclaringClass().isAssignableFrom(defaultTarget.getClass())) { return method.invoke(defaultTarget, mi.getArguments()); } // If this is the isActive() method, we can handle it ourselves! if (method.equals(Authenticator.class.getMethod("isActive"))) { return Boolean.FALSE; } // Otherwise, something has gone wrong with wiring! throw new RuntimeException("Don't know where to route call to method " + method); } catch (InvocationTargetException e) { // Unwrap invocation target exceptions throw e.getTargetException(); } } })); }
From source file:org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.java
protected void initializeProxy(Object delegate) { if (this.getAdviceChain().length == 0) { return;/*from w w w . ja v a 2s .co m*/ } ProxyFactory factory = new ProxyFactory(); for (Advice advice : getAdviceChain()) { factory.addAdvisor(new DefaultPointcutAdvisor(advice)); } factory.addInterface(ContainerDelegate.class); factory.setTarget(delegate); this.proxy = (ContainerDelegate) factory.getProxy(ContainerDelegate.class.getClassLoader()); }
From source file:org.springframework.aop.framework.AdvisedSupport.java
/** * Cannot add introductions this way unless the advice implements IntroductionInfo. *///from www.j a v a2 s .co m public void addAdvice(int pos, Advice advice) throws AopConfigException { if (advice instanceof Interceptor && !(advice instanceof MethodInterceptor)) { throw new AopConfigException(getClass().getName() + " only handles AOP Alliance MethodInterceptors"); } if (advice instanceof IntroductionInfo) { // We don't need an IntroductionAdvisor for this kind of introduction: // It's fully self-describing. addAdvisor(pos, new DefaultIntroductionAdvisor(advice, (IntroductionInfo) advice)); } else if (advice instanceof DynamicIntroductionAdvice) { // We need an IntroductionAdvisor for this kind of introduction. throw new AopConfigException( "DynamicIntroductionAdvice may only be added as part of IntroductionAdvisor"); } else { addAdvisor(pos, new DefaultPointcutAdvisor(advice)); } }
From source file:org.springframework.batch.core.listener.AbstractListenerFactoryBean.java
@Override public Object getObject() { if (metaDataMap == null) { metaDataMap = new HashMap<String, String>(); }/*from www. j av a 2 s . c o m*/ // Because all annotations and interfaces should be checked for, make // sure that each meta data // entry is represented. for (ListenerMetaData metaData : this.getMetaDataValues()) { if (!metaDataMap.containsKey(metaData.getPropertyName())) { // put null so that the annotation and interface is checked metaDataMap.put(metaData.getPropertyName(), null); } } Set<Class<?>> listenerInterfaces = new HashSet<Class<?>>(); // For every entry in the map, try and find a method by interface, name, // or annotation. If the same Map<String, Set<MethodInvoker>> invokerMap = new HashMap<String, Set<MethodInvoker>>(); boolean synthetic = false; for (Entry<String, String> entry : metaDataMap.entrySet()) { final ListenerMetaData metaData = this.getMetaDataFromPropertyName(entry.getKey()); Set<MethodInvoker> invokers = new HashSet<MethodInvoker>(); MethodInvoker invoker; invoker = getMethodInvokerForInterface(metaData.getListenerInterface(), metaData.getMethodName(), delegate, metaData.getParamTypes()); if (invoker != null) { invokers.add(invoker); } invoker = getMethodInvokerByName(entry.getValue(), delegate, metaData.getParamTypes()); if (invoker != null) { invokers.add(invoker); synthetic = true; } if (metaData.getAnnotation() != null) { invoker = getMethodInvokerByAnnotation(metaData.getAnnotation(), delegate, metaData.getParamTypes()); if (invoker != null) { invokers.add(invoker); synthetic = true; } } if (!invokers.isEmpty()) { invokerMap.put(metaData.getMethodName(), invokers); listenerInterfaces.add(metaData.getListenerInterface()); } } if (listenerInterfaces.isEmpty()) { listenerInterfaces.add(this.getDefaultListenerClass()); } if (!synthetic) { int count = 0; for (Class<?> listenerInterface : listenerInterfaces) { if (listenerInterface.isInstance(delegate)) { count++; } } // All listeners can be supplied by the delegate itself if (count == listenerInterfaces.size()) { return delegate; } } boolean ordered = false; if (delegate instanceof Ordered) { ordered = true; listenerInterfaces.add(Ordered.class); } // create a proxy listener for only the interfaces that have methods to // be called ProxyFactory proxyFactory = new ProxyFactory(); if (delegate instanceof Advised) { proxyFactory.setTargetSource(((Advised) delegate).getTargetSource()); } else { proxyFactory.setTarget(delegate); } proxyFactory.setInterfaces(listenerInterfaces.toArray(new Class[0])); proxyFactory .addAdvisor(new DefaultPointcutAdvisor(new MethodInvokerMethodInterceptor(invokerMap, ordered))); return proxyFactory.getProxy(); }