sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1454870 - /sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/
Date Sun, 10 Mar 2013 16:10:57 GMT
Author: desruisseaux
Date: Sun Mar 10 16:10:57 2013
New Revision: 1454870

URL: http://svn.apache.org/r1454870
Log:
Added remaining converters. We still need to tune them, especially
regarding the value returned by properties() and inverse().

Added:
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/CollectionConverter.java   (with props)
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/DateConverter.java   (with props)
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/FileConverter.java   (with props)
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/InjectiveConverter.java
      - copied, changed from r1454769, sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/SurjectiveConverter.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/LongConverter.java   (with props)
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/NumberConverter.java   (with props)
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/URIConverter.java   (with props)
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/URLConverter.java   (with props)
Modified:
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/StringConverter.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/SurjectiveConverter.java

Added: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/CollectionConverter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/CollectionConverter.java?rev=1454870&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/CollectionConverter.java (added)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/CollectionConverter.java [UTF-8] Sun Mar 10 16:10:57 2013
@@ -0,0 +1,122 @@
+/*
+ * 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.converter;
+
+import java.util.Collection;
+import java.util.ArrayList;
+import java.util.LinkedHashSet;
+import java.io.Serializable;
+import java.io.ObjectStreamException;
+import net.jcip.annotations.Immutable;
+
+
+/**
+ * Handles conversions from {@link Collection} to various objects.
+ * The source class is fixed to {@code Collection}. The target class is determined
+ * by the inner class which extends this {@code CollectionConverter} class.
+ *
+ * <p>All subclasses will have a unique instance. For this reason, it is not necessary to
+ * override the {@code hashCode()} and {@code equals(Object)} methods, since identity
+ * comparisons will work just well.</p>
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-3.02)
+ * @version 0.3
+ * @module
+ */
+@Immutable
+abstract class CollectionConverter<T> extends SurjectiveConverter<Collection<?>,T> implements Serializable {
+    /**
+     * For cross-version compatibility.
+     */
+    private static final long serialVersionUID = -4515250904953131514L;
+
+    /**
+     * Returns the source class, which is always {@link Collection}.
+     */
+    @Override
+    @SuppressWarnings({"unchecked","rawtypes"})
+    public final Class<Collection<?>> getSourceClass() {
+        return (Class) Collection.class;
+    }
+
+
+    /**
+     * Converter from {@link Collection} to {@link java.util.List}.
+     */
+    @Immutable
+    static final class List extends CollectionConverter<java.util.List<?>> {
+        /** Cross-version compatibility. */ static final long serialVersionUID = 5492247760609833586L;
+        /** The unique, shared instance. */ static final List INSTANCE = new List();
+        /** For {@link #INSTANCE} only.  */ private List() {}
+
+        @Override
+        @SuppressWarnings({"unchecked","rawtypes"})
+        public Class<java.util.List<?>> getTargetClass() {
+            return (Class) java.util.List.class;
+        }
+
+        @Override
+        public java.util.List<?> convert(final Collection<?> source) {
+            if (source == null) {
+                return null;
+            }
+            if (source instanceof java.util.List<?>) {
+                return (java.util.List<?>) source;
+            }
+            return new ArrayList<>(source);
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+
+    /**
+     * Converter from {@link Collection} to {@link java.util.Set}.
+     */
+    @Immutable
+    static final class Set extends CollectionConverter<java.util.Set<?>> {
+        /** Cross-version compatibility. */ static final long serialVersionUID = -4200659837453206164L;
+        /** The unique, shared instance. */ static final Set INSTANCE = new Set();
+        /** For {@link #INSTANCE} only.  */ private Set() {}
+
+        @Override
+        @SuppressWarnings({"unchecked","rawtypes"})
+        public Class<java.util.Set<?>> getTargetClass() {
+            return (Class) java.util.Set.class;
+        }
+
+        @Override
+        public java.util.Set<?> convert(final Collection<?> source) {
+            if (source == null) {
+                return null;
+            }
+            if (source instanceof java.util.Set<?>) {
+                return (java.util.Set<?>) source;
+            }
+            return new LinkedHashSet<>(source);
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+}

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

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

Added: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/DateConverter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/DateConverter.java?rev=1454870&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/DateConverter.java (added)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/DateConverter.java [UTF-8] Sun Mar 10 16:10:57 2013
@@ -0,0 +1,150 @@
+/*
+ * 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.converter;
+
+import java.util.Date;
+import java.util.Set;
+import java.util.EnumSet;
+import java.io.Serializable;
+import java.io.ObjectStreamException;
+import net.jcip.annotations.Immutable;
+import org.apache.sis.util.ObjectConverter;
+import org.apache.sis.math.FunctionProperty;
+
+
+/**
+ * Handles conversions from {@link Date} to various objects.
+ *
+ * {@section String representation}
+ * There is currently no converter between {@link String} and {@link java.util.Date} because the
+ * date format is not yet defined (we are considering the ISO format for a future SIS version).
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-2.4)
+ * @version 0.3
+ * @module
+ */
+@Immutable
+abstract class DateConverter<T> extends SurjectiveConverter<Date,T> implements Serializable {
+    /**
+     * For cross-version compatibility.
+     */
+    private static final long serialVersionUID = -7770401534710581917L;
+
+    /**
+     * For inner classes only.
+     */
+    DateConverter() {
+    }
+
+    /**
+     * Returns the function properties.
+     */
+    @Override
+    public Set<FunctionProperty> properties() {
+        return EnumSet.of(FunctionProperty.SURJECTIVE, FunctionProperty.ORDER_PRESERVING);
+    }
+
+    /**
+     * Returns the source class, which is always {@link Date}.
+     */
+    @Override
+    public final Class<Date> getSourceClass() {
+        return Date.class;
+    }
+
+    /**
+     * Converter from dates to long integers.
+     */
+    @Immutable
+    static final class Long extends DateConverter<java.lang.Long> {
+        /** Cross-version compatibility. */ static final long serialVersionUID = 3163928356094316134L;
+        /** The unique, shared instance. */ static final Long INSTANCE = new Long();
+        /** For {@link #INSTANCE} only.  */ private Long() {}
+
+        /** Returns the function properties, which is bijective. */
+        @Override public Set<FunctionProperty> properties() {
+            return EnumSet.of(FunctionProperty.INJECTIVE, FunctionProperty.SURJECTIVE,
+                    FunctionProperty.ORDER_PRESERVING, FunctionProperty.INVERTIBLE);
+        }
+
+        @Override public Class<java.lang.Long> getTargetClass() {
+            return java.lang.Long.class;
+        }
+
+        @Override public java.lang.Long convert(final Date source) {
+            return (source != null) ? source.getTime() : null;
+        }
+
+        @Override public ObjectConverter<java.lang.Long, Date> inverse() {
+            return LongConverter.Date.INSTANCE;
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+    /**
+     * Converter from dates to SQL dates.
+     */
+    @Immutable
+    static final class SQL extends DateConverter<java.sql.Date> {
+        /** Cross-version compatibility. */ static final long serialVersionUID = -3644605344718636345L;
+        /** The unique, shared instance. */ static final SQL INSTANCE = new SQL();
+        /** For {@link #INSTANCE} only.  */ private SQL() {}
+
+        @Override public Class<java.sql.Date> getTargetClass() {
+            return java.sql.Date.class;
+        }
+
+        @Override public java.sql.Date convert(final Date source) {
+            return (source != null) ? new java.sql.Date(source.getTime()) : null;
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+    /**
+     * Converter from dates to timestamps. This converter is not injective, because
+     * the same date could be mapped to many timestamps since timestamps have an
+     * additional nanoseconds field.
+     */
+    @Immutable
+    static final class Timestamp extends DateConverter<java.sql.Timestamp> {
+        /** Cross-version compatibility. */ static final long serialVersionUID = 3798633184562706892L;
+        /** The unique, shared instance. */ static final Timestamp INSTANCE = new Timestamp();
+        /** For {@link #INSTANCE} only.  */ private Timestamp() {}
+
+        @Override public Class<java.sql.Timestamp> getTargetClass() {
+            return java.sql.Timestamp.class;
+        }
+
+        @Override public java.sql.Timestamp convert(final Date source) {
+            return (source != null) ? new java.sql.Timestamp(source.getTime()) : null;
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+}

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

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

Added: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/FileConverter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/FileConverter.java?rev=1454870&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/FileConverter.java (added)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/FileConverter.java [UTF-8] Sun Mar 10 16:10:57 2013
@@ -0,0 +1,145 @@
+/*
+ * 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.converter;
+
+import java.io.File;
+import java.io.Serializable;
+import java.io.ObjectStreamException;
+import java.net.MalformedURLException;
+import net.jcip.annotations.Immutable;
+import org.apache.sis.util.ObjectConverter;
+import org.apache.sis.util.UnconvertibleObjectException;
+
+
+/**
+ * Handles conversions from {@link File} to various objects.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-3.01)
+ * @version 0.3
+ * @module
+ */
+@Immutable
+abstract class FileConverter<T> extends InjectiveConverter<File,T> implements Serializable {
+    /**
+     * For cross-version compatibility.
+     */
+    private static final long serialVersionUID = -2150865427977735620L;
+
+    /**
+     * For inner classes only.
+     */
+    FileConverter() {
+    }
+
+    /**
+     * Returns the source class, which is always {@link File}.
+     */
+    @Override
+    public final Class<File> getSourceClass() {
+        return File.class;
+    }
+
+    /**
+     * Converter from {@link File} to {@link java.lang.String}.
+     */
+    @Immutable
+    static final class String extends FileConverter<java.lang.String> {
+        /** Cross-version compatibility. */ static final long serialVersionUID = -6811286687809954151L;
+        /** The unique, shared instance. */ static final String INSTANCE = new String();
+        /** For {@link #INSTANCE} only.  */ private String() {}
+
+        @Override public Class<java.lang.String> getTargetClass() {
+            return java.lang.String.class;
+        }
+
+        @Override public java.lang.String convert(final File source) {
+            return (source != null) ? source.getAbsolutePath() : null;
+        }
+
+        /** Returns the inverse, since this converter is "almost" bijective. */
+        @Override public ObjectConverter<java.lang.String, File> inverse() {
+            return StringConverter.File.INSTANCE;
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+    /**
+     * Converter from {@link File} to {@link java.net.URI}.
+     */
+    @Immutable
+    static final class URI extends FileConverter<java.net.URI> {
+        /** Cross-version compatibility. */ static final long serialVersionUID = 1032598133849975567L;
+        /** The unique, shared instance. */ static final URI INSTANCE = new URI();
+        /** For {@link #INSTANCE} only.  */ private URI() {}
+
+        @Override public Class<java.net.URI> getTargetClass() {
+            return java.net.URI.class;
+        }
+
+        @Override public java.net.URI convert(final File source) {
+            return (source != null) ? source.toURI() : null;
+        }
+
+        @Override public ObjectConverter<java.net.URI, File> inverse() {
+            return URIConverter.File.INSTANCE;
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+    /**
+     * Converter from {@link File} to {@link java.net.URL}.
+     */
+    @Immutable
+    static final class URL extends FileConverter<java.net.URL> {
+        /** Cross-version compatibility. */ static final long serialVersionUID = 621496099287330756L;
+        /** The unique, shared instance. */ static final URL INSTANCE = new URL();
+        /** For {@link #INSTANCE} only.  */ private URL() {}
+
+        @Override public Class<java.net.URL> getTargetClass() {
+            return java.net.URL.class;
+        }
+
+        @Override public java.net.URL convert(final File source) throws UnconvertibleObjectException {
+            if (source == null) {
+                return null;
+            }
+            try {
+                return source.toURI().toURL();
+            } catch (MalformedURLException e) {
+                throw new UnconvertibleObjectException(formatErrorMessage(source), e);
+            }
+        }
+
+        @Override public ObjectConverter<java.net.URL, File> inverse() {
+            return URLConverter.File.INSTANCE;
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+}

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

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

Copied: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/InjectiveConverter.java (from r1454769, sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/SurjectiveConverter.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/InjectiveConverter.java?p2=sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/InjectiveConverter.java&p1=sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/SurjectiveConverter.java&r1=1454769&r2=1454870&rev=1454870&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/SurjectiveConverter.java [UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/InjectiveConverter.java [UTF-8] Sun Mar 10 16:10:57 2013
@@ -25,11 +25,9 @@ import org.apache.sis.util.resources.Err
 
 
 /**
- * Base class for non-invertible surjective {@link ObjectConverter}s.
- * Surjective converters are converters for which many different source values can produce
- * the same target value. In many cases, the target value having many possible sources is
- * the {@code null} value. This is the case in particular when the converter is used as a
- * filter.
+ * Base class for (usually invertible) injective {@link ObjectConverter}s.
+ * Injective converters are converters for which each source value can produce
+ * only one target value.
  *
  * <p>This base class is stateless. Consequently sub-classes that choose to implement
  * {@link java.io.Serializable} do not need to care about this base class.</p>
@@ -41,31 +39,23 @@ import org.apache.sis.util.resources.Err
  * @since   0.3
  * @version 0.3
  * @module
+ *
+ * @see SurjectiveConverter
  */
-public abstract class SurjectiveConverter<S,T> implements ObjectConverter<S,T> {
+public abstract class InjectiveConverter<S,T> implements ObjectConverter<S,T> {
     /**
      * Creates a new converter.
      */
-    protected SurjectiveConverter() {
+    protected InjectiveConverter() {
     }
 
     /**
-     * Returns {@link FunctionProperty#SURJECTIVE} by default.
+     * Returns {@link FunctionProperty#INJECTIVE} and {@link FunctionProperty#INVERTIBLE} by default.
      * Subclasses may add more properties (order preserving, <i>etc.</i>).
      */
     @Override
     public Set<FunctionProperty> properties() {
-        return EnumSet.of(FunctionProperty.SURJECTIVE);
-    }
-
-    /**
-     * Unsupported operation, since surjective converters are non-invertible
-     * (unless the converter is bijective, which is decided by subclasses).
-     */
-    @Override
-    public ObjectConverter<T,S> inverse() throws UnsupportedOperationException {
-        throw new UnsupportedOperationException(Errors.format(
-                Errors.Keys.UnsupportedOperation_1, "inverse"));
+        return EnumSet.of(FunctionProperty.INJECTIVE, FunctionProperty.INVERTIBLE);
     }
 
     /**

Added: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/LongConverter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/LongConverter.java?rev=1454870&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/LongConverter.java (added)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/LongConverter.java [UTF-8] Sun Mar 10 16:10:57 2013
@@ -0,0 +1,80 @@
+/*
+ * 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.converter;
+
+import java.io.Serializable;
+import java.io.ObjectStreamException;
+import net.jcip.annotations.Immutable;
+import org.apache.sis.util.ObjectConverter;
+
+
+/**
+ * Handles conversions from {@link java.lang.Long} to various objects.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-2.4)
+ * @version 0.3
+ * @module
+ */
+@Immutable
+abstract class LongConverter<T> extends InjectiveConverter<Long,T> implements Serializable {
+    /**
+     * For cross-version compatibility.
+     */
+    private static final long serialVersionUID = -7313843433890738313L;
+
+    /**
+     * For inner classes only.
+     */
+    LongConverter() {
+    }
+
+    /**
+     * Returns the source class, which is always {@link Long}.
+     */
+    @Override
+    public final Class<Long> getSourceClass() {
+        return Long.class;
+    }
+
+    /**
+     * Converter from long integers to dates.
+     */
+    @Immutable
+    static final class Date extends LongConverter<java.util.Date> {
+        /** Cross-version compatibility. */ static final long serialVersionUID = 3999693055029959455L;
+        /** The unique, shared instance. */ static final Date INSTANCE = new Date();
+        /** For {@link #INSTANCE} only.  */ private Date() {}
+
+        @Override public Class<java.util.Date> getTargetClass() {
+            return java.util.Date.class;
+        }
+
+        @Override public java.util.Date convert(final Long target) {
+            return (target != null) ? new java.util.Date(target) : null;
+        }
+
+        @Override public ObjectConverter<java.util.Date, Long> inverse() {
+            return DateConverter.Long.INSTANCE;
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+}

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

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

Added: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/NumberConverter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/NumberConverter.java?rev=1454870&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/NumberConverter.java (added)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/NumberConverter.java [UTF-8] Sun Mar 10 16:10:57 2013
@@ -0,0 +1,313 @@
+/*
+ *    Geotoolkit.org - An Open Source Java GIS Toolkit
+ *    http://www.geotoolkit.org
+ *
+ *    (C) 2007-2012, Open Source Geospatial Foundation (OSGeo)
+ *    (C) 2009-2012, Geomatys
+ *
+ *    This library is free software; you can redistribute it and/or
+ *    modify it under the terms of the GNU Lesser General Public
+ *    License as published by the Free Software Foundation;
+ *    version 2.1 of the License.
+ *
+ *    This library is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *    Lesser General Public License for more details.
+ */
+package org.apache.sis.internal.converter;
+
+import java.io.Serializable;
+import java.io.ObjectStreamException;
+import net.jcip.annotations.Immutable;
+import org.apache.sis.util.Numbers;
+
+
+/**
+ * Handles conversions from {@link java.lang.Number} to various objects.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-2.4)
+ * @version 0.3
+ * @module
+ */
+@Immutable
+abstract class NumberConverter<T> extends SurjectiveConverter<Number,T> implements Serializable {
+    /**
+     * For cross-version compatibility.
+     */
+    private static final long serialVersionUID = -8715054480508622025L;
+
+    /**
+     * For inner classes only.
+     */
+    NumberConverter() {
+    }
+
+    /**
+     * Returns the source class, which is always {@link Number}.
+     */
+    @Override
+    public final Class<Number> getSourceClass() {
+        return Number.class;
+    }
+
+    /**
+     * Converter from numbers to comparables. This special case exists because {@link Number}
+     * does not implement {@link java.lang.Comparable} directly, but all known subclasses do.
+     */
+    @Immutable
+    static final class Comparable extends NumberConverter<java.lang.Comparable<?>> {
+        /** Cross-version compatibility. */ static final long serialVersionUID = 3716134638218072176L;
+        /** The unique, shared instance. */ static final Comparable INSTANCE = new Comparable();
+        /** For {@link #INSTANCE} only.  */ private Comparable() {}
+
+        @Override
+        @SuppressWarnings({"rawtypes","unchecked"})
+        public Class<java.lang.Comparable<?>> getTargetClass() {
+            return (Class) java.lang.Comparable.class;
+        }
+
+        @Override public java.lang.Comparable<?> convert(final Number source) {
+            if (source == null || source instanceof java.lang.Comparable<?>) {
+                return (java.lang.Comparable<?>) source;
+            }
+            return (java.lang.Comparable<?>) Numbers.narrowestNumber(source);
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+    /**
+     * Converter from numbers to strings.
+     */
+    @Immutable
+    static final class String extends NumberConverter<java.lang.String> {
+        /** Cross-version compatibility. */ static final long serialVersionUID = 1460382215827540172L;
+        /** The unique, shared instance. */ static final String INSTANCE = new String();
+        /** For {@link #INSTANCE} only.  */ private String() {}
+
+        @Override public Class<java.lang.String> getTargetClass() {
+            return java.lang.String.class;
+        }
+
+        @Override public java.lang.String convert(final Number source) {
+            return (source != null) ? source.toString() : null;
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+    /**
+     * Converter from numbers to doubles.
+     */
+    @Immutable
+    static final class Double extends NumberConverter<java.lang.Double> {
+        /** Cross-version compatibility. */ static final long serialVersionUID = 1643009985070268985L;
+        /** The unique, shared instance. */ static final Double INSTANCE = new Double();
+        /** For {@link #INSTANCE} only.  */ private Double() {}
+
+        @Override public Class<java.lang.Double> getTargetClass() {
+            return java.lang.Double.class;
+        }
+
+        @Override public java.lang.Double convert(final Number source) {
+            return (source != null) ? java.lang.Double.valueOf(source.doubleValue()) : null;
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+    /**
+     * Converter from numbers to floats.
+     */
+    @Immutable
+    static final class Float extends NumberConverter<java.lang.Float> {
+        /** Cross-version compatibility. */ static final long serialVersionUID = -5900985555014433974L;
+        /** The unique, shared instance. */ static final Float INSTANCE = new Float();
+        /** For {@link #INSTANCE} only.  */ private Float() {}
+
+        @Override public Class<java.lang.Float> getTargetClass() {
+            return java.lang.Float.class;
+        }
+
+        @Override public java.lang.Float convert(final Number source) {
+            return (source != null) ? java.lang.Float.valueOf(source.floatValue()) : null;
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+    /**
+     * Converter from numbers to longs.
+     */
+    @Immutable
+    static final class Long extends NumberConverter<java.lang.Long> {
+        /** Cross-version compatibility. */ static final long serialVersionUID = -5320144566275003574L;
+        /** The unique, shared instance. */ static final Long INSTANCE = new Long();
+        /** For {@link #INSTANCE} only.  */ private Long() {}
+
+        @Override public Class<java.lang.Long> getTargetClass() {
+            return java.lang.Long.class;
+        }
+
+        @Override public java.lang.Long convert(final Number source) {
+            return (source != null) ? java.lang.Long.valueOf(source.longValue()) : null;
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+    /**
+     * Converter from numbers to integers.
+     */
+    @Immutable
+    static final class Integer extends NumberConverter<java.lang.Integer> {
+        /** Cross-version compatibility. */ static final long serialVersionUID = 2661178278691398269L;
+        /** The unique, shared instance. */ static final Integer INSTANCE = new Integer();
+        /** For {@link #INSTANCE} only.  */ private Integer() {}
+
+        @Override public Class<java.lang.Integer> getTargetClass() {
+            return java.lang.Integer.class;
+        }
+
+        @Override public java.lang.Integer convert(final Number source) {
+            return (source != null) ? java.lang.Integer.valueOf(source.intValue()) : null;
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+    /**
+     * Converter from numbers to shorts.
+     */
+    @Immutable
+    static final class Short extends NumberConverter<java.lang.Short> {
+        /** Cross-version compatibility. */ static final long serialVersionUID = -5943559376400249179L;
+        /** The unique, shared instance. */ static final Short INSTANCE = new Short();
+        /** For {@link #INSTANCE} only.  */ private Short() {}
+
+        @Override public Class<java.lang.Short> getTargetClass() {
+            return java.lang.Short.class;
+        }
+
+        @Override public java.lang.Short convert(final Number source) {
+            return (source != null) ? java.lang.Short.valueOf(source.shortValue()) : null;
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+    /**
+     * Converter from numbers to shorts.
+     */
+    @Immutable
+    static final class Byte extends NumberConverter<java.lang.Byte> {
+        /** Cross-version compatibility. */ static final long serialVersionUID = 1381038535870541045L;
+        /** The unique, shared instance. */ static final Byte INSTANCE = new Byte();
+        /** For {@link #INSTANCE} only.  */ private Byte() {}
+
+        @Override public Class<java.lang.Byte> getTargetClass() {
+            return java.lang.Byte.class;
+        }
+
+        @Override public java.lang.Byte convert(final Number source) {
+            return (source != null) ? java.lang.Byte.valueOf(source.byteValue()) : null;
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+    /**
+     * Converter from numbers to {@link java.math.BigDecimal}.
+     */
+    @Immutable
+    static final class BigDecimal extends NumberConverter<java.math.BigDecimal> {
+        /** Cross-version compatibility. */ static final long serialVersionUID = -6318144992861058878L;
+        /** The unique, shared instance. */ static final BigDecimal INSTANCE = new BigDecimal();
+        /** For {@link #INSTANCE} only.  */ private BigDecimal() {
+        }
+
+        @Override public Class<java.math.BigDecimal> getTargetClass() {
+            return java.math.BigDecimal.class;
+        }
+
+        @Override public java.math.BigDecimal convert(final Number source) {
+            if (source == null) {
+                return null;
+            }
+            if (source instanceof java.math.BigDecimal) {
+                return (java.math.BigDecimal) source;
+            }
+            if (source instanceof java.math.BigInteger) {
+                return new java.math.BigDecimal((java.math.BigInteger) source);
+            }
+            if (Numbers.isInteger(source.getClass())) {
+                return java.math.BigDecimal.valueOf(source.longValue());
+            }
+            return java.math.BigDecimal.valueOf(source.doubleValue());
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+    /**
+     * Converter from numbers to {@link java.math.BigInteger}.
+     */
+    @Immutable
+    static final class BigInteger extends NumberConverter<java.math.BigInteger> {
+        /** Cross-version compatibility. */ static final long serialVersionUID = 5940724099300523246L;
+        /** The unique, shared instance. */ static final BigInteger INSTANCE = new BigInteger();
+        /** For {@link #INSTANCE} only.  */ private BigInteger() {
+        }
+
+        @Override public Class<java.math.BigInteger> getTargetClass() {
+            return java.math.BigInteger.class;
+        }
+
+        @Override public java.math.BigInteger convert(final Number source) {
+            if (source == null) {
+                return null;
+            }
+            if (source instanceof java.math.BigInteger) {
+                return (java.math.BigInteger) source;
+            }
+            if (source instanceof java.math.BigDecimal) {
+                return ((java.math.BigDecimal) source).toBigInteger();
+            }
+            return java.math.BigInteger.valueOf(source.longValue());
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+}

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

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

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/StringConverter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/StringConverter.java?rev=1454870&r1=1454869&r2=1454870&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/StringConverter.java [UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/StringConverter.java [UTF-8] Sun Mar 10 16:10:57 2013
@@ -30,6 +30,7 @@ import org.apache.sis.math.FunctionPrope
 import org.apache.sis.util.Locales;
 import org.apache.sis.util.Numbers;
 import org.apache.sis.util.CharSequences;
+import org.apache.sis.util.ObjectConverter;
 import org.apache.sis.util.UnconvertibleObjectException;
 import org.apache.sis.util.iso.Types;
 import org.apache.sis.util.iso.SimpleInternationalString;
@@ -57,6 +58,12 @@ abstract class StringConverter<T> extend
     private static final long serialVersionUID = -3397013355582381432L;
 
     /**
+     * For inner classes only.
+     */
+    StringConverter() {
+    }
+
+    /**
      * Returns the source class, which is always {@link String}.
      */
     @Override
@@ -425,6 +432,8 @@ abstract class StringConverter<T> extend
 
     /**
      * Converter from {@link String} to {@link java.io.File}.
+     * This converter is almost bijective, but not completely since various path separators
+     * ({@code '/'} and {@code '\'}) produce the same {@code File} object.
      */
     @Immutable
     static final class File extends StringConverter<java.io.File> {
@@ -440,6 +449,11 @@ abstract class StringConverter<T> extend
             return new java.io.File(source);
         }
 
+        /** Returns the inverse, since this converter is "almost" bijective. */
+        @Override public ObjectConverter<java.io.File, String> inverse() {
+            return FileConverter.String.INSTANCE;
+        }
+
         /** Returns the singleton instance on deserialization. */
         Object readResolve() throws ObjectStreamException {
             return INSTANCE;
@@ -486,6 +500,11 @@ abstract class StringConverter<T> extend
             return new java.net.URI(source);
         }
 
+        /** Returns the inverse, since this converter is "almost" bijective. */
+        @Override public ObjectConverter<java.net.URI, String> inverse() {
+            return URIConverter.String.INSTANCE;
+        }
+
         /** Returns the singleton instance on deserialization. */
         Object readResolve() throws ObjectStreamException {
             return INSTANCE;
@@ -509,6 +528,11 @@ abstract class StringConverter<T> extend
             return new java.net.URL(source);
         }
 
+        /** Returns the inverse, since this converter is "almost" bijective. */
+        @Override public ObjectConverter<java.net.URL, String> inverse() {
+            return URLConverter.String.INSTANCE;
+        }
+
         /** Returns the singleton instance on deserialization. */
         Object readResolve() throws ObjectStreamException {
             return INSTANCE;

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/SurjectiveConverter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/SurjectiveConverter.java?rev=1454870&r1=1454869&r2=1454870&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/SurjectiveConverter.java [UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/SurjectiveConverter.java [UTF-8] Sun Mar 10 16:10:57 2013
@@ -25,7 +25,7 @@ import org.apache.sis.util.resources.Err
 
 
 /**
- * Base class for non-invertible surjective {@link ObjectConverter}s.
+ * Base class for (usually non-invertible) surjective {@link ObjectConverter}s.
  * Surjective converters are converters for which many different source values can produce
  * the same target value. In many cases, the target value having many possible sources is
  * the {@code null} value. This is the case in particular when the converter is used as a
@@ -41,6 +41,8 @@ import org.apache.sis.util.resources.Err
  * @since   0.3
  * @version 0.3
  * @module
+ *
+ * @see InjectiveConverter
  */
 public abstract class SurjectiveConverter<S,T> implements ObjectConverter<S,T> {
     /**

Added: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/URIConverter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/URIConverter.java?rev=1454870&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/URIConverter.java (added)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/URIConverter.java [UTF-8] Sun Mar 10 16:10:57 2013
@@ -0,0 +1,158 @@
+/*
+ * 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.converter;
+
+import java.io.Serializable;
+import java.io.ObjectStreamException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import net.jcip.annotations.Immutable;
+import org.apache.sis.util.ObjectConverter;
+import org.apache.sis.util.UnconvertibleObjectException;
+
+
+/**
+ * Handles conversions from {@link java.net.URI} to various objects.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-3.01)
+ * @version 0.3
+ * @module
+ */
+@Immutable
+abstract class URIConverter<T> extends InjectiveConverter<URI,T> implements Serializable {
+    /**
+     * For cross-version compatibility.
+     */
+    private static final long serialVersionUID = 5419481828621160876L;
+
+    /**
+     * For inner classes only.
+     */
+    URIConverter() {
+    }
+
+    /**
+     * Returns the source class, which is always {@link URI}.
+     */
+    @Override
+    public final Class<URI> getSourceClass() {
+        return URI.class;
+    }
+
+    /**
+     * Converter from {@link URI} to {@link java.lang.String}.
+     * This converter does not encode the string, i.e. the conversion is performed with
+     * the {@link URI#toString()} method rather than {@link URI#toASCIIString()}. We do
+     * that in order to avoid too many transformations if we convert back and forward to
+     * {@code String}.
+     */
+    @Immutable
+    static final class String extends URIConverter<java.lang.String> {
+        /** Cross-version compatibility. */ static final long serialVersionUID = -1745990349642467147L;
+        /** The unique, shared instance. */ static final String INSTANCE = new String();
+        /** For {@link #INSTANCE} only.  */ private String() {}
+
+        @Override public Class<java.lang.String> getTargetClass() {
+            return java.lang.String.class;
+        }
+
+        @Override public java.lang.String convert(final URI source) {
+            return (source != null) ? source.toString() : null;
+        }
+
+        /** Returns the inverse, since this converter is "almost" bijective. */
+        @Override public ObjectConverter<java.lang.String, URI> inverse() {
+            return StringConverter.URI.INSTANCE;
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+    /**
+     * Converter from {@link URI} to {@link java.io.File}.
+     */
+    @Immutable
+    static final class File extends URIConverter<java.io.File> {
+        /** Cross-version compatibility. */ static final long serialVersionUID = 5289256237146366469L;
+        /** The unique, shared instance. */ static final File INSTANCE = new File();
+        /** For {@link #INSTANCE} only.  */ private File() {}
+
+        @Override public Class<java.io.File> getTargetClass() {
+            return java.io.File.class;
+        }
+
+        @Override public java.io.File convert(final URI source) throws UnconvertibleObjectException {
+            if (source == null) {
+                return null;
+            }
+            try {
+                return new java.io.File(source);
+            } catch (IllegalArgumentException e) {
+                throw new UnconvertibleObjectException(formatErrorMessage(source), e);
+            }
+        }
+
+        /** Returns the inverse, since this converter is "almost" bijective. */
+        @Override public ObjectConverter<java.io.File, URI> inverse() {
+            return FileConverter.URI.INSTANCE;
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+    /**
+     * Converter from {@link URI} to {@link java.net.URL}.
+     */
+    @Immutable
+    static final class URL extends URIConverter<java.net.URL> {
+        /** Cross-version compatibility. */ static final long serialVersionUID = -7866572007304228474L;
+        /** The unique, shared instance. */ static final URL INSTANCE = new URL();
+        /** For {@link #INSTANCE} only.  */ private URL() {}
+
+        @Override public Class<java.net.URL> getTargetClass() {
+            return java.net.URL.class;
+        }
+
+        @Override public java.net.URL convert(final URI source) throws UnconvertibleObjectException {
+            if (source == null) {
+                return null;
+            }
+            try {
+                return source.toURL();
+            } catch (MalformedURLException e) {
+                throw new UnconvertibleObjectException(formatErrorMessage(source), e);
+            }
+        }
+
+        /** Returns the inverse, since this converter is "almost" bijective. */
+        @Override public ObjectConverter<java.net.URL, URI> inverse() {
+            return URLConverter.URI.INSTANCE;
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+}

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

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

Added: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/URLConverter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/URLConverter.java?rev=1454870&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/URLConverter.java (added)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/URLConverter.java [UTF-8] Sun Mar 10 16:10:57 2013
@@ -0,0 +1,156 @@
+/*
+ * 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.converter;
+
+import java.io.Serializable;
+import java.io.ObjectStreamException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import net.jcip.annotations.Immutable;
+import org.apache.sis.util.ObjectConverter;
+import org.apache.sis.util.UnconvertibleObjectException;
+
+
+/**
+ * Handles conversions from {@link java.net.URL} to various objects.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-3.01)
+ * @version 0.3
+ * @module
+ */
+@Immutable
+abstract class URLConverter<T> extends InjectiveConverter<URL,T> implements Serializable {
+    /**
+     * For cross-version compatibility.
+     */
+    private static final long serialVersionUID = 4843540356265851861L;
+
+    /**
+     * For inner classes only.
+     */
+    URLConverter() {
+    }
+
+    /**
+     * Returns the source class, which is always {@link URL}.
+     */
+    @Override
+    public final Class<URL> getSourceClass() {
+        return URL.class;
+    }
+
+    /**
+     * Converter from {@link URL} to {@link java.lang.String}.
+     * This converter does not encode the string. We do that in order to avoid too many
+     * transformations if we convert back and forward to {@code String}.
+     */
+    @Immutable
+    static final class String extends URLConverter<java.lang.String> {
+        /** Cross-version compatibility. */ static final long serialVersionUID = 8091677760312351740L;
+        /** The unique, shared instance. */ static final String INSTANCE = new String();
+        /** For {@link #INSTANCE} only.  */ private String() {}
+
+        @Override public Class<java.lang.String> getTargetClass() {
+            return java.lang.String.class;
+        }
+
+        @Override public java.lang.String convert(final URL source) {
+            return (source != null) ? source.toExternalForm() : null;
+        }
+
+        /** Returns the inverse, since this converter is "almost" bijective. */
+        @Override public ObjectConverter<java.lang.String, URL> inverse() {
+            return StringConverter.URL.INSTANCE;
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+    /**
+     * Converter from {@link URL} to {@link java.io.File}.
+     */
+    @Immutable
+    static final class File extends URLConverter<java.io.File> {
+        /** Cross-version compatibility. */ static final long serialVersionUID = 1228852836485762335L;
+        /** The unique, shared instance. */ static final File INSTANCE = new File();
+        /** For {@link #INSTANCE} only.  */ private File() {}
+
+        @Override public Class<java.io.File> getTargetClass() {
+            return java.io.File.class;
+        }
+
+        @Override public java.io.File convert(final URL source) throws UnconvertibleObjectException {
+            if (source == null) {
+                return null;
+            }
+            try {
+                return new java.io.File(source.toURI());
+            } catch (URISyntaxException | IllegalArgumentException e) {
+                throw new UnconvertibleObjectException(formatErrorMessage(source), e);
+            }
+        }
+
+        /** Returns the inverse, since this converter is "almost" bijective. */
+        @Override public ObjectConverter<java.io.File, URL> inverse() {
+            return FileConverter.URL.INSTANCE;
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+    /**
+     * Converter from {@link URL} to {@link java.net.URI}.
+     */
+    @Immutable
+    static final class URI extends URLConverter<java.net.URI> {
+        /** Cross-version compatibility. */ static final long serialVersionUID = -1653233667050600894L;
+        /** The unique, shared instance. */ static final URI INSTANCE = new URI();
+        /** For {@link #INSTANCE} only.  */ private URI() {}
+
+        @Override public Class<java.net.URI> getTargetClass() {
+            return java.net.URI.class;
+        }
+
+        @Override public java.net.URI convert(final URL source) throws UnconvertibleObjectException {
+            if (source == null) {
+                return null;
+            }
+            try {
+                return source.toURI();
+            } catch (URISyntaxException e) {
+                throw new UnconvertibleObjectException(formatErrorMessage(source), e);
+            }
+        }
+
+        /** Returns the inverse, since this converter is "almost" bijective. */
+        @Override public ObjectConverter<java.net.URI, URL> inverse() {
+            return URIConverter.URL.INSTANCE;
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+}

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

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



Mime
View raw message