KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > aspectwerkz > definition > DeploymentScope


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.aspectwerkz.definition;
5
6 import com.tc.aspectwerkz.transform.TransformationConstants;
7 import com.tc.aspectwerkz.expression.ExpressionInfo;
8
9 /**
10  * Represents a deployment scope pointcut expression, that is used by the system to "prepare" the
11  * join points that are picked out by this pointcut. Needed to allow hot-deployment of aspects
12  * in a safe and predictable way.
13  * <p/>
14  * Can not and should not be created by the user only given to him from the framework.
15  *
16  * @author <a HREF="mailto:jboner@codehaus.org">Jonas BonŽr </a>
17  */

18 public final class DeploymentScope {
19
20   private final String JavaDoc m_name;
21   private final String JavaDoc m_expression;
22   /**
23    * System prepared pointcut that matches all.
24    */

25   public static final DeploymentScope MATCH_ALL = new DeploymentScope(
26           TransformationConstants.ASPECTWERKZ_PREFIX + "DeploymentScopes",
27           "within(*..*)"
28   );
29
30   /**
31    * Creates a new pointcut, should only be created by the system.
32    *
33    * @param name
34    * @param expression
35    */

36   DeploymentScope(final String JavaDoc name, final String JavaDoc expression) {
37     m_name = name;
38     m_expression = expression;
39   }
40
41   /**
42    * Returns the name of the pointcut.
43    *
44    * @return
45    */

46   public String JavaDoc getName() {
47     return m_name;
48   }
49
50   /**
51    * Returns the expression as a string.
52    *
53    * @return
54    */

55   public String JavaDoc getExpression() {
56     return m_expression;
57   }
58
59   /**
60    * Merges the scope expression with a new expression. Uses '&&' to merge them.
61    *
62    * @param expression
63    * @return
64    */

65   public ExpressionInfo newExpressionInfo(final ExpressionInfo expression) {
66     return new ExpressionInfo(
67             new StringBuffer JavaDoc().
68                     append('(').
69                     append(expression.toString()).
70                     append(')').
71                     append(" && ").
72                     append(m_expression).
73                     toString(),
74             expression.getNamespace()
75     );
76   }
77
78   public boolean equals(Object JavaDoc o) {
79     if (this == o) {
80       return true;
81     }
82     if (!(o instanceof DeploymentScope)) {
83       return false;
84     }
85
86     final DeploymentScope deploymentScope = (DeploymentScope) o;
87
88     if (!m_expression.equals(deploymentScope.m_expression)) {
89       return false;
90     }
91     if (!m_name.equals(deploymentScope.m_name)) {
92       return false;
93     }
94
95     return true;
96   }
97
98   public int hashCode() {
99     int result;
100     result = m_name.hashCode();
101     result = 29 * result + m_expression.hashCode();
102     return result;
103   }
104 }
Popular Tags