You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by tl...@apache.org on 2013/08/25 17:49:59 UTC

svn commit: r1517321 [13/16] - in /sis/branches/Shapefile: ./ application/ application/sis-console/ application/sis-console/src/main/artifact/ application/sis-console/src/main/java/org/apache/sis/console/ application/sis-console/src/main/resources/org/...

Modified: sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultLocalName.java
URL: http://svn.apache.org/viewvc/sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultLocalName.java?rev=1517321&r1=1517320&r2=1517321&view=diff
==============================================================================
--- sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultLocalName.java [UTF-8] (original)
+++ sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultLocalName.java [UTF-8] Sun Aug 25 15:49:51 2013
@@ -25,11 +25,14 @@ import javax.xml.bind.annotation.XmlRoot
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 import org.opengis.util.NameSpace;
 import org.opengis.util.LocalName;
+import org.opengis.util.TypeName;
+import org.opengis.util.MemberName;
 import org.opengis.util.GenericName;
 import org.opengis.util.InternationalString;
 import org.apache.sis.xml.Namespaces;
 import org.apache.sis.util.Immutable;
 import org.apache.sis.util.ArgumentChecks;
+import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.internal.jaxb.gco.CharSequenceAdapter;
 
 // Related to JDK7
@@ -72,6 +75,12 @@ public class DefaultLocalName extends Ab
 
     /**
      * The name, either as a {@link String} or an {@link InternationalString}.
+     *
+     * {@section Note on JAXB annotation}
+     * The {@link XmlElement} annotation applied here is appropriate for subclasses only ({@link DefaultTypeName}
+     * and {@link DefaultMemberName}). It is <strong>not</strong> appropriate when (un)marshalling directly this
+     * {@code DefaultLocalName} class. In this later case, we will rather rely on the {@link String} conversion
+     * performed by {@link org.apache.sis.internal.jaxb.gco.GO_GenericName}.
      */
     @XmlJavaTypeAdapter(CharSequenceAdapter.class)
     @XmlElement(name = "aName", namespace = Namespaces.GCO)
@@ -132,6 +141,45 @@ public class DefaultLocalName extends Ab
     }
 
     /**
+     * Returns a SIS local name implementation with the values of the given arbitrary implementation.
+     * This method performs the first applicable actions in the following choices:
+     *
+     * <ul>
+     *   <li>If the given object is {@code null}, then this method returns {@code null}.</li>
+     *   <li>Otherwise if the given object is already an instance of {@code DefaultLocalName},
+     *       then it is returned unchanged.</li>
+     *   <li>Otherwise a new {@code DefaultLocalName} instance is created using the
+     *       {@link DefaultNameFactory#createLocalName(NameSpace, CharSequence)} method,
+     *       or the {@code createTypeName} or {@code createMemberName} variants if the
+     *       given object implements the corresponding interface.</li>
+     * </ul>
+     *
+     * @param  object The object to get as a SIS implementation, or {@code null} if none.
+     * @return A SIS implementation containing the values of the given object (may be the
+     *         given object itself), or {@code null} if the argument was null.
+     */
+    public static DefaultLocalName castOrCopy(final LocalName object) {
+        if (object == null || object instanceof DefaultLocalName) {
+            return (DefaultLocalName) object;
+        }
+        final NameSpace scope = object.scope();
+        final InternationalString name = object.toInternationalString();
+        final LocalName result;
+        if (object instanceof MemberName) {
+            result = DefaultFactories.SIS_NAMES.createMemberName(scope, name, ((MemberName) object).getAttributeType());
+        } else if (object instanceof TypeName) {
+            result = DefaultFactories.SIS_NAMES.createTypeName(scope, name);
+        } else {
+            result = DefaultFactories.SIS_NAMES.createLocalName(scope, name);
+        }
+        /*
+         * Following cast should be safe because the SIS_NAMES factory is fixed to a
+         * DefaultNameFactory instance, which is known to create AbstractName instances.
+         */
+        return (DefaultLocalName) result;
+    }
+
+    /**
      * Returns the scope (name space) in which this name is local. This method returns a
      * non-null value in all cases, even when the scope given to the constructor was null.
      */

