1 4 package com.tc.aspectwerkz.definition; 5 6 7 import com.tc.aspectwerkz.DeploymentModel; 8 import com.tc.aspectwerkz.reflect.MethodInfo; 9 import com.tc.aspectwerkz.expression.ExpressionInfo; 10 import com.tc.aspectwerkz.aspect.AdviceType; 11 import com.tc.aspectwerkz.cflow.CflowBinding; 12 import com.tc.aspectwerkz.util.Strings; 13 14 import java.util.List ; 15 16 21 public class AdviceDefinition { 22 23 28 private String m_name; 29 30 33 private AdviceType m_type; 34 35 38 private final String m_aspectClassName; 39 40 43 private final String m_aspectName; 44 45 48 private ExpressionInfo m_expressionInfo; 49 50 53 private final MethodInfo m_method; 54 55 58 private String m_attribute = ""; 59 60 63 private AspectDefinition m_aspectDefinition; 64 65 68 private String m_specialArgumentType; 69 70 73 private boolean m_hasCflowOrCflowBelow = false; 74 75 90 public static AdviceDefinition newInstance(final String adviceName, 91 final AdviceType adviceType, 92 final String expression, 93 final String specialArgumentType, 94 final String aspectName, 95 final String aspectClassName, 96 final MethodInfo method, 97 final AspectDefinition aspectDef) { 98 ExpressionInfo expressionInfo = new ExpressionInfo( 99 expression, 100 aspectDef.getQualifiedName() 101 ); 102 103 String adviceCallSignature = null; 105 String resolvedSpecialArgumentType = specialArgumentType; 106 if (adviceName.indexOf('(') > 0) { 107 adviceCallSignature = adviceName.substring(adviceName.indexOf('(') + 1, adviceName.lastIndexOf(')')); 108 String [] parameters = Strings.splitString(adviceCallSignature, ","); 109 for (int i = 0; i < parameters.length; i++) { 110 String [] parameterInfo = Strings.splitString( 111 Strings.replaceSubString(parameters[i].trim(), " ", " "), 112 " " 113 ); 114 if (parameterInfo[1].equals(specialArgumentType)) { 116 resolvedSpecialArgumentType = parameterInfo[0]; 117 expressionInfo.setSpecialArgumentName(parameterInfo[1]); 118 } else { 119 expressionInfo.addArgument( 120 parameterInfo[1], 121 parameterInfo[0], 122 aspectDef.getClassInfo().getClassLoader() 123 ); 124 } 125 } 126 } 127 128 return new AdviceDefinition( 129 adviceName, 130 adviceType, 131 resolvedSpecialArgumentType, 132 aspectName, 133 aspectClassName, 134 expressionInfo, 135 method, 136 aspectDef 137 ); 138 } 139 140 153 public AdviceDefinition(final String name, 154 final AdviceType type, 155 final String specialArgumentType, 156 final String aspectName, 157 final String aspectClassName, 158 final ExpressionInfo expressionInfo, 159 final MethodInfo methodInfo, 160 final AspectDefinition aspectDef) { 161 if (name == null) { 162 throw new IllegalArgumentException ("name can not be null"); 163 } 164 if (type == null) { 165 throw new IllegalArgumentException ("illegal advice type"); 166 } 167 if (aspectName == null) { 168 throw new IllegalArgumentException ("aspect name can not be null"); 169 } 170 if (aspectClassName == null) { 171 throw new IllegalArgumentException ("class name can not be null"); 172 } 173 if (methodInfo == null) { 174 throw new IllegalArgumentException ("methodInfo can not be null"); 175 } 176 if (aspectDef == null) { 177 throw new IllegalArgumentException ("aspect definition can not be null"); 178 } 179 m_name = name; 180 m_type = type; 181 m_specialArgumentType = specialArgumentType; 182 m_aspectName = aspectName; 183 m_aspectClassName = aspectClassName; 184 m_expressionInfo = expressionInfo; 185 m_method = methodInfo; 186 m_aspectDefinition = aspectDef; 187 188 List cflowBindings = CflowBinding.getCflowBindingsForCflowOf(m_expressionInfo); 190 m_hasCflowOrCflowBelow = (cflowBindings.size() > 0); 191 } 192 193 198 public AdviceType getType() { 199 return m_type; 200 } 201 202 207 public String getName() { 208 return m_name; 209 } 210 211 216 public String getQualifiedName() { 217 return m_aspectDefinition.getQualifiedName() + '.' + m_name; 218 } 219 220 225 public void setName(final String name) { 226 m_name = name.trim(); 227 } 228 229 236 public ExpressionInfo getExpressionInfo() { 237 return m_expressionInfo; 238 } 239 240 245 public void setExpressionInfo(final ExpressionInfo newExpression) { 246 m_expressionInfo = newExpression; 247 List cflowBindings = CflowBinding.getCflowBindingsForCflowOf(m_expressionInfo); 249 m_hasCflowOrCflowBelow = (cflowBindings.size() > 0); 250 } 251 252 257 public String getAspectClassName() { 258 return m_aspectClassName; 259 } 260 261 266 public String getAspectName() { 267 return m_aspectName; 268 } 269 270 275 public String getSpecialArgumentType() { 276 return m_specialArgumentType; 277 } 278 279 284 public MethodInfo getMethodInfo() { 285 return m_method; 286 } 287 288 293 public DeploymentModel getDeploymentModel() { 294 return m_aspectDefinition.getDeploymentModel(); 295 } 296 297 302 public String getAttribute() { 303 return m_attribute; 304 } 305 306 311 public void setAttribute(final String attribute) { 312 m_attribute = attribute; 313 } 314 315 320 public AspectDefinition getAspectDefinition() { 321 return m_aspectDefinition; 322 } 323 324 329 public boolean hasCflowOrCflowBelow() { 330 return m_hasCflowOrCflowBelow; 331 } 332 333 339 public AdviceDefinition copyAt(final ExpressionInfo expressionInfo) { 340 return new AdviceDefinition( 341 getName(), 342 getType(), 343 getSpecialArgumentType(), 344 getAspectName(), 345 getAspectClassName(), 346 expressionInfo, 347 getMethodInfo(), 348 m_aspectDefinition 349 ); 350 } 351 352 359 public boolean equals(Object o) { 360 if (this == o) return true; 361 if (!(o instanceof AdviceDefinition)) return false; 362 363 final AdviceDefinition adviceDefinition = (AdviceDefinition) o; 364 365 if (!m_aspectName.equals(adviceDefinition.m_aspectName)) return false; 366 if (!m_name.equals(adviceDefinition.m_name)) return false; 367 368 return true; 369 } 370 371 public int hashCode() { 372 int result; 373 result = m_name.hashCode(); 374 result = 29 * result + m_aspectName.hashCode(); 375 return result; 376 } 377 } | Popular Tags |