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:positiveInteger.
028: *
029: * <p>
030: * <pre>
031: * <code>
032: * <xs:simpleType name="positiveInteger" id="positiveInteger">
033: * <xs:annotation>
034: * <xs:documentation source="http://www.w3.org/TR/xmlschema-2/#positiveInteger"/>
035: * </xs:annotation>
036: * <xs:restriction base="xs:nonNegativeInteger">
037: * <xs:minInclusive value="1" id="positiveInteger.minInclusive"/>
038: * </xs:restriction>
039: * </xs:simpleType>
040: *
041: * </code>
042: * </pre>
043: * </p>
044: *
045: * @generated
046: */
047: public class XSPositiveIntegerBinding implements SimpleBinding {
048: /**
049: * @generated
050: */
051: public QName getTarget() {
052: return XS.POSITIVEINTEGER;
053: }
054:
055: /**
056: * <!-- begin-user-doc -->
057: * <!-- end-user-doc -->
058: *
059: * @generated modifiable
060: */
061: public int getExecutionMode() {
062: return AFTER;
063: }
064:
065: /**
066: * <!-- begin-user-doc -->
067: * This binding returns objects of type {@link java.math.BigInteger}.
068: * <!-- end-user-doc -->
069: *
070: * @generated modifiable
071: */
072: public Class getType() {
073: return BigInteger.class;
074: }
075:
076: /**
077: * <!-- begin-user-doc -->
078: * Restriction of integer to positive values.
079: * <p>
080: * Please just treat this as a Number, actual value returned
081: * may be BigInteger or Long or Integer.
082: * </p>
083: * @param instance with text to be parsed
084: * @param value Number from parent XSNonNegativeIntegerStratagy
085: * @return Number positive in range 1 to ...
086: * <!-- begin-user-doc -->
087: */
088: public Object parse(InstanceComponent instance, Object value)
089: throws Exception {
090: Number number = (Number) value;
091:
092: if (number.intValue() < 1) {
093: throw new ValidationException("positiveInteger value '"
094: + number + "' must be positive.");
095: }
096:
097: return BigInteger.valueOf(number.longValue());
098: }
099:
100: /**
101: * <!-- begin-user-doc -->
102: * <!-- end-user-doc -->
103: *
104: * @generated modifiable
105: */
106: public String encode(Object object, String value) throws Exception {
107: Number number = (Number) object;
108:
109: if (number.intValue() == 0) {
110: throw new ValidationException("positiveInteger value '"
111: + number + "' must be positive.");
112: }
113:
114: return value;
115: }
116: }
|