01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.gml2;
17:
18: import java.util.HashMap;
19: import javax.xml.namespace.QName;
20: import org.geotools.feature.FeatureType;
21:
22: public class FeatureTypeCache {
23: HashMap map = new HashMap();
24:
25: // public FeatureType get(String name) {
26: // synchronized (this) {
27: // return (FeatureType) map.get(name);
28: // }
29: // }
30: public FeatureType get(String namespaceURI, String name) {
31: QName qname = new QName(namespaceURI, name);
32:
33: synchronized (this ) {
34: return (FeatureType) map.get(qname);
35: }
36: }
37:
38: public void put(FeatureType type) {
39: if (type.getTypeName() == null) {
40: throw new IllegalArgumentException(
41: "Type name must be non null");
42: }
43:
44: QName name = null;
45:
46: if (type.getNamespace() != null) {
47: name = new QName(type.getNamespace().toString(), type
48: .getTypeName());
49: } else {
50: name = new QName(type.getTypeName());
51: }
52:
53: synchronized (this ) {
54: if (map.get(name) != null) {
55: FeatureType other = (FeatureType) map.get(name);
56:
57: if (!other.equals(type)) {
58: String msg = "Type with same name already exists in cache.";
59: throw new IllegalArgumentException(msg);
60: }
61:
62: return;
63: }
64:
65: map.put(name, type);
66: }
67: }
68: }
|