001: /*
002: * The Apache Software License, Version 1.1
003: *
004: *
005: * Copyright (c) 2000 The Apache Software Foundation. All rights
006: * reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Apache Software Foundation (http://www.apache.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "Xerces" and "Apache Software Foundation" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact apache@apache.org.
031: *
032: * 5. Products derived from this software may not be called "Apache",
033: * nor may "Apache" appear in their name, without prior written
034: * permission of the Apache Software Foundation.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the Apache Software Foundation and was
052: * originally based on software copyright (c) 1999, International
053: * Business Machines, Inc., http://www.apache.org. For more
054: * information on the Apache Software Foundation, please see
055: * <http://www.apache.org/>.
056: */
057:
058: /**
059: * @version $Id: AbstractDatatypeValidator.java,v 1.12 2001/05/31 21:13:05 neilg Exp $
060: * @author Elena Litani
061: * @author Jeffrey Rodriguez
062: */package org.apache.xerces.validators.datatype;
063:
064: import java.util.Hashtable;
065: import java.util.Locale;
066: import org.apache.xerces.validators.datatype.DatatypeValidator;
067: import org.apache.xerces.utils.regex.RegularExpression;
068:
069: public abstract class AbstractDatatypeValidator implements
070: DatatypeValidator, Cloneable {
071:
072: protected DatatypeValidator fBaseValidator = null;
073: protected String fPattern = null;
074: protected RegularExpression fRegex = null;
075: protected short fFacetsDefined = 0;
076: protected DatatypeMessageProvider fMessageProvider = new DatatypeMessageProvider();
077: protected Locale fLocale = null;
078: protected short fFlags = 0; //flags fixed facets
079:
080: /**
081: * Checks that "content" string is valid
082: * datatype.
083: * If invalid a Datatype validation exception is thrown.
084: *
085: * @param content A string containing the content to be validated
086: * @param derivedBylist
087: * Flag which is true when type
088: * is derived by list otherwise it
089: * it is derived by extension.
090: *
091: * @exception throws InvalidDatatypeException if the content is
092: * invalid according to the rules for the validators
093: * @exception InvalidDatatypeValueException
094: * @see org.apache.xerces.validators.datatype.InvalidDatatypeValueException
095: */
096: abstract public Object validate(String content, Object state)
097: throws InvalidDatatypeValueException;
098:
099: abstract public Object clone() throws CloneNotSupportedException;
100:
101: /**
102: * default value for whiteSpace facet is collapse
103: * this function is overwritten in StringDatatypeValidator
104: */
105: public short getWSFacet() {
106: return DatatypeValidator.COLLAPSE;
107: }
108:
109: // returns the base datatypeValidator of the current validator.
110: public DatatypeValidator getBaseValidator() {
111: return fBaseValidator;
112: }
113:
114: protected String getErrorString(int major, int minor, Object args[]) {
115: try {
116: return fMessageProvider.createMessage(fLocale, major,
117: minor, args);
118: } catch (Exception e) {
119: return "Illegal Errorcode " + minor;
120: }
121: }
122:
123: /**
124: * set the locate to be used for error messages
125: */
126: public void setLocale(Locale locale) {
127: fLocale = locale;
128: }
129:
130: }
|