sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1799839 - in /sis/branches/JDK8: core/sis-feature/src/main/java/org/apache/sis/feature/builder/ core/sis-feature/src/main/java/org/apache/sis/internal/feature/ core/sis-utility/src/main/java/org/apache/sis/setup/ storage/sis-xmlstore/src/m...
Date Sun, 25 Jun 2017 21:46:43 GMT
Author: desruisseaux
Date: Sun Jun 25 21:46:42 2017
New Revision: 1799839

URL: http://svn.apache.org/viewvc?rev=1799839&view=rev
Log:
Add a FeatureTypeBuilder.addAttribute(GeometryType) method.
This required a revisit of FeatureTypeBuilder constructor, by moving the 'template' argument
in a separated method.

Modified:
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/AssociationRoleBuilder.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/AttributeTypeBuilder.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/CharacteristicTypeBuilder.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/FeatureTypeBuilder.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/OperationWrapper.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/PropertyTypeBuilder.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/TypeBuilder.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/ESRI.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Geometries.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/JTS.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Java2D.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/GeometryLibrary.java
    sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/gpx/Types.java

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/AssociationRoleBuilder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/AssociationRoleBuilder.java?rev=1799839&r1=1799838&r2=1799839&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/AssociationRoleBuilder.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/AssociationRoleBuilder.java
[UTF-8] Sun Jun 25 21:46:42 2017
@@ -66,7 +66,7 @@ public final class AssociationRoleBuilde
      * @param owner  the builder of the {@code FeatureType} for which to add this property.
      */
     AssociationRoleBuilder(final FeatureTypeBuilder owner, final FeatureType type, final
GenericName typeName) {
-        super(owner, null);
+        super(owner);
         this.type     = type;
         this.typeName = typeName;
     }
@@ -77,7 +77,7 @@ public final class AssociationRoleBuilde
      * @param owner  the builder of the {@code FeatureType} for which to add this property.
      */
     AssociationRoleBuilder(final FeatureTypeBuilder owner, final FeatureAssociationRole template)
{
-        super(owner, template);
+        super(owner);
         property      = template;
         minimumOccurs = template.getMinimumOccurs();
         maximumOccurs = template.getMaximumOccurs();
@@ -88,6 +88,7 @@ public final class AssociationRoleBuilde
             type     = template.getValueType();
             typeName = type.getName();
         }
+        initialize(template);
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/AttributeTypeBuilder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/AttributeTypeBuilder.java?rev=1799839&r1=1799838&r2=1799839&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/AttributeTypeBuilder.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/AttributeTypeBuilder.java
[UTF-8] Sun Jun 25 21:46:42 2017
@@ -129,7 +129,7 @@ public final class AttributeTypeBuilder<
      * @param valueClass  the class of attribute values.
      */
     AttributeTypeBuilder(final FeatureTypeBuilder owner, final Class<V> valueClass)
{
-        super(owner, null);
+        super(owner);
         this.valueClass = valueClass;
         characteristics = new ArrayList<>();
     }
