sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1493263 - in /sis/branches/JDK7: application/sis-console/ core/sis-metadata/ core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ core/sis-metadata/src/main/java/org/apache/sis/metadata/ core/sis-referencing/ core/sis-utility/...
Date Fri, 14 Jun 2013 22:15:27 GMT
Author: desruisseaux
Date: Fri Jun 14 22:15:26 2013
New Revision: 1493263

URL: http://svn.apache.org/r1493263
Log:
OSGi configuration: unregister listeners of undeployed modules.

Added:
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Modules.java
  (with props)
Modified:
    sis/branches/JDK7/application/sis-console/pom.xml
    sis/branches/JDK7/core/sis-metadata/pom.xml
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
    sis/branches/JDK7/core/sis-referencing/pom.xml
    sis/branches/JDK7/core/sis-utility/pom.xml
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemRegistry.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/TypeRegistration.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/OSGiActivator.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/SystemListener.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/XML.java
    sis/branches/JDK7/ide-project/NetBeans/nbproject/project.xml
    sis/branches/JDK7/storage/sis-netcdf/pom.xml
    sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStoreProvider.java
    sis/branches/JDK7/storage/sis-storage/pom.xml

Modified: sis/branches/JDK7/application/sis-console/pom.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/pom.xml?rev=1493263&r1=1493262&r2=1493263&view=diff
==============================================================================
--- sis/branches/JDK7/application/sis-console/pom.xml (original)
+++ sis/branches/JDK7/application/sis-console/pom.xml Fri Jun 14 22:15:26 2013
@@ -92,6 +92,7 @@ Console application.
               org.apache.sis.console
             </Export-Package>
             <Main-Class>org.apache.sis.console.Command</Main-Class>
+            <Bundle-SymbolicName>org.apache.sis.console</Bundle-SymbolicName>
           </instructions>
         </configuration>
       </plugin>

Modified: sis/branches/JDK7/core/sis-metadata/pom.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/pom.xml?rev=1493263&r1=1493262&r2=1493263&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/pom.xml (original)
+++ sis/branches/JDK7/core/sis-metadata/pom.xml Fri Jun 14 22:15:26 2013
@@ -121,6 +121,17 @@ Implementations of metadata derived from
           </execution>
         </executions>
       </plugin>
+
+      <!-- Package as OSGi bundle -->
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <configuration>
+          <instructions>
+            <Bundle-SymbolicName>org.apache.sis.metadata</Bundle-SymbolicName>
+          </instructions>
+        </configuration>
+      </plugin>
     </plugins>
   </build>
 

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java?rev=1493263&r1=1493262&r2=1493263&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
[UTF-8] Fri Jun 14 22:15:26 2013
@@ -24,6 +24,7 @@ import org.apache.sis.metadata.iso.exten
 import org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox;
 import org.apache.sis.metadata.iso.extent.DefaultSpatialTemporalExtent;
 import org.apache.sis.internal.system.SystemListener;
+import org.apache.sis.internal.system.Modules;
 import org.apache.sis.util.resources.Errors;
 
 
@@ -48,6 +49,7 @@ public abstract class ReferencingService
      * in order to force a new {@code ReferencingServices} lookup if the classpath changes.
      */
     protected ReferencingServices() {
+        super(Modules.METADATA);
         SystemListener.add(this);
     }
 

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java?rev=1493263&r1=1493262&r2=1493263&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
[UTF-8] Fri Jun 14 22:15:26 2013
@@ -36,6 +36,7 @@ import org.apache.sis.util.ComparisonMod
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.collection.TreeTable;
 import org.apache.sis.util.collection.CheckedContainer;
+import org.apache.sis.internal.system.Modules;
 import org.apache.sis.internal.system.SystemListener;
 import org.apache.sis.internal.simple.SimpleCitation;
 
@@ -139,7 +140,7 @@ public class MetadataStandard implements
             ISO_19119,
             ISO_19123
         };
