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