KickJava   Java API By Example, From Geeks To Geeks.

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


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.BigDecimal JavaDoc;
19 import java.math.BigInteger JavaDoc;
20
21 import javax.xml.datatype.DatatypeConstants JavaDoc;
22 import javax.xml.datatype.Duration JavaDoc;
23
24 import com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeValueException;
25 import com.sun.org.apache.xerces.internal.impl.dv.ValidationContext;
26
27 /**
28  * Used to validate the <dayTimeDuration> type
29  *
30  * @xerces.internal
31  *
32  * @author Ankit Pasricha, IBM
33  *
34  * @version $Id: DayTimeDurationDV.java,v 1.1.4.1 2005/09/06 11:43:02 neerajbj Exp $
35  */

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