-        SystemListener.add(new SystemListener() {
+        SystemListener.add(new SystemListener(Modules.METADATA) {
             @Override protected void classpathChanged() {
                 clearCache();
             }

Modified: sis/branches/JDK7/core/sis-referencing/pom.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/pom.xml?rev=1493263&r1=1493262&r2=1493263&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/pom.xml (original)
+++ sis/branches/JDK7/core/sis-referencing/pom.xml Fri Jun 14 22:15:26 2013
@@ -91,6 +91,17 @@ Implementations of Coordinate Reference 
           </execution>
         </executions>
       </plugin>
+
+      <!-- Package as OSGi bundle -->
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <configuration>
+          <instructions>
+            <Bundle-SymbolicName>org.apache.sis.referencing</Bundle-SymbolicName>
+          </instructions>
+        </configuration>
+      </plugin>
     </plugins>
   </build>
 

Modified: sis/branches/JDK7/core/sis-utility/pom.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/pom.xml?rev=1493263&r1=1493262&r2=1493263&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/pom.xml (original)
+++ sis/branches/JDK7/core/sis-utility/pom.xml Fri Jun 14 22:15:26 2013
@@ -153,6 +153,7 @@ Miscellaneous utilities.
         <artifactId>maven-bundle-plugin</artifactId>
         <configuration>
           <instructions>
+            <Bundle-SymbolicName>org.apache.sis.utility</Bundle-SymbolicName>
             <Bundle-Activator>org.apache.sis.internal.system.OSGiActivator</Bundle-Activator>
           </instructions>
         </configuration>

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemRegistry.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemRegistry.java?rev=1493263&r1=1493262&r2=1493263&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemRegistry.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemRegistry.java
[UTF-8] Fri Jun 14 22:15:26 2013
@@ -24,6 +24,7 @@ import org.apache.sis.util.ThreadSafe;
 import org.apache.sis.util.ObjectConverter;
 import org.apache.sis.util.UnconvertibleObjectException;
 import org.apache.sis.internal.system.SystemListener;
+import org.apache.sis.internal.system.Modules;
 
 
 /**
@@ -72,7 +73,7 @@ public final class SystemRegistry extend
          * then those converters are lost. This is of concern only for applications using
          * a modularization framework like OSGi. See package javadoc for more information.
          */
-        SystemListener.add(new SystemListener() {
+        SystemListener.add(new SystemListener(Modules.UTILITIES) {
             @Override protected void classpathChanged() {
                 INSTANCE.clear();
             }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/TypeRegistration.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/TypeRegistration.java?rev=1493263&r1=1493262&r2=1493263&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/TypeRegistration.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/TypeRegistration.java
[UTF-8] Fri Jun 14 22:15:26 2013
@@ -23,6 +23,7 @@ import java.lang.ref.Reference;
 import java.lang.ref.WeakReference;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
+import org.apache.sis.internal.system.Modules;
 import org.apache.sis.internal.system.SystemListener;
 
 
@@ -50,7 +51,7 @@ public abstract class TypeRegistration {
      */
     private static Reference<JAXBContext> context;
     static {
-        SystemListener.add(new SystemListener() {
+        SystemListener.add(new SystemListener(Modules.UTILITIES) {
             @Override protected void classpathChanged() {
                 context = null;
             }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java?rev=1493263&r1=1493262&r2=1493263&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
[UTF-8] Fri Jun 14 22:15:26 2013
@@ -51,6 +51,7 @@ public final class DefaultFactories exte
      * For the singleton system listener only.
      */
     private DefaultFactories() {
+        super(Modules.UTILITIES);
     }
 
     /**

Added: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Modules.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Modules.java?rev=1493263&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Modules.java
(added)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Modules.java
[UTF-8] Fri Jun 14 22:15:26 2013
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.system;
+
+
+/**
+ * Constants related to SIS modules management.
+ * This class contains the OSGi module symbolic names, as declared in the {@code Bundle-SymbolicName}
+ * entry of the {@code META-INF/MANIFEST.MF} file in each JAR files.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3
+ * @version 0.3
+ * @module
+ */
+public final class Modules {
+    /**
+     * The {@value} module name.
+     */
+    public static final String UTILITIES = "org.apache.sis.utility";
+
+    /**
+     * The {@value} module name.
+     */
+    public static final String METADATA = "org.apache.sis.metadata";
+
+    /**
+     * The {@value} module name.
+     */
+    public static final String NETCDF = "org.apache.sis.storage.netcdf";
+
+    /**
+     * Do not allows instantiation of this class.
+     */
+    private Modules() {
+    }
+}

Propchange: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Modules.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/Modules.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/OSGiActivator.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/OSGiActivator.java?rev=1493263&r1=1493262&r2=1493263&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/OSGiActivator.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/OSGiActivator.java
[UTF-8] Fri Jun 14 22:15:26 2013
@@ -74,9 +74,14 @@ public final class OSGiActivator impleme
     @Override
     public void bundleChanged(final BundleEvent event) {
         switch (event.getType()) {
-            case BundleEvent.STARTED:
+            case BundleEvent.STARTED: {
+                SystemListener.fireClasspathChanged();
+                break;
+            }
             case BundleEvent.STOPPED: {
                 SystemListener.fireClasspathChanged();
+                SystemListener.removeModule(event.getBundle().getSymbolicName());
+                break;
             }
         }
     }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/SystemListener.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/SystemListener.java?rev=1493263&r1=1493262&r2=1493263&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/SystemListener.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/SystemListener.java
[UTF-8] Fri Jun 14 22:15:26 2013
@@ -38,6 +38,23 @@ public abstract class SystemListener imp
     private static SystemListener[] listeners;
 
     /**
+     * The OSGi module symbolic name, as declared in the {@code Bundle-SymbolicName} entry
of the
+     * {@code META-INF/MANIFEST.MF} file. Shall be one of {@link Modules} constants. This
is used
+     * in order to detect which listeners to remove when a module is uninstalled.
+     */
+    private final String module;
+
+    /**
+     * Creates a nes listener.
+     *
+     * @param module The OSGi module symbolic name, as declared in the {@code Bundle-SymbolicName}
+     *        entry of the {@code META-INF/MANIFEST.MF} file. Shall be one of {@link Modules}
constants.
+     */
+    protected SystemListener(final String module) {
+        this.module = module;
+    }
+
+    /**
      * Adds the given listener to the list of listeners to notify when a change occurs.
      * This method doesn't check if the given listener is already present in the array,
      * unless assertions are enabled.
@@ -62,10 +79,6 @@ public abstract class SystemListener imp
      * a paranoiac check.`
      *
      * @param listener The listener to remove.
-     *
-     * @todo Not yet used. Given that the intend of this method is to remove all listeners
-     *       registered by a specific module, a possible approach would be to remove all
-     *       listeners associated to that through some module identifier.
      */
     public static synchronized void remove(final SystemListener listener) {
         SystemListener[] list = listeners;
@@ -80,18 +93,31 @@ public abstract class SystemListener imp
     }
 
     /**
-     * For sub-classes constructors.
+     * Removes all listeners for the module of the given name.
+     * This method is invoked by {@link OSGiActivator}.
+     *
+     * @param name The name of the module for which to remove listeners, or {@code null}
if the module
+     *        to uninstall does not have symbolic name (in which case it is probably not
a SIS module).
      */
-    protected SystemListener() {
+    static synchronized void removeModule(final String name) {
+        if (name != null) {
+            final SystemListener[] list = listeners;
+            if (list != null) {
+                int count = 0;
+                final SystemListener[] modified = new SystemListener[list.length];
+                for (final SystemListener listener : list) {
+                    if (!name.equals(listener.module)) {
+                        modified[count++] = listener;
+                    }
+                }
+                if (count != list.length) {
+                    listeners = Arrays.copyOf(modified, count);
+                }
+            }
+        }
     }
 
     /**
-     * Invoked when the classpath is likely to have changed.
-     * Any classes using {@link java.util.ServiceLoader} are advised to clear their cache.
-     */
-    protected abstract void classpathChanged();
-
-    /**
      * Notifies all registered listeners that the classpath may have changed.
      */
     public static void fireClasspathChanged() {
@@ -105,4 +131,10 @@ public abstract class SystemListener imp
             }
         }
     }
+
+    /**
+     * Invoked when the classpath is likely to have changed.
+     * Any classes using {@link java.util.ServiceLoader} are advised to clear their cache.
+     */
+    protected abstract void classpathChanged();
 }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/XML.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/XML.java?rev=1493263&r1=1493262&r2=1493263&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/XML.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/XML.java [UTF-8] Fri
Jun 14 22:15:26 2013
@@ -26,6 +26,7 @@ import javax.xml.bind.Marshaller;
 import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.JAXBException;
 import org.apache.sis.util.Static;
+import org.apache.sis.internal.system.Modules;
 import org.apache.sis.internal.system.SystemListener;
 import org.apache.sis.internal.jaxb.TypeRegistration;
 
@@ -263,7 +264,7 @@ public final class XML extends Static {
      * be created because the {@code JAXBContext} may be different.
      */
     static {
-        SystemListener.add(new SystemListener() {
+        SystemListener.add(new SystemListener(Modules.UTILITIES) {
             @Override protected void classpathChanged() {
                 POOL = null;
             }

Modified: sis/branches/JDK7/ide-project/NetBeans/nbproject/project.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/ide-project/NetBeans/nbproject/project.xml?rev=1493263&r1=1493262&r2=1493263&view=diff
==============================================================================
--- sis/branches/JDK7/ide-project/NetBeans/nbproject/project.xml (original)
+++ sis/branches/JDK7/ide-project/NetBeans/nbproject/project.xml Fri Jun 14 22:15:26 2013
@@ -46,6 +46,7 @@
             <word>namespaces</word>
             <word>timezone</word>
             <word>Unicode</word>
+            <word>uninstall</word>
             <word>unmarshal</word>
             <word>unmarshaller</word>
             <word>unmarshallers</word>

Modified: sis/branches/JDK7/storage/sis-netcdf/pom.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-netcdf/pom.xml?rev=1493263&r1=1493262&r2=1493263&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-netcdf/pom.xml (original)
+++ sis/branches/JDK7/storage/sis-netcdf/pom.xml Fri Jun 14 22:15:26 2013
@@ -86,6 +86,24 @@ Bridge between NetCDF Climate and Foreca
 
 
   <!-- ===========================================================
+           Build configuration
+       =========================================================== -->
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <configuration>
+          <instructions>
+            <Bundle-SymbolicName>org.apache.sis.storage.netcdf</Bundle-SymbolicName>
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+
+  <!-- ===========================================================
            Dependencies
        =========================================================== -->
   <dependencies>

Modified: sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStoreProvider.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStoreProvider.java?rev=1493263&r1=1493262&r2=1493263&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStoreProvider.java
[UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStoreProvider.java
[UTF-8] Fri Jun 14 22:15:26 2013
@@ -26,6 +26,8 @@ import org.apache.sis.internal.netcdf.De
 import org.apache.sis.internal.netcdf.impl.ChannelDecoder;
 import org.apache.sis.internal.netcdf.ucar.DecoderWrapper;
 import org.apache.sis.internal.storage.ChannelDataInput;
+import org.apache.sis.internal.system.SystemListener;
+import org.apache.sis.internal.system.Modules;
 import org.apache.sis.storage.DataStore;
 import org.apache.sis.storage.DataStoreProvider;
 import org.apache.sis.storage.StorageConnector;
@@ -79,6 +81,18 @@ public class NetcdfStoreProvider extends
     private static volatile Constructor<? extends Decoder> createFromUCAR;
 
     /**
+     * Clears the cached constructors if the classpath has changed,
+     * because the UCAR library may no longer be on the classpath.
+     */
+    static {
+        SystemListener.add(new SystemListener(Modules.NETCDF) {
+            @Override protected void classpathChanged() {
+                reset();
+            }
+        });
+    }
+
+    /**
      * Creates a new provider.
      */
     public NetcdfStoreProvider() {
@@ -236,37 +250,51 @@ public class NetcdfStoreProvider extends
     }
 
     /**
-     * Get the {@link java.lang.Class} that represent the {@link ucar.nc2.NetcdfFile type}.
-     * We do not synchronize this method since it is not a big deal if {@code Class.forName(…)}
is invoked twice.
-     * The {@code Class.forName(…)} method performs itself the required synchronization
for returning the same
-     * singleton {@code Class} instance.
+     * Gets the {@link java.lang.Class} that represent the {@link ucar.nc2.NetcdfFile type}.
      */
     private static void ensureInitialized() {
         if (netcdfFileClass == null) {
-            try {
-                netcdfFileClass = Class.forName(UCAR_CLASSNAME);
-            } catch (ClassNotFoundException e) {
-                netcdfFileClass = Void.TYPE;
-                return;
-            }
-            try {
+            synchronized (NetcdfStoreProvider.class) {
                 /*
-                 * UCAR API.
+                 * No double-check because it is not a big deal if the constructors are fetched
twice.
+                 * The sychronization is mostly a safety against concurrent execution of
'reset()'.
                  */
-                canOpenFromPath = netcdfFileClass.getMethod("canOpen", String.class);
-                assert canOpenFromPath.getReturnType() == Boolean.TYPE;
-                /*
-                 * SIS Wrapper API.
-                 */
-                final Class<? extends Decoder> wrapper =
-                        Class.forName("org.apache.sis.internal.netcdf.ucar.DecoderWrapper").asSubclass(Decoder.class);
-                final Class<?>[] parameterTypes = new Class<?>[] {WarningListeners.class,
netcdfFileClass};
-                createFromUCAR = wrapper.getConstructor(parameterTypes);
-                parameterTypes[1] = String.class;
-                createFromPath = wrapper.getConstructor(parameterTypes);
-            } catch (ReflectiveOperationException e) {
-                throw new AssertionError(e); // Should never happen (shall be verified by
the JUnit tests).
+                try {
+                    netcdfFileClass = Class.forName(UCAR_CLASSNAME);
+                } catch (ClassNotFoundException e) {
+                    netcdfFileClass = Void.TYPE;
+                    return;
+                }
+                try {
+                    /*
+                     * UCAR API.
+                     */
+                    canOpenFromPath = netcdfFileClass.getMethod("canOpen", String.class);
+                    assert canOpenFromPath.getReturnType() == Boolean.TYPE;
+                    /*
+                     * SIS Wrapper API.
+                     */
+                    final Class<? extends Decoder> wrapper =
+                            Class.forName("org.apache.sis.internal.netcdf.ucar.DecoderWrapper").asSubclass(Decoder.class);
+                    final Class<?>[] parameterTypes = new Class<?>[] {WarningListeners.class,
netcdfFileClass};
+                    createFromUCAR = wrapper.getConstructor(parameterTypes);
+                    parameterTypes[1] = String.class;
+                    createFromPath = wrapper.getConstructor(parameterTypes);
+                } catch (ReflectiveOperationException e) {
+                    throw new AssertionError(e); // Should never happen (shall be verified
by the JUnit tests).
+                }
             }
         }
     }
+
+    /**
+     * Invoked when the classpath changed. Clears the cached class and constructors, since
we don't know
+     * if the UCAR library is still on the classpath.
+     */
+    static synchronized void reset() {
+        netcdfFileClass = null;
+        canOpenFromPath = null;
+        createFromUCAR  = null;
+        createFromPath  = null;
+    }
 }

Modified: sis/branches/JDK7/storage/sis-storage/pom.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/pom.xml?rev=1493263&r1=1493262&r2=1493263&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/pom.xml (original)
+++ sis/branches/JDK7/storage/sis-storage/pom.xml Fri Jun 14 22:15:26 2013
@@ -87,4 +87,22 @@ Provides the interfaces and base classes
     </contributor>
   </contributors>
 
+
+  <!-- ===========================================================
+           Build configuration
+       =========================================================== -->
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <configuration>
+          <instructions>
+            <Bundle-SymbolicName>org.apache.sis.storage</Bundle-SymbolicName>
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
 </project>



Mime
View raw message