コード例 #1
0
        public IMethodLevelBehavior <Attribute> CreateInterceptorModeBehavior(Type beanType)
        {
            MethodLevelHashMap <Attribute> methodToAnnotationMap = new MethodLevelHashMap <Attribute>();

            MethodInfo[] methods = ReflectUtil.GetMethods(beanType);
            foreach (MethodInfo method in methods)
            {
                Attribute annotation = LookForAnnotation(method);
                if (annotation != null)
                {
                    methodToAnnotationMap.Put(method, annotation);
                    continue;
                }
                Type[] parameters = TypeUtil.GetParameterTypesToTypes(method.GetParameters());
                foreach (Type currInterface in beanType.GetInterfaces())
                {
                    MethodInfo methodOnInterface = ReflectUtil.GetDeclaredMethod(true, currInterface, null, method.Name, parameters);
                    if (methodOnInterface == null)
                    {
                        continue;
                    }
                    annotation = LookForAnnotation(methodOnInterface);
                    if (annotation == null)
                    {
                        continue;
                    }
                    methodToAnnotationMap.Put(method, annotation);
                    break;
                }
            }
            return(new MethodLevelBehavior <Attribute>(LookForAnnotation(beanType), methodToAnnotationMap));
        }
コード例 #2
0
        public static IMethodLevelBehavior <T> Create <A>(Type beanType, AnnotationCache <A> annotationCache, Type behaviourType,
                                                          IBehaviorTypeExtractor <A, T> behaviourTypeExtractor, IBeanContextFactory beanContextFactory, IServiceContext beanContext) where A : Attribute
        {
            BehaviorKey key = new BehaviorKey(beanType, behaviourType);

            IMethodLevelBehavior <T> behavior = (IMethodLevelBehavior <T>)beanTypeToBehavior.Get(key);

            if (behavior != null)
            {
                if (behavior == noBehavior)
                {
                    return(null);
                }
                return(behavior);
            }
            A annotation = annotationCache.GetAnnotation(beanType);

            if (annotation == null)
            {
                beanTypeToBehavior.Put(key, noBehavior);
                return(null);
            }
            T defaultBehaviour = behaviourTypeExtractor.ExtractBehaviorType(annotation);
            MethodLevelHashMap <T> methodLevelBehaviour = null;

            MethodInfo[] methods = ReflectUtil.GetMethods(beanType);
            for (int a = methods.Length; a-- > 0;)
            {
                MethodInfo method             = methods[a];
                A          annotationOnMethod = annotationCache.GetAnnotation(method);
                if (annotationOnMethod != null)
                {
                    if (methodLevelBehaviour == null)
                    {
                        methodLevelBehaviour = new MethodLevelHashMap <T>();
                    }
                    T behaviourTypeOnMethod = behaviourTypeExtractor.ExtractBehaviorType(annotationOnMethod);
                    if (behaviourTypeOnMethod != null)
                    {
                        methodLevelBehaviour.Put(method, behaviourTypeOnMethod);
                    }
                }
            }
            if (methodLevelBehaviour == null)
            {
                methodLevelBehaviour = new MethodLevelHashMap <T>(0);
            }
            behavior = new MethodLevelBehavior <T>(defaultBehaviour, methodLevelBehaviour);
            beanTypeToBehavior.Put(key, behavior);
            return(behavior);
        }
コード例 #3
0
 public MethodLevelBehavior(T defaultBehaviour, MethodLevelHashMap <T> methodLevelBehaviour)
 {
     this.defaultBehaviour     = defaultBehaviour;
     this.methodLevelBehaviour = methodLevelBehaviour;
 }