]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/geotools/osgi/GisResourcesActivator.java
e904df7e8426d4744b6a595fada4a781a90bd6f9
1 package org
.argeo
.geotools
.osgi
;
4 import java
.util
.Enumeration
;
5 import java
.util
.HashMap
;
7 import java
.util
.Properties
;
9 import org
.apache
.commons
.logging
.Log
;
10 import org
.apache
.commons
.logging
.LogFactory
;
11 import org
.argeo
.geotools
.GeoToolsConstants
;
12 import org
.geotools
.data
.DataStore
;
13 import org
.geotools
.data
.FileDataStoreFinder
;
14 import org
.osgi
.framework
.Bundle
;
15 import org
.osgi
.framework
.BundleActivator
;
16 import org
.osgi
.framework
.BundleContext
;
19 * Publishes as OSGi services (typically {@link DataStore}) resources contained
20 * or references within the bundle declaring this activator.
22 public class GisResourcesActivator
implements BundleActivator
{
23 private final static Log log
= LogFactory
24 .getLog(GisResourcesActivator
.class);
27 * Keep track of the registered datastores in order to dispose them when the
30 private Map
<String
, DataStore
> registeredDataStores
= new HashMap
<String
, DataStore
>();
32 @SuppressWarnings("unchecked")
33 public void start(BundleContext context
) throws Exception
{
34 Bundle bundle
= context
.getBundle();
36 // TODO deal with other data types
38 Enumeration
<URL
> resources
= bundle
.findEntries("/", "*.shp", true);
39 while (resources
.hasMoreElements()) {
40 URL url
= resources
.nextElement();
41 DataStore ds
= FileDataStoreFinder
.getDataStore(url
);
42 Properties props
= new Properties();
43 String alias
= url
.getPath();
44 props
.setProperty(GeoToolsConstants
.ALIAS_KEY
, alias
);
45 context
.registerService(DataStore
.class.getName(), ds
, props
);
46 registeredDataStores
.put(alias
, ds
);
47 if (log
.isDebugEnabled())
48 log
.debug("Registered data store " + alias
+ ": " + ds
);
52 public void stop(BundleContext context
) throws Exception
{
53 for (String alias
: registeredDataStores
.keySet()) {
54 DataStore ds
= registeredDataStores
.get(alias
);
57 if (log
.isDebugEnabled())
58 log
.debug("Disposed data store " + alias
+ ": " + ds
);
59 } catch (Exception e
) {
60 log
.warn("Could not dispose data store " + ds
+ ": "