@@ -140,7 +140,7 @@ public final class AttributeTypeBuilder<
      * @param owner  the builder of the {@code FeatureType} for which to add the attribute.
      */
     AttributeTypeBuilder(final FeatureTypeBuilder owner, final AttributeType<V> template)
{
-        super(owner, template);
+        super(owner);
         property      = template;
         minimumOccurs = template.getMinimumOccurs();
         maximumOccurs = template.getMaximumOccurs();
@@ -151,6 +151,7 @@ public final class AttributeTypeBuilder<
         for (final AttributeType<?> c : tc.values()) {
             characteristics.add(new CharacteristicTypeBuilder<>(this, c));
         }
+        initialize(template);
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/CharacteristicTypeBuilder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/CharacteristicTypeBuilder.java?rev=1799839&r1=1799838&r2=1799839&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/CharacteristicTypeBuilder.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/CharacteristicTypeBuilder.java
[UTF-8] Sun Jun 25 21:46:42 2017
@@ -95,7 +95,7 @@ public final class CharacteristicTypeBui
      * @param valueClass  the class of characteristic values.
      */
     CharacteristicTypeBuilder(final AttributeTypeBuilder<?> owner, final Class<V>
valueClass) {
-        super(null, owner.getLocale());
+        super(owner.getLocale());
         this.owner = owner;
         this.valueClass = valueClass;
     }
@@ -106,11 +106,12 @@ public final class CharacteristicTypeBui
      * @param owner  the builder of the {@code AttributeType} for which to add this property.
      */
     CharacteristicTypeBuilder(final AttributeTypeBuilder<?> owner, final AttributeType<V>
template) {
-        super(template, owner.getLocale());
+        super(owner.getLocale());
         this.owner     = owner;
         characteristic = template;
         valueClass     = template.getValueClass();
         defaultValue   = template.getDefaultValue();
+        initialize(template);
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/FeatureTypeBuilder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/FeatureTypeBuilder.java?rev=1799839&r1=1799838&r2=1799839&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/FeatureTypeBuilder.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/FeatureTypeBuilder.java
[UTF-8] Sun Jun 25 21:46:42 2017
@@ -29,11 +29,14 @@ import org.opengis.util.NameSpace;
 import org.opengis.util.GenericName;
 import org.opengis.util.NameFactory;
 import org.opengis.util.FactoryException;
+import org.opengis.metadata.acquisition.GeometryType;
+import org.apache.sis.setup.GeometryLibrary;
 import org.apache.sis.feature.AbstractOperation;
 import org.apache.sis.feature.DefaultFeatureType;
 import org.apache.sis.feature.FeatureOperations;
 import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.internal.feature.AttributeConvention;
+import org.apache.sis.internal.feature.Geometries;
 import org.apache.sis.internal.feature.Resources;
 import org.apache.sis.util.CorruptedObjectException;
 import org.apache.sis.util.resources.Errors;
@@ -182,6 +185,11 @@ public class FeatureTypeBuilder extends
     AttributeTypeBuilder<?> defaultGeometry;
 
     /**
+     * Provides method for creating geometric objects using the library specified by the
user.
+     */
+    private final Geometries geometries;
+
+    /**
      * The object created by this builder, or {@code null} if not yet created.
      * This field must be cleared every time that a setter method is invoked on this builder.
      */
@@ -198,97 +206,153 @@ public class FeatureTypeBuilder extends
      * Creates a new builder instance using the given feature type as a template.
      *
      * @param template  an existing feature type to use as a template, or {@code null} if
none.
+     *
+     * @see #setAll(FeatureType)
      */
     public FeatureTypeBuilder(final FeatureType template) {
-        this(template, null, null);
+        this(null, null, null);
+        if (template != null) {
+            initialize(template);
+        }
     }
 
     /**
-     * Creates a new builder instance using the given name factory, template and locale for
formatting error messages.
+     * Creates a new builder instance using the given name factory, geometry library
+     * and locale for formatting error messages.
      *
-     * @param template  an existing feature type to use as a template, or {@code null} if
none.
-     * @param factory   the factory to use for creating names, or {@code null} for the default
factory.
-     * @param locale    the locale to use for formatting error messages, or {@code null}
for the default locale.
+     * @param factory  the factory to use for creating names, or {@code null} for the default
factory.
+     * @param library  the library to use for creating geometric objects, or {@code null}
for the default.
+     * @param locale   the locale to use for formatting error messages, or {@code null} for
the default locale.
      */
-    public FeatureTypeBuilder(final FeatureType template, NameFactory factory, final Locale
locale) {
-        super(template, locale);
+    public FeatureTypeBuilder(NameFactory factory, final GeometryLibrary library, final Locale
locale) {
+        super(locale);
         if (factory == null) {
             factory = DefaultFactories.forBuildin(NameFactory.class);
         }
-        nameFactory = factory;
-        properties  = new ArrayList<>();
-        superTypes  = new ArrayList<>();
-        idDelimiter = ":";
+        nameFactory          = factory;
+        geometries           = Geometries.implementation(library);
+        properties           = new ArrayList<>();
+        superTypes           = new ArrayList<>();
+        idDelimiter          = ":";
+        defaultMinimumOccurs = 1;
+        defaultMaximumOccurs = 1;
+    }
+
+    /**
+     * Clears all setting in this builder. After invoking this method, this {@code FeatureTypeBuilder}
+     * is in same state that after it has been constructed. This method can be invoked for
reusing the
+     * same builder for creating other {@code FeatureType} instances after {@link #build()}
invocation.
+     *
+     * @return {@code this} for allowing method calls chaining.
+     */
+    public FeatureTypeBuilder clear() {
+        reset();
+        properties.clear();
+        superTypes.clear();
+        isAbstract           = false;
+        namespace            = null;
         defaultMinimumOccurs = 1;
         defaultMaximumOccurs = 1;
+        idPrefix             = null;
+        idSuffix             = null;
+        idDelimiter          = ":";
+        identifierCount      = 0;
+        defaultGeometry      = null;
+        clearCache();
+        return this;
+    }
+
+    /**
+     * Sets all properties of this builder to the values of the given feature type.
+     * This builder is {@linkplain #clear() cleared} before the properties of the given type
are copied.
+     *
+     * @param  template  an existing feature type to use as a template, or {@code null} if
none.
+     * @return {@code this} for allowing method calls chaining.
+     *
+     * @see #FeatureTypeBuilder(FeatureType)
+     */
+    public FeatureTypeBuilder setAll(final FeatureType template) {
+        clear();
         if (template != null) {
-            feature    = template;
-            isAbstract = template.isAbstract();
-            superTypes.addAll(template.getSuperTypes());
+            initialize(template);
+        }
+        return this;
+    }
+
+    /**
+     * Initializes this builder to the value of the given type.
+     * The caller is responsible to invoke {@link #clear()} (if needed) before this method.
+     *
+     * @see #setAll(FeatureType)
+     */
+    private void initialize(final FeatureType template) {
+        super.initialize(template);
+        feature    = template;
+        isAbstract = template.isAbstract();
+        superTypes.addAll(template.getSuperTypes());
+        /*
+         * For each attribute and association, wrap those properties in a builder.
+         * For each operation, wrap them in pseudo-builder only if the operation
+         * is not one of the operations automatically generated by this builder.
+         */
+        final Map<String,Set<AttributeRole>> propertyRoles = new HashMap<>();
+        for (final PropertyType property : template.getProperties(false)) {
+            PropertyTypeBuilder builder;
+            if (property instanceof AttributeType<?>) {
+                builder = new AttributeTypeBuilder<>(this, (AttributeType<?>)
property);
+            } else if (property instanceof FeatureAssociationRole) {
+                builder = new AssociationRoleBuilder(this, (FeatureAssociationRole) property);
+            } else {
+                builder = null;                             // Do not create OperationWrapper
now - see below.
+            }
             /*
-             * For each attribute and association, wrap those properties in a builder.
-             * For each operation, wrap them in pseudo-builder only if the operation
-             * is not one of the operations automatically generated by this builder.
+             * If the property name is one of our (Apache SIS specific) conventional names,
try to reconstitute
+             * the attribute roles that caused FeatureTypeBuilder to produce such property.
Those roles usually
+             * need to be applied on the source properties used for calculating the current
property. There is
+             * usually at most one role for each source property, but we nevertheless allow
an arbitrary amount.
              */
-            final Map<String,Set<AttributeRole>> propertyRoles = new HashMap<>();
-            for (final PropertyType property : template.getProperties(false)) {
-                PropertyTypeBuilder builder;
-                if (property instanceof AttributeType<?>) {
-                    builder = new AttributeTypeBuilder<>(this, (AttributeType<?>)
property);
-                } else if (property instanceof FeatureAssociationRole) {
-                    builder = new AssociationRoleBuilder(this, (FeatureAssociationRole) property);
-                } else {
-                    builder = null;                             // Do not create OperationWrapper
now - see below.
+            final AttributeRole role;
+            final GenericName name = property.getName();
+            if (AttributeConvention.IDENTIFIER_PROPERTY.equals(name)) {
+                role = AttributeRole.IDENTIFIER_COMPONENT;
+            } else if (AttributeConvention.GEOMETRY_PROPERTY.equals(name)) {
+                role = AttributeRole.DEFAULT_GEOMETRY;
+            } else if (AttributeConvention.ENVELOPE_PROPERTY.equals(name)) {
+                // If "sis:envelope" is an operation, skip it completely.
+                // It will be recreated if a default geometry exists.
+                role = null;
+            } else {
+                if (builder == null) {
+                    // For all unknown operation, wrap as-is.
+                    builder = new OperationWrapper(this, property);
                 }
-                /*
-                 * If the property name is one of our (Apache SIS specific) conventional
names, try to reconstitute
-                 * the attribute roles that caused FeatureTypeBuilder to produce such property.
Those roles usually
-                 * need to be applied on the source properties used for calculating the current
property. There is
-                 * usually at most one role for each source property, but we nevertheless
allow an arbitrary amount.
-                 */
-                final AttributeRole role;
-                final GenericName name = property.getName();
-                if (AttributeConvention.IDENTIFIER_PROPERTY.equals(name)) {
-                    role = AttributeRole.IDENTIFIER_COMPONENT;
-                } else if (AttributeConvention.GEOMETRY_PROPERTY.equals(name)) {
-                    role = AttributeRole.DEFAULT_GEOMETRY;
-                } else if (AttributeConvention.ENVELOPE_PROPERTY.equals(name)) {
-                    // If "sis:envelope" is an operation, skip it completely.
-                    // It will be recreated if a default geometry exists.
-                    role = null;
-                } else {
-                    if (builder == null) {
-                        // For all unknown operation, wrap as-is.
-                        builder = new OperationWrapper(this, property);
-                    }
-                    role = null;
-                }
-                if (role != null) {
-                    final Set<AttributeRole> rc = Collections.singleton(role);
-                    if (property instanceof AbstractOperation) {
-                        for (final String dependency : ((AbstractOperation) property).getDependencies())
{
-                            propertyRoles.merge(dependency, rc, AttributeRole::merge);
-                        }
-                    } else {
-                        propertyRoles.merge(name.toString(), rc, AttributeRole::merge);
+                role = null;
+            }
+            if (role != null) {
+                final Set<AttributeRole> rc = Collections.singleton(role);
+                if (property instanceof AbstractOperation) {
+                    for (final String dependency : ((AbstractOperation) property).getDependencies())
{
+                        propertyRoles.merge(dependency, rc, AttributeRole::merge);
                     }
-                }
-                if (builder != null) {
-                    properties.add(builder);
+                } else {
+                    propertyRoles.merge(name.toString(), rc, AttributeRole::merge);
                 }
             }
-            /*
-             * At this point we finished to collect information about the attribute roles.
-             * Now assign those roles to the attribute builders. Note that some roles may
-             * be ignored if we didn't found a suitable builder. The roles inference done
-             * in this constructor is only a "best effort".
-             */
-            if (!propertyRoles.isEmpty()) {
-                for (final Map.Entry<String,Set<AttributeRole>> entry : propertyRoles.entrySet())
{
-                    final PropertyTypeBuilder property = forName(properties, entry.getKey());
-                    if (property instanceof AttributeTypeBuilder<?>) {
-                        ((AttributeTypeBuilder<?>) property).roles().addAll(entry.getValue());
-                    }
+            if (builder != null) {
+                properties.add(builder);
+            }
+        }
+        /*
+         * At this point we finished to collect information about the attribute roles.
+         * Now assign those roles to the attribute builders. Note that some roles may
+         * be ignored if we didn't found a suitable builder. The roles inference done
+         * in this constructor is only a "best effort".
+         */
+        if (!propertyRoles.isEmpty()) {
+            for (final Map.Entry<String,Set<AttributeRole>> entry : propertyRoles.entrySet())
{
+                final PropertyTypeBuilder property = forName(properties, entry.getKey());
+                if (property instanceof AttributeTypeBuilder<?>) {
+                    ((AttributeTypeBuilder<?>) property).roles().addAll(entry.getValue());
                 }
             }
         }
@@ -297,6 +361,8 @@ public class FeatureTypeBuilder extends
     /**
      * If the {@code FeatureType} created by the last call to {@link #build()} has been cached,
      * clears that cache. This method must be invoked every time that a setter method is
invoked.
+     *
+     * @see #clear()
      */
     @Override
     final void clearCache() {
@@ -613,6 +679,56 @@ public class FeatureTypeBuilder extends
     }
 
     /**
+     * Creates a new attribute for geometries of the given type. This method delegates to
{@link #addAttribute(Class)}
+     * with a {@code valueClass} argument inferred from the combination of the {@link GeometryType}
argument given to
+     * this method with the {@link GeometryLibrary} argument given at {@linkplain #FeatureTypeBuilder(NameFactory,
+     * GeometryLibrary, Locale) builder creation time}.
+     * The geometry type can be:
+     *
+     * <ul>
+     *   <li>{@link GeometryType#POINT}  for {@code Point} or {@code Point2D} type.</li>
+     *   <li>{@link GeometryType#LINEAR} for {@code Polyline} or {@code LineString}
type.</li>
+     *   <li>{@link GeometryType#AREAL}  for {@code Polygon} type.</li>
+     * </ul>
+     *
+     * Geometric objects outside the above list can still be used by declaring their type
explicitely.
+     * However in this case there is no isolation level between the geometry types and the
library that implement them.
+     *
+     * <div class="note"><b>Example:</b>
+     * the following code creates an attribute named "MyPoint" with values of class
+     * {@link java.awt.geom.Point2D} if the library in use is {@linkplain GeometryLibrary#JAVA2D
Java2D}.
+     * The Coordinate Reference System (CRS) uses (<var>longitude</var>, <var>latitude</var>)
axes on the WGS 84 datum.
+     * Finally that new attribute is declared the feature <em>default</em> geometry:
+     *
+     * {@preformat java
+     *   builder.addAttribute(GeometryType.POINT).setName("MyPoint")
+     *          .setCRS(CommonCRS.WGS84.normalizedGeographic())
+     *          .addRole(AttributeRole.DEFAULT_GEOMETRY);
+     * }
+     *
+     * If the library in use is JTS or ESRI instead than Java2D,
+     * then the {@code Point} class of those libraries will be used instead of {@code Point2D}.
+     * The fully-qualified class names are given in the {@link GeometryLibrary} javadoc.</div>
+     *
+     * @param  type  kind of geometric object (point, polyline or polygon).
+     * @return a builder for an {@code AttributeType}.
+     */
+    public AttributeTypeBuilder<?> addAttribute(final GeometryType type) {
+        ensureNonNull("type", type);
+        final Class<?> c;
+        if (type.equals(GeometryType.POINT)) {
+            c = geometries.pointClass;
+        } else if (type.equals(GeometryType.LINEAR)) {
+            c = geometries.polylineClass;
+        } else if (type.equals(GeometryType.AREAL)) {
+            c = geometries.polygonClass;
+        } else {
+            throw new IllegalArgumentException(errors().getString(Errors.Keys.UnsupportedArgumentValue_1,
type));
+        }
+        return addAttribute(c);
+    }
+
+    /**
      * Creates a new {@code FeatureAssociationRole} builder for features of the given type.
      * The default association name is the name of the given type, but callers should invoke
one
      * of the {@code AssociationRoleBuilder.setName(…)} methods on the returned instance
with a better name.
@@ -742,6 +858,8 @@ public class FeatureTypeBuilder extends
      *
      * @return the feature type.
      * @throws IllegalStateException if the builder contains inconsistent information.
+     *
+     * @see #clear()
      */
     @Override
     public FeatureType build() throws IllegalStateException {

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/OperationWrapper.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/OperationWrapper.java?rev=1799839&r1=1799838&r2=1799839&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/OperationWrapper.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/OperationWrapper.java
[UTF-8] Sun Jun 25 21:46:42 2017
@@ -43,10 +43,11 @@ final class OperationWrapper extends Pro
      * Creates a new wrapper for the given operation.
      */
     OperationWrapper(final FeatureTypeBuilder owner, final PropertyType operation) {
-        super(owner, operation);
+        super(owner);
         this.operation = operation;
         minimumOccurs = 1;
         maximumOccurs = 1;
+        initialize(operation);
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/PropertyTypeBuilder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/PropertyTypeBuilder.java?rev=1799839&r1=1799838&r2=1799839&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/PropertyTypeBuilder.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/PropertyTypeBuilder.java
[UTF-8] Sun Jun 25 21:46:42 2017
@@ -85,13 +85,12 @@ public abstract class PropertyTypeBuilde
     }
 
     /**
-     * Creates a new {@code PropertyType} builder initialized to the values of an existing
property.
+     * Creates a new {@code PropertyType} builder.
      *
-     * @param owner     the builder of the {@code FeatureType} for which to add this property.
-     * @param template  an existing property to use as a template, or {@code null} if none.
+     * @param owner  the builder of the {@code FeatureType} for which to add this property.
      */
-    PropertyTypeBuilder(final FeatureTypeBuilder owner, final PropertyType template) {
-        super(template, owner.getLocale());
+    PropertyTypeBuilder(final FeatureTypeBuilder owner) {
+        super(owner.getLocale());
         this.owner    = owner;
         minimumOccurs = owner.defaultMinimumOccurs;
         maximumOccurs = owner.defaultMaximumOccurs;

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/TypeBuilder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/TypeBuilder.java?rev=1799839&r1=1799838&r2=1799839&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/TypeBuilder.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/TypeBuilder.java
[UTF-8] Sun Jun 25 21:46:42 2017
@@ -88,6 +88,8 @@ public abstract class TypeBuilder implem
 
     /**
      * Creates a new builder initialized to the values of the given builder.
+     * This constructor is for {@link AttributeTypeBuilder#setValueClass(Class)}
+     * and {@link CharacteristicTypeBuilder#setValueClass(Class)} implementations.
      *
      * @param builder  the builder from which to copy information.
      */
@@ -96,19 +98,36 @@ public abstract class TypeBuilder implem
     }
 
     /**
-     * Creates a new builder initialized to the values of an existing type.
+     * Creates a new builder initialized to the given configuration.
      */
-    TypeBuilder(final IdentifiedType template, final Locale locale) {
+    TypeBuilder(final Locale locale) {
         identification = new HashMap<>(4);
         putIfNonNull(Errors.LOCALE_KEY, locale);
-        if (template != null) {
-            putIfNonNull(AbstractIdentifiedType.NAME_KEY,        template.getName());
-            putIfNonNull(AbstractIdentifiedType.DEFINITION_KEY,  template.getDefinition());
-            putIfNonNull(AbstractIdentifiedType.DESIGNATION_KEY, template.getDesignation());
-            putIfNonNull(AbstractIdentifiedType.DESCRIPTION_KEY, template.getDescription());
-            if (template instanceof Deprecable && ((Deprecable) template).isDeprecated())
{
-                identification.put(AbstractIdentifiedType.DEPRECATED_KEY, Boolean.TRUE);
-            }
+    }
+
+    /**
+     * Resets the identification map. After invoking this method, this {@code TypeBuilder}
+     * is in same state that after it has been {@linkplain #TypeBuilder(Locale) constructed}.
+     *
+     * @see #clearCache()
+     */
+    final void reset() {
+        final Object locale = identification.get(Errors.LOCALE_KEY);
+        identification.clear();
+        putIfNonNull(Errors.LOCALE_KEY, locale);
+    }
+
+    /**
+     * Initializes this builder to the value of the given type.
+     * The caller is responsible to invoke {@link #reset()} (if needed) before this method.
+     */
+    final void initialize(final IdentifiedType template) {
+        putIfNonNull(AbstractIdentifiedType.NAME_KEY,        template.getName());
+        putIfNonNull(AbstractIdentifiedType.DEFINITION_KEY,  template.getDefinition());
+        putIfNonNull(AbstractIdentifiedType.DESIGNATION_KEY, template.getDesignation());
+        putIfNonNull(AbstractIdentifiedType.DESCRIPTION_KEY, template.getDescription());
+        if (template instanceof Deprecable && ((Deprecable) template).isDeprecated())
{
+            identification.put(AbstractIdentifiedType.DEPRECATED_KEY, Boolean.TRUE);
         }
     }
 
@@ -152,6 +171,8 @@ public abstract class TypeBuilder implem
 
     /**
      * If the object created by the last call to {@code build()} has been cached, clears
that cache.
+     *
+     * @see #reset()
      */
     abstract void clearCache();
 

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/ESRI.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/ESRI.java?rev=1799839&r1=1799838&r2=1799839&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/ESRI.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/ESRI.java
[UTF-8] Sun Jun 25 21:46:42 2017
@@ -21,6 +21,7 @@ import com.esri.core.geometry.Geometry;
 import com.esri.core.geometry.Envelope2D;
 import com.esri.core.geometry.MultiPath;
 import com.esri.core.geometry.Polyline;
+import com.esri.core.geometry.Polygon;
 import com.esri.core.geometry.Point;
 import org.apache.sis.geometry.GeneralEnvelope;
 import org.apache.sis.setup.GeometryLibrary;
@@ -43,7 +44,7 @@ final class ESRI extends Geometries {
      * Creates the singleton instance.
      */
     ESRI() {
-        super(GeometryLibrary.ESRI, Geometry.class, Point.class);
+        super(GeometryLibrary.ESRI, Geometry.class, Point.class, Polyline.class, Polygon.class);
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Geometries.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Geometries.java?rev=1799839&r1=1799838&r2=1799839&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Geometries.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Geometries.java
[UTF-8] Sun Jun 25 21:46:42 2017
@@ -61,9 +61,9 @@ public abstract class Geometries {
     public final Class<?> rootClass;
 
     /**
-     * The class for a point.
+     * The class for a point, ployline and polygon.
      */
-    public final Class<?> pointClass;
+    public final Class<?> pointClass, polylineClass, polygonClass;
 
     /**
      * The default geometry implementation to use. Unmodifiable after class initialization.
@@ -78,10 +78,14 @@ public abstract class Geometries {
     /**
      * Creates a new adapter for the given root geometry class.
      */
-    Geometries(final GeometryLibrary library, final Class<?> rootClass, final Class<?>
pointClass) {
-        this.library    = library;
-        this.rootClass  = rootClass;
-        this.pointClass = pointClass;
+    Geometries(final GeometryLibrary library, final Class<?> rootClass, final Class<?>
pointClass,
+            final Class<?> polylineClass, final Class<?> polygonClass)
+    {
+        this.library       = library;
+        this.rootClass     = rootClass;
+        this.pointClass    = pointClass;
+        this.polylineClass = polylineClass;
+        this.polygonClass  = polygonClass;
         fallback = implementation;
     }
 

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/JTS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/JTS.java?rev=1799839&r1=1799838&r2=1799839&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/JTS.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/JTS.java
[UTF-8] Sun Jun 25 21:46:42 2017
@@ -50,7 +50,9 @@ final class JTS extends Geometries {
     JTS() throws ClassNotFoundException, NoSuchMethodException {
         super(/*GeometryLibrary.JTS, */ null,                               // TODO
               Class.forName("com.vividsolutions.jts.geom.Geometry"),
-              Class.forName("com.vividsolutions.jts.geom.Point"));
+              Class.forName("com.vividsolutions.jts.geom.Point"),
+              Class.forName("com.vividsolutions.jts.geom.LineString"),
+              Class.forName("com.vividsolutions.jts.geom.Polygon"));
         getEnvelopeInternal = rootClass.getMethod("getEnvelopeInternal", (Class[]) null);
         final Class<?> envt = getEnvelopeInternal.getReturnType();
         getMinX = envt.getMethod("getMinX", (Class[]) null);

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Java2D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Java2D.java?rev=1799839&r1=1799838&r2=1799839&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Java2D.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Java2D.java
[UTF-8] Sun Jun 25 21:46:42 2017
@@ -44,7 +44,7 @@ final class Java2D extends Geometries {
      * Creates the singleton instance.
      */
     Java2D() {
-        super(GeometryLibrary.JAVA2D, Shape.class, Point2D.class);
+        super(GeometryLibrary.JAVA2D, Shape.class, Point2D.class, Shape.class, Shape.class);
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/GeometryLibrary.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/GeometryLibrary.java?rev=1799839&r1=1799838&r2=1799839&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/GeometryLibrary.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/GeometryLibrary.java
[UTF-8] Sun Jun 25 21:46:42 2017
@@ -16,6 +16,8 @@
  */
 package org.apache.sis.setup;
 
+import org.opengis.metadata.acquisition.GeometryType;
+
 
 /**
  * Some libraries providing geometric objects or topological operations.
@@ -29,6 +31,7 @@ package org.apache.sis.setup;
  * @version 0.8
  *
  * @see OptionKey#GEOMETRY_LIBRARY
+ * @see GeometryType
  *
  * @since 0.8
  * @module
@@ -37,24 +40,36 @@ public enum GeometryLibrary {
     /**
      * The Java Topology Suite (JTS) library. This open source library provides an object
model
      * for Euclidean planar geometry together with a set of fundamental geometric functions.
+     * The library is licensed under Eclipse Distribution License.
+     *
+     * <table class="sis">
+     *   <caption>Implementation classes</caption>
+     *   <tr><th>Geometry type</th>               <th>Class name</th></tr>
+     *   <tr><td>Root geometry class</td>         <td>{@code org.locationtech.jts.geom.Geometry}</td></tr>
+     *   <tr><td>{@link GeometryType#POINT}</td>  <td>{@code org.locationtech.jts.geom.Point}</td></tr>
+     *   <tr><td>{@link GeometryType#LINEAR}</td> <td>{@code org.locationtech.jts.geom.LineString}</td></tr>
+     *   <tr><td>{@link GeometryType#AREAL}</td>  <td>{@code org.locationtech.jts.geom.Polygon}</td></tr>
+     * </table>
      *
-     * <ul>
-     *   <li><b>Package name:</b> {@code com.vividsolutions.jts.geom}</li>
-     *   <li><b>Web site:</b> <a href="http://locationtech.github.io/jts/">http://locationtech.github.io/jts/</a></li>
-     *   <li><b>License:</b> LGPL prior JTS 1.14, Eclipse Distribution
License afterward.</li>
-     * </ul>
+     * @see <a href="http://locationtech.github.io/jts/">JTS home page</a>
      */
 //  JTS,
 
     /**
      * The ESRI geometry API library. This library can be used for spatial vector data processing.
      * It is used in ESRI GIS Tools for Hadoop and has an Android port.
+     * The library is available under Apache 2 license.
+     *
+     * <table class="sis">
+     *   <caption>Implementation classes</caption>
+     *   <tr><th>Geometry type</th>               <th>Class name</th></tr>
+     *   <tr><td>Root geometry class</td>         <td>{@code com.esri.core.geometry.Geometry}</td></tr>
+     *   <tr><td>{@link GeometryType#POINT}</td>  <td>{@code com.esri.core.geometry.Point}</td></tr>
+     *   <tr><td>{@link GeometryType#LINEAR}</td> <td>{@code com.esri.core.geometry.Polyline}</td></tr>
+     *   <tr><td>{@link GeometryType#AREAL}</td>  <td>{@code com.esri.core.geometry.Polygon}</td></tr>
+     * </table>
      *
-     * <ul>
-     *   <li><b>Package name:</b> {@code com.esri.core.geometry}</li>
-     *   <li><b>Web site:</b> <a href="https://github.com/Esri/geometry-api-java/wiki">https://github.com/Esri/geometry-api-java/wiki</a></li>
-     *   <li><b>License:</b> Apache 2.</li>
-     * </ul>
+     * @see <a href="https://github.com/Esri/geometry-api-java/wiki">API wiki page</a>
      */
     ESRI,
 
@@ -63,11 +78,18 @@ public enum GeometryLibrary {
      * than other libraries, but is available on most standard Java environments and constitute
a reliable
      * fallback when no other library is available.
      *
-     * <ul>
-     *   <li><b>Package name:</b> {@code java.awt.geom}</li>
-     *   <li><b>Web site:</b> <a href="http://docs.oracle.com/javase/8/docs/technotes/guides/2d/index.html">http://docs.oracle.com/javase/8/docs/technotes/guides/2d/index.html</a></li>
-     *   <li><b>License:</b> GPL with classpath exception.</li>
-     * </ul>
+     * <table class="sis">
+     *   <caption>Implementation classes</caption>
+     *   <tr><th>Geometry type</th>               <th>Class name</th></tr>
+     *   <tr><td>{@link GeometryType#POINT}</td>  <td>{@code java.awt.geom.Point2D}</td></tr>
+     *   <tr><td>{@link GeometryType#LINEAR}</td> <td>{@code java.awt.Shape}</td></tr>
+     *   <tr><td>{@link GeometryType#AREAL}</td>  <td>{@code java.awt.Shape}</td></tr>
+     * </table>
+     *
+     * Note that contrarily to JTS and ESRI libraries,
+     * a point does not extend any root geometry class in Java2D.
+     *
+     * @see <a href="http://docs.oracle.com/javase/8/docs/technotes/guides/2d/index.html">Java2D
home page</a>
      */
     JAVA2D
 }

Modified: sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/gpx/Types.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/gpx/Types.java?rev=1799839&r1=1799838&r2=1799839&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/gpx/Types.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/storage/gpx/Types.java
[UTF-8] Sun Jun 25 21:46:42 2017
@@ -29,6 +29,7 @@ import org.opengis.util.InternationalStr
 import org.apache.sis.setup.GeometryLibrary;
 import org.opengis.metadata.citation.OnlineResource;
 import org.opengis.metadata.content.ContentInformation;
+import org.opengis.metadata.acquisition.GeometryType;
 import org.apache.sis.storage.gps.Fix;
 import org.apache.sis.storage.FeatureNaming;
 import org.apache.sis.storage.IllegalNameException;
@@ -139,7 +140,7 @@ final class Types {
          * │ sis:identifier │ Integer │   [1 … 1]   │      SIS-specific property
          * └────────────────┴─────────┴─────────────┘
          */
-        FeatureTypeBuilder builder = new FeatureTypeBuilder(null, factory, locale);
+        final FeatureTypeBuilder builder = new FeatureTypeBuilder(factory, library, locale);
         builder.setNameSpace(Tags.PREFIX).setName("GPXEntity").setAbstract(true);
         builder.addAttribute(Integer.class).setName(AttributeConvention.IDENTIFIER_PROPERTY);
         final FeatureType parent = builder.build();
@@ -171,9 +172,8 @@ final class Types {
          * │ dgpsid           │ Integer        │ gpx:dgpsStationType    │   [0 …
1]   │
          * └──────────────────┴────────────────┴────────────────────────┴─────────────┘
          */
-        builder = new FeatureTypeBuilder(null, factory, locale).setSuperTypes(parent);
-        builder.setNameSpace(Tags.PREFIX).setName("WayPoint");
-        builder.addAttribute(geometries.pointClass).setName(geomName)
+        builder.clear().setSuperTypes(parent).setNameSpace(Tags.PREFIX).setName("WayPoint");
+        builder.addAttribute(GeometryType.POINT).setName(geomName)
                 .setCRS(CommonCRS.WGS84.normalizedGeographic())
                 .addRole(AttributeRole.DEFAULT_GEOMETRY);
         builder.setDefaultCardinality(0, 1);
@@ -216,8 +216,7 @@ final class Types {
          */
         final AttributeType<?> groupResult = GroupAsPolylineOperation.getResult(geometries);
         GroupAsPolylineOperation groupOp = new GroupAsPolylineOperation(geomInfo, Tags.ROUTE_POINTS,
groupResult);
-        builder = new FeatureTypeBuilder(null, factory, locale).setSuperTypes(parent);
-        builder.setNameSpace(Tags.PREFIX).setName("Route");
+        builder.clear().setSuperTypes(parent).setNameSpace(Tags.PREFIX).setName("Route");
         builder.addProperty(groupOp);
         builder.addProperty(FeatureOperations.envelope(envpInfo, null, groupOp));
         builder.setDefaultCardinality(0, 1);
@@ -242,8 +241,7 @@ final class Types {
          * └────────────────┴──────────┴─────────────┴─────────────┘
          */
         groupOp = new GroupAsPolylineOperation(geomInfo, Tags.TRACK_POINTS, groupResult);
-        builder = new FeatureTypeBuilder(null, factory, locale).setSuperTypes(parent);
-        builder.setNameSpace(Tags.PREFIX).setName("TrackSegment");
+        builder.clear().setSuperTypes(parent).setNameSpace(Tags.PREFIX).setName("TrackSegment");
         builder.addProperty(groupOp);
         builder.addProperty(FeatureOperations.envelope(envpInfo, null, groupOp));
         builder.setDefaultCardinality(0, 1);
@@ -268,8 +266,7 @@ final class Types {
          * └────────────────┴────────────────┴────────────────────────┴─────────────┘
          */
         groupOp = new GroupAsPolylineOperation(geomInfo, Tags.TRACK_SEGMENTS, groupResult);
-        builder = new FeatureTypeBuilder(null, factory, locale).setSuperTypes(parent);
-        builder.setNameSpace(Tags.PREFIX).setName("Track");
+        builder.clear().setSuperTypes(parent).setNameSpace(Tags.PREFIX).setName("Track");
         builder.addProperty(groupOp);
         builder.addProperty(FeatureOperations.envelope(envpInfo, null, groupOp));
         builder.setDefaultCardinality(0, 1);



Mime
View raw message