001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.aspectwerkz.joinpoint.management;
005:
006: import java.util.List;
007: import java.util.ArrayList;
008:
009: import com.tc.aspectwerkz.aspect.AdviceInfo;
010:
011: /**
012: * Container for the advice infos that belongs to a specific join point.
013: *
014: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
015: * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
016: */
017: public class AdviceInfoContainer {
018:
019: /**
020: * Null AdviceInfoContainer instance
021: */
022: public static final AdviceInfoContainer NULL;
023:
024: static {
025: NULL = new AdviceInfoContainer(new ArrayList(),
026: new ArrayList(), new ArrayList(), new ArrayList(),
027: new ArrayList());
028: }
029:
030: private final AdviceInfo[] m_aroundAdvices;
031: private final AdviceInfo[] m_beforeAdvices;
032: private final AdviceInfo[] m_afterFinallyAdvices;
033: private final AdviceInfo[] m_afterReturningAdvices;
034: private final AdviceInfo[] m_afterThrowingAdvices;
035:
036: /**
037: * Creates a advice info container.
038: *
039: * @param aroundAdvices
040: * @param beforeAdvices
041: * @param afterFinallyAdvices
042: * @param afterReturningAdvices
043: * @param afterThrowingAdvices
044: */
045: public AdviceInfoContainer(final List aroundAdvices,
046: final List beforeAdvices, final List afterFinallyAdvices,
047: final List afterReturningAdvices,
048: final List afterThrowingAdvices) {
049: m_aroundAdvices = (AdviceInfo[]) aroundAdvices
050: .toArray(AdviceInfo.EMPTY_ADVICE_INFO_ARRAY);
051: m_beforeAdvices = (AdviceInfo[]) beforeAdvices
052: .toArray(AdviceInfo.EMPTY_ADVICE_INFO_ARRAY);
053: m_afterFinallyAdvices = (AdviceInfo[]) afterFinallyAdvices
054: .toArray(AdviceInfo.EMPTY_ADVICE_INFO_ARRAY);
055: m_afterReturningAdvices = (AdviceInfo[]) afterReturningAdvices
056: .toArray(AdviceInfo.EMPTY_ADVICE_INFO_ARRAY);
057: m_afterThrowingAdvices = (AdviceInfo[]) afterThrowingAdvices
058: .toArray(AdviceInfo.EMPTY_ADVICE_INFO_ARRAY);
059: }
060:
061: /**
062: * Returns the around advice infos.
063: *
064: * @return
065: */
066: public AdviceInfo[] getAroundAdviceInfos() {
067: return m_aroundAdvices;
068: }
069:
070: /**
071: * Returns the before advice infos.
072: *
073: * @return
074: */
075: public AdviceInfo[] getBeforeAdviceInfos() {
076: return m_beforeAdvices;
077: }
078:
079: /**
080: * Returns the after finally advice infos.
081: *
082: * @return
083: */
084: public AdviceInfo[] getAfterFinallyAdviceInfos() {
085: return m_afterFinallyAdvices;
086: }
087:
088: /**
089: * Returns the after returning advice infos.
090: *
091: * @return
092: */
093: public AdviceInfo[] getAfterReturningAdviceInfos() {
094: return m_afterReturningAdvices;
095: }
096:
097: /**
098: * Returns the after throwing advice infos.
099: *
100: * @return
101: */
102: public AdviceInfo[] getAfterThrowingAdviceInfos() {
103: return m_afterThrowingAdvices;
104: }
105:
106: /**
107: * Return all advice infos.
108: *
109: * @return
110: */
111: public AdviceInfo[] getAllAdviceInfos() {
112: int size = m_beforeAdvices.length + m_aroundAdvices.length
113: + m_afterReturningAdvices.length
114: + m_afterThrowingAdvices.length
115: + m_afterFinallyAdvices.length;
116: AdviceInfo[] advices = new AdviceInfo[size];
117:
118: int destPos = 0;
119: System.arraycopy(m_beforeAdvices, 0, advices, destPos,
120: m_beforeAdvices.length);
121: destPos += m_beforeAdvices.length;
122: System.arraycopy(m_aroundAdvices, 0, advices, destPos,
123: m_aroundAdvices.length);
124: destPos += m_aroundAdvices.length;
125: System.arraycopy(m_afterReturningAdvices, 0, advices, destPos,
126: m_afterReturningAdvices.length);
127: destPos += m_afterReturningAdvices.length;
128: System.arraycopy(m_afterThrowingAdvices, 0, advices, destPos,
129: m_afterThrowingAdvices.length);
130: destPos += m_afterThrowingAdvices.length;
131: System.arraycopy(m_afterFinallyAdvices, 0, advices, destPos,
132: m_afterFinallyAdvices.length);
133: destPos += m_afterFinallyAdvices.length;
134:
135: return advices;
136: }
137:
138: }
|