01: package org.geotools.catalog.property;
02:
03: import java.io.File;
04: import java.io.IOException;
05: import java.net.URI;
06: import java.net.URISyntaxException;
07: import java.util.Map;
08: import java.util.logging.Level;
09:
10: import org.geotools.catalog.Catalog;
11: import org.geotools.catalog.DataStoreService;
12: import org.geotools.catalog.GeoResource;
13: import org.geotools.catalog.ServiceInfo;
14: import org.geotools.catalog.defaults.DefaultServiceInfo;
15: import org.geotools.data.DataStore;
16: import org.geotools.data.property.PropertyDataStoreFactory;
17: import org.geotools.util.ProgressListener;
18:
19: /**
20: * Service handle for PropertyDataStore.
21: *
22: * @author Justin Deoliveira, The Open Planning Project, jdeolive@openplans.org
23: *
24: */
25: public class PropertyService extends DataStoreService {
26:
27: File directory;
28:
29: public PropertyService(Catalog parent, Map params, File directory,
30: PropertyDataStoreFactory propDataStoreFactory) {
31: super (parent, params, propDataStoreFactory);
32: this .directory = directory;
33: }
34:
35: public boolean canResolve(Class adaptee) {
36: if (adaptee != null && adaptee.isAssignableFrom(File.class))
37: return true;
38:
39: return super .canResolve(adaptee);
40: }
41:
42: public Object resolve(Class adaptee, ProgressListener monitor)
43: throws IOException {
44: if (adaptee != null && adaptee.isAssignableFrom(File.class)) {
45: return directory;
46: }
47:
48: return super .resolve(adaptee, monitor);
49: }
50:
51: protected GeoResource createGeoResource(String typeName,
52: DataStore dataStore) {
53: return new PropertyGeoResource(this , typeName);
54: }
55:
56: protected ServiceInfo createMetaData(DataStore dataStore,
57: ProgressListener monitor) {
58:
59: String namespace = null;
60: try {
61: namespace = (String) PropertyDataStoreFactory.NAMESPACE
62: .lookUp(getConnectionParams());
63: } catch (IOException e) {
64: logger.log(Level.WARNING, "Error looking up namespace", e);
65: }
66:
67: if (namespace == null) {
68: return super .createMetaData(dataStore, monitor);
69: }
70:
71: DefaultServiceInfo info = (DefaultServiceInfo) super
72: .createMetaData(dataStore, monitor);
73:
74: try {
75: info.setSchema(new URI(namespace));
76: } catch (URISyntaxException e) {
77: logger.log(Level.WARNING, "Error parsing namespace:"
78: + namespace, e);
79: }
80:
81: return info;
82: }
83:
84: public URI getIdentifier() {
85: return directory.toURI();
86: }
87:
88: }
|