KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > aspectwerkz > definition > DeploymentScope


1 /**************************************************************************************
2  * Copyright (c) Jonas Bonér, Alexandre Vasseur. All rights reserved. *
3  * http://aspectwerkz.codehaus.org *
4  * ---------------------------------------------------------------------------------- *
5  * The software in this package is published under the terms of the LGPL license *
6  * a copy of which has been included with this distribution in the license.txt file. *
7  **************************************************************************************/

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

22 public final class DeploymentScope {
23
24     private final String JavaDoc m_name;
25     private final String JavaDoc m_expression;
26     /**
27      * System prepared pointcut that matches all.
28      */

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

40     DeploymentScope(final String JavaDoc name, final String JavaDoc expression) {
41         m_name = name;
42         m_expression = expression;
43     }
44
45     /**
46      * Returns the name of the pointcut.
47      *
48      * @return
49      */

50     public String JavaDoc getName() {
51         return m_name;
52     }
53
54     /**
55      * Returns the expression as a string.
56      *
57      * @return
58      */

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

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