KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > innig > macker > rule > RegexPattern


1 /*______________________________________________________________________________
2  *
3  * Macker http://innig.net/macker/
4  *
5  * Copyright 2002-2003 Paul Cantrell
6  *
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License version 2, as published by the
9  * Free Software Foundation. See the file LICENSE.html for more information.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the license for more details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
17  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
18  *______________________________________________________________________________
19  */

20  
21 package net.innig.macker.rule;
22
23 import net.innig.macker.structure.ClassInfo;
24
25 import java.util.*;
26
27 import org.apache.regexp.RE;
28 import org.apache.regexp.RESyntaxException;
29
30 public final class RegexPattern
31     implements Pattern
32     {
33     //--------------------------------------------------------------------------
34
// Constructors
35
//--------------------------------------------------------------------------
36

37     public RegexPattern(String JavaDoc regexStr)
38         throws MackerRegexSyntaxException
39         { regex = new MackerRegex(regexStr); }
40         
41     //--------------------------------------------------------------------------
42
// Properties
43
//--------------------------------------------------------------------------
44

45     public MackerRegex getRegex()
46         { return regex; }
47     
48     private final MackerRegex regex;
49
50     //--------------------------------------------------------------------------
51
// Evaluation
52
//--------------------------------------------------------------------------
53

54     public boolean matches(EvaluationContext context, ClassInfo classInfo)
55         throws RulesException
56         { return regex.matches(context, classInfo.getFullName()); }
57     
58     public String JavaDoc getMatch(EvaluationContext context, ClassInfo classInfo)
59         throws RulesException
60         { return regex.getMatch(context, classInfo.getFullName()); }
61     
62     public String JavaDoc toString()
63         { return regex.toString(); }
64     }
65
66
Popular Tags