Modified: sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultMemberName.java
URL: http://svn.apache.org/viewvc/sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultMemberName.java?rev=1517321&r1=1517320&r2=1517321&view=diff
==============================================================================
--- sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultMemberName.java [UTF-8] (original)
+++ sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultMemberName.java [UTF-8] Sun Aug 25 15:49:51 2013
@@ -76,6 +76,8 @@ public class DefaultMemberName extends D
 
     /**
      * Returns the type of the data associated with the record member.
+     *
+     * @return The type of the data associated with the record member.
      */
     @Override
     public TypeName getAttributeType() {

Modified: sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultNameFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultNameFactory.java?rev=1517321&r1=1517320&r2=1517321&view=diff
==============================================================================
--- sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultNameFactory.java [UTF-8] (original)
+++ sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultNameFactory.java [UTF-8] Sun Aug 25 15:49:51 2013
@@ -83,6 +83,9 @@ public class DefaultNameFactory extends 
     /**
      * Creates an international string from a set of strings in different locales.
      *
+     * @param strings String value for each locale key.
+     * @return The international string.
+     *
      * @see Types#toInternationalString(CharSequence)
      */
     @Override

Modified: sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultNameSpace.java
URL: http://svn.apache.org/viewvc/sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultNameSpace.java?rev=1517321&r1=1517320&r2=1517321&view=diff
==============================================================================
--- sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultNameSpace.java [UTF-8] (original)
+++ sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultNameSpace.java [UTF-8] Sun Aug 25 15:49:51 2013
@@ -114,8 +114,8 @@ public class DefaultNameSpace implements
      * However we can (in an opportunist way) handles local names as well. In case of conflict,
      * the namespace will have precedence.
      *
-     * <p>This field is initialized soon after {@code DefaultNameSpace} and should be treated
-     * like a final field from that point.</p>
+     * <p>This field is initialized by {@link #init()} soon after {@code DefaultNameSpace} creation
+     * and shall be treated like a final field from that point.</p>
      */
     private transient WeakValueHashMap<String,Object> childs;
 
@@ -372,6 +372,7 @@ public class DefaultNameSpace implements
         if (name == null) {
             name = key;
         }
+        final WeakValueHashMap<String,Object> childs = this.childs; // Paranoiac protection against accidental changes.
         DefaultNameSpace child;
         synchronized (childs) {
             final Object existing = childs.get(key);
@@ -412,6 +413,7 @@ public class DefaultNameSpace implements
     final DefaultLocalName local(final CharSequence name, final DefaultLocalName candidate) {
         ensureNonNull("name", name);
         final String key = name.toString();
+        final WeakValueHashMap<String,Object> childs = this.childs; // Paranoiac protection against accidental changes.
         DefaultLocalName child;
         synchronized (childs) {
             final Object existing = childs.get(key);

Modified: sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultScopedName.java
URL: http://svn.apache.org/viewvc/sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultScopedName.java?rev=1517321&r1=1517320&r2=1517321&view=diff
==============================================================================
--- sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultScopedName.java [UTF-8] (original)
+++ sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultScopedName.java [UTF-8] Sun Aug 25 15:49:51 2013
@@ -19,7 +19,6 @@ package org.apache.sis.util.iso;
 import java.util.List;
 import java.util.Iterator;
 import java.util.ConcurrentModificationException;
-import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 import org.opengis.util.NameSpace;
 import org.opengis.util.LocalName;
@@ -32,7 +31,6 @@ import org.apache.sis.util.resources.Err
 import org.apache.sis.internal.util.UnmodifiableArrayList;
 
 
-
 /**
  * A composite of a {@linkplain DefaultNameSpace name space} (as a {@linkplain DefaultLocalName local name})
  * and a {@linkplain AbstractName generic name} valid in that name space.
@@ -247,8 +245,10 @@ public class DefaultScopedName extends A
     }
 
     /**
-     * Returns every elements of the {@linkplain #getParsedNames() parsed names list}
+     * Returns every elements in the sequence of {@linkplain #getParsedNames() parsed names}
      * except for the {@linkplain #head() head}.
+     *
+     * @return All elements except the first one in the in the list of {@linkplain #getParsedNames() parsed names}.
      */
     @Override
     public synchronized GenericName tail() {
@@ -265,8 +265,10 @@ public class DefaultScopedName extends A
     }
 
     /**
-     * Returns every element of the {@linkplain #getParsedNames() parsed names list}
+     * Returns every element in the sequence of {@linkplain #getParsedNames() parsed names}
      * except for the {@linkplain #tip() tip}.
+     *
+     * @return All elements except the last one in the in the list of {@linkplain #getParsedNames() parsed names}.
      */
     @Override
     public synchronized GenericName path() {
@@ -286,7 +288,6 @@ public class DefaultScopedName extends A
      * Returns the sequence of local name for this generic name.
      */
     @Override
-    @XmlElement(name = "parsedName", required = true)
     public List<? extends LocalName> getParsedNames() {
         return parsedNames;
     }

Modified: sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java
URL: http://svn.apache.org/viewvc/sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java?rev=1517321&r1=1517320&r2=1517321&view=diff
==============================================================================
--- sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java [UTF-8] (original)
+++ sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java [UTF-8] Sun Aug 25 15:49:51 2013
@@ -519,6 +519,7 @@ public final class Types extends Static 
         if (name == null || name.isEmpty()) {
             return null;
         }
+        // -------- Begin workaround for GeoAPI 3.0 (TODO: remove after upgrade to GeoAPI 3.1) ------------
         final String typeName = codeType.getName();
         try {
             // Forces initialization of the given class in order
@@ -527,6 +528,7 @@ public final class Types extends Static 
         } catch (ClassNotFoundException e) {
             throw new TypeNotPresentException(typeName, e); // Should never happen.
         }
+        // -------- End workaround ------------------------------------------------------------------------
         return CodeList.valueOf(codeType, new CodeListFilter(name, canCreate));
     }
 

Modified: sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/iso/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/iso/package-info.java?rev=1517321&r1=1517320&r2=1517321&view=diff
==============================================================================
--- sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/iso/package-info.java [UTF-8] (original)
+++ sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/iso/package-info.java [UTF-8] Sun Aug 25 15:49:51 2013
@@ -132,9 +132,7 @@
 })
 @XmlAccessorType(XmlAccessType.NONE)
 @XmlJavaTypeAdapters({
-    @XmlJavaTypeAdapter(GO_GenericName.class),
-    @XmlJavaTypeAdapter(LocalNameAdapter.class),
-    @XmlJavaTypeAdapter(ScopedNameAdapter.class)
+    @XmlJavaTypeAdapter(GO_GenericName.class)
 })
 package org.apache.sis.util.iso;
 

Modified: sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java
URL: http://svn.apache.org/viewvc/sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java?rev=1517321&r1=1517320&r2=1517321&view=diff
==============================================================================
--- sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java [UTF-8] (original)
+++ sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java [UTF-8] Sun Aug 25 15:49:51 2013
@@ -52,6 +52,18 @@ import org.apache.sis.util.Classes;
  */
 public final class Logging extends Static {
     /**
+     * The threshold at which {@link #unexpectedException(Logger, String, String, Throwable, Level)} shall
+     * set the throwable in the {@link LogRecord}. For any record to be logged at a lower {@link Level},
+     * the {@link LogRecord#setThrown(Throwable)} method will not be invoked.
+     *
+     * <p>The default value is 600, which is the {@link PerformanceLevel#PERFORMANCE} value.
+     * This value is between {@link Level#FINE} (500) and {@link Level#CONFIG} (700).
+     * Consequently we will ignore the stack traces of recoverable failures, but will report
+     * stack traces that may impact performance, configuration, or correctness.</p>
+     */
+    private static final int LEVEL_THRESHOLD_FOR_STACKTRACE = 600;
+
+    /**
      * The factory for obtaining {@link Logger} instances, or {@code null} if none.
      * If {@code null} (the default), then the standard JDK logging framework will be used.
      * {@code Logging} scans the classpath for logger factories on class initialization.
@@ -383,7 +395,7 @@ public final class Logging extends Stati
         if (method != null) {
             record.setSourceMethodName(method);
         }
-        if (level.intValue() > 500) {
+        if (level.intValue() >= LEVEL_THRESHOLD_FOR_STACKTRACE) {
             record.setThrown(error);
         }
         record.setLoggerName(logger.getName());

Modified: sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/logging/MonolineFormatter.java
URL: http://svn.apache.org/viewvc/sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/logging/MonolineFormatter.java?rev=1517321&r1=1517320&r2=1517321&view=diff
==============================================================================
--- sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/logging/MonolineFormatter.java [UTF-8] (original)
+++ sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/logging/MonolineFormatter.java [UTF-8] Sun Aug 25 15:49:51 2013
@@ -33,6 +33,7 @@ import org.apache.sis.internal.system.OS
 import org.apache.sis.internal.util.X364;
 import org.apache.sis.io.IO;
 import org.apache.sis.io.LineAppender;
+import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.Configuration;
 import org.apache.sis.util.ThreadSafe;
@@ -859,6 +860,7 @@ loop:   for (int i=0; ; i++) {
     @Debug
     @Configuration
     public static MonolineFormatter install(final Logger logger, final Level level) throws SecurityException {
+        ArgumentChecks.ensureNonNull("logger", logger);
         MonolineFormatter monoline = null;
         for (final Handler handler : logger.getHandlers()) {
             if (handler instanceof ConsoleHandler) {

Modified: sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/logging/WarningListener.java
URL: http://svn.apache.org/viewvc/sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/logging/WarningListener.java?rev=1517321&r1=1517320&r2=1517321&view=diff
==============================================================================
--- sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/logging/WarningListener.java [UTF-8] (original)
+++ sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/logging/WarningListener.java [UTF-8] Sun Aug 25 15:49:51 2013
@@ -34,7 +34,7 @@ import java.util.logging.LogRecord;
  * The difference between using this listener or configuring the logging {@link java.util.logging.Handler} is
  * that listeners allow to handle the warnings on a per-{@code DataStore} (or any other emitter) instance.
  *
- * @param <S> The type of the source of warnings.
+ * @param <S> The base type of objects that emit warnings (the <cite>source</cite>).
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
@@ -46,6 +46,15 @@ import java.util.logging.LogRecord;
  */
 public interface WarningListener<S> extends EventListener {
     /**
+     * Returns the type of objects that emit warnings of interest for this listener.
+     * This is typically, but not necessarily, the class having the name returned by
+     * {@link LogRecord#getSourceClassName()}, or one of its parent classes.
+     *
+     * @return The base type of objects that emit warnings (the <cite>source</cite>).
+     */
+    Class<S> getSourceClass();
+
+    /**
      * Reports the occurrence of a non-fatal error. The emitter process (often a
      * {@link org.apache.sis.storage.DataStore} in the midst of a reading process)
      * will continue following the call to this method.

Modified: sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/logging/WarningListeners.java
URL: http://svn.apache.org/viewvc/sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/logging/WarningListeners.java?rev=1517321&r1=1517320&r2=1517321&view=diff
==============================================================================
--- sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/logging/WarningListeners.java [UTF-8] (original)
+++ sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/logging/WarningListeners.java [UTF-8] Sun Aug 25 15:49:51 2013
@@ -46,7 +46,7 @@ import org.apache.sis.util.resources.Err
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.3
+ * @version 0.4
  * @module
  *
  * @see WarningListener
@@ -257,4 +257,15 @@ public class WarningListeners<S> impleme
         }
         throw new NoSuchElementException(Errors.format(Errors.Keys.NoSuchElement_1, listener));
     }
+
+    /**
+     * Returns {@code true} if this object contains at least one listener.
+     *
+     * @return {@code true} if this object contains at least one listener, {@code false} otherwise.
+     *
+     * @since 0.4
+     */
+    public synchronized boolean hasListeners() {
+        return listeners != null;
+    }
 }

Modified: sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
URL: http://svn.apache.org/viewvc/sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java?rev=1517321&r1=1517320&r2=1517321&view=diff
==============================================================================
--- sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java [UTF-8] (original)
+++ sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java [UTF-8] Sun Aug 25 15:49:51 2013
@@ -99,6 +99,11 @@ public final class Errors extends Indexe
         public static final int CanNotParseFile_2 = 79;
 
         /**
+         * Can not read “{0}”.
+         */
+        public static final int CanNotRead_1 = 108;
+
+        /**
          * Can not set a value for property “{0}”.
          */
         public static final int CanNotSetPropertyValue_1 = 75;
@@ -216,6 +221,11 @@ public final class Errors extends Indexe
         public static final int IllegalLanguageCode_1 = 12;
 
         /**
+         * Member “{0}” can not be associated to type “{1}”.
+         */
+        public static final int IllegalMemberType_2 = 106;
+
+        /**
          * Option ‘{0}’ can not take the “{1}” value.
          */
         public static final int IllegalOptionValue_2 = 101;
@@ -306,6 +316,11 @@ public final class Errors extends Indexe
         public static final int MissingRequiredModule_1 = 84;
 
         /**
+         * Missing scheme in URI.
+         */
+        public static final int MissingSchemeInURI = 109;
+
+        /**
          * Missing value for option “{0}”.
          */
         public static final int MissingValueForOption_1 = 99;
@@ -506,6 +521,11 @@ public final class Errors extends Indexe
         public static final int UnknownCommand_1 = 102;
 
         /**
+         * Format of “{0}” is not recognized.
+         */
+        public static final int UnknownFormatFor_1 = 107;
+
+        /**
          * Option “{0}” is not recognized.
          */
         public static final int UnknownOption_1 = 98;

Modified: sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
URL: http://svn.apache.org/viewvc/sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties?rev=1517321&r1=1517320&r2=1517321&view=diff
==============================================================================
--- sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties [ISO-8859-1] (original)
+++ sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties [ISO-8859-1] Sun Aug 25 15:49:51 2013
@@ -31,6 +31,7 @@ CanNotComputeDerivative         = Can no
 CanNotInstantiate_1             = Can not instantiate an object of type \u2018{0}\u2019.
 CanNotOpen_1                    = Can not open \u201c{0}\u201d.
 CanNotParseFile_2               = Can not parse \u201c{1}\u201d as a file in the {0} format.
+CanNotRead_1                    = Can not read \u201c{0}\u201d.
 CanNotSetPropertyValue_1        = Can not set a value for property \u201c{0}\u201d.
 ClassNotFinal_1                 = Class \u2018{0}\u2019 is not final.
 CloneNotSupported_1             = Can not clone an object of type \u2018{0}\u2019.
@@ -54,6 +55,7 @@ IllegalBitsPattern_1            = Illega
 IllegalClass_2                  = Class \u2018{1}\u2019 is illegal. It must be \u2018{0}\u2019 or a derived class.
 IllegalFormatPatternForClass_2  = The \u201c{1}\u201d pattern can not be applied to formating of objects of type \u2018{0}\u2019.
 IllegalLanguageCode_1           = The \u201c{0}\u201d language is not recognized.
+IllegalMemberType_2             = Member \u201c{0}\u201d can not be associated to type \u201c{1}\u201d.
 IllegalOrdinateRange_3          = The [{0} \u2026 {1}] range of ordinate values is not valid for the \u201c{2}\u201d axis.
 IllegalPropertyClass_2          = Property \u2018{0}\u2019 can be associated to an instance of \u2018{1}\u2019.
 IllegalRange_2                  = Range [{0} \u2026 {1}] is not valid.
@@ -72,6 +74,7 @@ MismatchedCRS                   = The co
 MismatchedDimension_2           = Mismatched object dimension: {0}D and {1}D.
 MismatchedDimension_3           = Argument \u2018{0}\u2019 has {2} dimension{2,choice,1#|2#s}, while {1} was expected.
 MissingRequiredModule_1         = This operation requires the \u201c{0}\u201d module.
+MissingSchemeInURI              = Missing scheme in URI.
 MissingValueForOption_1         = Missing value for option \u201c{0}\u201d.
 MissingValueForProperty_1       = Missing value for property \u201c{0}\u201d.
 MissingValueInColumn_1          = Missing value in the \u201c{0}\u201d column.
@@ -113,6 +116,7 @@ UnexpectedEndOfFile_1           = Unexpe
 UnexpectedEndOfString_1         = More characters were expected at the end of \u201c{0}\u201d.
 UnexpectedFileFormat_2          = File \u201c{1}\u201d seems to be encoded in an other format than {0}.
 UnknownCommand_1                = Command \u201c{0}\u201d is not recognized.
+UnknownFormatFor_1              = Format of \u201c{0}\u201d is not recognized.
 UnknownOption_1                 = Option \u201c{0}\u201d is not recognized.
 UnknownType_1                   = Type \u2018{0}\u2019 is unknown in this context.
 UnknownTypeForProperty_1        = Type of the \u201c{0}\u201d property is unknown.

Modified: sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties?rev=1517321&r1=1517320&r2=1517321&view=diff
==============================================================================
--- sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties [ISO-8859-1] (original)
+++ sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties [ISO-8859-1] Sun Aug 25 15:49:51 2013
@@ -21,6 +21,7 @@ CanNotComputeDerivative         = La d\u
 CanNotInstantiate_1             = Ne peut pas cr\u00e9er un objet de type \u2018{0}\u2019.
 CanNotOpen_1                    = Ne peut pas ouvrir \u201c{0}\u201d.
 CanNotParseFile_2               = Ne peut pas lire \u201c{1}\u201d comme un fichier au format {0}.
+CanNotRead_1                    = Ne peut pas lire \u201c{0}\u201d.
 CanNotSetPropertyValue_1        = Ne peut pas d\u00e9finir une valeur pour la propri\u00e9t\u00e9 \u201c{0}\u201d.
 ClassNotFinal_1                 = La classe \u2018{0}\u2019 n\u2019est pas finale.
 CloneNotSupported_1             = Un objet de type \u2018{0}\u2019 ne peut pas \u00eatre clon\u00e9.
@@ -44,6 +45,7 @@ IllegalBitsPattern_1            = Patter
 IllegalClass_2                  = La classe \u2018{1}\u2019 est ill\u00e9gale. Il doit s\u2019agir d\u2019une classe \u2018{0}\u2019 ou d\u00e9riv\u00e9e.
 IllegalFormatPatternForClass_2  = Le mod\u00e8le \u201c{1}\u201d ne peut pas \u00eatre appliqu\u00e9 au formatage d\u2019objets de type \u2018{0}\u2019.
 IllegalLanguageCode_1           = Le code de langue \u201c{0}\u201d n\u2019est pas reconnu.
+IllegalMemberType_2             = Le membre \u201c{0}\u201d ne peut pas \u00eatre associ\u00e9 au type \u201c{1}\u201d.
 IllegalOrdinateRange_3          = La plage de valeurs de coordonn\u00e9es [{1} \u2026 {2}] n\u2019est pas valide pour l\u2019axe \u201c{0}\u201d.
 IllegalPropertyClass_2          = La propri\u00e9t\u00e9 \u2018{0}\u2019 ne peut pas \u00eatre associ\u00e9e \u00e0 une valeur de type \u2018{1}\u2019.
 IllegalRange_2                  = La plage [{0} \u2026 {1}] n\u2019est pas valide.
@@ -62,6 +64,7 @@ MismatchedCRS                   = Le sys
 MismatchedDimension_2           = Les dimensions des objets ({0}D et {1}D) ne concordent pas.
 MismatchedDimension_3           = L\u2019argument \u2018{0}\u2019 a {2} dimension{2,choice,1#|2#s}, alors qu\u2019on en attendait {1}.
 MissingRequiredModule_1         = Cette op\u00e9ration requiert le module \u201c{0}\u201d.
+MissingSchemeInURI              = Il manque le sch\u00e9ma d\u2019URI.
 MissingValueForOption_1         = Aucune valeur n\u2019a \u00e9t\u00e9 d\u00e9finie pour l\u2019option \u201c{0}\u201d.
 MissingValueForProperty_1       = Aucune valeur n\u2019a \u00e9t\u00e9 d\u00e9finie pour la propri\u00e9t\u00e9 \u201c{0}\u201d.
 MissingValueInColumn_1          = Il manque une valeur dans la colonne \u201c{0}\u201d.
@@ -102,6 +105,7 @@ UnexpectedEndOfFile_1           = Fin de
 UnexpectedEndOfString_1         = D\u2019autres caract\u00e8res \u00e9taient attendus \u00e0 la fin du texte \u201c{0}\u201d.
 UnexpectedFileFormat_2          = Le fichier \u201c{1}\u201d semble \u00eatre encod\u00e9 dans un autre format que {0}.
 UnknownCommand_1                = La commande \u201c{0}\u201d n\u2019est pas reconnue.
+UnknownFormatFor_1              = Le format de \u201c{0}\u201d n\u2019est pas reconnu.
 UnknownOption_1                 = L\u2019option \u201c{0}\u201d n\u2019est pas reconnue.
 UnknownType_1                   = Le type \u2018{0}\u2019 n\u2019est pas reconnu dans ce contexte.
 UnknownTypeForProperty_1        = Le type de la propri\u00e9t\u00e9 \u201c{0}\u201d est inconnu.

Modified: sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java
URL: http://svn.apache.org/viewvc/sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java?rev=1517321&r1=1517320&r2=1517321&view=diff
==============================================================================
--- sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java [UTF-8] (original)
+++ sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java [UTF-8] Sun Aug 25 15:49:51 2013
@@ -248,7 +248,7 @@ public class IndexedResourceBundle exten
                 /*
                  * If there is no explicit resources for this instance, inherit the resources
                  * from the parent. Note that this IndexedResourceBundle instance may still
-                 * differ from its parent in the way date and numbers are formatted.
+                 * differ from its parent in the way dates and numbers are formatted.
                  */
                 if (resources == null) {
                     // If we get a NullPointerException or ClassCastException here,

Modified: sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.java
URL: http://svn.apache.org/viewvc/sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.java?rev=1517321&r1=1517320&r2=1517321&view=diff
==============================================================================
--- sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.java [UTF-8] (original)
+++ sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.java [UTF-8] Sun Aug 25 15:49:51 2013
@@ -63,7 +63,7 @@ public final class Messages extends Inde
          * Property “{0}” has been discarded in favor of “{1}”, because those two properties are
          * mutually exclusive.
          */
-        public static final int DiscardedExclusiveProperty_2 = 4;
+        public static final int DiscardedExclusiveProperty_2 = 1;
 
         /**
          * Text were discarded for some locales.
@@ -76,9 +76,10 @@ public final class Messages extends Inde
         public static final int PropertyHiddenBy_2 = 3;
 
         /**
-         * Unavailable content.
+         * Can not parse “{1}” as an instance of {0}. The value is stored as plain text instead, but
+         * will be ignored by some processing.
          */
-        public static final int UnavailableContent = 1;
+        public static final int UnparsableValueStoredAsText_2 = 4;
     }
 
     /**

Modified: sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.properties
URL: http://svn.apache.org/viewvc/sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.properties?rev=1517321&r1=1517320&r2=1517321&view=diff
==============================================================================
--- sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.properties [ISO-8859-1] (original)
+++ sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.properties [ISO-8859-1] Sun Aug 25 15:49:51 2013
@@ -18,4 +18,4 @@ ChangedContainerCapacity_2      = Change
 DiscardedExclusiveProperty_2    = Property \u201c{0}\u201d has been discarded in favor of \u201c{1}\u201d, because those two properties are mutually exclusive.
 PropertyHiddenBy_2              = Property \u201c{0}\u201d is hidden by \u201c{1}\u201d.
 LocalesDiscarded                = Text were discarded for some locales.
-UnavailableContent              = Unavailable content.
+UnparsableValueStoredAsText_2   = Can not parse \u201c{1}\u201d as an instance of {0}. The value is stored as plain text instead, but will be ignored by some processing.

Modified: sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages_fr.properties?rev=1517321&r1=1517320&r2=1517321&view=diff
==============================================================================
--- sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages_fr.properties [ISO-8859-1] (original)
+++ sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages_fr.properties [ISO-8859-1] Sun Aug 25 15:49:51 2013
@@ -18,4 +18,4 @@ ChangedContainerCapacity_2      = Change
 DiscardedExclusiveProperty_2    = La propri\u00e9t\u00e9 \u201c{0}\u201d a \u00e9t\u00e9 \u00e9cart\u00e9e en faveur de \u201c{1}\u201d, parce que ces deux propri\u00e9t\u00e9s sont mutuellement exclusives.
 PropertyHiddenBy_2              = La propri\u00e9t\u00e9 \u201c{0}\u201d est masqu\u00e9e par \u201c{1}\u201d.
 LocalesDiscarded                = Des textes ont \u00e9t\u00e9 ignor\u00e9s pour certaines langues.
-UnavailableContent              = Contenu non-disponible.
+UnparsableValueStoredAsText_2   = La valeur \u201c{1}\u201d ne peut pas \u00eatre interpr\u00e9t\u00e9e comme une instance de {0}. Elle est donc m\u00e9moris\u00e9e sous sa forme textuelle, mais sera ignor\u00e9e par certains traitements.

Modified: sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java
URL: http://svn.apache.org/viewvc/sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java?rev=1517321&r1=1517320&r2=1517321&view=diff
==============================================================================
--- sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java [UTF-8] (original)
+++ sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java [UTF-8] Sun Aug 25 15:49:51 2013
@@ -110,6 +110,11 @@ public final class Vocabulary extends In
         public static final int CurrentDirectory = 33;
 
         /**
+         * Cycle omitted
+         */
+        public static final int CycleOmitted = 54;
+
+        /**
          * Daylight time
          */
         public static final int DaylightTime = 24;
@@ -290,6 +295,11 @@ public final class Vocabulary extends In
         public static final int Type = 1;
 
         /**
+         * Unavailable content.
+         */
+        public static final int UnavailableContent = 53;
+
+        /**
          * Untitled
          */
         public static final int Untitled = 37;
@@ -318,6 +328,11 @@ public final class Vocabulary extends In
          * Versions
          */
         public static final int Versions = 15;
+
+        /**
+         * World
+         */
+        public static final int World = 55;
     }
 
     /**

Modified: sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties
URL: http://svn.apache.org/viewvc/sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties?rev=1517321&r1=1517320&r2=1517321&view=diff
==============================================================================
--- sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties [ISO-8859-1] (original)
+++ sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties [ISO-8859-1] Sun Aug 25 15:49:51 2013
@@ -25,6 +25,7 @@ Code_1             = {0} code
 Commands           = Commands
 CurrentDateTime    = Current date and time
 CurrentDirectory   = Current directory
+CycleOmitted       = Cycle omitted
 DaylightTime       = Daylight time
 Destination        = Destination
 Dimensions         = Dimensions
@@ -62,8 +63,10 @@ TemporaryFiles     = Temporary files
 Timezone           = Timezone
 Type               = Type
 Untitled           = Untitled
+UnavailableContent = Unavailable content.
 UserHome           = User home directory
 Value              = Value
 Variables          = Variables
 Version_2          = {0} version {1}
 Versions           = Versions
+World              = World

Modified: sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties?rev=1517321&r1=1517320&r2=1517321&view=diff
==============================================================================
--- sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties [ISO-8859-1] (original)
+++ sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties [ISO-8859-1] Sun Aug 25 15:49:51 2013
@@ -25,6 +25,7 @@ Code_1             = Code {0}
 Commands           = Commandes
 CurrentDateTime    = Date et heure courantes
 CurrentDirectory   = R\u00e9pertoire courant
+CycleOmitted       = Cycle omit
 DaylightTime       = Heure normale
 Destination        = Destination
 Dimensions         = Dimensions
@@ -62,8 +63,10 @@ TemporaryFiles     = Fichiers temporaire
 Timezone           = Fuseau horaire
 Type               = Type
 Untitled           = Sans titre
+UnavailableContent = Contenu non-disponible.
 UserHome           = R\u00e9pertoire de l'utilisateur
 Value              = Valeur
 Variables          = Variables
 Version_2          = {0} version {1}
 Versions           = Versions
+World              = Monde

Modified: sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/xml/MarshalContext.java
URL: http://svn.apache.org/viewvc/sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/xml/MarshalContext.java?rev=1517321&r1=1517320&r2=1517321&view=diff
==============================================================================
--- sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/xml/MarshalContext.java [UTF-8] (original)
+++ sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/xml/MarshalContext.java [UTF-8] Sun Aug 25 15:49:51 2013
@@ -19,6 +19,7 @@ package org.apache.sis.xml;
 import java.util.Locale;
 import java.util.TimeZone;
 import org.apache.sis.util.Version;
+import org.opengis.util.InternationalString;
 
 
 /**
@@ -37,29 +38,8 @@ public abstract class MarshalContext {
     }
 
     /**
-     * Returns the schema version of the XML document being (un)marshalled.
-     * The {@code prefix} argument can be any of the following values (case-sensitive):
-     *
-     * <table class="sis">
-     *   <tr>
-     *     <th>Prefix</th>
-     *     <th>Standard</th>
-     *     <th>Typical values</th>
-     *   </tr>
-     *   <tr>
-     *     <td>gml</td> <td>Geographic Markup Language</td> <td>{@code 3.0}, {@code 3.2}</td>
-     *   </tr>
-     * </table>
-     *
-     * @param  prefix One of the above-cited prefix.
-     * @return The version for the given schema, or {@code null} if unknown.
-     */
-    public abstract Version getVersion(final String prefix);
-
-    /**
-     * Returns the locale to use for (un)marshalling, or {@code null} if no locale were explicitly
-     * specified. The locale returned by this method can be used for choosing a language in an
-     * {@link org.opengis.util.InternationalString}.
+     * Returns the locale to use for (un)marshalling, or {@code null} if no locale were explicitly specified.
+     * The locale returned by this method can be used for choosing a language in an {@link InternationalString}.
      *
      * <p>This locale may vary in different fragments of the same XML document.
      * In particular children of {@link org.opengis.metadata.Metadata} inherit the locale
@@ -82,8 +62,7 @@ public abstract class MarshalContext {
     public abstract Locale getLocale();
 
     /**
-     * Returns the timezone to use for (un)marshalling, or {@code null} if none were explicitely
-     * specified.
+     * Returns the timezone to use for (un)marshalling, or {@code null} if none were explicitely specified.
      *
      * {@section Handling of <code>null</code> timezone}
      * A {@code null} value means that the timezone is unspecified. Callers are encouraged
@@ -92,4 +71,24 @@ public abstract class MarshalContext {
      * @return The timezone for the XML fragment being (un)marshalled, or {@code null} if unspecified.
      */
     public abstract TimeZone getTimeZone();
+
+    /**
+     * Returns the schema version of the XML document being (un)marshalled.
+     * The {@code prefix} argument can be any of the following values (case-sensitive):
+     *
+     * <table class="sis">
+     *   <tr>
+     *     <th>Prefix</th>
+     *     <th>Standard</th>
+     *     <th>Typical values</th>
+     *   </tr>
+     *   <tr>
+     *     <td>gml</td> <td>Geographic Markup Language</td> <td>{@code 3.0}, {@code 3.2}</td>
+     *   </tr>
+     * </table>
+     *
+     * @param  prefix One of the above-cited prefix.
+     * @return The version for the given schema, or {@code null} if unknown.
+     */
+    public abstract Version getVersion(final String prefix);
 }

Modified: sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/xml/MarshallerPool.java
URL: http://svn.apache.org/viewvc/sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/xml/MarshallerPool.java?rev=1517321&r1=1517320&r2=1517321&view=diff
==============================================================================
--- sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/xml/MarshallerPool.java [UTF-8] (original)
+++ sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/xml/MarshallerPool.java [UTF-8] Sun Aug 25 15:49:51 2013
@@ -18,6 +18,7 @@ package org.apache.sis.xml;
 
 import java.util.Map;
 import java.util.Deque;
+import java.util.ServiceLoader;
 import java.util.concurrent.LinkedBlockingDeque;
 import java.util.concurrent.atomic.AtomicBoolean;
 import javax.xml.bind.JAXBContext;
@@ -60,6 +61,11 @@ import org.apache.sis.util.ArgumentCheck
 @ThreadSafe
 public class MarshallerPool {
     /**
+     * The indentation string, fixed to 2 spaces instead of 4 because ISO/OGC XML are very verbose.
+     */
+    private static final String INDENTATION = "  ";
+
+    /**
      * Amount of nanoseconds to wait before to remove unused (un)marshallers.
      * This is a very approximative value: actual timeout will not be shorter,
      * but may be twice longer.
@@ -89,6 +95,22 @@ public class MarshallerPool {
     private final Object mapper;
 
     /**
+     * The provider of {@code AdapterReplacement} instances.
+     * <strong>Every usage of this service loader must be synchronized.</strong>
+     *
+     * {@note Each <code>MarshallerPool</code> has its own service loader instance rather than using a
+     *        system-wide instance because the <code>ClassLoader</code> used by the service loader is
+     *        the <cite>context class loader</cite>, which depends on the thread that created the pool.
+     *        So two pools in two different applications could have two different set of replacements.}
+     */
+    private final ServiceLoader<AdapterReplacement> replacements;
+
+    /**
+     * The {@link PooledTemplate} to use for initializing recycled (un)marshaller.
+     */
+    private final PooledTemplate template;
+
+    /**
      * The pool of marshaller. This pool is initially empty and will be filled with elements as needed.
      * Marshallers (if any) shall be fetched using the {@link Deque#poll()} method and, after use,
      * given back to the pool using the {@link Deque#push(Object)} method.
@@ -124,42 +146,40 @@ public class MarshallerPool {
 
     /**
      * Creates a new factory using the SIS default {@code JAXBContext} instance.
-     * The keys in the {@code properties} map can be one or many of following constants:
+     * The {@code properties} map is optional. If non-null, then the keys can be {@link XML} constants or the
+     * names of any other properties recognized by <em>both</em> {@code Marshaller} and {@code Unmarshaller}
+     * implementations.
+     *
+     * <p><b>Tip:</b> if the properties for the {@code Marshaller} differ from the properties
+     * for the {@code Unmarshaller}, then consider overriding the {@link #createMarshaller()}
+     * or {@link #createUnmarshaller()} methods instead.</p>
      *
-     * <ul>
-     *   <li>{@link XML#DEFAULT_NAMESPACE} for specifying the default namespace of the XML document to write.</li>
-     * </ul>
-     *
-     * @param  properties    The set of properties to be given to the pool, or {@code null} if none.
+     * @param  properties The set of properties to be given to the (un)marshaller, or {@code null} if none.
      * @throws JAXBException If the JAXB context can not be created.
      */
-    public MarshallerPool(final Map<String,String> properties) throws JAXBException {
+    public MarshallerPool(final Map<String,?> properties) throws JAXBException {
         this(TypeRegistration.getSharedContext(), properties);
     }
 
     /**
      * Creates a new factory using the given JAXB context.
-     * The keys in the {@code properties} map can be one or many of following constants:
-     *
-     * <ul>
-     *   <li>{@link XML#DEFAULT_NAMESPACE} for specifying the default namespace of the XML document to write.</li>
-     * </ul>
+     * The {@code properties} map is optional. If non-null, then the keys can be {@link XML} constants or the
+     * names of any other properties recognized by <em>both</em> {@code Marshaller} and {@code Unmarshaller}
+     * implementations.
+     *
+     * <p><b>Tip:</b> if the properties for the {@code Marshaller} differ from the properties
+     * for the {@code Unmarshaller}, then consider overriding the {@link #createMarshaller()}
+     * or {@link #createUnmarshaller()} methods instead.</p>
      *
-     * @param  context       The JAXB context.
-     * @param  properties    The set of properties to be given to the pool, or {@code null} if none.
+     * @param  context The JAXB context.
+     * @param  properties The set of properties to be given to the (un)marshaller, or {@code null} if none.
      * @throws JAXBException If the marshaller pool can not be created.
      */
     @SuppressWarnings({"unchecked", "rawtypes"}) // Generic array creation
-    public MarshallerPool(final JAXBContext context, final Map<String,String> properties) throws JAXBException {
+    public MarshallerPool(final JAXBContext context, final Map<String,?> properties) throws JAXBException {
         ArgumentChecks.ensureNonNull("context", context);
         this.context = context;
-        String rootNamespace = "";
-        if (properties != null) {
-            rootNamespace = properties.get(XML.DEFAULT_NAMESPACE);
-            if (rootNamespace == null) {
-                rootNamespace = "";
-            }
-        }
+        replacements = ServiceLoader.load(AdapterReplacement.class);
         /*
          * Detects if we are using the endorsed JAXB implementation (i.e. the one provided in
          * separated JAR files) or the one bundled in JDK 6. We use the JAXB context package
@@ -180,6 +200,12 @@ public class MarshallerPool {
             implementation = OTHER;
         }
         /*
+         * Prepares a copy of the property map (if any), then removes the
+         * properties which are handled especially by this constructor.
+         */
+        template = new PooledTemplate(properties, implementation == INTERNAL);
+        final Object rootNamespace = template.remove(XML.DEFAULT_NAMESPACE, "");
+        /*
          * Instantiates the OGCNamespacePrefixMapper appropriate for the implementation
          * we just detected. Note that we may get NoClassDefFoundError instead than the
          * usual ClassNotFoundException if the class was found but its parent class has
@@ -202,14 +228,14 @@ public class MarshallerPool {
      * This method:
      *
      * <ul>
-     *   <li>{@link Pooled#reset() Resets} the (un)marshaller to its initial state.</li>
+     *   <li>{@link Pooled#reset(Pooled) Resets} the (un)marshaller to its initial state.</li>
      *   <li>{@linkplain Deque#push(Object) Pushes} the (un)marshaller in the given queue.</li>
      *   <li>Registers a delayed task for disposing expired (un)marshallers after the timeout.</li>
      * </ul>
      */
     private <T> void recycle(final Deque<T> queue, final T marshaller) {
         try {
-            ((Pooled) marshaller).reset();
+            ((Pooled) marshaller).reset(template);
         } catch (JAXBException exception) {
             // Not expected to happen because we are supposed
             // to reset the properties to their initial values.
@@ -307,7 +333,7 @@ public class MarshallerPool {
     public Marshaller acquireMarshaller() throws JAXBException {
         Marshaller marshaller = marshallers.poll();
         if (marshaller == null) {
-            marshaller = new PooledMarshaller(createMarshaller(), implementation == INTERNAL);
+            marshaller = new PooledMarshaller(createMarshaller(), template);
         }
         return marshaller;
     }
@@ -333,7 +359,7 @@ public class MarshallerPool {
     public Unmarshaller acquireUnmarshaller() throws JAXBException {
         Unmarshaller unmarshaller = unmarshallers.poll();
         if (unmarshaller == null) {
-            unmarshaller = new PooledUnmarshaller(createUnmarshaller(), implementation == INTERNAL);
+            unmarshaller = new PooledUnmarshaller(createUnmarshaller(), template);
         }
         return unmarshaller;
     }
@@ -387,7 +413,7 @@ public class MarshallerPool {
     }
 
     /**
-     * Creates an configure a new JAXB marshaller.
+     * Creates an configures a new JAXB marshaller.
      * This method is invoked only when no existing marshaller is available in the pool.
      * Subclasses can override this method if they need to change the marshaller configuration.
      *
@@ -401,16 +427,18 @@ public class MarshallerPool {
         switch (implementation) {
             case INTERNAL: {
                 marshaller.setProperty("com.sun.xml.internal.bind.namespacePrefixMapper", mapper);
+                marshaller.setProperty("com.sun.xml.internal.bind.indentString", INDENTATION);
                 break;
             }
             case ENDORSED: {
                 marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", mapper);
+                marshaller.setProperty("com.sun.xml.bind.indentString", INDENTATION);
                 break;
             }
             // Do nothing for the OTHER case.
         }
-        synchronized (AdapterReplacement.PROVIDER) {
-            for (final AdapterReplacement adapter : AdapterReplacement.PROVIDER) {
+        synchronized (replacements) {
+            for (final AdapterReplacement adapter : replacements) {
                 adapter.register(marshaller);
             }
         }
@@ -418,7 +446,7 @@ public class MarshallerPool {
     }
 
     /**
-     * Creates an configure a new JAXB unmarshaller.
+     * Creates an configures a new JAXB unmarshaller.
      * This method is invoked only when no existing unmarshaller is available in the pool.
      * Subclasses can override this method if they need to change the unmarshaller configuration.
      *
@@ -427,8 +455,8 @@ public class MarshallerPool {
      */
     protected Unmarshaller createUnmarshaller() throws JAXBException {
         final Unmarshaller unmarshaller = context.createUnmarshaller();
-        synchronized (AdapterReplacement.PROVIDER) {
-            for (final AdapterReplacement adapter : AdapterReplacement.PROVIDER) {
+        synchronized (replacements) {
+            for (final AdapterReplacement adapter : replacements) {
                 adapter.register(unmarshaller);
             }
         }

Modified: sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/xml/NilObject.java
URL: http://svn.apache.org/viewvc/sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/xml/NilObject.java?rev=1517321&r1=1517320&r2=1517321&view=diff
==============================================================================
--- sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/xml/NilObject.java [UTF-8] (original)
+++ sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/xml/NilObject.java [UTF-8] Sun Aug 25 15:49:51 2013
@@ -81,6 +81,8 @@ public interface NilObject {
      * Returns the reason why this object contains no information.
      *
      * @return The reason why this object contains no information.
+     *
+     * @see NilReason#forObject(Object)
      */
     NilReason getNilReason();
 }

Modified: sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/xml/NilReason.java
URL: http://svn.apache.org/viewvc/sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/xml/NilReason.java?rev=1517321&r1=1517320&r2=1517321&view=diff
==============================================================================
--- sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/xml/NilReason.java [UTF-8] (original)
+++ sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/xml/NilReason.java [UTF-8] Sun Aug 25 15:49:51 2013
@@ -16,17 +16,21 @@
  */
 package org.apache.sis.xml;
 
+import java.util.Map;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.io.Serializable;
 import java.lang.reflect.Proxy;
 import java.lang.reflect.InvocationHandler;
+import org.opengis.util.InternationalString;
 import org.apache.sis.util.Immutable;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.LenientComparable;
 import org.apache.sis.util.collection.WeakHashSet;
+import org.apache.sis.util.collection.WeakValueHashMap;
+import org.apache.sis.internal.jaxb.PrimitiveTypeProperties;
 
 
 /**
@@ -48,7 +52,7 @@ import org.apache.sis.util.collection.We
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-3.18)
- * @version 0.3
+ * @version 0.4
  * @module
  *
  * @see NilObject
@@ -150,6 +154,13 @@ public final class NilReason implements 
     private transient InvocationHandler handler;
 
     /**
+     * The values created by {@link #createNilObject(Class)}. They are often instances of {@link NilObject},
+     * except for some JDK types like {@link String}, {@link Boolean} or {@link Integer} which are handled
+     * in a special way.
+     */
+    private transient Map<Class<?>, Object> nilObjects;
+
+    /**
      * Creates a new reason for the given XML value or the given URI.
      */
     private NilReason(final Object reason) {
@@ -334,31 +345,165 @@ public final class NilReason implements 
 
     /**
      * Returns an object of the given type which is nil for the reason represented by this instance.
-     * This method returns an object which implement the given interface together with the
-     * {@link NilObject} interface. The {@link NilObject#getNilReason()} method will return
-     * this {@code NilReason} instance, and all other methods (except the ones inherited from
-     * the {@code Object} class) will return an empty collection, empty array, {@code null},
-     * {@link Double#NaN NaN}, {@code 0} or {@code false}, in this preference order,
-     * depending on the method return type.
+     * The {@code type} argument can be one of the following cases:
+     *
+     * <ul>
+     *   <li><p>An <strong>interface</strong>: in such case, this method returns an object which implement the given
+     *       interface together with the {@link NilObject} and {@link LenientComparable} interfaces:
+     *       <ul>
+     *         <li>The {@link NilObject#getNilReason()} method will return this {@code NilReason} instance.</li>
+     *         <li>The {@code equals(…)} and {@code hashCode()} methods behave as documented in {@link LenientComparable}.</li>
+     *         <li>The {@code toString()} method is unspecified (may contain debugging information).</li>
+     *         <li>All other methods return an empty collections, empty arrays, {@code null}, {@link Double#NaN NaN},
+     *             {@code 0} or {@code false}, in this preference order, depending on the method return type.</li>
+     *       </ul></p>
+     *   </li>
+     *   <li><p>One of {@code Boolean}, {@link Byte}, {@link Short}, {@code Integer}, {@link Long}, {@link Float},
+     *       {@code Double} or {@code String} types: in such case, this method returns a specific instance which
+     *       will be recognized as "nil" by the XML marshaller.</p></li>
+     * </ul>
      *
      * @param  <T> The compile-time type of the {@code type} argument.
-     * @param  type The object type as an <strong>interface</strong>.
-     *         This is usually a <a href="http://www.geoapi.org">GeoAPI</a> interface.
+     * @param  type The object type as an <strong>interface</strong>
+     *         (usually a <a href="http://www.geoapi.org">GeoAPI</a> one) or one of the special types.
+     * @throws IllegalArgumentException If the given type is not a supported type.
      * @return An {@link NilObject} of the given type.
      */
     @SuppressWarnings("unchecked")
-    public <T> T createNilObject(final Class<T> type) {
+    public synchronized <T> T createNilObject(final Class<T> type) {
         ArgumentChecks.ensureNonNull("type", type);
-        if (NilObjectHandler.isIgnoredInterface(type)) {
-            throw new IllegalArgumentException(Errors.format(Errors.Keys.IllegalArgumentValue_2, "type", type));
+        /*
+         * Check for existing instance in the cache before to create a new object. Returning a unique
+         * instance is mandatory for the types handled by 'createNilPrimitive(Class)'. Since we have
+         * to cache those values anyway, we opportunistically extend the caching to other types too.
+         *
+         * Implementation note: we have two synchronizations here: one lock on 'this' because of the
+         * 'synchronized' statement in this method signature, and an other lock in WeakValueHashMap.
+         * The second lock may seem useless since we already hold a lock on 'this'. But it is actually
+         * needed because the garbage-collected entries are removed from the map in a background thread
+         * (see ReferenceQueueConsumer), which is synchronized on the map itself. It is better to keep
+         * the synchronization on the map shorter than the snychronization on 'this' because a single
+         * ReferenceQueueConsumer thread is shared by all the SIS library.
+         */
+        if (nilObjects == null) {
+            nilObjects = new WeakValueHashMap<Class<?>, Object>((Class) Class.class);
         }
-        InvocationHandler h;
-        synchronized (this) {
-            if ((h = handler) == null) {
-                handler = h = new NilObjectHandler(this);
+        Object object = nilObjects.get(type);
+        if (object == null) {
+            /*
+             * If no object has been previously created, check for the usual case where the requested type
+             * is an interface. We still have a special case for InternationalString. For all other cases,
+             * we will rely on the proxy.
+             */
+            if (type.isInterface()) {
+                if (NilObjectHandler.isIgnoredInterface(type)) {
+                    throw new IllegalArgumentException(Errors.format(Errors.Keys.IllegalArgumentValue_2, "type", type));
+                }
+                if (type == InternationalString.class) {
+                    object = new NilInternationalString(this);
+                } else {
+                    if (handler == null) {
+                        handler = new NilObjectHandler(this);
+                    }
+                    object = Proxy.newProxyInstance(NilReason.class.getClassLoader(),
+                            new Class<?>[] {type, NilObject.class, LenientComparable.class}, handler);
+                }
+            } else {
+                /*
+                 * If the requested type is not an interface, this is usually an error except for some
+                 * special cases: Boolean, Byte, Short, Integer, Long, Float, Double or String.
+                 */
+                object = createNilPrimitive(type);
+                PrimitiveTypeProperties.associate(object, this);
+            }
+            if (nilObjects.put(type, object) != null) {
+                throw new AssertionError(type); // Should never happen.
             }
         }
-        return (T) Proxy.newProxyInstance(NilReason.class.getClassLoader(),
-                new Class<?>[] {type, NilObject.class, LenientComparable.class}, h);
+        return type.cast(object);
+    }
+
+    /**
+     * Returns a new {@code Boolean}, {@link Byte}, {@link Short}, {@code Integer}, {@link Long},
+     * {@link Float}, {@code Double} or {@code String} instance to be considered as a nil value.
+     * The caller is responsible for registering the value in {@link PrimitiveTypeProperties}.
+     *
+     * <p><b>REMINDER:<b> If more special cases are added, do not forget to update the {@link #mayBeNil(Object)}
+     * method and to update the {@link #createNilObject(Class)} and {@link #forObject(Object)} javadoc.</p>
+     *
+     * {@note There is no special case for <code>Character</code> because Java <code>char</code>s are not really
+     *        full Unicode characters. They are parts of UTF-16 encoding instead. If there is a need to represent
+     *        a single Unicode character, we should probably still use a <code>String</code> where the string may
+     *        contain up to 2 Java characters. This may also facilitate the encoding in the XML files, since many
+     *        files use an other encoding than UTF-16 anyway.}
+     *
+     * @throws IllegalArgumentException If the given type is not a supported type.
+     */
+    private static Object createNilPrimitive(final Class<?> type) {
+        if (type == String .class) return new String("");         // REALLY need a new instance.
+        if (type == Boolean.class) return new Boolean(false);     // REALLY need a new instance, not Boolean.FALSE.
+        if (type == Byte   .class) return new Byte((byte) 0);     // REALLY need a new instance, not Byte.valueOf(0).
+        if (type == Short  .class) return new Short((byte) 0);    // REALLY need a new instance, not Short.valueOf(0).
+        if (type == Integer.class) return new Integer(0);         // REALLY need a new instance, not Integer.valueOf(0).
+        if (type == Long   .class) return new Long(0);            // REALLY need a new instance, not Long.valueOf(0).
+        if (type == Float  .class) return new Float(Float.NaN);   // REALLY need a new instance, not Float.valueOf(…).
+        if (type == Double .class) return new Double(Double.NaN); // REALLY need a new instance, not Double.valueOf(…).
+        throw new IllegalArgumentException(Errors.format(Errors.Keys.IllegalArgumentValue_2, "type", type));
+    }
+
+    /**
+     * Returns {@code true} if the given object may be one of the sentinel values
+     * created by {@link #createNilPrimitive(Class)}. This method only checks the value.
+     * If this method returns {@code true}, then the caller still need to check the actual instance using the
+     * {@link PrimitiveTypeProperties} class. The purpose of this method is to filter the values that can not
+     * be sentinel values, in order to avoid the synchronization done by {@code PrimitiveTypeProperties}.
+     */
+    private static boolean mayBeNil(final Object object) {
+        // 'instanceof' checks on instances of final classes are expected to be very fast.
+        if (object instanceof String)  return ((String)  object).isEmpty();
+        if (object instanceof Boolean) return ((Boolean) object).booleanValue() == false && object != Boolean.FALSE;
+        if (object instanceof Number) {
+            /*
+             * Following test may return false positives for Long, Float and Double types, but this is okay
+             * since the real check will be done by PrimitiveTypeProperties.  The purpose of this method is
+             * only to perform a cheap filtering. Note that this method relies on the fact that casting NaN
+             * to 'int' produces 0.
+             */
+            return ((Number) object).intValue() == 0;
+        }
+        return false;
+    }
+
+    /**
+     * If the given object is nil, returns the reason why it does not contain information.
+     * This method performs the following choices:
+     *
+     * <ul>
+     *   <li>If the given object implements the {@link NilObject} interface, then this method delegates
+     *       to the {@link NilObject#getNilReason()} method.</li>
+     *   <li>Otherwise if the given object is one of the {@code Boolean}, {@link Byte}, {@link Short}, {@code Integer},
+     *       {@link Long}, {@link Float}, {@code Double} or {@code String} instances returned by
+     *       {@link #createNilObject(Class)}, then this method returns the associated reason.</li>
+     *   <li>Otherwise this method returns {@code null}.</li>
+     * </ul>
+     *
+     * @param  object The object for which to get the {@code NilReason}, or {@code null}.
+     * @return The reason why the given object contains no information,
+     *         or {@code null} if the given object is not nil.
+     *
+     * @see NilObject#getNilReason()
+     *
+     * @since 0.4
+     */
+    public static NilReason forObject(final Object object) {
+        if (object != null) {
+            if (object instanceof NilObject) {
+                return ((NilObject) object).getNilReason();
+            }
+            if (mayBeNil(object)) {
+                return (NilReason) PrimitiveTypeProperties.property(object);
+            }
+        }
+        return null;
     }
 }

Modified: sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/xml/Pooled.java
URL: http://svn.apache.org/viewvc/sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/xml/Pooled.java?rev=1517321&r1=1517320&r2=1517321&view=diff
==============================================================================
--- sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/xml/Pooled.java [UTF-8] (original)
+++ sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/xml/Pooled.java [UTF-8] Sun Aug 25 15:49:51 2013
@@ -28,9 +28,12 @@ import javax.xml.bind.JAXBException;
 import javax.xml.bind.PropertyException;
 import javax.xml.bind.ValidationEventHandler;
 import javax.xml.bind.annotation.adapters.XmlAdapter;
+import org.apache.sis.util.Locales;
 import org.apache.sis.util.Version;
+import org.apache.sis.util.ArraysExt;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.resources.Errors;
+import org.apache.sis.util.logging.WarningListener;
 import org.apache.sis.internal.util.CollectionsExt;
 import org.apache.sis.internal.jaxb.Context;
 
@@ -83,26 +86,29 @@ abstract class Pooled {
      *   <li>For each entry having a key of type {@link String}, the value is the argument
      *       to be given to the {@code marshaller.setProperty(key, value)} method.</li>
      * </ul>
+     *
+     * This map is never {@code null}.
      */
-    private final Map<Object,Object> initialProperties;
+    final Map<Object,Object> initialProperties;
 
     /**
-     * The object converters to use during (un)marshalling.
-     * Can be set by the {@link XML#CONVERTER} property.
+     * Bit masks for various boolean attributes. This include whatever the language codes
+     * or the country codes should be substituted by a simpler character string elements.
+     * Those bits are determined by the {@link XML#STRING_SUBSTITUTES} property.
      */
-    private ValueConverter converter;
+    private int bitMasks;
 
     /**
-     * The reference resolver to use during unmarshalling.
-     * Can be set by the {@link XML#RESOLVER} property.
+     * An optional locale for {@link org.opengis.util.InternationalString} and
+     * {@link org.opengis.util.CodeList}. Can be set by the {@link XML#LOCALE} property.
      */
-    private ReferenceResolver resolver;
+    private Locale locale;
 
     /**
-     * The GML version to be marshalled or unmarshalled, or {@code null} if unspecified.
-     * If null, then the latest version is assumed.
+     * The timezone, or {@code null} if unspecified.
+     *  Can be set by the {@link XML#TIMEZONE} property.
      */
-    private Version gmlVersion;
+    private TimeZone timezone;
 
     /**
      * The base URL of ISO 19139 (or other standards) schemas. It shall be an unmodifiable
@@ -112,33 +118,37 @@ abstract class Pooled {
     private Map<String,String> schemas;
 
     /**
-     * An optional locale for {@link org.opengis.util.InternationalString} and
-     * {@link org.opengis.util.CodeList}. Can be set by the {@link XML#LOCALE} property.
+     * The GML version to be marshalled or unmarshalled, or {@code null} if unspecified.
+     * If null, then the latest version is assumed.
      */
-    private Locale locale;
+    private Version gmlVersion;
 
     /**
-     * The timezone, or {@code null} if unspecified.
-     *  Can be set by the {@link XML#TIMEZONE} property.
+     * The reference resolver to use during unmarshalling.
+     * Can be set by the {@link XML#RESOLVER} property.
      */
-    private TimeZone timezone;
+    private ReferenceResolver resolver;
 
     /**
-     * Bit masks for various boolean attributes. This include whatever the language codes
-     * or the country codes should be substituted by a simpler character string elements.
-     * Those bits are determined by the {@link XML#STRING_SUBSTITUTES} property.
+     * The object converters to use during (un)marshalling.
+     * Can be set by the {@link XML#CONVERTER} property.
      */
-    private int bitMasks;
+    private ValueConverter converter;
+
+    /**
+     * The object to inform about warnings, or {@code null} if none.
+     */
+    private WarningListener<?> warningListener;
 
     /**
-     * The {@link System#nanoTime()} value of the last call to {@link #reset()}.
+     * The {@link System#nanoTime()} value of the last call to {@link #reset(Pooled)}.
      * This is used for disposing (un)marshallers that have not been used for a while,
      * since {@code reset()} is invoked just before to push a (un)marshaller in the pool.
      */
     volatile long resetTime;
 
     /**
-     * Default constructor.
+     * Creates a {@link PooledTemplate}.
      *
      * @param internal {@code true} if the JAXB implementation is the one bundled in JDK 6,
      *        or {@code false} if this is the external implementation provided as a JAR file
@@ -147,7 +157,32 @@ abstract class Pooled {
     Pooled(final boolean internal) {
         this.internal = internal;
         initialProperties = new LinkedHashMap<Object,Object>();
-        bitMasks = initialBitMasks();
+    }
+
+    /**
+     * Creates a {@link PooledMarshaller} or {@link PooledUnmarshaller}. The {@link #initialize(Pooled)}
+     * method must be invoked after this constructor for completing the initialization.
+     *
+     * @param template The {@link PooledTemplate} from which to get the initial values.
+     */
+    Pooled(final Pooled template) {
+        initialProperties = new LinkedHashMap<Object,Object>();
+        internal = template.internal;
+    }
+
+    /**
+     * Completes the creation of a {@link PooledMarshaller} or {@link PooledUnmarshaller}.
+     * This method is not invoked in the {@link #Pooled(Pooled)} constructor in order to
+     * give to subclasses a chance to complete their construction first.
+     *
+     * @param  template The {@link PooledTemplate} from which to get the initial values.
+     * @throws JAXBException If an error occurred while setting a property.
+     */
+    final void initialize(final Pooled template) throws JAXBException {
+        reset(template); // Set the SIS properties first. JAXB properties are set below.
+        for (final Map.Entry<Object,Object> entry : template.initialProperties.entrySet()) {
+            setStandardProperty((String) entry.getKey(), entry.getValue());
+        }
     }
 
     /**
@@ -163,26 +198,28 @@ abstract class Pooled {
      * This method is invoked by {@link MarshallerPool} just before to push a
      * (un)marshaller in the pool after its usage.
      *
+     * @param  template The {@link PooledTemplate} from which to get the initial values.
      * @throws JAXBException If an error occurred while restoring a property.
      */
-    public final void reset() throws JAXBException {
+    public final void reset(final Pooled template) throws JAXBException {
         for (final Map.Entry<Object,Object> entry : initialProperties.entrySet()) {
             reset(entry.getKey(), entry.getValue());
         }
         initialProperties.clear();
-        converter  = null;
-        resolver   = null;
-        gmlVersion = null;
-        schemas    = null;
-        locale     = null;
-        timezone   = null;
-        bitMasks   = initialBitMasks();
-        resetTime  = System.nanoTime();
+        bitMasks        = initialBitMasks();
+        locale          = template.locale;
+        timezone        = template.timezone;
+        schemas         = template.schemas;
+        gmlVersion      = template.gmlVersion;
+        resolver        = template.resolver;
+        converter       = template.converter;
+        warningListener = template.warningListener;
+        resetTime       = System.nanoTime();
     }
 
     /**
      * Resets the given marshaller property to its initial state. This method is invoked
-     * automatically by the {@link #reset()} method. The key is either a {@link String}
+     * automatically by the {@link #reset(Pooled)} method. The key is either a {@link String}
      * or a {@link Class}. If this is a string, then the value shall be given to the
      * {@code setProperty(key, value)} method. Otherwise the value shall be given to
      * {@code setFoo(value)} method where {@code "Foo"} is determined from the key.
@@ -203,8 +240,8 @@ abstract class Pooled {
 
     /**
      * Saves the current value of a property. This method is invoked before a value is
-     * modified for the first time, in order to allow {@link #reset()} to restore the
-     * (un)marshaller to its initial state.
+     * modified for the first time, in order to allow {@link #reset(Pooled)} to restore
+     * the (un)marshaller to its initial state.
      *
      * @param type  The property to save.
      * @param value The current value of the property.
@@ -241,12 +278,12 @@ abstract class Pooled {
     public final void setProperty(String name, final Object value) throws PropertyException {
         try {
             /* switch (name) */ {
-                if (name.equals(XML.CONVERTER)) {
-                    converter = (ValueConverter) value;
+                if (name.equals(XML.LOCALE)) {
+                    locale = (value instanceof CharSequence) ? Locales.parse(value.toString()) : (Locale) value;
                     return;
                 }
-                else if (name.equals(XML.RESOLVER)) {
-                    resolver = (ReferenceResolver) value;
+                else if (name.equals(XML.TIMEZONE)) {
+                    timezone = (value instanceof CharSequence) ? TimeZone.getTimeZone(value.toString()) : (TimeZone) value;
                     return;
                 }
                 else if (name.equals(XML.SCHEMAS)) {
@@ -273,34 +310,45 @@ abstract class Pooled {
                     gmlVersion = (value instanceof CharSequence) ? new Version(value.toString()) : (Version) value;
                     return;
                 }
-                else if (name.equals(XML.LOCALE)) {
-                    locale = (Locale) value;
+                else if (name.equals(XML.RESOLVER)) {
+                    resolver = (ReferenceResolver) value;
                     return;
                 }
-                else if (name.equals(XML.TIMEZONE)) {
-                    timezone = (TimeZone) value;
+                else if (name.equals(XML.CONVERTER)) {
+                    converter = (ValueConverter) value;
                     return;
                 }
                 else if (name.equals(XML.STRING_SUBSTITUTES)) {
                     int mask = initialBitMasks();
-                    final CharSequence[] substitutes = CharSequences.split((CharSequence) value, ',');
-                    if (substitutes != null) {
-                        for (final CharSequence substitute : substitutes) {
+                    if (value != null) {
+                        for (final CharSequence substitute : (CharSequence[]) value) {
                             if (CharSequences.equalsIgnoreCase(substitute, "language")) {
                                 mask |= Context.SUBSTITUTE_LANGUAGE;
                             } else if (CharSequences.equalsIgnoreCase(substitute, "country")) {
                                 mask |= Context.SUBSTITUTE_COUNTRY;
+                            } else if (CharSequences.equalsIgnoreCase(substitute, "filename")) {
+                                mask |= Context.SUBSTITUTE_FILENAME;
+                            } else if (CharSequences.equalsIgnoreCase(substitute, "mimetype")) {
+                                mask |= Context.SUBSTITUTE_MIMETYPE;
                             }
                         }
                     }
                     bitMasks = mask;
                     return;
                 }
+                else if (name.equals(XML.WARNING_LISTENER)) {
+                    warningListener = (WarningListener<?>) value;
+                    return;
+                }
             }
-        } catch (ClassCastException e) {
+        } catch (RuntimeException e) { // (ClassCastException | IllegalArgumentException) on the JDK7 branch.
             throw new PropertyException(Errors.format(
                     Errors.Keys.IllegalPropertyClass_2, name, value.getClass()), e);
         }
+        /*
+         * If we reach this point, the given name is not a SIS property. Try to handle
+         * it as a (un)marshaller-specific property, after saving the previous value.
+         */
         name = convertPropertyKey(name);
         if (!initialProperties.containsKey(name)) {
             if (initialProperties.put(name, getStandardProperty(name)) != null) {
@@ -316,22 +364,21 @@ abstract class Pooled {
      */
     public final Object getProperty(final String name) throws PropertyException {
         /*switch (name)*/ {
-            if (name.equals(XML.CONVERTER))   return converter;
-            if (name.equals(XML.RESOLVER))    return resolver;
-            if (name.equals(XML.SCHEMAS))     return schemas;
-            if (name.equals(XML.GML_VERSION)) return gmlVersion;
-            if (name.equals(XML.LOCALE))      return locale;
-            if (name.equals(XML.TIMEZONE))    return timezone;
+            if (name.equals(XML.LOCALE))           return locale;
+            if (name.equals(XML.TIMEZONE))         return timezone;
+            if (name.equals(XML.SCHEMAS))          return schemas;
+            if (name.equals(XML.GML_VERSION))      return gmlVersion;
+            if (name.equals(XML.RESOLVER))         return resolver;
+            if (name.equals(XML.CONVERTER))        return converter;
+            if (name.equals(XML.WARNING_LISTENER)) return warningListener;
             if (name.equals(XML.STRING_SUBSTITUTES)) {
-                final StringBuilder buffer = new StringBuilder();
-                if ((bitMasks & Context.SUBSTITUTE_LANGUAGE) != 0) buffer.append("language,");
-                if ((bitMasks & Context.SUBSTITUTE_COUNTRY)  != 0) buffer.append("country,");
-                final int length = buffer.length();
-                if (length != 0) {
-                    buffer.setLength(length - 1); // Remove the last coma.
-                    return buffer.toString();
-                }
-                return null;
+                int n = 0;
+                final String[] substitutes = new String[4];
+                if ((bitMasks & Context.SUBSTITUTE_LANGUAGE) != 0) substitutes[n++] = "language";
+                if ((bitMasks & Context.SUBSTITUTE_COUNTRY)  != 0) substitutes[n++] = "country";
+                if ((bitMasks & Context.SUBSTITUTE_FILENAME) != 0) substitutes[n++] = "filename";
+                if ((bitMasks & Context.SUBSTITUTE_MIMETYPE) != 0) substitutes[n++] = "mimetype";
+                return (n != 0) ? ArraysExt.resize(substitutes, n) : null;
             }
             else {
                 return getStandardProperty(convertPropertyKey(name));
@@ -428,6 +475,6 @@ abstract class Pooled {
      * @see Context#finish();
      */
     final Context begin() {
-        return new Context(converter, resolver, gmlVersion, schemas, locale, timezone, bitMasks);
+        return new Context(bitMasks, locale, timezone, schemas, gmlVersion, resolver, converter, warningListener);
     }
 }

Modified: sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/xml/PooledMarshaller.java
URL: http://svn.apache.org/viewvc/sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/xml/PooledMarshaller.java?rev=1517321&r1=1517320&r2=1517321&view=diff
==============================================================================
--- sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/xml/PooledMarshaller.java [UTF-8] (original)
+++ sis/branches/Shapefile/core/sis-utility/src/main/java/org/apache/sis/xml/PooledMarshaller.java [UTF-8] Sun Aug 25 15:49:51 2013
@@ -60,20 +60,21 @@ final class PooledMarshaller extends Poo
 
     /**
      * Creates a pooled marshaller wrapping the given one.
+     * Callers shall invoke {@link #reset(Pooled)} after construction for completing the initialization.
      *
-     * @param marshaller The marshaller to use for the actual work.
-     * @param internal {@code true} if the JAXB implementation is the one bundled in JDK 6,
-     *        or {@code false} if this is the external implementation provided as a JAR file
-     *        in the endorsed directory.
+     * @param  marshaller The marshaller to use for the actual work.
+     * @param  template The {@link PooledTemplate} from which to get the initial values.
+     * @throws JAXBException If an error occurred while setting a property.
      */
-    PooledMarshaller(final Marshaller marshaller, final boolean internal) {
-        super(internal);
+    PooledMarshaller(final Marshaller marshaller, final Pooled template) throws JAXBException {
+        super(template);
         this.marshaller = marshaller;
+        initialize(template);
     }
 
     /**
      * Resets the given marshaller property to its initial state.
-     * This method is invoked automatically by {@link #reset()}.
+     * This method is invoked automatically by {@link #reset(Pooled)}.
      *
      * @param  key   The property to reset.
      * @param  value The saved initial value to give to the property.
@@ -238,7 +239,7 @@ final class PooledMarshaller extends Poo
 
     /**
      * Delegates to the wrapped marshaller. The initial state will be saved
-     * if it was not already done, for future restoration by {@link #reset()}.
+     * if it was not already done, for future restoration by {@link #reset(Pooled)}.
      */
     @Override
     @SuppressWarnings("rawtypes")
@@ -258,7 +259,7 @@ final class PooledMarshaller extends Poo
 
     /**
      * Delegates to the wrapped marshaller. The initial state will be saved
-     * if it was not already done, for future restoration by {@link #reset()}.
+     * if it was not already done, for future restoration by {@link #reset(Pooled)}.
      */
     @Override
     public void setSchema(final Schema schema) {
@@ -276,7 +277,7 @@ final class PooledMarshaller extends Poo
 
     /**
      * Delegates to the wrapped marshaller. The initial state will be saved
-     * if it was not already done, for future restoration by {@link #reset()}.
+     * if it was not already done, for future restoration by {@link #reset(Pooled)}.
      */
     @Override
     public void setEventHandler(final ValidationEventHandler handler) throws JAXBException {
@@ -294,7 +295,7 @@ final class PooledMarshaller extends Poo
 
     /**
      * Delegates to the wrapped marshaller. The initial state will be saved
-     * if it was not already done, for future restoration by {@link #reset()}.
+     * if it was not already done, for future restoration by {@link #reset(Pooled)}.
      */
     @Override
     public void setAttachmentMarshaller(final AttachmentMarshaller am) {
@@ -314,7 +315,7 @@ final class PooledMarshaller extends Poo
 
     /**
      * Delegates to the wrapped marshaller. The initial state will be saved
-     * if it was not already done, for future restoration by {@link #reset()}.
+     * if it was not already done, for future restoration by {@link #reset(Pooled)}.
      */
     @Override
     public void setListener(final Listener listener) {