KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > spring > SpringUtils


1 package jfun.yan.spring;
2
3 import jfun.yan.Components;
4 import jfun.yan.PropertyBinder;
5 import jfun.yan.etc.FilteredPropertyBinder;
6 import jfun.yan.etc.PropertyPredicate;
7 import jfun.yan.etc.TypeFilteredPropertyPredicate;
8
9 import org.aopalliance.intercept.MethodInterceptor;
10 import org.springframework.aop.Advisor;
11 import org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator;
12 import org.springframework.beans.factory.BeanFactoryAware;
13 import org.springframework.beans.factory.BeanNameAware;
14 import org.springframework.context.ApplicationContextAware;
15 import org.springframework.context.ApplicationEventPublisherAware;
16 import org.springframework.context.MessageSourceAware;
17 import org.springframework.context.ResourceLoaderAware;
18
19
20
21 /**
22  * Some common spring related utility functions.
23  * <p>
24  * @author Ben Yu
25  * Nov 20, 2005 10:28:50 PM
26  */

27 public class SpringUtils{
28   /**
29    * Is this type part of the Spring infrastructure that
30    * needs special care?
31    * @param type the type.
32    * @return true if this is a special Spring infrastructure type
33    * (one of those marker interfaces.)
34    */

35   public static boolean isSpringInfrastructureClass(Class JavaDoc type){
36     return Advisor.class.isAssignableFrom(type) ||
37     MethodInterceptor.class.isAssignableFrom(type) ||
38     AbstractAutoProxyCreator.class.isAssignableFrom(type);
39   }
40   /**
41    * Get the PropertyPredicate object that filters all Spring
42    * XXXAware marker interfaces we know so far.
43    */

44   public static TypeFilteredPropertyPredicate getSpringAwareMarkerInterfaceFilter(){
45     final TypeFilteredPropertyPredicate tfpp = new TypeFilteredPropertyPredicate();
46     return tfpp.addType(ApplicationContextAware.class)
47     .addType(BeanNameAware.class)
48     .addType(BeanFactoryAware.class)
49     .addType(ResourceLoaderAware.class)
50     .addType(MessageSourceAware.class)
51     .addType(ApplicationEventPublisherAware.class);
52   }
53   private static final TypeFilteredPropertyPredicate aware_marker_interfaces =
54     getSpringAwareMarkerInterfaceFilter();
55   /**
56    * Decorate an autowiring mode by filtering out Spring
57    * XXXAware marker interfaces.
58    * @param binder the autowiring mode.
59    * @return the new autowiring mode.
60    */

61   public static PropertyBinder getAutowireWithoutAwareMarkerInterfaces(
62       PropertyBinder binder){
63     return new FilteredPropertyBinder(aware_marker_interfaces,
64         Components.useDefault(), binder);
65   }
66 }
67
Popular Tags