KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thaiopensource > datatype > xsd > regex > xerces > RegexEngineImpl


1 package com.thaiopensource.datatype.xsd.regex.xerces;
2
3 import com.thaiopensource.datatype.xsd.regex.RegexEngine;
4 import com.thaiopensource.datatype.xsd.regex.Regex;
5 import com.thaiopensource.datatype.xsd.regex.RegexSyntaxException;
6
7 import org.apache.xerces.utils.regex.RegularExpression;
8 import org.apache.xerces.utils.regex.ParseException;
9
10 /**
11  * An implementation of <code>RegexEngine</code> using the Xerces 1 regular expression
12  * implementation.
13  */

14 public class RegexEngineImpl implements RegexEngine {
15   public RegexEngineImpl() {
16     // Force a linkage error on instantiation if the Xerces classes
17
// are not available.
18
try {
19       new RegularExpression("", "X");
20     }
21     catch (ParseException e) {
22     }
23   }
24   public Regex compile(String JavaDoc expr) throws RegexSyntaxException {
25     try {
26       final RegularExpression re = new RegularExpression(expr, "X");
27       return new Regex() {
28       public boolean matches(String JavaDoc str) {
29         return re.matches(str);
30       }
31     };
32     }
33     catch (ParseException e) {
34       throw new RegexSyntaxException(e.getMessage(), e.getLocation());
35     }
36   }
37 }
38
Popular Tags