Save This Page
Home » xmlbeans-2.4.0-src » org.apache.xmlbeans.impl.regex » [javadoc | source]
    1   /*   Copyright 2004 The Apache Software Foundation
    2    *
    3    *   Licensed under the Apache License, Version 2.0 (the "License");
    4    *   you may not use this file except in compliance with the License.
    5    *   You may obtain a copy of the License at
    6    *
    7    *       http://www.apache.org/licenses/LICENSE-2.0
    8    *
    9    *   Unless required by applicable law or agreed to in writing, software
   10    *   distributed under the License is distributed on an "AS IS" BASIS,
   11    *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   12    *   See the License for the specific language governing permissions and
   13    *  limitations under the License.
   14    */
   15   
   16   package org.apache.xmlbeans.impl.regex;
   17   
   18   import org.apache.xmlbeans.impl.common.XMLChar;
   19   
   20   import java.util.HashMap;
   21   import java.util.Map;
   22   
   23   public class SchemaRegularExpression extends RegularExpression
   24   {
   25       private SchemaRegularExpression(String pattern)
   26       {
   27           super(pattern, "X");
   28       }
   29   
   30       public static RegularExpression forPattern(String s)
   31       {
   32           SchemaRegularExpression tre = (SchemaRegularExpression)knownPatterns.get(s);
   33           if (tre != null)
   34               return tre;
   35           return new RegularExpression(s, "X");
   36       }
   37   
   38       static final Map knownPatterns = buildKnownPatternMap();
   39   
   40       private static Map buildKnownPatternMap()
   41       {
   42           Map result = new HashMap();
   43           result.put("\\c+", new SchemaRegularExpression("\\c+")
   44               { public boolean matches(String s) { return XMLChar.isValidNmtoken(s); } } );
   45           result.put("\\i\\c*", new SchemaRegularExpression("\\i\\c*")
   46               { public boolean matches(String s) { return XMLChar.isValidName(s); } } );
   47           result.put("[\\i-[:]][\\c-[:]]*", new SchemaRegularExpression("[\\i-[:]][\\c-[:]]*")
   48               { public boolean matches(String s) { return XMLChar.isValidNCName(s); } } );
   49           return result;
   50       }
   51   }

Save This Page
Home » xmlbeans-2.4.0-src » org.apache.xmlbeans.impl.regex » [javadoc | source]