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;
9
10 import org.codehaus.aspectwerkz.aspect.management.AspectManager;
11 import org.codehaus.aspectwerkz.aspect.AdviceType;
12 import org.codehaus.aspectwerkz.transform.AsmHelper;
13 import org.codehaus.aspectwerkz.transform.AsmHelper;
14
15 import java.io.ObjectInputStream;
16 import java.io.Serializable;
17
18 /***
19 * Contains advice info, like indexes describing the aspect and a method (advice or introduced),
20 * aspect manager etc.
21 *
22 * @author <a href="mailto:jboner@codehaus.org">Jonas Bonér </a>
23 * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur </a>
24 */
25 public class AdviceInfo implements Serializable {
26 /***
27 * Index for the aspect.
28 */
29 private int m_aspectIndex;
30
31 /***
32 * Index for the advice method.
33 */
34 private int m_methodIndex;
35
36 /***
37 * The uuid - informational purpose
38 */
39 private String m_uuid;
40
41 /***
42 * The aspect manager
43 */
44 private transient AspectManager m_aspectManager;
45
46 /***
47 * The advice method arg index mapped to the target method arg index
48 */
49 private int[] m_methodToArgIndexes;
50
51 /***
52 * The "special" argument for the advice.
53 */
54 private String m_specialArgumentType;
55
56 /***
57 * The advice type.
58 */
59 private AdviceType m_type;
60
61 /***
62 * Creates a new advice info.
63 *
64 * @param aspectIndex the aspect index
65 * @param methodIndex the method index
66 * @param aspectManager the aspectManager
67 * @param type the advice type
68 * @param specialArgumentType the special arg type
69 */
70 public AdviceInfo(final int aspectIndex,
71 final int methodIndex,
72 final AspectManager aspectManager,
73 final AdviceType type,
74 final String specialArgumentType) {
75 m_aspectIndex = aspectIndex;
76 m_methodIndex = methodIndex;
77 m_aspectManager = aspectManager;
78 m_type = type;
79 m_specialArgumentType = AsmHelper.convertReflectDescToTypeDesc(specialArgumentType);
80 }
81
82 /***
83 * Return the aspect index.
84 *
85 * @return the aspect index
86 */
87 public int getAspectIndex() {
88 return m_aspectIndex;
89 }
90
91 /***
92 * Return the method index.
93 *
94 * @return the method index
95 */
96 public int getMethodIndex() {
97 return m_methodIndex;
98 }
99
100 /***
101 * Return the aspectManager.
102 *
103 * @return the aspect manager
104 */
105 public AspectManager getAspectManager() {
106 return m_aspectManager;
107 }
108
109 /***
110 * Sets the advice method to target method arg mapping A value of -1 means "not mapped"
111 *
112 * @param map
113 */
114 public void setMethodToArgIndexes(final int[] map) {
115 m_methodToArgIndexes = map;
116 }
117
118 /***
119 * Returns the advice method to target method arg index mapping.
120 *
121 * @return the indexes
122 */
123 public int[] getMethodToArgIndexes() {
124 return m_methodToArgIndexes;
125 }
126
127 /***
128 * Returns the special argument type.
129 *
130 * @return
131 */
132 public String getSpecialArgumentType() {
133 return m_specialArgumentType;
134 }
135
136 /***
137 * Returns the advice type.
138 *
139 * @return
140 */
141 public AdviceType getType() {
142 return m_type;
143 }
144
145 public String toString() {
146 StringBuffer sb = new StringBuffer("AdviceInfo[");
147 sb.append(m_type).append(',');
148 sb.append(m_aspectManager).append(',');
149 sb.append(m_aspectIndex).append(',');
150 sb.append(m_methodIndex).append(',');
151 sb.append(m_specialArgumentType).append(']');
152 sb.append(hashCode());
153 return sb.toString();
154 }
155
156 /***
157 * Provides custom deserialization.
158 *
159 * @param stream the object input stream containing the serialized object
160 * @throws Exception in case of failure
161 */
162 private void readObject(final ObjectInputStream stream) throws Exception {
163 ObjectInputStream.GetField fields = stream.readFields();
164 m_uuid = (String) fields.get("m_uuid", null);
165 m_type = (AdviceType) fields.get("m_type", null);
166 m_methodIndex = fields.get("m_methodIndex", 0);
167 m_aspectIndex = fields.get("m_aspectIndex", 0);
168 m_methodToArgIndexes = (int[]) fields.get("m_methodToArgIndexes", null);
169 m_specialArgumentType = (String) fields.get("m_specialArgumentType", null);
170 m_aspectManager = SystemLoader.getSystem(
171 Thread.currentThread().
172 getContextClassLoader()
173 ).getAspectManager(m_uuid);
174 }
175 }