01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.aspectwerkz.definition;
05:
06: import com.tc.aspectwerkz.transform.TransformationConstants;
07: import com.tc.aspectwerkz.expression.ExpressionInfo;
08:
09: /**
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 m_name;
21: private final String m_expression;
22: /**
23: * System prepared pointcut that matches all.
24: */
25: public static final DeploymentScope MATCH_ALL = new DeploymentScope(
26: TransformationConstants.ASPECTWERKZ_PREFIX
27: + "DeploymentScopes", "within(*..*)");
28:
29: /**
30: * Creates a new pointcut, should only be created by the system.
31: *
32: * @param name
33: * @param expression
34: */
35: DeploymentScope(final String name, final String expression) {
36: m_name = name;
37: m_expression = expression;
38: }
39:
40: /**
41: * Returns the name of the pointcut.
42: *
43: * @return
44: */
45: public String getName() {
46: return m_name;
47: }
48:
49: /**
50: * Returns the expression as a string.
51: *
52: * @return
53: */
54: public String getExpression() {
55: return m_expression;
56: }
57:
58: /**
59: * Merges the scope expression with a new expression. Uses '&&' to merge them.
60: *
61: * @param expression
62: * @return
63: */
64: public ExpressionInfo newExpressionInfo(
65: final ExpressionInfo expression) {
66: return new ExpressionInfo(new StringBuffer().append('(')
67: .append(expression.toString()).append(')').append(
68: " && ").append(m_expression).toString(),
69: expression.getNamespace());
70: }
71:
72: public boolean equals(Object o) {
73: if (this == o) {
74: return true;
75: }
76: if (!(o instanceof DeploymentScope)) {
77: return false;
78: }
79:
80: final DeploymentScope deploymentScope = (DeploymentScope) o;
81:
82: if (!m_expression.equals(deploymentScope.m_expression)) {
83: return false;
84: }
85: if (!m_name.equals(deploymentScope.m_name)) {
86: return false;
87: }
88:
89: return true;
90: }
91:
92: public int hashCode() {
93: int result;
94: result = m_name.hashCode();
95: result = 29 * result + m_expression.hashCode();
96: return result;
97: }
98: }
|