sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1496639 - in /sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb: AdapterReplacement.java TypeRegistration.java
Date Tue, 25 Jun 2013 21:14:27 GMT
Author: desruisseaux
Date: Tue Jun 25 21:14:26 2013
New Revision: 1496639

URL: http://svn.apache.org/r1496639
Log:
Added in the javadoc a warning about a shortcomming of AdapterReplacement,
and try to take in account classpath changes in OSGi environment.

Modified:
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/AdapterReplacement.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/TypeRegistration.java

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/AdapterReplacement.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/AdapterReplacement.java?rev=1496639&r1=1496638&r2=1496639&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/AdapterReplacement.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/AdapterReplacement.java
[UTF-8] Tue Jun 25 21:14:26 2013
@@ -32,6 +32,11 @@ import javax.xml.bind.annotation.adapter
  * <p>This interface is mostly for handling extensions to metadata profile provided
as extension,
  * like the {@code FRA} extension for France provided in the {@code sis-metadata-fra} module.</p>
  *
+ * <p><b>WARNING:</b> there is currently no mechanism for ensuring that
the registration performed
+ * by an {@code AdapterReplacement} instance does not overwrite the registration performed
by an
+ * other {@code AdapterReplacement} instance. This is okay as long as the instances are defined
+ * only in SIS. However we will need to revisit this issue if we move this interface to public
API.</p>
+ *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-3.00)
  * @version 0.3
@@ -44,8 +49,10 @@ public interface AdapterReplacement {
     /**
      * The system-wide provider of {@code AdapterReplacement} instances.
      * <strong>Every usage of this service loader must be synchronized.</strong>
-     * This loader is public for allowing modules to unregister their instance
-     * when the module is unloaded (e.g. from an OSGi container), as below:
+     * This loader is public for {@link org.apache.sis.xml.MarshallerPool} usage.
+     *
+     * <p>This loader needs to be cleared as below when modules are loaded or unloaded.
+     * This is done opportunistically by {@link TypeRegistration}.</p>
      *
      * {@preformat java
      *     synchronized (AdapterReplacement.PROVIDER) {

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=1496639&r1=1496638&r2=1496639&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] Tue Jun 25 21:14:26 2013
@@ -47,13 +47,24 @@ import org.apache.sis.internal.system.Sy
  */
 public abstract class TypeRegistration {
     /**
-     * The JAXB context, or {@code null} if not yet created.
+     * The JAXB context, or {@code null} if not yet created or if the classpath changed.
      */
     private static Reference<JAXBContext> context;
     static {
         SystemListener.add(new SystemListener(Modules.UTILITIES) {
             @Override protected void classpathChanged() {
-                context = null;
+                synchronized (TypeRegistration.class) {
+                    context = null;
+                }
+                /*
+                 * Opportunistically clears the AdapterReplacement.PROVIDER. We can not do
this work in the
+                 * AdapterReplacement interface because we can not declare static initializer
in interfaces.
+                 * This TypeRegistration class is an acceptable fallback because MarshallerPool
uses this
+                 * class before to use AdapterReplacement.
+                 */
+                synchronized (AdapterReplacement.PROVIDER) {
+                    AdapterReplacement.PROVIDER.reload();
+                }
             }
         });
     }
@@ -105,9 +116,8 @@ public abstract class TypeRegistration {
      * @throws JAXBException If an error occurred while creating the JAXB context.
      */
     public static synchronized JAXBContext getSharedContext() throws JAXBException {
-        final Reference<JAXBContext> ref = context; // Protect from changes by the
listener.
-        if (ref != null) {
-            final JAXBContext instance = ref.get();
+        if (context != null) {
+            final JAXBContext instance = context.get();
             if (instance != null) {
                 return instance;
             }



Mime
View raw message