KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jdon > aop > interceptor > InterceptorsChain


1 /*
2  * Copyright 2003-2006 the original author or authors.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  *
15  */

16 package com.jdon.aop.interceptor;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.HashMap JavaDoc;
20 import java.util.List JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import org.aopalliance.intercept.MethodInterceptor;
24
25 import com.jdon.aop.joinpoint.Pointcut;
26 import com.jdon.container.pico.Startable;
27 import com.jdon.util.Debug;
28
29
30 /**
31  * Interceptors chain
32  *
33  * all interceptors will add in this collection
34  *
35  * @author <a HREF="mailto:banqiao@jdon.com">banq</a>
36  *
37  */

38 public class InterceptorsChain implements Startable{
39     private final static String JavaDoc module = InterceptorsChain.class.getName();
40     public final static String JavaDoc NAME = "InterceptorsChain";
41     
42     /**
43      * the key is interceptor target
44      * the value is the interceptor instance
45      */

46     private Map JavaDoc chain = new HashMap JavaDoc();
47     
48     public void start(){
49         Debug.logVerbose("[JdonFramework]InterceptorsChain start..", module);
50     }
51     
52     public void stop(){
53         chain.clear();
54     }
55   
56     public void addInterceptor(String JavaDoc pointcut, MethodInterceptor interceptor ){
57         List JavaDoc interceptors = getInterceptors(pointcut);
58         if ((interceptors == null) && isPointcut(pointcut)){
59             interceptors = new ArrayList JavaDoc();
60             chain.put(pointcut, interceptors);
61         }
62         interceptors.add(interceptor);
63     }
64     
65     private boolean isPointcut(String JavaDoc pointcut){
66         if ((pointcut.equals(Pointcut.TARGET_PROPS_SERVICES)) ||
67             (pointcut.equals(Pointcut.EJB_TARGET_PROPS_SERVICES)) ||
68             (pointcut.equals(Pointcut.POJO_TARGET_PROPS_SERVICES)))
69             return true;
70         else
71             return false;
72     }
73     
74     
75     /**
76      * @return Returns the interceptors.
77      */

78     public List JavaDoc getInterceptors(String JavaDoc pointcut) {
79         return (List JavaDoc)chain.get(pointcut);
80     }
81     
82     public int size(){
83         return chain.size();
84     }
85 }
86
Popular Tags