sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1510391 [2/2] - in /sis/branches/JDK6: ./ core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/code/ core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/ core/sis-metadata/src/main/java/org/apache/sis/internal/metadata...
Date Mon, 05 Aug 2013 08:52:16 GMT
Modified: sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/MetadataUtilitiesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/MetadataUtilitiesTest.java?rev=1510391&r1=1510390&r2=1510391&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/MetadataUtilitiesTest.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/MetadataUtilitiesTest.java
[UTF-8] Mon Aug  5 08:52:15 2013
@@ -21,8 +21,6 @@ import org.junit.Test;
 import org.apache.sis.test.TestCase;
 
 import static org.junit.Assert.*;
-import static java.lang.Boolean.TRUE;
-import static java.lang.Boolean.FALSE;
 
 
 /**
@@ -30,7 +28,7 @@ import static java.lang.Boolean.FALSE;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.3
+ * @version 0.4
  * @module
  */
 public final strictfp class MetadataUtilitiesTest extends TestCase {
@@ -51,22 +49,4 @@ public final strictfp class MetadataUtil
         assertEquals(new Date(1000), MetadataUtilities.toDate(1000));
         assertNull(MetadataUtilities.toDate(Long.MIN_VALUE));
     }
-
-    /**
-     * Tests {@link MetadataUtilities#setBoolean(int, byte, Boolean)}.
-     * This will indirectly test the getter method through Java assertion.
-     */
-    @Test
-    public void testSetBoolean() {
-        final int mask0 =  3; // 0b000011;
-        final int mask1 = 12; // 0b001100;
-        final int mask2 = 48; // 0b110000;
-        int flags = 0;
-        flags = MetadataUtilities.setBoolean(flags, mask1, null ); assertEquals( 0 /*0b000000*/,
flags);
-        flags = MetadataUtilities.setBoolean(flags, mask1, TRUE ); assertEquals(12 /*0b001100*/,
flags);
-        flags = MetadataUtilities.setBoolean(flags, mask2, FALSE); assertEquals(44 /*0b101100*/,
flags);
-        flags = MetadataUtilities.setBoolean(flags, mask1, null ); assertEquals(32 /*0b100000*/,
flags);
-        flags = MetadataUtilities.setBoolean(flags, mask0, TRUE ); assertEquals(35 /*0b100011*/,
flags);
-        flags = MetadataUtilities.setBoolean(flags, mask0, FALSE); assertEquals(34 /*0b100010*/,
flags);
-    }
 }

Modified: sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/xml/MetadataMarshallingTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/xml/MetadataMarshallingTest.java?rev=1510391&r1=1510390&r2=1510391&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/xml/MetadataMarshallingTest.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/xml/MetadataMarshallingTest.java
[UTF-8] Mon Aug  5 08:52:15 2013
@@ -26,6 +26,9 @@ import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.JAXBException;
 import org.opengis.util.InternationalString;
 import org.apache.sis.util.iso.SimpleInternationalString;
+import org.apache.sis.metadata.iso.extent.DefaultExtent;
+import org.apache.sis.metadata.iso.extent.DefaultTemporalExtent;
+import org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox;
 import org.apache.sis.metadata.iso.lineage.DefaultProcessing;
 import org.apache.sis.metadata.iso.lineage.DefaultProcessStep;
 import org.apache.sis.metadata.iso.quality.AbstractElement;
@@ -37,6 +40,7 @@ import org.junit.AfterClass;
 import org.junit.Test;
 
 import static org.apache.sis.test.Assert.*;
+import static org.apache.sis.test.TestUtilities.date;
 import static org.apache.sis.test.TestUtilities.getSingleton;
 
 
@@ -48,7 +52,7 @@ import static org.apache.sis.test.TestUt
  * @author  Cédric Briançon (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-2.5)
- * @version 0.3
+ * @version 0.4
  * @module
  */
 @DependsOn(FreeTextMarshallingTest.class)
