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 javax.xml.bind.ValidationException;
019: import javax.xml.namespace.QName;
020:
021: import org.geotools.xml.InstanceComponent;
022: import org.geotools.xml.SimpleBinding;
023:
024: /**
025: * Binding object for the type http://www.w3.org/2001/XMLSchema:boolean.
026: *
027: * <p>
028: * <pre>
029: * <code>
030: * <xs:simpleType name="boolean" id="boolean">
031: * <xs:annotation>
032: * <xs:appinfo>
033: * <hfp:hasFacet name="pattern"/>
034: * <hfp:hasFacet name="whiteSpace"/>
035: * <hfp:hasProperty name="ordered" value="false"/>
036: * <hfp:hasProperty name="bounded" value="false"/>
037: * <hfp:hasProperty name="cardinality" value="finite"/>
038: * <hfp:hasProperty name="numeric" value="false"/>
039: * </xs:appinfo>
040: * <xs:documentation source="http://www.w3.org/TR/xmlschema-2/#boolean"/>
041: * </xs:annotation>
042: * <xs:restriction base="xs:anySimpleType">
043: * <xs:whiteSpace value="collapse" fixed="true" id="boolean.whiteSpace"/>
044: * </xs:restriction>
045: * </xs:simpleType>
046: *
047: * </code>
048: * </pre>
049: * </p>
050: *
051: * @generated
052: */
053: public class XSBooleanBinding implements SimpleBinding {
054: /**
055: * @generated
056: */
057: public QName getTarget() {
058: return XS.BOOLEAN;
059: }
060:
061: /**
062: * <!-- begin-user-doc -->
063: * <!-- end-user-doc -->
064: *
065: * @generated modifiable
066: */
067: public int getExecutionMode() {
068: return AFTER;
069: }
070:
071: /**
072: * <!-- begin-user-doc -->
073: * This binding returns objects of type {@link Boolean}.
074: * <!-- end-user-doc -->
075: *
076: * @generated modifiable
077: */
078: public Class getType() {
079: return Boolean.class;
080: }
081:
082: /**
083: * <!-- begin-user-doc -->
084: * This binding returns objects of type {@link Boolean}.
085: * <!-- end-user-doc -->
086: *
087: * @generated modifiable
088: */
089: public Object parse(InstanceComponent instance, Object value)
090: throws Exception {
091: if ("1".equals(value) || "true".equals(value)) {
092: return Boolean.TRUE;
093: } else if ("0".equals(value) || "false".equals(value)) {
094: return Boolean.FALSE;
095: }
096:
097: throw new ValidationException("boolean indeterminate from '"
098: + value + "'");
099: }
100:
101: /**
102: * <!-- begin-user-doc -->
103: * <!-- end-user-doc -->
104: *
105: * @generated modifiable
106: */
107: public String encode(Object object, String value) {
108: Boolean bool = (Boolean) object;
109:
110: if (Boolean.TRUE.equals(bool)) {
111: return "true";
112: } else if (Boolean.FALSE.equals(bool)) {
113: return "false";
114: }
115:
116: return null;
117: }
118: }
|