286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * Copyright 2004,2005 The Apache Software Foundation.
286N/A *
286N/A * Licensed under the Apache License, Version 2.0 (the "License");
286N/A * you may not use this file except in compliance with the License.
286N/A * You may obtain a copy of the License at
286N/A *
286N/A * http://www.apache.org/licenses/LICENSE-2.0
286N/A *
286N/A * Unless required by applicable law or agreed to in writing, software
286N/A * distributed under the License is distributed on an "AS IS" BASIS,
286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286N/A * See the License for the specific language governing permissions and
286N/A * limitations under the License.
286N/A */
286N/Apackage com.sun.org.apache.xerces.internal.impl.dv.xs;
286N/A
286N/Aimport java.math.BigDecimal;
286N/Aimport java.math.BigInteger;
286N/A
286N/Aimport javax.xml.datatype.DatatypeConstants;
286N/Aimport javax.xml.datatype.Duration;
286N/A
286N/Aimport com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeValueException;
286N/Aimport com.sun.org.apache.xerces.internal.impl.dv.ValidationContext;
286N/A
286N/A/**
286N/A * Used to validate the <dayTimeDuration> type
286N/A *
286N/A * @xerces.internal
286N/A *
286N/A * @author Ankit Pasricha, IBM
286N/A *
286N/A * @version $Id: DayTimeDurationDV.java,v 1.6 2010-11-01 04:39:46 joehw Exp $
286N/A */
286N/Aclass DayTimeDurationDV extends DurationDV {
286N/A
286N/A public Object getActualValue(String content, ValidationContext context)
286N/A throws InvalidDatatypeValueException {
286N/A try {
286N/A return parse(content, DurationDV.DAYTIMEDURATION_TYPE);
286N/A }
286N/A catch (Exception ex) {
286N/A throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "dayTimeDuration"});
286N/A }
286N/A }
286N/A
286N/A protected Duration getDuration(DateTimeData date) {
286N/A int sign = 1;
286N/A if (date.day<0 || date.hour<0 || date.minute<0 || date.second<0) {
286N/A sign = -1;
286N/A }
286N/A return datatypeFactory.newDuration(sign == 1, null, null,
286N/A date.day != DatatypeConstants.FIELD_UNDEFINED?BigInteger.valueOf(sign*date.day):null,
286N/A date.hour != DatatypeConstants.FIELD_UNDEFINED?BigInteger.valueOf(sign*date.hour):null,
286N/A date.minute != DatatypeConstants.FIELD_UNDEFINED?BigInteger.valueOf(sign*date.minute):null,
286N/A date.second != DatatypeConstants.FIELD_UNDEFINED?new BigDecimal(String.valueOf(sign*date.second)):null);
286N/A }
286N/A}