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