1/* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5/* 6 * Licensed to the Apache Software Foundation (ASF) under one or more 7 * contributor license agreements. See the NOTICE file distributed with 8 * this work for additional information regarding copyright ownership. 9 * The ASF licenses this file to You under the Apache License, Version 2.0 10 * (the "License"); you may not use this file except in compliance with 11 * the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22package com.sun.org.apache.xerces.internal.impl.dv.xs; 23 24import java.math.BigDecimal; 25import java.math.BigInteger; 26 27import javax.xml.datatype.DatatypeConstants; 28import javax.xml.datatype.Duration; 29 30import com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeValueException; 31import com.sun.org.apache.xerces.internal.impl.dv.ValidationContext; 32 33/** 34 * Used to validate the <dayTimeDuration> type 35 * 36 * @xerces.internal 37 * 38 * @author Ankit Pasricha, IBM 39 * 40 */ 41class DayTimeDurationDV extends DurationDV { 42 43 public Object getActualValue(String content, ValidationContext context) 44 throws InvalidDatatypeValueException { 45 try { 46 return parse(content, DurationDV.DAYTIMEDURATION_TYPE); 47 } 48 catch (Exception ex) { 49 throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "dayTimeDuration"}); 50 } 51 } 52 53 protected Duration getDuration(DateTimeData date) { 54 int sign = 1; 55 if (date.day<0 || date.hour<0 || date.minute<0 || date.second<0) { 56 sign = -1; 57 } 58 return datatypeFactory.newDuration(sign == 1, null, null, 59 date.day != DatatypeConstants.FIELD_UNDEFINED?BigInteger.valueOf(sign*date.day):null, 60 date.hour != DatatypeConstants.FIELD_UNDEFINED?BigInteger.valueOf(sign*date.hour):null, 61 date.minute != DatatypeConstants.FIELD_UNDEFINED?BigInteger.valueOf(sign*date.minute):null, 62 date.second != DatatypeConstants.FIELD_UNDEFINED?new BigDecimal(String.valueOf(sign*date.second)):null); 63 } 64} 65