1 8 package org.codehaus.aspectwerkz.definition; 9 10 import org.codehaus.aspectwerkz.expression.ExpressionInfo; 11 import org.codehaus.aspectwerkz.aspect.AdviceType; 12 import org.codehaus.aspectwerkz.reflect.MethodInfo; 13 import org.codehaus.aspectwerkz.util.Strings; 14 import org.codehaus.aspectwerkz.DeploymentModel; 15 import org.codehaus.aspectwerkz.cflow.CflowBinding; 16 17 import java.util.List ; 18 19 24 public class AdviceDefinition { 25 26 31 private String m_name; 32 33 36 private AdviceType m_type; 37 38 41 private final String m_aspectClassName; 42 43 46 private final String m_aspectName; 47 48 51 private ExpressionInfo m_expressionInfo; 52 53 56 private final MethodInfo m_method; 57 58 61 private String m_attribute = ""; 62 63 66 private AspectDefinition m_aspectDefinition; 67 68 71 private String m_specialArgumentType; 72 73 76 private boolean m_hasCflowOrCflowBelow = false; 77 78 93 public static AdviceDefinition newInstance(final String adviceName, 94 final AdviceType adviceType, 95 final String expression, 96 final String specialArgumentType, 97 final String aspectName, 98 final String aspectClassName, 99 final MethodInfo method, 100 final AspectDefinition aspectDef) { 101 ExpressionInfo expressionInfo = new ExpressionInfo( 102 expression, 103 aspectDef.getQualifiedName() 104 ); 105 106 String adviceCallSignature = null; 108 String resolvedSpecialArgumentType = specialArgumentType; 109 if (adviceName.indexOf('(') > 0) { 110 adviceCallSignature = adviceName.substring(adviceName.indexOf('(') + 1, adviceName.lastIndexOf(')')); 111 String [] parameters = Strings.splitString(adviceCallSignature, ","); 112 for (int i = 0; i < parameters.length; i++) { 113 String [] parameterInfo = Strings.splitString( 114 Strings.replaceSubString(parameters[i].trim(), " ", " "), 115 " " 116 ); 117 if (parameterInfo[1].equals(specialArgumentType)) { 119 resolvedSpecialArgumentType = parameterInfo[0]; 120 expressionInfo.setSpecialArgumentName(parameterInfo[1]); 121 } else { 122 expressionInfo.addArgument( 123 parameterInfo[1], 124 parameterInfo[0], 125 aspectDef.getClassInfo().getClassLoader() 126 ); 127 } 128 } 129 } 130 131 return new AdviceDefinition( 132 adviceName, 133 adviceType, 134 resolvedSpecialArgumentType, 135 aspectName, 136 aspectClassName, 137 expressionInfo, 138 method, 139 aspectDef 140 ); 141 } 142 143 154 public AdviceDefinition(final String name, 155 final AdviceType type, 156 final String specialArgumentType, 157 final String aspectName, 158 final String aspectClassName, 159 final ExpressionInfo expressionInfo, 160 final MethodInfo methodInfo, 161 final AspectDefinition aspectDef) { 162 if (name == null) { 163 throw new IllegalArgumentException ("name can not be null"); 164 } 165 if (type == null) { 166 throw new IllegalArgumentException ("illegal advice type"); 167 } 168 if (aspectName == null) { 169 throw new IllegalArgumentException ("aspect name can not be null"); 170 } 171 if (aspectClassName == null) { 172 throw new IllegalArgumentException ("class name can not be null"); 173 } 174 if (methodInfo == null) { 175 throw new IllegalArgumentException ("methodInfo can not be null"); 176 } 177 if (aspectDef == null) { 178 throw new IllegalArgumentException ("aspect definition can not be null"); 179 } 180 m_name = name; 181 m_type = type; 182 m_specialArgumentType = specialArgumentType; 183 m_aspectName = aspectName; 184 m_aspectClassName = aspectClassName; 185 m_expressionInfo = expressionInfo; 186 m_method = methodInfo; 187 m_aspectDefinition = aspectDef; 188 189 List cflowBindings = CflowBinding.getCflowBindingsForCflowOf(m_expressionInfo); 191 m_hasCflowOrCflowBelow = (cflowBindings.size() > 0); 192 } 193 194 199 public AdviceType getType() { 200 return m_type; 201 } 202 203 208 public String getName() { 209 return m_name; 210 } 211 212 217 public String getQualifiedName() { 218 return m_aspectDefinition.getQualifiedName() + '.' + m_name; 219 } 220 221 226 public void setName(final String name) { 227 m_name = name.trim(); 228 } 229 230 237 public ExpressionInfo getExpressionInfo() { 238 return m_expressionInfo; 239 } 240 241 246 public void setExpressionInfo(final ExpressionInfo newExpression) { 247 m_expressionInfo = newExpression; 248 List cflowBindings = CflowBinding.getCflowBindingsForCflowOf(m_expressionInfo); 250 m_hasCflowOrCflowBelow = (cflowBindings.size() > 0); 251 } 252 253 258 public String getAspectClassName() { 259 return m_aspectClassName; 260 } 261 262 267 public String getAspectName() { 268 return m_aspectName; 269 } 270 271 276 public String getSpecialArgumentType() { 277 return m_specialArgumentType; 278 } 279 280 285 public MethodInfo getMethodInfo() { 286 return m_method; 287 } 288 289 294 public DeploymentModel getDeploymentModel() { 295 return m_aspectDefinition.getDeploymentModel(); 296 } 297 298 303 public String getAttribute() { 304 return m_attribute; 305 } 306 307 312 public void setAttribute(final String attribute) { 313 m_attribute = attribute; 314 } 315 316 321 public AspectDefinition getAspectDefinition() { 322 return m_aspectDefinition; 323 } 324 325 330 public boolean hasCflowOrCflowBelow() { 331 return m_hasCflowOrCflowBelow; 332 } 333 334 340 public AdviceDefinition copyAt(final ExpressionInfo expressionInfo) { 341 return new AdviceDefinition( 342 getName(), 343 getType(), 344 getSpecialArgumentType(), 345 getAspectName(), 346 getAspectClassName(), 347 expressionInfo, 348 getMethodInfo(), 349 m_aspectDefinition 350 ); 351 } 352 353 360 public boolean equals(Object o) { 361 if (this == o) return true; 362 if (!(o instanceof AdviceDefinition)) return false; 363 364 final AdviceDefinition adviceDefinition = (AdviceDefinition) o; 365 366 if (!m_aspectName.equals(adviceDefinition.m_aspectName)) return false; 367 if (!m_name.equals(adviceDefinition.m_name)) return false; 368 369 return true; 370 } 371 372 public int hashCode() { 373 int result; 374 result = m_name.hashCode(); 375 result = 29 * result + m_aspectName.hashCode(); 376 return result; 377 } 378 } | Popular Tags |