KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > apache > xerces > validators > datatype > YearDatatypeValidator


1
2
3
4 /*
5  * The Apache Software License, Version 1.1
6  *
7  *
8  * Copyright (c) 1999, 2000 The Apache Software Foundation. All rights
9  * reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  *
15  * 1. Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  *
18  * 2. Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in
20  * the documentation and/or other materials provided with the
21  * distribution.
22  *
23  * 3. The end-user documentation included with the redistribution,
24  * if any, must include the following acknowledgment:
25  * "This product includes software developed by the
26  * Apache Software Foundation (http://www.apache.org/)."
27  * Alternately, this acknowledgment may appear in the software itself,
28  * if and wherever such third-party acknowledgments normally appear.
29  *
30  * 4. The names "Xerces" and "Apache Software Foundation" must
31  * not be used to endorse or promote products derived from this
32  * software without prior written permission. For written
33  * permission, please contact apache@apache.org.
34  *
35  * 5. Products derived from this software may not be called "Apache",
36  * nor may "Apache" appear in their name, without prior written
37  * permission of the Apache Software Foundation.
38  *
39  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
40  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
41  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
42  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
43  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
45  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
46  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
47  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
48  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
49  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50  * SUCH DAMAGE.
51  * ====================================================================
52  *
53  * This software consists of voluntary contributions made by many
54  * individuals on behalf of the Apache Software Foundation and was
55  * originally based on software copyright (c) 2001, International
56  * Business Machines, Inc., http://www.apache.org. For more
57  * information on the Apache Software Foundation, please see
58  * <http://www.apache.org/>.
59  */

60
61 package org.enhydra.apache.xerces.validators.datatype;
62
63 import java.util.Hashtable JavaDoc;
64
65 /**
66  * Validator for <gYear> datatype (W3C Schema Datatypes)
67  *
68  * @author Elena Litani
69  * @version $Id: YearDatatypeValidator.java,v 1.1.1.1 2003/03/10 16:34:47 taweili Exp $
70  */

71
72 public class YearDatatypeValidator extends DateTimeValidator {
73
74     public YearDatatypeValidator() throws InvalidDatatypeFacetException{
75         super();
76     }
77
78
79     public YearDatatypeValidator ( DatatypeValidator base, Hashtable JavaDoc facets,
80                                          boolean derivedByList ) throws InvalidDatatypeFacetException {
81         super (base, facets, derivedByList);
82     }
83
84     /**
85      * Parses, validates and computes normalized version of gYear object
86      *
87      * @param str The lexical representation of year object CCYY
88      * with possible time zone Z or (-),(+)hh:mm
89      * @param date uninitialized date object
90      * @return normalized date representation
91      * @exception Exception Invalid lexical representation
92      */

93     protected int[] parse(String JavaDoc str, int[] date) throws SchemaDateTimeException{
94         resetBuffer(str);
95
96         //create structure to hold an object
97
if ( date == null ) {
98             date = new int[TOTAL_SIZE];
99         }
100         resetDateObj(date);
101
102         // check for preceding '-' sign
103
int start = 0;
104         if (fBuffer.charAt(0)=='-') {
105             start = 1;
106         }
107         int sign = findUTCSign(start, fEnd);
108         if (sign == -1) {
109             date[CY]=parseIntYear(fEnd);
110         }
111         else {
112             date[CY]=parseIntYear(sign);
113             getTimeZone (date, sign);
114         }
115
116         //initialize values
117
date[M]=MONTH;
118         date[D]=1;
119
120         //validate and normalize
121

122         //REVISIT: do we need SchemaDateTimeException?
123
validateDateTime(date);
124         
125         if ( date[utc]!=0 && date[utc]!='Z' ) {
126             normalize(date);
127         }
128         return date;
129     }
130
131     /**
132      * Converts year object representation to String
133      *
134      * @param date year object
135      * @return lexical representation of month: CCYY with optional time zone sign
136      */

137     protected String JavaDoc dateToString(int[] date) {
138
139         message.setLength(0);
140         message.append(date[CY]);
141         message.append((char)date[utc]);
142         return message.toString();
143     }
144
145 }
146
147
148
Popular Tags