KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > impl > dv > xs > YearMonthDurationDV


1 /*
2  * Copyright 2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package com.sun.org.apache.xerces.internal.impl.dv.xs;
17
18 import java.math.BigInteger JavaDoc;
19
20 import javax.xml.datatype.DatatypeConstants JavaDoc;
21 import javax.xml.datatype.Duration JavaDoc;
22
23 import com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeValueException;
24 import com.sun.org.apache.xerces.internal.impl.dv.ValidationContext;
25
26 /**
27  * Used to validate the <yearMonthDuration> type
28  *
29  * @xerces.internal
30  *
31  * @author Ankit Pasricha, IBM
32  *
33  * @version $Id: YearMonthDurationDV.java,v 1.1.4.1 2005/09/06 11:43:10 neerajbj Exp $
34  */

35 class YearMonthDurationDV extends DurationDV {
36     
37     public Object JavaDoc getActualValue(String JavaDoc content, ValidationContext context)
38         throws InvalidDatatypeValueException {
39         try {
40             return parse(content, DurationDV.YEARMONTHDURATION_TYPE);
41         }
42         catch (Exception JavaDoc ex) {
43             throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object JavaDoc[]{content, "yearMonthDuration"});
44         }
45     }
46     
47     protected Duration JavaDoc getDuration(DateTimeData date) {
48         int sign = 1;
49         if ( date.year<0 || date.month<0) {
50             sign = -1;
51         }
52         return factory.newDuration(sign == 1,
53                 date.year != DatatypeConstants.FIELD_UNDEFINED?BigInteger.valueOf(sign*date.year):null,
54                 date.month != DatatypeConstants.FIELD_UNDEFINED?BigInteger.valueOf(sign*date.month):null,
55                 null,
56                 null,
57                 null,
58                 null);
59     }
60 }
61
Popular Tags