sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1754804 - in /sis/branches/JDK8/core: sis-feature/src/main/java/org/apache/sis/feature/builder/ sis-utility/src/main/java/org/apache/sis/util/resources/
Date Mon, 01 Aug 2016 22:28:25 GMT
Author: desruisseaux
Date: Mon Aug  1 22:28:25 2016
New Revision: 1754804

URL: http://svn.apache.org/viewvc?rev=1754804&view=rev
Log:
Initial implementation of AttributeTypeBuilder.setValueClass(Class<N>) method, together
with some getter methods.

Modified:
    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/PropertyTypeBuilder.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/TypeBuilder.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties

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=1754804&r1=1754803&r2=1754804&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] Mon Aug  1 22:28:25 2016
@@ -17,8 +17,11 @@
 package org.apache.sis.feature.builder;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
+import java.lang.reflect.Array;
 import org.opengis.util.GenericName;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.apache.sis.feature.DefaultAttributeType;
@@ -28,6 +31,8 @@ import org.apache.sis.internal.feature.A
 import org.apache.sis.internal.feature.Geometries;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.Classes;
+import org.apache.sis.util.ObjectConverters;
+import org.apache.sis.util.UnconvertibleObjectException;
 
 // Branch-dependent imports
 import java.util.Objects;
@@ -40,20 +45,26 @@ import org.opengis.feature.PropertyType;
  * A different instance of {@code AttributeTypeBuilder} exists for each feature attribute
