KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > aspectwerkz > joinpoint > management > AdviceInfoContainer


1 /**************************************************************************************
2  * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
3  * http://aspectwerkz.codehaus.org *
4  * ---------------------------------------------------------------------------------- *
5  * The software in this package is published under the terms of the LGPL license *
6  * a copy of which has been included with this distribution in the license.txt file. *
7  **************************************************************************************/

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

23 public class AdviceInfoContainer {
24
25     /**
26      * Null AdviceInfoContainer instance
27      */

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

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

68     public AdviceInfo[] getAroundAdviceInfos() {
69         return m_aroundAdvices;
70     }
71
72     /**
73      * Returns the before advice infos.
74      *
75      * @return
76      */

77     public AdviceInfo[] getBeforeAdviceInfos() {
78         return m_beforeAdvices;
79     }
80
81     /**
82      * Returns the after finally advice infos.
83      *
84      * @return
85      */

86     public AdviceInfo[] getAfterFinallyAdviceInfos() {
87         return m_afterFinallyAdvices;
88     }
89
90     /**
91      * Returns the after returning advice infos.
92      *
93      * @return
94      */

95     public AdviceInfo[] getAfterReturningAdviceInfos() {
96         return m_afterReturningAdvices;
97     }
98
99     /**
100      * Returns the after throwing advice infos.
101      *
102      * @return
103      */

104     public AdviceInfo[] getAfterThrowingAdviceInfos() {
105         return m_afterThrowingAdvices;
106     }
107
108     /**
109      * Return all advice infos.
110      *
111      * @return
112      */

113     public AdviceInfo[] getAllAdviceInfos() {
114         int size = m_beforeAdvices.length + m_aroundAdvices.length + m_afterReturningAdvices.length
115                     + m_afterThrowingAdvices.length + m_afterFinallyAdvices.length;
116         AdviceInfo[] advices = new AdviceInfo[size];
117
118         int destPos = 0;
119         System.arraycopy(m_beforeAdvices, 0, advices, destPos, m_beforeAdvices.length);
120         destPos += m_beforeAdvices.length;
121         System.arraycopy(m_aroundAdvices, 0, advices, destPos, m_aroundAdvices.length);
122         destPos += m_aroundAdvices.length;
123         System.arraycopy(m_afterReturningAdvices, 0, advices, destPos, m_afterReturningAdvices.length);
124         destPos += m_afterReturningAdvices.length;
125         System.arraycopy(m_afterThrowingAdvices, 0, advices, destPos, m_afterThrowingAdvices.length);
126         destPos += m_afterThrowingAdvices.length;
127         System.arraycopy(m_afterFinallyAdvices, 0, advices, destPos, m_afterFinallyAdvices.length);
128         destPos += m_afterFinallyAdvices.length;
129
130         return advices;
131     }
132
133 }
Popular Tags