@@ -131,7 +135,7 @@ public final strictfp class MetadataMars
         assertInstanceOf("Wrong value for <gmd:result>", DefaultConformanceResult.class,
                 getSingleton(((AbstractElement) metadata).getResults()));
         /*
-         * Final comparison: ensure that we didn't lost any information, then release.
+         * Final comparison: ensure that we didn't lost any information.
          */
         assertXmlEquals(resource, marshal(marshaller, metadata), "xmlns:*", "xsi:schemaLocation",
"xsi:type");
         pool.recycle(unmarshaller);
@@ -162,10 +166,48 @@ public final strictfp class MetadataMars
         assertTrue(xml.startsWith("<?xml"));
         assertXmlEquals(getResource("ProcessStep.xml"), xml, "xmlns:*", "xsi:schemaLocation");
         /*
-         * Final comparison: ensure that we didn't lost any information, then release.
+         * Final comparison: ensure that we didn't lost any information.
          */
         assertEquals(processStep, unmarshal(unmarshaller, xml));
         pool.recycle(unmarshaller);
         pool.recycle(marshaller);
     }
+
+    /**
+     * Tests the (un)marshalling of a {@code <gmd:EX_Extent>} object.
+     * This test opportunistically tests setting {@code "gml:id"} value.
+     *
+     * <p><b>XML test file:</b>
+     * <a href="{@scmUrl gmd-data}/Extent.xml">Extent.xml</a></p>
+     *
+     * @throws IOException   If an error occurred while reading the XML file.
+     * @throws JAXBException If an error occurred during the during marshalling / unmarshalling
processes.
+     *
+     * @since 0.4
+     */
+    @Test
+    public void testExtent() throws IOException, JAXBException {
+        final Marshaller   marshaller   = pool.acquireMarshaller();
+        final Unmarshaller unmarshaller = pool.acquireUnmarshaller();
+        final DefaultGeographicBoundingBox bbox = new DefaultGeographicBoundingBox(-99, -79,
14.9844, 31);
+        bbox.getIdentifierMap().put(IdentifierSpace.ID, "bbox");
+        final DefaultTemporalExtent temporal = new DefaultTemporalExtent();
+        if (PENDING_FUTURE_SIS_VERSION) {
+            // This block needs sis-temporal module.
+            temporal.setBounds(date("2010-01-27 13:26:10"), date("2010-08-27 13:26:10"));
+        }
+        final DefaultExtent extent = new DefaultExtent(null, bbox, null, temporal);
+        /*
+         * XML marshalling, and compare with the content of "ProcessStep.xml" file.
+         */
+        final String xml = marshal(marshaller, extent);
+        assertTrue(xml.startsWith("<?xml"));
+        assertXmlEquals(getResource("Extent.xml"), xml, "xmlns:*", "xsi:schemaLocation");
+        /*
+         * Final comparison: ensure that we didn't lost any information.
+         */
+        assertEquals(extent, unmarshal(unmarshaller, xml));
+        pool.recycle(unmarshaller);
+        pool.recycle(marshaller);
+    }
 }

Modified: sis/branches/JDK6/core/sis-metadata/src/test/resources/org/apache/sis/xml/PositionalAccuracy.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-metadata/src/test/resources/org/apache/sis/xml/PositionalAccuracy.xml?rev=1510391&r1=1510390&r2=1510391&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-metadata/src/test/resources/org/apache/sis/xml/PositionalAccuracy.xml
(original)
+++ sis/branches/JDK6/core/sis-metadata/src/test/resources/org/apache/sis/xml/PositionalAccuracy.xml
Mon Aug  5 08:52:15 2013
@@ -19,10 +19,10 @@
 -->
 
 <gmd:DQ_RelativeInternalPositionalAccuracy
