KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > aspectwerkz > joinpoint > management > AdviceInfoContainer


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.aspectwerkz.joinpoint.management;
5
6 import java.util.List JavaDoc;
7 import java.util.ArrayList JavaDoc;
8
9 import com.tc.aspectwerkz.aspect.AdviceInfo;
10
11 /**
12  * Container for the advice infos that belongs to a specific join point.
13  *
14  * @author <a HREF="mailto:jboner@codehaus.org">Jonas BonŽr </a>
15  * @author <a HREF="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
16  */

17 public class AdviceInfoContainer {
18
19   /**
20    * Null AdviceInfoContainer instance
21    */

22   public static final AdviceInfoContainer NULL;
23
24   static {
25     NULL = new AdviceInfoContainer(
26             new ArrayList JavaDoc(), new ArrayList JavaDoc(), new ArrayList JavaDoc(), new ArrayList JavaDoc(), new ArrayList JavaDoc()
27     );
28   }
29
30   private final AdviceInfo[] m_aroundAdvices;
31   private final AdviceInfo[] m_beforeAdvices;
32   private final AdviceInfo[] m_afterFinallyAdvices;
33   private final AdviceInfo[] m_afterReturningAdvices;
34   private final AdviceInfo[] m_afterThrowingAdvices;
35
36   /**
37    * Creates a advice info container.
38    *
39    * @param aroundAdvices
40    * @param beforeAdvices
41    * @param afterFinallyAdvices
42    * @param afterReturningAdvices
43    * @param afterThrowingAdvices
44    */

45   public AdviceInfoContainer(final List JavaDoc aroundAdvices,
46                              final List JavaDoc beforeAdvices,
47                              final List JavaDoc afterFinallyAdvices,
48                              final List JavaDoc afterReturningAdvices,
49                              final List JavaDoc afterThrowingAdvices) {
50     m_aroundAdvices = (AdviceInfo[]) aroundAdvices.toArray(AdviceInfo.EMPTY_ADVICE_INFO_ARRAY);
51     m_beforeAdvices = (AdviceInfo[]) beforeAdvices.toArray(AdviceInfo.EMPTY_ADVICE_INFO_ARRAY);
52     m_afterFinallyAdvices = (AdviceInfo[]) afterFinallyAdvices.toArray(AdviceInfo.EMPTY_ADVICE_INFO_ARRAY);
53     m_afterReturningAdvices = (AdviceInfo[]) afterReturningAdvices.toArray(AdviceInfo.EMPTY_ADVICE_INFO_ARRAY);
54     m_afterThrowingAdvices = (AdviceInfo[]) afterThrowingAdvices.toArray(AdviceInfo.EMPTY_ADVICE_INFO_ARRAY);
55   }
56
57   /**
58    * Returns the around advice infos.
59    *
60    * @return
61    */

62   public AdviceInfo[] getAroundAdviceInfos() {
63     return m_aroundAdvices;
64   }
65
66   /**
67    * Returns the before advice infos.
68    *
69    * @return
70    */

71   public AdviceInfo[] getBeforeAdviceInfos() {
72     return m_beforeAdvices;
73   }
74
75   /**
76    * Returns the after finally advice infos.
77    *
78    * @return
79    */

80   public AdviceInfo[] getAfterFinallyAdviceInfos() {
81     return m_afterFinallyAdvices;
82   }
83
84   /**
85    * Returns the after returning advice infos.
86    *
87    * @return
88    */

89   public AdviceInfo[] getAfterReturningAdviceInfos() {
90     return m_afterReturningAdvices;
91   }
92
93   /**
94    * Returns the after throwing advice infos.
95    *
96    * @return
97    */

98   public AdviceInfo[] getAfterThrowingAdviceInfos() {
99     return m_afterThrowingAdvices;
100   }
101
102   /**
103    * Return all advice infos.
104    *
105    * @return
106    */

107   public AdviceInfo[] getAllAdviceInfos() {
108     int size = m_beforeAdvices.length + m_aroundAdvices.length + m_afterReturningAdvices.length
109             + m_afterThrowingAdvices.length + m_afterFinallyAdvices.length;
110     AdviceInfo[] advices = new AdviceInfo[size];
111
112     int destPos = 0;
113     System.arraycopy(m_beforeAdvices, 0, advices, destPos, m_beforeAdvices.length);
114     destPos += m_beforeAdvices.length;
115     System.arraycopy(m_aroundAdvices, 0, advices, destPos, m_aroundAdvices.length);
116     destPos += m_aroundAdvices.length;
117     System.arraycopy(m_afterReturningAdvices, 0, advices, destPos, m_afterReturningAdvices.length);
118     destPos += m_afterReturningAdvices.length;
119     System.arraycopy(m_afterThrowingAdvices, 0, advices, destPos, m_afterThrowingAdvices.length);
120     destPos += m_afterThrowingAdvices.length;
121     System.arraycopy(m_afterFinallyAdvices, 0, advices, destPos, m_afterFinallyAdvices.length);
122     destPos += m_afterFinallyAdvices.length;
123
124     return advices;
125   }
126
127 }
Popular Tags