KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aop > pointcut > ast > IdentifierExpression


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.aop.pointcut.ast;
23
24 import java.util.regex.Matcher JavaDoc;
25 import java.util.regex.Pattern JavaDoc;
26
27 /**
28  * Comment
29  *
30  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
31  * @version $Revision: 38812 $
32  *
33  **/

34 public class IdentifierExpression
35 {
36    private String JavaDoc original;
37    private Pattern JavaDoc namePattern;
38    private boolean isAnnotation;
39    
40    private boolean isImplements;
41    private boolean isImplementing;
42    private ClassExpression implementsExpr;
43
44    public IdentifierExpression(String JavaDoc expr)
45    {
46       original = expr;
47       if (expr.startsWith("@"))
48       {
49          isAnnotation = true;
50       }
51       else if (expr.startsWith("$implements{"))
52       {
53          isImplements = true;
54          expr = expr.substring(12, expr.length() - 1);
55          implementsExpr = new ClassExpression(expr.trim());
56       }
57       else if (expr.startsWith("$implementing{"))
58       {
59          isImplementing = true;
60          expr = expr.substring(14, expr.length() - 1);
61          implementsExpr = new ClassExpression(expr.trim());
62       }
63       else
64       {
65          expr = expr.replaceAll("\\*", ".*");
66          namePattern = Pattern.compile(expr);
67       }
68    }
69
70    public boolean matches(String JavaDoc name)
71    {
72       if (isAnnotation) return false;
73       Matcher JavaDoc m = namePattern.matcher(name);
74       return m.matches();
75    }
76
77    public boolean matchesAnnotation(String JavaDoc annotation)
78    {
79       if (!isAnnotation) return false;
80       Matcher JavaDoc m = namePattern.matcher(annotation);
81       return m.matches();
82    }
83
84    public String JavaDoc getOriginal()
85    {
86       return original;
87    }
88
89    public boolean isAnnotation()
90    {
91       return this.isAnnotation;
92    }
93
94    public boolean isImplements()
95    {
96       return this.isImplements;
97    }
98    
99    public boolean isImplementing()
100    {
101       return this.isImplementing;
102    }
103    
104    public ClassExpression getImplementsExpression()
105    {
106       return implementsExpr;
107    }
108 }
109
Popular Tags