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.definition; 9 10 import org.codehaus.aspectwerkz.expression.ExpressionInfo; 11 import org.codehaus.aspectwerkz.aspect.AdviceType; 12 13 import java.lang.reflect.Method; 14 15 /*** 16 * Holds the meta-data for the advices. 17 * 18 * @author <a href="mailto:jboner@codehaus.org">Jonas Bonér </a> 19 */ 20 public class AdviceDefinition { 21 22 /*** 23 * The name of the advice. 24 */ 25 private String m_name; 26 27 /*** 28 * The type of the advice. 29 */ 30 private AdviceType m_type; 31 32 /*** 33 * The aspect class name. 34 */ 35 private final String m_aspectClassName; 36 37 /*** 38 * The aspect name. 39 */ 40 private final String m_aspectName; 41 42 /*** 43 * The pointcut expression. 44 */ 45 private ExpressionInfo m_expressionInfo; 46 47 /*** 48 * The method for the advice. 49 */ 50 private final Method m_method; 51 52 /*** 53 * Index for the method for this advice. 54 */ 55 private final int m_methodIndex; 56 57 /*** 58 * The attribute for the advice. 59 */ 60 private String m_attribute = ""; 61 62 /*** 63 * The aspect definition holding this advice definition. 64 */ 65 private AspectDefinition m_aspectDefinition; 66 67 /*** 68 * The special arg type, such as returning(TYPE) or throwing(TYPE). 69 */ 70 private String m_specialArgumentType; 71 72 /*** 73 * Creates a new advice meta-data instance. 74 * 75 * @param name the name of the expressionInfo 76 * @param type the type of the advice 77 * @param specialArgumentType the special arg type, such as returning(TYPE) or throwing(TYPE) 78 * @param aspectName the name of the aspect 79 * @param aspectClassName the class name of the aspect 80 * @param expressionInfo the expressionInfo 81 * @param method the method 82 * @param methodIndex the method index 83 */ 84 public AdviceDefinition(final String name, 85 final AdviceType type, 86 final String specialArgumentType, 87 final String aspectName, 88 final String aspectClassName, 89 final ExpressionInfo expressionInfo, 90 final Method method, 91 final int methodIndex, 92 final AspectDefinition aspectDef) { 93 if (name == null) { 94 throw new IllegalArgumentException("name can not be null"); 95 } 96 if (type == null) { 97 throw new IllegalArgumentException("illegal advice type"); 98 } 99 if (aspectName == null) { 100 throw new IllegalArgumentException("aspect name can not be null"); 101 } 102 if (aspectClassName == null) { 103 throw new IllegalArgumentException("class name can not be null"); 104 } 105 if (expressionInfo == null) { 106 throw new IllegalArgumentException("expressionInfo can not be null"); 107 } 108 if (method == null) { 109 throw new IllegalArgumentException("method can not be null"); 110 } 111 if (methodIndex < 0) { 112 throw new IllegalArgumentException("method index is not valid"); 113 } 114 if (aspectDef == null) { 115 throw new IllegalArgumentException("aspect definition can not be null"); 116 } 117 m_name = name; 118 m_type = type; 119 m_specialArgumentType = specialArgumentType; 120 m_aspectName = aspectName; 121 m_aspectClassName = aspectClassName; 122 m_expressionInfo = expressionInfo; 123 m_method = method; 124 m_methodIndex = methodIndex; 125 m_aspectDefinition = aspectDef; 126 } 127 128 /*** 129 * Returns the advice type. 130 * 131 * @return the advice type 132 */ 133 public AdviceType getType() { 134 return m_type; 135 } 136 137 /*** 138 * Returns the name of the advice. 139 * 140 * @return the name 141 */ 142 public String getName() { 143 return m_name; 144 } 145 146 /*** 147 * Sets the name of the advice. 148 * 149 * @param name the name 150 */ 151 public void setName(final String name) { 152 m_name = name.trim(); 153 } 154 155 /*** 156 * Returns the expression. 157 * 158 * @return the expression 159 */ 160 public ExpressionInfo getExpressionInfo() { 161 return m_expressionInfo; 162 } 163 164 /*** 165 * Returns the class name. 166 * 167 * @return the class name 168 */ 169 public String getAspectClassName() { 170 return m_aspectClassName; 171 } 172 173 /*** 174 * Returns the aspect name. 175 * 176 * @return the aspect name 177 */ 178 public String getAspectName() { 179 return m_aspectName; 180 } 181 182 /*** 183 * Returns the special arg type, such as returning(TYPE) or throwing(TYPE). 184 * 185 * @return 186 */ 187 public String getSpecialArgumentType() { 188 return m_specialArgumentType; 189 } 190 191 /*** 192 * Returns the method. 193 * 194 * @return the method 195 */ 196 public Method getMethod() { 197 return m_method; 198 } 199 200 /*** 201 * Returns the method index for the introduction method. 202 * 203 * @return the method index 204 */ 205 public int getMethodIndex() { 206 return m_methodIndex; 207 } 208 209 /*** 210 * Returns the the deployment model for the advice 211 * 212 * @return the deployment model 213 */ 214 public String getDeploymentModel() { 215 return m_aspectDefinition.getDeploymentModel(); 216 } 217 218 /*** 219 * Returns the attribute. 220 * 221 * @return the attribute 222 */ 223 public String getAttribute() { 224 return m_attribute; 225 } 226 227 /*** 228 * Sets the attribute. 229 * 230 * @param attribute the attribute 231 */ 232 public void setAttribute(final String attribute) { 233 m_attribute = attribute; 234 } 235 236 /*** 237 * Deep copy of the definition. 238 * 239 * @param expressionInfo 240 * @return 241 */ 242 public AdviceDefinition copyAt(final ExpressionInfo expressionInfo) { 243 return new AdviceDefinition( 244 getName(), 245 getType(), 246 getSpecialArgumentType(), 247 getAspectName(), 248 getAspectClassName(), 249 expressionInfo, 250 getMethod(), 251 getMethodIndex(), 252 m_aspectDefinition); 253 } 254 }