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.DatatypeConverter;
019: import javax.xml.namespace.NamespaceContext;
020: import javax.xml.namespace.QName;
021:
022: import org.geotools.xml.InstanceComponent;
023: import org.geotools.xml.SimpleBinding;
024:
025: import com.sun.xml.bind.DatatypeConverterImpl;
026:
027: /**
028: * Binding object for the type http://www.w3.org/2001/XMLSchema:QName.
029: *
030: * <p>
031: * <pre>
032: * <code>
033: * <xs:simpleType name="QName" id="QName">
034: * <xs:annotation>
035: * <xs:appinfo>
036: * <hfp:hasFacet name="length"/>
037: * <hfp:hasFacet name="minLength"/>
038: * <hfp:hasFacet name="maxLength"/>
039: * <hfp:hasFacet name="pattern"/>
040: * <hfp:hasFacet name="enumeration"/>
041: * <hfp:hasFacet name="whiteSpace"/>
042: * <hfp:hasProperty name="ordered" value="false"/>
043: * <hfp:hasProperty name="bounded" value="false"/>
044: * <hfp:hasProperty name="cardinality" value="countably infinite"/>
045: * <hfp:hasProperty name="numeric" value="false"/>
046: * </xs:appinfo>
047: * <xs:documentation source="http://www.w3.org/TR/xmlschema-2/#QName"/>
048: * </xs:annotation>
049: * <xs:restriction base="xs:anySimpleType">
050: * <xs:whiteSpace value="collapse" fixed="true" id="QName.whiteSpace"/>
051: * </xs:restriction>
052: * </xs:simpleType>
053: *
054: * </code>
055: * </pre>
056: * </p>
057: *
058: * @generated
059: */
060: public class XSQNameBinding implements SimpleBinding {
061:
062: protected NamespaceContext namespaceContext;
063:
064: public XSQNameBinding(NamespaceContext namespaceContext) {
065: this .namespaceContext = namespaceContext;
066:
067: DatatypeConverter
068: .setDatatypeConverter(DatatypeConverterImpl.theInstance);
069: }
070:
071: /**
072: * @generated
073: */
074: public QName getTarget() {
075: return XS.QNAME;
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 QName}.
091: * <!-- end-user-doc -->
092: *
093: * @generated modifiable
094: */
095: public Class getType() {
096: return QName.class;
097: }
098:
099: /**
100: * <!-- begin-user-doc -->
101: * This binding returns objects of type {@link QName}.
102: * <!-- end-user-doc -->
103: *
104: * @generated modifiable
105: */
106: public Object parse(InstanceComponent instance, Object value)
107: throws Exception {
108:
109: QName qName = DatatypeConverter.parseQName((String) value,
110: namespaceContext);
111:
112: if (qName != null) {
113: return qName;
114: }
115:
116: if (value == null) {
117: return new QName(null);
118: }
119:
120: String s = (String) value;
121: int i = s.indexOf(':');
122:
123: if (i != -1) {
124: String prefix = s.substring(0, i);
125: String local = s.substring(i + 1);
126:
127: return new QName(null, local, prefix);
128: }
129:
130: return new QName(null, s);
131: }
132:
133: public String encode(Object object, String value) throws Exception {
134: return DatatypeConverter.printQName((QName) object,
135: namespaceContext);
136: }
137:
138: }
|