to describe.
  * Those instances are created by {@link FeatureTypeBuilder#addAttribute(Class)}.
  *
- * @param <V> the class of property values.
+ * @param <V> the class of attribute values.
+ *
+ * @author  Johann Sorel (Geomatys)
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.8
+ * @version 0.8
+ * @module
  *
  * @see org.apache.sis.feature.DefaultAttributeType
  * @see FeatureTypeBuilder#addAttribute(Class)
  */
 public final class AttributeTypeBuilder<V> extends PropertyTypeBuilder {
     /**
-     * The class of property values. Can not be changed after construction
+     * The class of attribute values. Can not be changed after construction
      * because this value determines the parameterized type {@code <V>}.
      */
     private final Class<V> valueClass;
 
     /**
-     * The default value for the property, or {@code null} if none.
+     * The default value for the attribute, or {@code null} if none.
      */
     private V defaultValue;
 
@@ -70,23 +81,40 @@ public final class AttributeTypeBuilder<
     /**
      * Builders for the characteristics associated to the attribute.
      */
-    private final List<CharacteristicTypeBuilder<?>> characteristics = new ArrayList<>();
+    private final List<CharacteristicTypeBuilder<?>> characteristics;
+
+    /**
+     * Creates a new builder initialized to the values of the given builder.
+     * This constructor is for {@link #setValueClass(Class)} implementation only.
+     *
+     * @throws UnconvertibleObjectException if the default value can not be converted to
the given class.
+     */
+    private AttributeTypeBuilder(final AttributeTypeBuilder<?> builder, final Class<V>
valueClass)
+            throws UnconvertibleObjectException
+    {
+        super(builder);
+        this.valueClass = valueClass;
+        defaultValue = ObjectConverters.convert(builder.defaultValue, valueClass);
+        isIdentifier = builder.isIdentifier;
+        characteristics = builder.characteristics;
+    }
 
     /**
      * Creates a new {@code AttributeType} builder for values of the given class.
      *
-     * @param owner      the builder of the {@code FeatureType} for which to add this property.
-     * @param valueClass the class of property values.
+     * @param owner      the builder of the {@code FeatureType} for which to add the attribute.
+     * @param valueClass the class of attribute values.
      */
     AttributeTypeBuilder(final FeatureTypeBuilder owner, final Class<V> valueClass)
{
         super(owner, null);
         this.valueClass = valueClass;
+        characteristics = new ArrayList<>();
     }
 
     /**
      * Creates a new {@code AttributeType} builder initialized to the values of an existing
attribute.
      *
-     * @param owner  the builder of the {@code FeatureType} for which to add this property.
+     * @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);
@@ -94,14 +122,16 @@ public final class AttributeTypeBuilder<
         maximumOccurs = template.getMaximumOccurs();
         valueClass    = template.getValueClass();
         defaultValue  = template.getDefaultValue();
-        for (final AttributeType<?> c : template.characteristics().values()) {
+        final Map<String, AttributeType<?>> tc = template.characteristics();
+        characteristics = new ArrayList<>(tc.size());
+        for (final AttributeType<?> c : tc.values()) {
             characteristics.add(new CharacteristicTypeBuilder<>(this, c));
         }
     }
 
     /**
      * Returns a default name to use if the user did not specified a name. The first letter
will be changed to
-     * lower case (unless the name looks like an acronym) for compliance with Java convention
on property names.
+     * lower case (unless the name looks like an acronym) for compliance with Java convention
on attribute names.
      */
     @Override
     final String getDefaultName() {
@@ -151,10 +181,62 @@ public final class AttributeTypeBuilder<
     }
 
     /**
-     * Sets the default value for the property.
+     * Returns the class of attribute values.
+     *
+     * @return the class of attribute values.
+     *
+     * @see #setValueClass(Class)
+     */
+    public Class<V> getValueClass() {
+        return valueClass;
+    }
+
+    /**
+     * Sets the class of attribute values. Callers <strong>must</strong> use
the builder returned by this method
+     * instead of {@code this} builder after this method call, since the returned builder
may be a new instance.
+     *
+     * @param  <N>   the compile-time value of the {@code type} argument.
+     * @param  type  the new class of attribute values.
+     * @return the attribute builder — <em>not necessarily this instance.</em>
+     * @throws UnconvertibleObjectException if the {@linkplain #getDefaultValue() default
value}
+     *         can not be converted to the given {@code <N>} class.
+     *
+     * @see #getValueClass()
+     */
+    @SuppressWarnings("unchecked")
+    public <N> AttributeTypeBuilder<N> setValueClass(final Class<N> type)
throws UnconvertibleObjectException {
+        final FeatureTypeBuilder owner = owner();
+        ensureNonNull("type", type);
+        if (type == valueClass) {
+            return (AttributeTypeBuilder<N>) this;
+        }
+        final AttributeTypeBuilder<N> n = new AttributeTypeBuilder<>(this, type);
+        for (final CharacteristicTypeBuilder<?> c : n.characteristics) {
+            c.owner = n;
+        }
+        owner.replace(this, n);
+        dispose();
+        return n;
+    }
+
+    /**
+     * Returns the default value for the attribute, or {@code null} if none.
+     *
+     * @return the default attribute value, or {@code null} if none.
+     *
+     * @see #setDefaultValue(Object)
+     */
+    public V getDefaultValue() {
+        return defaultValue;
+    }
+
+    /**
+     * Sets the default value for the attribute.
      *
-     * @param  value  default property value, or {@code null} if none.
+     * @param  value  default attribute value, or {@code null} if none.
      * @return {@code this} for allowing method calls chaining.
+     *
+     * @see #getDefaultValue()
      */
     public AttributeTypeBuilder<V> setDefaultValue(final V value) {
         if (!Objects.equals(defaultValue, value)) {
@@ -165,14 +247,30 @@ public final class AttributeTypeBuilder<
     }
 
     /**
-     * Sets an enumeration of valid values for this attribute.
+     * Returns an enumeration of valid values for the attribute, or an empty array if none.
+     *
+     * @return valid values for the attribute, or an empty array if none.
+     */
+    @SuppressWarnings("unchecked")
+    public V[] getValidValues() {
+        final Collection<?> c = CollectionsExt.nonNull((Collection<?>)
+                getCharacteristic(AttributeConvention.VALID_VALUES_CHARACTERISTIC));
+        final V[] values = (V[]) Array.newInstance(valueClass, c.size());
+        int index = 0;
+        for (final Object value : c) {
+            values[index++] = (V) value;        // ArrayStoreException if 'value' is not
the expected type.
+        }
+        return values;
+    }
+
+    /**
+     * Sets an enumeration of valid values for the attribute.
      *
      * <p>This is a convenience method for {@link #addCharacteristic(Class)} with a
value
      * of type {@link Set} and a conventional name.</p>
      *
      * @param  values valid values.
      * @return {@code this} for allowing method calls chaining.
-     * @throws UnsupportedOperationException if this property does not support characteristics.
      *
      * @see #characteristics()
      * @see AttributeConvention#VALID_VALUES_CHARACTERISTIC
@@ -193,7 +291,6 @@ public final class AttributeTypeBuilder<
      *
      * @param  length  maximal length of {@link CharSequence} attribute values, or {@code
null}.
      * @return {@code this} for allowing method calls chaining.
-     * @throws UnsupportedOperationException if this property does not support length characteristics.
      *
      * @see #characteristics()
      * @see AttributeConvention#MAXIMAL_LENGTH_CHARACTERISTIC
@@ -212,7 +309,6 @@ public final class AttributeTypeBuilder<
      *
      * @param  crs  coordinate reference system associated to attribute values, or {@code
null}.
      * @return {@code this} for allowing method calls chaining.
-     * @throws UnsupportedOperationException if this property does not support CRS characteristics.
      *
      * @see #characteristics()
      * @see AttributeConvention#CRS_CHARACTERISTIC
@@ -222,6 +318,18 @@ public final class AttributeTypeBuilder<
     }
 
     /**
+     * Implementation of all getter methods for characteristics.
+     */
+    private Object getCharacteristic(final GenericName name) {
+        for (final CharacteristicTypeBuilder<?> characteristic : characteristics) {
+            if (name.equals(characteristic.getName())) {
+                return characteristic.getDefaultValue();
+            }
+        }
+        return null;
+    }
+
+    /**
      * Implementation of all setter methods for characteristics.
      */
     private <C> AttributeTypeBuilder<V> setCharacteristic(final GenericName name,
final Class<C> type, final C value) {
@@ -285,6 +393,7 @@ public final class AttributeTypeBuilder<
      * @param role the role to add to this attribute (shall not be null).
      */
     public void addRole(final AttributeRole role) {
+        final FeatureTypeBuilder owner = owner();
         ensureNonNull("role", role);
         switch (role) {
             case IDENTIFIER_COMPONENT: {
@@ -338,6 +447,20 @@ public final class AttributeTypeBuilder<
     }
 
     /**
+     * Replaces the given characteristic by a new one. Exactly one instance of the old characteristic
+     * shall exist (this is not verified).
+     *
+     * @see CharacteristicTypeBuilder#setValueClass(Class)
+     */
+    final void replace(final CharacteristicTypeBuilder<?> old, final CharacteristicTypeBuilder<?>
n) {
+        /*
+         * We do not verify if lastIndexOf(old) >= 0 because
+         * an element not found would be a bug in our algorithm.
+         */
+        characteristics.set(characteristics.lastIndexOf(old), n);
+    }
+
+    /**
      * {@inheritDoc}
      */
     @Override
@@ -373,7 +496,7 @@ public final class AttributeTypeBuilder<
     }
 
     /**
-     * Creates a new property type from the current setting.
+     * Creates a new attribute type from the current setting.
      */
     @Override
     final PropertyType create() {

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=1754804&r1=1754803&r2=1754804&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] Mon Aug  1 22:28:25 2016
@@ -19,6 +19,8 @@ package org.apache.sis.feature.builder;
 import org.opengis.util.GenericName;
 import org.apache.sis.feature.DefaultAttributeType;
 import org.apache.sis.util.Classes;
+import org.apache.sis.util.ObjectConverters;
+import org.apache.sis.util.UnconvertibleObjectException;
 
 // Branch-dependent imports
 import java.util.Objects;
@@ -45,11 +47,12 @@ import org.opengis.feature.AttributeType
 public final class CharacteristicTypeBuilder<V> extends TypeBuilder {
     /**
      * The attribute type builder instance that created this {@code CharacteristicTypeBuilder}
builder.
+     * This is set at construction time and considered as immutable until it is set to {@code
null}.
      */
-    private final AttributeTypeBuilder<?> owner;
+    AttributeTypeBuilder<?> owner;
 
     /**
-     * The class of attribute values. Can not be changed after construction
+     * The class of characteristic values. Can not be changed after construction
      * because this value determines the parameterized type {@code <V>}.
      */
     private final Class<V> valueClass;
@@ -66,6 +69,22 @@ public final class CharacteristicTypeBui
     private transient AttributeType<V> characteristic;
 
     /**
+     * Creates a new builder initialized to the values of the given builder but a different
type.
+     * This constructor is for {@link #setValueClass(Class)} implementation only.
+     *
+     * @throws UnconvertibleObjectException if the default value can not be converted to
the given class.
+     */
+    private CharacteristicTypeBuilder(final CharacteristicTypeBuilder<?> builder, final
Class<V> valueClass)
+            throws UnconvertibleObjectException
+    {
+        super(builder);
+        this.owner        = builder.owner;
+        this.valueClass   = valueClass;
+        this.defaultValue = ObjectConverters.convert(builder.defaultValue, valueClass);
+        // Do not copy the 'characteristic' reference since the 'valueClass' is different.
+    }
+
+    /**
      * Creates a new characteristic builder for values of the given class.
      *
      * @param owner      the builder of the {@code AttributeType} for which to add this property.
@@ -97,6 +116,7 @@ public final class CharacteristicTypeBui
     @Override
     final void clearCache() {
         characteristic = null;
+        ensureAlive(owner);
         owner.clearCache();
     }
 
@@ -156,14 +176,55 @@ public final class CharacteristicTypeBui
      */
     @Override
     final GenericName name(final String scope, final String localPart) {
+        ensureAlive(owner);
         return owner.name(scope, localPart);
     }
 
     /**
-     * Sets the default value with check of the value class.
+     * Returns the class of characteristic values.
+     *
+     * @return the class of characteristic values.
+     *
+     * @see #setValueClass(Class)
      */
-    final void set(final Object value) {
-        setDefaultValue(valueClass.cast(value));
+    public Class<V> getValueClass() {
+        return valueClass;
+    }
+
+    /**
+     * Sets the class of characteristic values. Callers <strong>must</strong>
use the builder returned by this method
+     * instead of {@code this} builder after this method call, since the returned builder
may be a new instance.
+     *
+     * @param  <N>   the compile-time value of the {@code type} argument.
+     * @param  type  the new class of characteristic values.
+     * @return the characteristic builder — <em>not necessarily this instance.</em>
+     * @throws UnconvertibleObjectException if the {@linkplain #getDefaultValue() default
value}
+     *         can not be converted to the given {@code <N>} class.
+     *
+     * @see #getValueClass()
+     */
+    @SuppressWarnings("unchecked")
+    public <N> CharacteristicTypeBuilder<N> setValueClass(final Class<N>
type) throws UnconvertibleObjectException {
+        ensureAlive(owner);
+        ensureNonNull("type", type);
+        if (type == valueClass) {
+            return (CharacteristicTypeBuilder<N>) this;
+        }
+        final CharacteristicTypeBuilder<N> n = new CharacteristicTypeBuilder<>(this,
type);
+        owner.replace(this, n);
+        owner = null;
+        return n;
+    }
+
+    /**
+     * Returns the default value for the characteristic, or {@code null} if none.
+     *
+     * @return the default characteristic value, or {@code null} if none.
+     *
+     * @see #setDefaultValue(Object)
+     */
+    public V getDefaultValue() {
+        return defaultValue;
     }
 
     /**
@@ -171,6 +232,8 @@ public final class CharacteristicTypeBui
      *
      * @param  value  characteristic default value, or {@code null} if none.
      * @return {@code this} for allowing method calls chaining.
+     *
+     * @see #getDefaultValue()
      */
     public CharacteristicTypeBuilder<V> setDefaultValue(final V value) {
         if (!Objects.equals(defaultValue, value)) {
@@ -181,6 +244,13 @@ public final class CharacteristicTypeBui
     }
 
     /**
+     * Sets the default value with check of the value class.
+     */
+    final void set(final Object value) {
+        setDefaultValue(valueClass.cast(value));
+    }
+
+    /**
      * {@inheritDoc}
      */
     @Override

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=1754804&r1=1754803&r2=1754804&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] Mon Aug  1 22:28:25 2016
@@ -425,6 +425,20 @@ public class FeatureTypeBuilder extends
     }
 
     /**
+     * Replaces the given attribute by a new one. Exactly one instance of the old attribute
+     * shall exist (this is not verified).
+     *
+     * @see AttributeTypeBuilder#setValueClass(Class)
+     */
+    final void replace(final AttributeTypeBuilder<?> old, final AttributeTypeBuilder<?>
n) {
+        /*
+         * We do not verify if lastIndexOf(old) >= 0 because
+         * an element not found would be a bug in our algorithm.
+         */
+        properties.set(properties.lastIndexOf(old), n);
+    }
+
+    /**
      * Creates a new {@code AttributeType} builder for values of the given class.
      * The default attribute name is the name of the given type, but callers should invoke
one
      * of the {@code AttributeTypeBuilder.setName(…)} methods on the returned instance
with a better name.

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=1754804&r1=1754803&r2=1754804&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] Mon Aug  1 22:28:25 2016
@@ -48,8 +48,11 @@ import org.opengis.feature.FeatureAssoci
 public abstract class PropertyTypeBuilder extends TypeBuilder {
     /**
      * The feature type builder instance that created this {@code PropertyTypeBuilder}.
+     * This is set at construction time and considered as immutable until it is set to {@code
null}.
+     *
+     * @see #owner()
      */
-    final FeatureTypeBuilder owner;
+    private FeatureTypeBuilder owner;
 
     /**
      * The minimum number of property values.
@@ -74,6 +77,20 @@ public abstract class PropertyTypeBuilde
     private transient PropertyType property;
 
     /**
+     * Creates a new builder initialized to the values of the given builder.
+     * This constructor is for {@link AttributeTypeBuilder#setValueClass(Class)} implementation.
+     *
+     * @param builder  the builder from which to copy values.
+     */
+    PropertyTypeBuilder(final PropertyTypeBuilder builder) {
+        super(builder);
+        owner         = builder.owner;
+        minimumOccurs = builder.minimumOccurs;
+        maximumOccurs = builder.maximumOccurs;
+        // Do not copy the 'property' reference since the 'valueClass' is different.
+    }
+
+    /**
      * Creates a new {@code PropertyType} builder initialized to the values of an existing
property.
      *
      * @param owner     the builder of the {@code FeatureType} for which to add this property.
@@ -88,6 +105,21 @@ public abstract class PropertyTypeBuilde
     }
 
     /**
+     * Returns the feature type builder instance that created this {@code PropertyTypeBuilder}.
+     */
+    final FeatureTypeBuilder owner() {
+        ensureAlive(owner);
+        return owner;
+    }
+
+    /**
+     * Flags this builder as a disposed one. The builder should not be used anymore after
this method call.
+     */
+    final void dispose() {
+        owner = null;
+    }
+
+    /**
      * Sets the minimum and maximum number of property values. Those numbers must be equal
or greater than zero.
      *
      * <p>If this method is not invoked, then the default values are the cardinality
specified by the last call
@@ -123,6 +155,7 @@ public abstract class PropertyTypeBuilde
      */
     @Override
     final GenericName name(final String scope, final String localPart) {
+        ensureAlive(owner);
         return owner.name(scope, localPart);
     }
 
@@ -133,6 +166,7 @@ public abstract class PropertyTypeBuilde
     @Override
     final void clearCache() {
         property = null;
+        ensureAlive(owner);
         owner.clearCache();
     }
 

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=1754804&r1=1754803&r2=1754804&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] Mon Aug  1 22:28:25 2016
@@ -61,12 +61,22 @@ public abstract class TypeBuilder implem
      * The feature name, definition, designation and description.
      * The name is mandatory; all other information are optional.
      */
-    private final Map<String,Object> identification = new HashMap<>(4);
+    private final Map<String,Object> identification;
+
+    /**
+     * Creates a new builder initialized to the values of the given builder.
+     *
+     * @param builder  the builder from which to copy information.
+     */
+    TypeBuilder(final TypeBuilder builder) {
+        identification = new HashMap<>(builder.identification);
+    }
 
     /**
      * Creates a new builder initialized to the values of an existing type.
      */
     TypeBuilder(final IdentifiedType template, final Locale locale) {
+        identification = new HashMap<>(4);
         putIfNonNull(Errors.LOCALE_KEY, locale);
         if (template != null) {
             putIfNonNull(AbstractIdentifiedType.NAME_KEY,        template.getName());
@@ -137,6 +147,7 @@ public abstract class TypeBuilder implem
      * @return the name of the {@code IdentifiedType} to create (may be a default name or
{@code null}).
      *
      * @see AbstractIdentifiedType#getName()
+     * @see #setName(GenericName)
      */
     public GenericName getName() {
         return (GenericName) identification().get(AbstractIdentifiedType.NAME_KEY);
@@ -170,6 +181,7 @@ public abstract class TypeBuilder implem
      * @return {@code this} for allowing method calls chaining.
      *
      * @see #getName()
+     * @see #setName(String)
      * @see AbstractIdentifiedType#NAME_KEY
      */
     public TypeBuilder setName(final GenericName name) {
@@ -193,6 +205,7 @@ public abstract class TypeBuilder implem
      * @return {@code this} for allowing method calls chaining.
      *
      * @see #getName()
+     * @see #setName(String, String)
      */
     public TypeBuilder setName(final String localPart) {
         ensureNonEmpty("localPart", localPart);
@@ -214,6 +227,7 @@ public abstract class TypeBuilder implem
      * @return {@code this} for allowing method calls chaining.
      *
      * @see #getName()
+     * @see #setName(String)
      */
     public TypeBuilder setName(String scope, final String localPart) {
         ensureNonEmpty("localPart", localPart);
@@ -340,6 +354,17 @@ public abstract class TypeBuilder implem
         }
     }
 
+    /**
+     * Ensures that this instance is still alive.
+     *
+     * @param owner  the owner of this instance. A value of null means that this instance
should not be used any more.
+     */
+    final void ensureAlive(final TypeBuilder owner) {
+        if (owner == null) {
+            throw new IllegalStateException(errors().getString(Errors.Keys.DisposedInstanceOf_1,
getClass()));
+        }
+    }
+
     /**
      * Same as {@link org.apache.sis.util.ArgumentChecks#ensureNonEmpty(String, CharSequence)},
      * but uses the current locale in case of error.

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java?rev=1754804&r1=1754803&r2=1754804&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] Mon Aug  1 22:28:25 2016
@@ -241,6 +241,11 @@ public final class Errors extends Indexe
         public static final short DirectoryNotExpected_1 = 165;
 
         /**
+         * This instance of ‘{0}’ has been disposed.
+         */
+        public static final short DisposedInstanceOf_1 = 234;
+
+        /**
          * Element “{0}” is duplicated.
          */
         public static final short DuplicatedElement_1 = 16;

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties?rev=1754804&r1=1754803&r2=1754804&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] Mon Aug  1 22:28:25 2016
@@ -59,6 +59,7 @@ DatabaseError_2                   = Data
 DatumOriginShallBeDate            = Origin of temporal datum shall be a date.
 DeadThread_1                      = Thread \u201c{0}\u201d is dead.
 DirectoryNotExpected_1            = The \u201c{0}\u201d file points to a directory instead
of a regular file.
+DisposedInstanceOf_1              = This instance of \u2018{0}\u2019 has been disposed.
 DuplicatedElement_1               = Element \u201c{0}\u201d is duplicated.
 DuplicatedIdentifier_1            = Name or identifier \u201c{0}\u201d is used more than
once.
 DuplicatedOption_1                = Option \u201c{0}\u201d is duplicated.

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties?rev=1754804&r1=1754803&r2=1754804&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] Mon Aug  1 22:28:25 2016
@@ -56,6 +56,7 @@ DatabaseError_2                   = Erre
 DatumOriginShallBeDate            = L\u2019origine d\u2019un r\u00e9f\u00e9rentiel temporel
doit \u00eatre une date.
 DeadThread_1                      = La t\u00e2che \u00ab\u202f{0}\u202f\u00bb est morte.
 DirectoryNotExpected_1            = Le fichier \u00ab\u202f{0}\u202f\u00bb d\u00e9signe un
r\u00e9pertoire plut\u00f4t qu\u2019un fichier r\u00e9gulier.
+DisposedInstanceOf_1              = Cette instance de \u2018{0}\u2019 a \u00e9t\u00e9 dispos\u00e9e.
 DuplicatedElement_1               = L\u2019\u00e9lement \u00ab\u202f{0}\u202f\u00bb est dupliqu\u00e9.
 DuplicatedIdentifier_1            = Le nom ou l\u2019identifiant \u00ab\u202f{0}\u202f\u00bb
est utilis\u00e9 plus d\u2019une fois.
 DuplicatedOption_1                = L\u2019option \u00ab\u202f{0}\u202f\u00bb est dupliqu\u00e9e.



Mime
View raw message