KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > jayasoft > ivy > matcher > GlobPatternMatcher


1 /*
2  * This file is subject to the licence found in LICENCE.TXT in the root directory of the project.
3  * Copyright Jayasoft 2005 - All rights reserved
4  *
5  * #SNAPSHOT#
6  */

7 package fr.jayasoft.ivy.matcher;
8
9 import org.apache.oro.text.GlobCompiler;
10 import org.apache.oro.text.regex.MalformedPatternException;
11 import org.apache.oro.text.regex.Pattern;
12 import org.apache.oro.text.regex.Perl5Matcher;
13
14 import fr.jayasoft.ivy.util.Message;
15
16
17 public final class GlobPatternMatcher implements PatternMatcher {
18     public static class GlobMatcher implements Matcher {
19         private Pattern _p;
20
21         public GlobMatcher(String JavaDoc exp) {
22             try {
23                 _p = new GlobCompiler().compile(exp);
24             } catch (MalformedPatternException e) {
25                 Message.error("impossible to compile glob pattern: "+exp);
26             }
27         }
28
29         public boolean matches(String JavaDoc str) {
30             return _p != null && new Perl5Matcher().matches(str, _p);
31         }
32
33         public boolean isExact() {
34             return false;
35         }
36     }
37     private static final GlobPatternMatcher INSTANCE = new GlobPatternMatcher();
38     public static PatternMatcher getInstance() {
39         return INSTANCE;
40     }
41     
42     private GlobPatternMatcher() {
43     }
44
45     public String JavaDoc getName() {
46         return GLOB;
47     }
48
49     public Matcher getMatcher(String JavaDoc exp) {
50         if (ANY_EXPRESSION.equals(exp)) {
51             return AnyMatcher.getInstance();
52         }
53         return new GlobMatcher(exp);
54     }
55 }
56
Popular Tags