-  xmlns:gmd = "http://www.isotc211.org/2005/gmd"
-  xmlns:gco = "http://www.isotc211.org/2005/gco"
-  xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
-  xsi:schemaLocation = "http://www.isotc211.org/2005/gmd http://schemas.opengis.net/iso/19139/20070417/gmd/gmd.xsd">
+    xmlns:gmd = "http://www.isotc211.org/2005/gmd"
+    xmlns:gco = "http://www.isotc211.org/2005/gco"
+    xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation = "http://www.isotc211.org/2005/gmd http://schemas.opengis.net/iso/19139/20070417/gmd/gmd.xsd">
 
   <!-- The <nameOfMeasure> element below is the main purpose of MetadataMarshallingTest.testPositionalAccuracy().
        The <result> element was added only in order to allow validation of this XML
file, with the addition of an

Modified: sis/branches/JDK6/core/sis-metadata/src/test/resources/org/apache/sis/xml/ProcessStep.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-metadata/src/test/resources/org/apache/sis/xml/ProcessStep.xml?rev=1510391&r1=1510390&r2=1510391&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-metadata/src/test/resources/org/apache/sis/xml/ProcessStep.xml
(original)
+++ sis/branches/JDK6/core/sis-metadata/src/test/resources/org/apache/sis/xml/ProcessStep.xml
Mon Aug  5 08:52:15 2013
@@ -19,11 +19,11 @@
 -->
 
 <gmd:LI_ProcessStep
-  xmlns:gmd = "http://www.isotc211.org/2005/gmd"
-  xmlns:gco = "http://www.isotc211.org/2005/gco"
-  xmlns:gmi = "http://www.isotc211.org/2005/gmi"
-  xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
-  xsi:schemaLocation = "http://www.isotc211.org/2005/gmd http://schemas.opengis.net/iso/19139/20070417/gmd/gmd.xsd">
+    xmlns:gmd = "http://www.isotc211.org/2005/gmd"
+    xmlns:gco = "http://www.isotc211.org/2005/gco"
+    xmlns:gmi = "http://www.isotc211.org/2005/gmi"
+    xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation = "http://www.isotc211.org/2005/gmd http://schemas.opengis.net/iso/19139/20070417/gmd/gmd.xsd">
 
   <!-- As of February 2011, there is not yet any XSD schema for the "gmi" namespace on
the
        OGC web site. Consequently the validation of this file does not work fully yet. -->

Modified: sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Boolean.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Boolean.java?rev=1510391&r1=1510390&r2=1510391&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Boolean.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Boolean.java
[UTF-8] Mon Aug  5 08:52:15 2013
@@ -44,7 +44,7 @@ public final class GO_Boolean extends Pr
      * @param value The value.
      */
     private GO_Boolean(final Boolean value) {
-        super(value, !value);
+        super(value, value.booleanValue() == false && value != Boolean.FALSE);
     }
 
     /**

Modified: sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/CodeListAdapter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/CodeListAdapter.java?rev=1510391&r1=1510390&r2=1510391&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/CodeListAdapter.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/CodeListAdapter.java
[UTF-8] Mon Aug  5 08:52:15 2013
@@ -74,23 +74,6 @@ public abstract class CodeListAdapter<Va
     }
 
     /**
-     * Forces the initialization of the given code list class, since some
-     * calls to {@link CodeList#valueOf(Class, String)} are done whereas
-     * the constructor has not already been called.
-     *
-     * @param <T>  The code list type.
-     * @param type The code list class to initialize.
-     */
-    protected static <T extends CodeList<T>> void ensureClassLoaded(final Class<T>
type) {
-        final String name = type.getName();
-        try {
-            Class.forName(name, true, type.getClassLoader());
-        } catch (ClassNotFoundException e) {
-            throw new TypeNotPresentException(name, e); // Should never happen.
-        }
-    }
-
-    /**
      * Wraps the proxy value into an adapter.
      *
      * @param proxy The proxy version of {@link CodeList}, to be marshalled.

Modified: sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/jdk7/Files.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/jdk7/Files.java?rev=1510391&r1=1510390&r2=1510391&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/jdk7/Files.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/jdk7/Files.java
[UTF-8] Mon Aug  5 08:52:15 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.sis.internal.jdk7;
 
+import java.util.Set;
 import java.io.File;
 import java.io.IOException;
 import java.io.RandomAccessFile;
@@ -45,22 +46,15 @@ public final class Files {
      * @return The channel.
      * @throws IOException If an error occurred while opening the channel.
      */
