01: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
02: * This code is licensed under the GPL 2.0 license, availible at the root
03: * application directory.
04: */
05:
06: package org.geoserver.wfs.xml;
07:
08: import javax.xml.bind.DatatypeConverter;
09: import javax.xml.namespace.NamespaceContext;
10: import javax.xml.namespace.QName;
11:
12: import org.geotools.xml.InstanceComponent;
13: import org.vfny.geoserver.global.Data;
14: import org.vfny.geoserver.global.NameSpaceInfo;
15:
16: /**
17: * Overrides the base class parsing code so that prefix can be resolved
18: * to URI's using the GeoServer {@link Data} catalog as well
19: * @author Andrea Aime - TOPP
20: */
21: public class XSQNameBinding extends
22: org.geotools.xs.bindings.XSQNameBinding {
23:
24: Data data;
25:
26: public XSQNameBinding(NamespaceContext namespaceContext, Data data) {
27: super (namespaceContext);
28: this .data = data;
29: }
30:
31: /**
32: * <!-- begin-user-doc -->
33: * This binding returns objects of type {@link QName}.
34: * <!-- end-user-doc -->
35: *
36: * @generated modifiable
37: */
38: public Object parse(InstanceComponent instance, Object value)
39: throws Exception {
40:
41: QName qName = DatatypeConverter.parseQName((String) value,
42: namespaceContext);
43:
44: if (qName != null) {
45: return qName;
46: }
47:
48: if (value == null) {
49: return new QName(null);
50: }
51:
52: String s = (String) value;
53: int i = s.indexOf(':');
54:
55: if (i != -1) {
56: String prefix = s.substring(0, i);
57: String local = s.substring(i + 1);
58: String namespaceURI = null;
59: NameSpaceInfo nsInfo = data.getNameSpace(prefix);
60: if (nsInfo != null)
61: namespaceURI = nsInfo.getURI();
62:
63: return new QName(namespaceURI, local, prefix);
64: }
65:
66: return new QName(null, s);
67: }
68:
69: }
|