KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.thaiopensource.datatype.xsd.regex.jdk1_4;
2
3 import java.util.regex.Pattern JavaDoc;
4 import java.util.regex.Matcher JavaDoc;
5
6 import com.thaiopensource.datatype.xsd.regex.RegexEngine;
7 import com.thaiopensource.datatype.xsd.regex.Regex;
8 import com.thaiopensource.datatype.xsd.regex.RegexSyntaxException;
9
10 /**
11  * An implementation of <code>RegexEngine</code> using the JDK 1.4 <code>java.util.regex</code>
12  * package.
13  */

14 public class RegexEngineImpl implements RegexEngine {
15   public RegexEngineImpl() {
16     // Force a linkage error on instantiation if JDK 1.4 is not available.
17
Pattern.compile("x");
18   }
19
20   public Regex compile(String JavaDoc str) throws RegexSyntaxException {
21     // Don't catch PatternSyntaxException
22
// The Translator should detect all syntax errors
23
final Pattern JavaDoc pattern = Pattern.compile(Translator.translate(str));
24     return new Regex() {
25       public boolean matches(String JavaDoc str) {
26         return pattern.matcher(str).matches();
27       }
28     };
29   }
30 }
31
Popular Tags