-    public static ByteChannel newByteChannel(final File file, final Object... options) throws
IOException {
+    public static ByteChannel newByteChannel(final File file, final Set<?> options)
throws IOException {
         String mode = "r";
         if (options != null) {
-            for (final Object option : options) {
-                final String s = option.toString().trim();
-                if (s.equalsIgnoreCase("WRITE")) {
-                    if (mode.length() == 1) { // Have precedence only over "r" mode.
-                        mode = "rw";
-                    }
-                } else if (s.equalsIgnoreCase("SYNC")) {
-                    mode = "rws";
-                    break; // Have precedence over all other modes.
-                } else if (s.equalsIgnoreCase("DSYNC")) {
-                    mode = "rwd";
-                    // Continue in case there is also a "rws".
-                }
+            if (options.contains(StandardOpenOption.DSYNC)) {
+                mode = "rwd";
+            } else if (options.contains(StandardOpenOption.SYNC)) {
+                mode = "rws";
+            } else if (options.contains(StandardOpenOption.WRITE)) {
+                mode = "rw";
             }
         }
         return new RandomAccessFile(file, mode).getChannel();

Added: sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/jdk7/StandardOpenOption.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/jdk7/StandardOpenOption.java?rev=1510391&view=auto
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/jdk7/StandardOpenOption.java
(added)
+++ sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/jdk7/StandardOpenOption.java
[UTF-8] Mon Aug  5 08:52:15 2013
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.jdk7;
+
+
+/**
+ * Place holder for {@link java.nio.file.StandardOpenOption}.
+ * This class exists only on the JDK6 branch of SIS.
+ *
+ * We simulate the enum by {@link String} values.
+ * This allow us to avoid putting a non-standard enum in public API.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.4
+ * @version 0.4
+ * @module
+ */
+public final class StandardOpenOption {
+    /**
+     * Do not allow instantiation of this class.
+     */
+    private StandardOpenOption() {
+    }
+
+    /** See {@link java.nio.file.StandardOpenOption#READ}. */
+    public static final String READ = "READ";
+
+    /** See {@link java.nio.file.StandardOpenOption#WRITE}. */
+    public static final String WRITE = "WRITE";
+
+    /** See {@link java.nio.file.StandardOpenOption#APPEND}. */
+    public static final String APPEND = "APPEND";
+
+    /** See {@link java.nio.file.StandardOpenOption#TRUNCATE_EXISTING}. */
+    public static final String TRUNCATE_EXISTING = "TRUNCATE_EXISTING";
+
+    /** See {@link java.nio.file.StandardOpenOption#DELETE_ON_CLOSE}. */
+    public static final String DELETE_ON_CLOSE = "DELETE_ON_CLOSE";
+
+    /** See {@link java.nio.file.StandardOpenOption#SYNC}. */
+    public static final String SYNC = "SYNC";
+
+    /** See {@link java.nio.file.StandardOpenOption#DSYNC}. */
+    public static final String DSYNC = "DSYNC";
+}

Propchange: sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/jdk7/StandardOpenOption.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Modified: sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java?rev=1510391&r1=1510390&r2=1510391&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java [UTF-8]
(original)
+++ sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java [UTF-8]
Mon Aug  5 08:52:15 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/JDK6/core/sis-utility/src/main/java/org/apache/sis/xml/NilReason.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/xml/NilReason.java?rev=1510391&r1=1510390&r2=1510391&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/xml/NilReason.java [UTF-8]
(original)
+++ sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/xml/NilReason.java [UTF-8]
Mon Aug  5 08:52:15 2013
@@ -461,7 +461,7 @@ public final class NilReason implements 
     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;
+        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

Modified: sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/test/TestCase.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/test/TestCase.java?rev=1510391&r1=1510390&r2=1510391&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/test/TestCase.java [UTF-8]
(original)
+++ sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/test/TestCase.java [UTF-8]
Mon Aug  5 08:52:15 2013
@@ -50,7 +50,7 @@ import static org.apache.sis.test.TestCo
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-3.16)
- * @version 0.3
+ * @version 0.4
  * @module
  */
 @RunWith(TestRunner.class)
@@ -72,6 +72,23 @@ public abstract strictfp class TestCase 
     public static final boolean PENDING_NEXT_GEOAPI_RELEASE = false;
 
     /**
+     * A flag for code that are pending future SIS development before to be enabled.
+     * This flag is always set to {@code false}. It shall be used as below:
+     *
+     * {@preformat java
+     *     if (PENDING_FUTURE_SIS_VERSION) {
+     *         // Do some stuff here.
+     *     }
+     * }
+     *
+     * The intend is to make easier to identify test cases that fail with the current version
+     * of SIS (e.g. because of unsupported operations), but should pass in a future version.
+     *
+     * @since 0.4
+     */
+    public static final boolean PENDING_FUTURE_SIS_VERSION = false;
+
+    /**
      * The output writer where to print debugging information (never {@code null}).
      * Texts sent to this printer will be show only if the test fails, or if the
      * {@value org.apache.sis.test.TestConfiguration#VERBOSE_OUTPUT_KEY} system property

Modified: sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/IOUtilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/IOUtilities.java?rev=1510391&r1=1510390&r2=1510391&view=diff
==============================================================================
--- sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/IOUtilities.java
[UTF-8] (original)
+++ sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/IOUtilities.java
[UTF-8] Mon Aug  5 08:52:15 2013
@@ -16,6 +16,11 @@
  */
 package org.apache.sis.internal.storage;
 
+import java.util.Set;
+import java.util.List;
+import java.util.HashSet;
+import java.util.Collections;
+import java.util.Arrays;
 import java.util.Locale;
 import java.io.File;
 import java.io.FileInputStream;
@@ -37,6 +42,7 @@ import org.apache.sis.util.resources.Err
 // Related to JDK7
 import org.apache.sis.internal.jdk7.Files;
 import org.apache.sis.internal.jdk7.StandardCharsets;
+import org.apache.sis.internal.jdk7.StandardOpenOption;
 
 
 /**
@@ -56,6 +62,12 @@ import org.apache.sis.internal.jdk7.Stan
  */
 public final class IOUtilities extends Static {
     /**
+     * Options to be rejected by {@link #open(Object, String, OpenOption[])} for safety reasons.
+     */
+    private static final List<String> ILLEGAL_OPTIONS = Arrays.asList( // EnumSet of
StandardOpenOption on JDK7 branch
+            StandardOpenOption.APPEND, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.DELETE_ON_CLOSE);
+
+    /**
      * Do not allow instantiation of this class.
      */
     private IOUtilities() {
@@ -278,14 +290,12 @@ public final class IOUtilities extends S
             return new File(uri);
         } catch (IllegalArgumentException cause) {
             /*
-             * Typically happen when the URI contains fragment that can not be represented
-             * in a File (e.g. a Query part), so it could be considered as if the URI with
-             * the fragment part can not represent an existing file.
+             * Typically happen when the URI scheme is not "file". But may also happen if
the
+             * URI contains fragment that can not be represented in a File (e.g. a Query
part).
+             * The IllegalArgumentException does not allow us to distinguish those cases.
              */
-            final MalformedURLException e = new MalformedURLException(Exceptions.formatChainedMessages(
-                    null, Errors.format(Errors.Keys.IllegalArgumentValue_2, "URL", url),
cause));
-            e.initCause(cause);
-            throw e;
+            throw new IOException(Exceptions.formatChainedMessages(null,
+                    Errors.format(Errors.Keys.IllegalArgumentValue_2, "URL", url), cause),
cause);
         }
     }
 
@@ -311,7 +321,10 @@ public final class IOUtilities extends S
         if (path == null) {
             return null;
         }
-        // Check if the path seems to be an ordinary file.
+        /*
+         * Check if the path seems to be a local file. Those paths are assumed never encoded.
+         * The heuristic rules applied here may change in any future SIS version.
+         */
         if (path.indexOf('?') < 0 && path.indexOf('#') < 0) {
             final int s = path.indexOf(':');
             /*
@@ -325,11 +338,14 @@ public final class IOUtilities extends S
         }
         final URL url = new URL(path);
         final String scheme = url.getProtocol();
-        if (scheme != null) {
-            if (scheme.equalsIgnoreCase("file")) {
-                return toFile(url, encoding);
-            }
+        if (scheme != null && scheme.equalsIgnoreCase("file")) {
+            return toFile(url, encoding);
         }
+        /*
+         * Leave the URL in its original encoding on the assumption that this is the encoding
expected by
+         * the server. This is different than the policy for URI, because the later are always
in UTF-8.
+         * If a URI is needed, callers should use toURI(url, encoding).
+         */
         return url;
     }
 
@@ -348,26 +364,49 @@ public final class IOUtilities extends S
      * The given options are used for opening the channel on a <em>best effort basis</em>.
      * In particular, even if the caller provided the {@code WRITE} option, he still needs
      * to verify if the returned channel implements {@link java.nio.channels.WritableByteChannel}.
+     * This is because the channel may be opened by {@link URL#openStream()}, in which case
the
+     * options are ignored.
+     *
+     * <p>The following options are illegal and will cause an exception to be thrown
if provided:
+     * {@code APPEND}, {@code TRUNCATE_EXISTING}, {@code DELETE_ON_CLOSE}. We reject those
options
+     * because this method is primarily designed for readable channels, with optional data
edition.
+     * Since the write option is not guaranteed to be honored, we have to reject the options
that
+     * would alter significatively the channel behavior depending on whether we have been
able to
+     * honor the options or not.</p>
      *
      * @param  input The file to open, or {@code null}.
-     * @param  encoding If the URL is encoded in a {@code application/x-www-form-urlencoded}
-     *         MIME format, the character encoding (normally {@code "UTF-8"}). If the URL
is
-     *         not encoded, then {@code null}. This argument is ignored if the given path
does
-     *         not need to be converted from URL to {@code File}.
-     * @param  options The options to use for creating a new byte channel, or an empty set
for read-only.
-     * @return The input stream for the given file, or {@code null} if the given type is
unknown.
+     * @param  encoding If the input is an encoded URL, the character encoding (normally
{@code "UTF-8"}).
+     *         If the URL is not encoded, then {@code null}. This argument is ignored if
the given input
+     *         does not need to be converted from URL to {@code File}.
+     * @param  options The options to use for creating a new byte channel. Can be null or
empty for read-only.
+     * @return The channel for the given input, or {@code null} if the given input is of
unknown type.
      * @throws IOException If an error occurred while opening the given file.
      */
     public static ReadableByteChannel open(Object input, final String encoding, Object...
options) throws IOException {
+        /*
+         * Unconditionally verify the options, even if we may not use them.
+         */
+        final Set<Object> optionSet;
+        if (options == null || options.length == 0) {
+            optionSet = Collections.emptySet();
+        } else {
+            optionSet = new HashSet<Object>(Arrays.asList(options));
+            optionSet.add(StandardOpenOption.READ);
+            if (optionSet.removeAll(ILLEGAL_OPTIONS)) {
+                throw new IllegalArgumentException(Errors.format(Errors.Keys.IllegalArgumentValue_2,
+                        "options", Arrays.toString(options)));
+            }
+        }
+        /*
+         * Check for inputs that are already readable channels or input streams. We perform
an explicit check
+         * for FileInputStream even if  Channels.newChannel(InputStream)  does this check
implicitly, because
+         * Channels.newChannel(…) restricts itself to the exact FileInputStream class while
we want to invoke
+         * getChannel() for any subclasses.
+         */
         if (input instanceof ReadableByteChannel) {
             return (ReadableByteChannel) input;
         }
         if (input instanceof InputStream) {
-            /*
-             * Channels.newChannel(InputStream) checks for FileInputStream, but it requires
that exact class.
-             * Concequently we have to perform our own check if we want to allow any FileInputStream
subclass
-             * to have their 'getChannel()' method invoked.
-             */
             if (input instanceof FileInputStream) {
                 return ((FileInputStream) input).getChannel();
             }
@@ -379,36 +418,55 @@ public final class IOUtilities extends S
          * In the following cases, we will try hard to convert to Path objects before to
fallback
          * on File, URL or URI, because only Path instances allow us to use the given OpenOptions.
          */
-        if (input instanceof CharSequence) { // Needs to be before the check for File or
URL.
-            input = toFileOrURL(input.toString(), encoding);
-        }
-        /*
-         * If the input is a File or a CharSequence that we have been able to convert to
a File,
-         * try to convert to a Path in order to be able to use the OpenOptions. Only if we
fail
-         * to convert to a Path (which is unlikely), we will use directly the File.
-         */
-        if (input instanceof File) {
-            return Files.newByteChannel((File) input, options);
-        }
-        /*
-         * If the user gave us a URI, try again to convert to a Path for the same reasons
than the above File case.
-         * A failure here is much more likely than in the File case, because JDK7 does not
provide file systems for
-         * HTTP or FTP protocols by default.
-         */
-        if (input instanceof URI) { // Needs to be before the check for URL.
+        if (input instanceof URL) {
+            try {
+                input = toFile((URL) input, encoding);
+            } catch (IOException e) {
+                // This is normal if the URL uses HTTP or FTP protocol for instance.
+                // Log the exception at FINE level without stack trace. We will open
+                // the channel later using the URL instead than using the Path.
+                recoverableException(e);
+            }
+        } else if (input instanceof URI) {
+            /*
+             * If the user gave us a URI, try to convert to a Path before to fallback to
URL, in order to be
+             * able to use the given OpenOptions.  Note that the conversion to Path is likely
to fail if the
+             * URL uses HTTP or FTP protocols, because JDK7 does not provide file systems
for them by default.
+             */
             final URI uri = (URI) input;
             try {
-                return Files.newByteChannel(new File(uri), options);
+                input = new File(uri);
             } catch (IllegalArgumentException e) {
                 input = uri.toURL();
-                // We have been able to create a channel, maybe not with the given OpenOptions.
-                // Log the exception at a fine level and without stack trace, because it
was probably normal.
-                Logging.recoverableException(Logging.getLogger("org.apache.sis.storage"),
IOUtilities.class, "open", e);
+                // We have been able to convert to URL, but the given OpenOptions may not
be used.
+                // Log the exception at FINE level without stack trace, because the exception
is
+                // probably a normal behavior in this context.
+                recoverableException(e);
+            }
+        } else {
+            if (input instanceof CharSequence) { // Needs to be before the check for File
or URL.
+                input = toFileOrURL(input.toString(), encoding);
             }
         }
+        /*
+         * One last check for URL. The URL may be either the given input if we have not been
able
+         * to convert it to a Path, or a URI, File or CharSequence input converted to URL.
Do not
+         * try to convert the URL to a Path, because this has already been tried before this
point.
+         */
         if (input instanceof URL) {
             return Channels.newChannel(((URL) input).openStream());
         }
+        if (input instanceof File) {
+            return Files.newByteChannel((File) input, optionSet);
+        }
         return null;
     }
+
+    /**
+     * Invoked for reporting exceptions that may be normal behavior. This method logs
+     * the exception at {@link java.util.logging.Level#FINE} without stack trace.
+     */
+    private static void recoverableException(final Exception warning) {
+        Logging.recoverableException(Logging.getLogger("org.apache.sis.storage"), IOUtilities.class,
"open", warning);
+    }
 }

Modified: sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java?rev=1510391&r1=1510390&r2=1510391&view=diff
==============================================================================
--- sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java
[UTF-8] (original)
+++ sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java
[UTF-8] Mon Aug  5 08:52:15 2013
@@ -41,6 +41,8 @@ import org.apache.sis.internal.jdk7.Auto
  * @since   0.3
  * @version 0.3
  * @module
+ *
+ * @see DataStores#open(Object)
  */
 public abstract class DataStore implements Localized, AutoCloseable {
     /**

Modified: sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreProvider.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreProvider.java?rev=1510391&r1=1510390&r2=1510391&view=diff
==============================================================================
--- sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreProvider.java
[UTF-8] (original)
+++ sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreProvider.java
[UTF-8] Mon Aug  5 08:52:15 2013
@@ -75,10 +75,10 @@ public abstract class DataStoreProvider 
      * only that there appears to be a reasonable chance of success based on a brief inspection
of the
      * {@linkplain StorageConnector#getStorage() storage object} or contents.
      *
-     * Implementors are responsible for restoring the input to its original stream position
on return of this method.
+     * <p>Implementors are responsible for restoring the input to its original stream
position on return of this method.
      * Implementors can use a mark/reset pair for this purpose. Marks are available as
      * {@link java.nio.ByteBuffer#mark()}, {@link java.io.InputStream#mark(int)} and
-     * {@link javax.imageio.stream.ImageInputStream#mark()}.
+     * {@link javax.imageio.stream.ImageInputStream#mark()}.</p>
      *
      * {@section Implementation example}
      * Implementations will typically check the first bytes of the stream for a "magic number"
associated
@@ -127,7 +127,7 @@ public abstract class DataStoreProvider 
      * @throws IllegalArgumentException If the set contains an invalid combination of options.
      * @throws DataStoreException If an error occurred while creating the data store instance.
      *
-     * @see DataStores#open(Object, Set)
+     * @see DataStores#open(Object)
      */
     public abstract DataStore open(StorageConnector storage) throws DataStoreException;
 }

Modified: sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStores.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStores.java?rev=1510391&r1=1510390&r2=1510391&view=diff
==============================================================================
--- sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStores.java
[UTF-8] (original)
+++ sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStores.java
[UTF-8] Mon Aug  5 08:52:15 2013
@@ -22,7 +22,7 @@ import org.apache.sis.internal.system.Sy
 
 
 /**
- * Creates {@link DataStore} instances from a given storage object.
+ * Static convenience methods creating {@link DataStore} instances from a given storage object.
  * Storage objects are typically {@link java.io.File} or {@link javax.sql.DataSource} instances,
  * but can also be any other objects documented in the {@link StorageConnector} class.
  *

Modified: sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/ProbeResult.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/ProbeResult.java?rev=1510391&r1=1510390&r2=1510391&view=diff
==============================================================================
--- sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/ProbeResult.java
[UTF-8] (original)
+++ sis/branches/JDK6/storage/sis-storage/src/main/java/org/apache/sis/storage/ProbeResult.java
[UTF-8] Mon Aug  5 08:52:15 2013
@@ -18,7 +18,7 @@ package org.apache.sis.storage;
 
 
 /**
- * Tells whether a storage (file, database, <i>etc.</i>) appears to be supported
by a {@code DataStore}.
+ * Tells whether a storage (file, database) appears to be supported by a {@code DataStore}.
  * There is three categories of values in this enumeration:
  *
  * <ul>
@@ -27,7 +27,8 @@ package org.apache.sis.storage;
  *       whether the storage can be opened. SIS will try to use such provider last, if no
better suited
  *       provider is found.</li>
  *   <li>All other values indicate that the storage can not be opened. The actual enumeration
value gives
- *       the reason (e.g. unknown format, or unsupported version).</li>
+ *       the reason (e.g. {@linkplain #UNKNOWN_FORMAT unknown format}, or
+ *       {@linkplain #UNSUPPORTED_VERSION unsupported version}).</li>
  * </ul>
  *
  * When a {@link DataStores#open DataStores.open(…)} method is invoked, SIS will iterate
over the list of known



Mime
View raw message