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: package org.geoserver.wfs.xml;
06:
07: import org.geotools.feature.AttributeTypeFactory;
08: import org.geotools.feature.Name;
09: import org.geotools.feature.type.ProfileImpl;
10: import org.geotools.feature.type.SchemaImpl;
11: import org.geotools.xs.XSSchema;
12: import org.geotools.xs.bindings.XS;
13: import org.opengis.feature.type.Schema;
14:
15: import java.util.Collections;
16: import java.util.Date;
17: import java.util.HashSet;
18: import java.util.Set;
19: import javax.xml.namespace.QName;
20:
21: /**
22: * A profile of {@link XSSchema} which makes the java class to type
23: * mapping unique.
24: */
25: public class XSProfile extends TypeMappingProfile {
26: static Set profiles = new HashSet();
27:
28: static {
29: Set proper = new HashSet();
30: proper.add(name(XS.BYTE)); //Byte.class
31: proper.add(name(XS.HEXBINARY)); //byte[].class
32: proper.add(name(XS.SHORT)); //Short.class
33: proper.add(name(XS.INT)); //Integer.class
34: proper.add(name(XS.FLOAT)); //Float.class
35: proper.add(name(XS.LONG)); //Long.class
36: proper.add(name(XS.QNAME)); //Qname.class
37: proper.add(name(XS.DATE)); //java.sql.Date.class
38: proper.add(name(XS.DATETIME)); //java.sql.Timestamp.class
39: proper.add(name(XS.TIME)); //java.sql.Time.class
40: proper.add(name(XS.BOOLEAN)); //Boolean.class
41: proper.add(name(XS.DOUBLE)); //Double.class
42: proper.add(name(XS.STRING)); //String.class
43: proper.add(name(XS.INTEGER)); //BigInteger.class
44: proper.add(name(XS.DECIMAL)); //BigDecimal.class
45: proper.add(name(XS.ANYURI)); //URI.class
46: profiles.add(new ProfileImpl(new XSSchema(), proper));
47:
48: //date mappings between java and xml schema are kind of messed up, so
49: // we create a custom schema which also contains a mapping for
50: // java.util.Date
51: Schema additional = new SchemaImpl(XS.NAMESPACE);
52: additional.put(name(XS.DATETIME), AttributeTypeFactory
53: .newAttributeType("date", Date.class));
54: profiles.add(new ProfileImpl(additional, Collections
55: .singleton(name(XS.DATETIME))));
56:
57: //profile.add(name(XS.ANYTYPE)); //Map.class
58: }
59:
60: static Name name(QName qName) {
61: return new Name(qName.getNamespaceURI(), qName.getLocalPart());
62: }
63:
64: public XSProfile() {
65: super(profiles);
66: }
67: }
|