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.text.DateFormat;
019: import java.util.Calendar;
020: import java.util.Date;
021:
022: import javax.xml.bind.DatatypeConverter;
023: import javax.xml.namespace.QName;
024:
025: import org.geotools.xml.InstanceComponent;
026: import org.geotools.xml.SimpleBinding;
027:
028: import com.sun.xml.bind.DatatypeConverterImpl;
029:
030: /**
031: * Binding object for the type http://www.w3.org/2001/XMLSchema:date.
032: *
033: * <p>
034: * <pre>
035: * <code>
036: * <xs:simpleType name="date" id="date">
037: * <xs:annotation>
038: * <xs:appinfo>
039: * <hfp:hasFacet name="pattern"/>
040: * <hfp:hasFacet name="enumeration"/>
041: * <hfp:hasFacet name="whiteSpace"/>
042: * <hfp:hasFacet name="maxInclusive"/>
043: * <hfp:hasFacet name="maxExclusive"/>
044: * <hfp:hasFacet name="minInclusive"/>
045: * <hfp:hasFacet name="minExclusive"/>
046: * <hfp:hasProperty name="ordered" value="partial"/>
047: * <hfp:hasProperty name="bounded" value="false"/>
048: * <hfp:hasProperty name="cardinality" value="countably infinite"/>
049: * <hfp:hasProperty name="numeric" value="false"/>
050: * </xs:appinfo>
051: * <xs:documentation source="http://www.w3.org/TR/xmlschema-2/#date"/>
052: * </xs:annotation>
053: * <xs:restriction base="xs:anySimpleType">
054: * <xs:whiteSpace value="collapse" fixed="true" id="date.whiteSpace"/>
055: * </xs:restriction>
056: * </xs:simpleType>
057: *
058: * </code>
059: * </pre>
060: * </p>
061: *
062: * @generated
063: */
064: public class XSDateBinding implements SimpleBinding {
065:
066: public XSDateBinding() {
067: DatatypeConverter
068: .setDatatypeConverter(DatatypeConverterImpl.theInstance);
069: }
070:
071: /**
072: * @generated
073: */
074: public QName getTarget() {
075: return XS.DATE;
076: }
077:
078: /**
079: * <!-- begin-user-doc -->
080: * <!-- end-user-doc -->
081: *
082: * @generated modifiable
083: */
084: public int getExecutionMode() {
085: return OVERRIDE;
086: }
087:
088: /**
089: * <!-- begin-user-doc -->
090: * This binding returns objects of type {@link Date}.
091: * <!-- end-user-doc -->
092: *
093: * @generated modifiable
094: */
095: public Class getType() {
096: return Date.class;
097: }
098:
099: /**
100: * <!-- begin-user-doc -->
101: * This binding returns objects of type {@link Calendar}.
102: * <!-- end-user-doc -->
103: *
104: * @generated modifiable
105: */
106: public Object parse(InstanceComponent instance, Object value)
107: throws Exception {
108:
109: Calendar calendar = DatatypeConverter.parseDate((String) value);
110: return calendar.getTime();
111: }
112:
113: public String encode(Object object, String value) throws Exception {
114: Date date = (Date) object;
115: Calendar calendar = Calendar.getInstance();
116: calendar.setTime(date);
117:
118: return DatatypeConverter.printDate(calendar);
119: }
120:
121: }
|