001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.xs.bindings;
017:
018: import java.math.BigInteger;
019:
020: import javax.xml.bind.ValidationException;
021: import javax.xml.namespace.QName;
022:
023: import org.geotools.xml.InstanceComponent;
024: import org.geotools.xml.SimpleBinding;
025:
026: /**
027: * Binding object for the type http://www.w3.org/2001/XMLSchema:nonPositiveInteger.
028: *
029: * <p>
030: * <pre>
031: * <code>
032: * <xs:simpleType name="nonPositiveInteger" id="nonPositiveInteger">
033: * <xs:annotation>
034: * <xs:documentation source="http://www.w3.org/TR/xmlschema-2/#nonPositiveInteger"/>
035: * </xs:annotation>
036: * <xs:restriction base="xs:integer">
037: * <xs:maxInclusive value="0" id="nonPositiveInteger.maxInclusive"/>
038: * </xs:restriction>
039: * </xs:simpleType>
040: *
041: * </code>
042: * </pre>
043: * </p>
044: *
045: * @generated
046: */
047: public class XSNonPositiveIntegerBinding implements SimpleBinding {
048: final BigInteger MIN_LONG = BigInteger.valueOf(Long.MIN_VALUE);
049: final BigInteger MIN_INTEGER = BigInteger
050: .valueOf(Integer.MIN_VALUE);
051:
052: /**
053: * @generated
054: */
055: public QName getTarget() {
056: return XS.NONPOSITIVEINTEGER;
057: }
058:
059: /**
060: * <!-- begin-user-doc -->
061: * <!-- end-user-doc -->
062: *
063: * @generated modifiable
064: */
065: public int getExecutionMode() {
066: return AFTER;
067: }
068:
069: /**
070: * <!-- begin-user-doc -->
071: * This binding returns objects of type {@link BigInteger}.
072: * <!-- end-user-doc -->
073: *
074: * @generated modifiable
075: */
076: public Class getType() {
077: return BigInteger.class;
078: }
079:
080: /**
081: * <!-- begin-user-doc -->
082: * @param instance
083: * @param value a BigInteger (after processing by parent)
084: * @return a Number that is not positive
085: * <!-- end-user-doc -->
086: *
087: * @generated modifiable
088: */
089: public Object parse(InstanceComponent instance, Object value)
090: throws Exception {
091: BigInteger number = (BigInteger) value;
092:
093: if (BigInteger.ZERO.compareTo(number) < 0) {
094: throw new ValidationException("Value '" + number
095: + "' must be non-positive (0 or below).");
096: }
097:
098: if (MIN_INTEGER.compareTo(number) <= 0) {
099: return new Integer(number.intValue());
100: }
101:
102: if (MIN_LONG.compareTo(number) <= 0) {
103: return new Long(number.longValue());
104: }
105:
106: return number;
107: }
108:
109: /**
110: * <!-- begin-user-doc -->
111: * <!-- end-user-doc -->
112: *
113: * @generated modifiable
114: */
115: public String encode(Object object, String value) throws Exception {
116: Number number = (Number) object;
117:
118: if (number.intValue() > 0) {
119: throw new ValidationException("Value '" + number
120: + "' must be non-positive (0 or below).");
121: }
122:
123: return value;
124: }
125: }
|