1 8 package org.codehaus.aspectwerkz.definition; 9 10 import java.util.ArrayList ; 11 import java.util.Collection ; 12 import java.util.HashMap ; 13 import java.util.List ; 14 import java.util.Map ; 15 16 import org.codehaus.aspectwerkz.reflect.ClassInfo; 17 import org.codehaus.aspectwerkz.DeploymentModel; 18 import org.codehaus.aspectwerkz.DeploymentModel; 19 import org.codehaus.aspectwerkz.aspect.DefaultAspectContainerStrategy; 20 21 27 public class AspectDefinition { 28 29 private final static String DEFAULT_ASPECTCONTAINER_CLASSNAME = DefaultAspectContainerStrategy.class.getName(); 30 31 34 public static final String ASPECTWERKZ_ASPECT_MODEL_TYPE = "aspectwerkz"; 35 36 39 private String m_name; 40 41 44 private String m_qualifiedName; 45 46 49 private final ClassInfo m_classInfo; 50 51 54 private DeploymentModel m_deploymentModel = DeploymentModel.PER_JVM; 55 56 59 private final List m_aroundAdviceDefinitions = new ArrayList (); 60 61 64 private final List m_beforeAdviceDefinitions = new ArrayList (); 65 66 69 private final List m_afterAdviceDefinitions = new ArrayList (); 70 71 74 private final List m_interfaceIntroductionDefinitions = new ArrayList (); 75 76 79 private final List m_pointcutDefinitions = new ArrayList (); 80 81 84 private Map m_parameters = new HashMap (); 85 86 89 private String m_containerClassName; 90 91 94 private SystemDefinition m_systemDefinition; 95 96 99 private String m_aspectModelType = ASPECTWERKZ_ASPECT_MODEL_TYPE; 100 101 108 public AspectDefinition(final String name, final ClassInfo classInfo, final SystemDefinition systemDefinition) { 109 if (name == null) { 110 throw new IllegalArgumentException ("aspect name can not be null"); 111 } 112 if (classInfo == null) { 113 throw new IllegalArgumentException ("aspect class info can not be null"); 114 } 115 m_name = name; 116 m_classInfo = classInfo; 117 m_systemDefinition = systemDefinition; 118 m_qualifiedName = systemDefinition.getUuid() + '/' + name; 119 120 setContainerClassName(DEFAULT_ASPECTCONTAINER_CLASSNAME); 122 } 123 124 129 public String getName() { 130 return m_name; 131 } 132 133 138 public void setName(final String name) { 139 m_name = name.trim(); 140 } 141 142 147 public String getQualifiedName() { 148 return m_qualifiedName; 149 } 150 151 156 public SystemDefinition getSystemDefinition() { 157 return m_systemDefinition; 158 } 159 160 165 public String getClassName() { 166 return m_classInfo.getName(); 167 } 168 169 174 public ClassInfo getClassInfo() { 175 return m_classInfo; 176 } 177 178 183 public String getAspectModel() { 184 return m_aspectModelType; 185 } 186 187 192 public boolean isAspectWerkzAspect() { 193 return m_aspectModelType.equals(ASPECTWERKZ_ASPECT_MODEL_TYPE); 194 } 195 196 201 public void setAspectModel(final String aspectModelType) { 202 m_aspectModelType = aspectModelType; 203 } 204 205 210 public void setDeploymentModel(final DeploymentModel deploymentModel) { 211 m_deploymentModel = deploymentModel; 212 } 213 214 219 public DeploymentModel getDeploymentModel() { 220 return m_deploymentModel; 221 } 222 223 228 public void addAroundAdviceDefinition(final AdviceDefinition adviceDef) { 229 if (!m_aroundAdviceDefinitions.contains(adviceDef)) { 230 m_aroundAdviceDefinitions.add(adviceDef); 231 } 232 } 233 234 239 public List getAroundAdviceDefinitions() { 240 return m_aroundAdviceDefinitions; 241 } 242 243 248 public void addBeforeAdviceDefinition(final AdviceDefinition adviceDef) { 249 if (!m_beforeAdviceDefinitions.contains(adviceDef)) { 250 m_beforeAdviceDefinitions.add(adviceDef); 251 } 252 } 253 254 259 public List getBeforeAdviceDefinitions() { 260 return m_beforeAdviceDefinitions; 261 } 262 263 268 public void addAfterAdviceDefinition(final AdviceDefinition adviceDef) { 269 if (!m_afterAdviceDefinitions.contains(adviceDef)) { 270 m_afterAdviceDefinitions.add(adviceDef); 271 } 272 } 273 274 279 public List getAfterAdviceDefinitions() { 280 return m_afterAdviceDefinitions; 281 } 282 283 288 public void addInterfaceIntroductionDefinition(final InterfaceIntroductionDefinition interfaceIntroDef) { 289 m_interfaceIntroductionDefinitions.add(interfaceIntroDef); 290 } 291 292 297 public List getInterfaceIntroductionDefinitions() { 298 return m_interfaceIntroductionDefinitions; 299 } 300 301 306 public void addPointcutDefinition(final PointcutDefinition pointcutDef) { 307 m_pointcutDefinitions.add(pointcutDef); 308 } 309 310 315 public Collection getPointcutDefinitions() { 316 return m_pointcutDefinitions; 317 } 318 319 325 public void addParameter(final String name, final String value) { 326 m_parameters.put(name, value); 327 } 328 329 334 public Map getParameters() { 335 return m_parameters; 336 } 337 338 343 public void setContainerClassName(final String containerClassName) { 344 if (containerClassName != null) { 345 m_containerClassName = containerClassName.replace('/', '.'); 346 } 347 } 348 349 354 public String getContainerClassName() { 355 return m_containerClassName; 356 } 357 358 363 public List getAdviceDefinitions() { 364 final List allAdvices = new ArrayList (); 365 allAdvices.addAll(m_aroundAdviceDefinitions); 366 allAdvices.addAll(m_beforeAdviceDefinitions); 367 allAdvices.addAll(m_afterAdviceDefinitions); 368 return allAdvices; 369 } 370 } | Popular Tags |