KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jdon > aop > joinpoint > AdvisorChainFactory


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.joinpoint;
17
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.List JavaDoc;
22
23 import org.aopalliance.intercept.MethodInterceptor;
24
25 import com.jdon.aop.interceptor.InterceptorsChain;
26 import com.jdon.bussinessproxy.TargetMetaDef;
27 import com.jdon.util.Debug;
28
29
30 /**
31  * create the all interceptor instances
32  * @author banq
33  */

34 public class AdvisorChainFactory {
35     
36   private final static String JavaDoc module = AdvisorChainFactory.class.getName();
37
38   private InterceptorsChain interceptorsChain;
39     
40     /**
41      * @param interceptorsChain
42      */

43   public AdvisorChainFactory(InterceptorsChain interceptorsChain) {
44       super();
45       this.interceptorsChain = interceptorsChain;
46   }
47     
48   /**
49    * create the all interceptor instances, and put them into interceptorsChain;
50    * the interceptors that prointcut is for SERVIERS are in the front,
51    * and then the EJB Interceptors , in the back there are POJO interceptors.
52    * you can change the orders bu replacing this class in container.xml
53    *
54    */

55   public List JavaDoc create(TargetMetaDef targetMetaDef) throws Exception JavaDoc {
56     Debug.logVerbose("[JdonFramework] enter create PointcutAdvisor " , module);
57     List JavaDoc interceptors = new ArrayList JavaDoc(interceptorsChain.size());
58     interceptors.addAll(interceptorsChain.getInterceptors(Pointcut.TARGET_PROPS_SERVICES));
59     Debug.logVerbose("[JdonFramework] find all service's interceptos size=" + interceptors.size(), module);
60     if (targetMetaDef.isEJB()){
61         List JavaDoc ejbInterceptors = interceptorsChain.getInterceptors(Pointcut.EJB_TARGET_PROPS_SERVICES);
62         if ((ejbInterceptors != null) && (ejbInterceptors.size() > 0)){
63             interceptors.addAll(ejbInterceptors);
64             Debug.logVerbose("[JdonFramework] find ejbService's interceptos size=" + interceptors.size(), module);
65         }
66     }else{
67         List JavaDoc pojoInterceptors = interceptorsChain.getInterceptors(Pointcut.POJO_TARGET_PROPS_SERVICES);
68         
69         Iterator JavaDoc iter = pojoInterceptors.iterator();
70         while(iter.hasNext()){
71             MethodInterceptor i = (MethodInterceptor)iter.next();
72         }
73         
74         if ((pojoInterceptors != null) && (pojoInterceptors.size() > 0)){
75             interceptors.addAll(pojoInterceptors);
76             Debug.logVerbose("[JdonFramework] find pojoService's interceptos size=" + interceptors.size(), module);
77         }
78     }
79     return interceptors;
80   }
81
82
83 }
84
Popular Tags