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.BigInteger;
25
26import javax.xml.datatype.DatatypeConstants;
27import javax.xml.datatype.Duration;
28
29import com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeValueException;
30import com.sun.org.apache.xerces.internal.impl.dv.ValidationContext;
31
32/**
33 * Used to validate the <yearMonthDuration> type
34 *
35 * @xerces.internal
36 *
37 * @author Ankit Pasricha, IBM
38 *
39 */
40class YearMonthDurationDV extends DurationDV {
41
42    public Object getActualValue(String content, ValidationContext context)
43        throws InvalidDatatypeValueException {
44        try {
45            return parse(content, DurationDV.YEARMONTHDURATION_TYPE);
46        }
47        catch (Exception ex) {
48            throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "yearMonthDuration"});
49        }
50    }
51
52    protected Duration getDuration(DateTimeData date) {
53        int sign = 1;
54        if ( date.year<0 || date.month<0) {
55            sign = -1;
56        }
57        return datatypeFactory.newDuration(sign == 1,
58                date.year != DatatypeConstants.FIELD_UNDEFINED?BigInteger.valueOf(sign*date.year):null,
59                date.month != DatatypeConstants.FIELD_UNDEFINED?BigInteger.valueOf(sign*date.month):null,
60                null,
61                null,
62                null,
63                null);
64    }
65}
66