001    package com.thaiopensource.datatype.xsd;
002    
003    import com.thaiopensource.datatype.xsd.regex.Regex;
004    import com.thaiopensource.datatype.xsd.regex.RegexEngine;
005    import com.thaiopensource.datatype.xsd.regex.RegexSyntaxException;
006    
007    class RegexDatatype extends TokenDatatype {
008      private final String pattern;
009      private Regex regex;
010    
011      RegexDatatype(String pattern) {
012        this.pattern = pattern;
013      }
014    
015      synchronized void compile(RegexEngine engine) throws RegexSyntaxException {
016        if (regex == null)
017          regex = engine.compile(pattern);
018      }
019    
020      public boolean lexicallyAllows(String str) {
021        return regex.matches(str);
022      }
023    
024      public boolean alwaysValid() {
025        return false;
026      }
027    }