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.namespace.QName;
021:
022: import org.geotools.xml.InstanceComponent;
023: import org.geotools.xml.SimpleBinding;
024:
025: /**
026: * Binding object for the type http://www.w3.org/2001/XMLSchema:integer.
027: *
028: * <p>
029: * <pre>
030: * <code>
031: * <xs:simpleType name="integer" id="integer">
032: * <xs:annotation>
033: * <xs:documentation source="http://www.w3.org/TR/xmlschema-2/#integer"/>
034: * </xs:annotation>
035: * <xs:restriction base="xs:decimal">
036: * <xs:fractionDigits value="0" fixed="true" id="integer.fractionDigits"/>
037: * <xs:pattern value="[\-+]?[0-9]+"/>
038: * </xs:restriction>
039: * </xs:simpleType>
040: *
041: * </code>
042: * </pre>
043: * </p>
044: *
045: * @generated
046: */
047: public class XSIntegerBinding implements SimpleBinding {
048: /**
049: * @generated
050: */
051: public QName getTarget() {
052: return XS.INTEGER;
053: }
054:
055: /**
056: * <!-- begin-user-doc -->
057: * <!-- end-user-doc -->
058: *
059: * @generated modifiable
060: */
061: public int getExecutionMode() {
062: return OVERRIDE;
063: }
064:
065: /**
066: * <!-- begin-user-doc -->
067: * This binding returns objects of type {@link 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: * This binding returns objects of type {@link BigInteger}.
079: * <!-- end-user-doc -->
080: *
081: * @generated modifiable
082: */
083: public Object parse(InstanceComponent instance, Object value)
084: throws Exception {
085: String string = (String) value;
086:
087: if (string.startsWith("+")) {
088: string = string.substring(1);
089: }
090:
091: return new BigInteger(string);
092: }
093:
094: /**
095: * <!-- begin-user-doc -->
096: * <!-- end-user-doc -->
097: *
098: * @generated modifiable
099: */
100: public String encode(Object object, String value) {
101: //dont cast to big integer, this binding is often subclassed
102: Number integer = (Number) object;
103:
104: return integer.toString();
105: }
106: }
|