1 4 package com.tc.aspectwerkz.definition; 5 6 import java.util.ArrayList ; 7 import java.util.Collection ; 8 import java.util.HashMap ; 9 import java.util.List ; 10 import java.util.Map ; 11 12 import com.tc.aspectwerkz.DeploymentModel; 13 import com.tc.aspectwerkz.reflect.ClassInfo; 14 import com.tc.aspectwerkz.reflect.ConstructorInfo; 15 import com.tc.aspectwerkz.aspect.DefaultAspectContainerStrategy; 16 import com.tc.aspectwerkz.transform.inlining.model.AspectWerkzAspectModel; 17 18 24 public class AspectDefinition { 25 26 private final static String DEFAULT_ASPECTCONTAINER_CLASSNAME = DefaultAspectContainerStrategy.class.getName(); 27 28 31 private String m_name; 32 33 36 private String m_qualifiedName; 37 38 41 private final ClassInfo m_classInfo; 42 43 46 private DeploymentModel m_deploymentModel = DeploymentModel.PER_JVM; 47 48 51 private final List m_aroundAdviceDefinitions = new ArrayList (); 52 53 56 private final List m_beforeAdviceDefinitions = new ArrayList (); 57 58 61 private final List m_afterAdviceDefinitions = new ArrayList (); 62 63 66 private final List m_interfaceIntroductionDefinitions = new ArrayList (); 67 68 71 private final List m_pointcutDefinitions = new ArrayList (); 72 73 76 private Map m_parameters = new HashMap (); 77 78 81 private String m_containerClassName; 82 83 86 private SystemDefinition m_systemDefinition; 87 88 91 private String m_aspectModelType = AspectWerkzAspectModel.TYPE; 92 93 100 public AspectDefinition(final String name, final ClassInfo classInfo, final SystemDefinition systemDefinition) { 101 if (name == null) { 102 throw new IllegalArgumentException ("aspect name can not be null"); 103 } 104 if (classInfo == null) { 105 throw new IllegalArgumentException ("aspect class info can not be null"); 106 } 107 m_name = name; 108 m_classInfo = classInfo; 109 m_systemDefinition = systemDefinition; 110 m_qualifiedName = systemDefinition.getUuid() + '/' + name; 111 112 boolean hasNoArg = false; 116 for (int i = 0; i < m_classInfo.getConstructors().length; i++) { 117 ConstructorInfo constructorInfo = m_classInfo.getConstructors()[i]; 118 if ("()V".equals(constructorInfo.getSignature())) { 119 hasNoArg = true; 120 break; 121 } 122 } 123 if (!hasNoArg) { 124 setContainerClassName(DEFAULT_ASPECTCONTAINER_CLASSNAME); 125 } 126 } 127 128 133 public String getName() { 134 return m_name; 135 } 136 137 142 public void setName(final String name) { 143 m_name = name.trim(); 144 } 145 146 151 public String getQualifiedName() { 152 return m_qualifiedName; 153 } 154 155 160 public SystemDefinition getSystemDefinition() { 161 return m_systemDefinition; 162 } 163 164 169 public String getClassName() { 170 return m_classInfo.getName(); 171 } 172 173 178 public ClassInfo getClassInfo() { 179 return m_classInfo; 180 } 181 182 187 public String getAspectModel() { 188 return m_aspectModelType; 189 } 190 191 196 public boolean isAspectWerkzAspect() { 197 return m_aspectModelType.equals(AspectWerkzAspectModel.TYPE); 198 } 199 200 205 public void setAspectModel(final String aspectModelType) { 206 m_aspectModelType = aspectModelType; 207 } 208 209 214 public void setDeploymentModel(final DeploymentModel deploymentModel) { 215 m_deploymentModel = deploymentModel; 216 } 217 218 223 public DeploymentModel getDeploymentModel() { 224 return m_deploymentModel; 225 } 226 227 232 public void addAroundAdviceDefinition(final AdviceDefinition adviceDef) { 233 if (!m_aroundAdviceDefinitions.contains(adviceDef)) { 234 m_aroundAdviceDefinitions.add(adviceDef); 235 } 236 } 237 238 243 public List getAroundAdviceDefinitions() { 244 return m_aroundAdviceDefinitions; 245 } 246 247 252 public void addBeforeAdviceDefinition(final AdviceDefinition adviceDef) { 253 if (!m_beforeAdviceDefinitions.contains(adviceDef)) { 254 m_beforeAdviceDefinitions.add(adviceDef); 255 } 256 } 257 258 263 public List getBeforeAdviceDefinitions() { 264 return m_beforeAdviceDefinitions; 265 } 266 267 272 public void addAfterAdviceDefinition(final AdviceDefinition adviceDef) { 273 if (!m_afterAdviceDefinitions.contains(adviceDef)) { 274 m_afterAdviceDefinitions.add(adviceDef); 275 } 276 } 277 278 283 public List getAfterAdviceDefinitions() { 284 return m_afterAdviceDefinitions; 285 } 286 287 292 public void addInterfaceIntroductionDefinition(final InterfaceIntroductionDefinition interfaceIntroDef) { 293 m_interfaceIntroductionDefinitions.add(interfaceIntroDef); 294 } 295 296 301 public List getInterfaceIntroductionDefinitions() { 302 return m_interfaceIntroductionDefinitions; 303 } 304 305 310 public void addPointcutDefinition(final PointcutDefinition pointcutDef) { 311 m_pointcutDefinitions.add(pointcutDef); 312 } 313 314 319 public Collection getPointcutDefinitions() { 320 return m_pointcutDefinitions; 321 } 322 323 329 public void addParameter(final String name, final Object value) { 330 m_parameters.put(name, value); 331 } 332 333 338 public Map getParameters() { 339 return m_parameters; 340 } 341 342 347 public void setContainerClassName(final String containerClassName) { 348 if (containerClassName != null) { 349 m_containerClassName = containerClassName.replace('/', '.'); 350 } else { 351 m_containerClassName = null; 352 } 353 } 354 355 360 public String getContainerClassName() { 361 return m_containerClassName; 362 } 363 364 369 public List getAdviceDefinitions() { 370 final List allAdvices = new ArrayList (); 371 allAdvices.addAll(m_aroundAdviceDefinitions); 372 allAdvices.addAll(m_beforeAdviceDefinitions); 373 allAdvices.addAll(m_afterAdviceDefinitions); 374 return allAdvices; 375 } 376 } | Popular Tags |