Author: desruisseaux
Date: Thu Mar 6 12:08:08 2014
New Revision: 1574852
URL: http://svn.apache.org/r1574852
Log:
Use the Map approach in AbstractIdentifiedType for allowing extension with new
properties in the future.
This is the same approach than AbstractIdentifiedObject. We will provide a
builder in next SIS version
for making construction easier, similar to the ParameterBuilder we just
experimented.
Modified:
sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractIdentifiedType.java
sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAttributeType.java
sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
Modified:
sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractIdentifiedType.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractIdentifiedType.java?rev=1574852&r1=1574851&r2=1574852&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractIdentifiedType.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractIdentifiedType.java
[UTF-8] Thu Mar 6 12:08:08 2014
@@ -16,9 +16,15 @@
*/
package org.apache.sis.feature;
+import java.util.Map;
import java.io.Serializable;
import org.opengis.util.GenericName;
-import org.apache.sis.util.ArgumentChecks;
+import org.opengis.util.InternationalString;
+import org.apache.sis.internal.system.DefaultFactories;
+import org.apache.sis.util.resources.Errors;
+import org.apache.sis.util.iso.Types;
+
+import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
// Related to JDK7
import java.util.Objects;
@@ -44,18 +50,148 @@ public class AbstractIdentifiedType impl
private static final long serialVersionUID = 277130188958446740L;
/**
+ * Key for the <code>{@value}</code> property to be given to the
constructor.
+ * This is used for setting the value to be returned by {@link #getName()}.
+ *
+ * @see #getName()
+ */
+ public static final String NAME_KEY = "name";
+
+ /**
+ * Key for the <code>{@value}</code> property to be given to the
constructor.
+ * This is used for setting the value to be returned by {@link
#getDefinition()}.
+ *
+ * @see #getDefinition()
+ */
+ public static final String DEFINITION_KEY = "definition";
+
+ /**
+ * Key for the <code>{@value}</code> property to be given to the
constructor.
+ * This is used for setting the value to be returned by {@link
#getDesignation()}.
+ *
+ * @see #getDesignation()
+ */
+ public static final String DESIGNATION_KEY = "designation";
+
+ /**
+ * Key for the <code>{@value}</code> property to be given to the
constructor.
+ * This is used for setting the value to be returned by {@link
#getDescription()}.
+ *
+ * @see #getDescription()
+ */
+ public static final String DESCRIPTION_KEY = "description";
+
+ /**
* The name of this type.
+ *
+ * @see #getName()
+ * @see #NAME_KEY
*/
private final GenericName name;
/**
- * Creates a type of the given name.
+ * Concise definition of the element.
*
- * @param name The name of this type.
+ * @see #getDefinition()
+ * @see #DEFINITION_KEY
*/
- protected AbstractIdentifiedType(final GenericName name) {
- ArgumentChecks.ensureNonNull("name", name);
- this.name = name;
+ private final InternationalString definition;
+
+ /**
+ * Natural language designator for the element.
+ * This can be used as an alternative to the {@linkplain #name} in user
interfaces.
+ *
+ * @see #getDesignation()
+ * @see #DESIGNATION_KEY
+ */
+ private final InternationalString designation;
+
+ /**
+ * Optional information beyond that required for concise definition of the
element.
+ * The description may assist in understanding the element scope and
application.
+ *
+ * @see #getDescription()
+ * @see #DESCRIPTION_KEY
+ */
+ private final InternationalString description;
+
+ /**
+ * Constructs a type from the given properties. Keys are strings from the
table below.
+ * The map given in argument shall contain an entry at least for the
{@value #NAME_KEY}.
+ * Other properties listed in the table below are optional.
+ *
+ * <table class="sis">
+ * <tr>
+ * <th>Property name</th>
+ * <th>Value type</th>
+ * <th>Returned by</th>
+ * </tr>
+ * <tr>
+ * <td>{@value #NAME_KEY}</td>
+ * <td>{@link GenericName} or {@link String}</td>
+ * <td>{@link #getName()}</td>
+ * </tr>
+ * <tr>
+ * <td>{@value #DEFINITION_KEY}</td>
+ * <td>{@link InternationalString} or {@link String}</td>
+ * <td>{@link #getDefinition()}</td>
+ * </tr>
+ * <tr>
+ * <td>{@value #DESIGNATION_KEY}</td>
+ * <td>{@link InternationalString} or {@link String}</td>
+ * <td>{@link #getDesignation()}</td>
+ * </tr>
+ * <tr>
+ * <td>{@value #DESCRIPTION_KEY}</td>
+ * <td>{@link InternationalString} or {@link String}</td>
+ * <td>{@link #getDescription()}</td>
+ * </tr>
+ * <tr>
+ * <td>{@value
org.apache.sis.referencing.AbstractIdentifiedObject#LOCALE_KEY}</td>
+ * <td>{@link Locale}</td>
+ * <td>(none)</td>
+ * </tr>
+ * </table>
+ *
+ * {@section Localization}
+ * All localizable attributes like {@code "definition"} may have a
language and country code suffix.
+ * For example the {@code "definition_fr"} property stands for remarks in
{@linkplain Locale#FRENCH French} and
+ * the {@code "definition_fr_CA"} property stands for remarks in
{@linkplain Locale#CANADA_FRENCH French Canadian}.
+ * They are convenience properties for building the {@code
InternationalString} value.
+ *
+ * <p>The {@code "locale"} property applies only in case of exception for
formatting the error message, and
+ * is used only on a <cite>best effort</cite> basis. The locale is
discarded after successful construction
+ * since localizations are applied by the {@link
InternationalString#toString(Locale)} method.</p>
+ *
+ * @param properties The name and other properties to be given to this
identified type.
+ * @throws IllegalArgumentException if a property has an invalid value.
+ */
+ protected AbstractIdentifiedType(final Map<String,?> properties) throws
IllegalArgumentException {
+ ensureNonNull("properties", properties);
+ Object value = properties.get(NAME_KEY);
+ if (value == null) {
+ throw new IllegalArgumentException(Errors.getResources(properties)
+ .getString(Errors.Keys.MissingValueForProperty_1,
NAME_KEY));
+ } else if (value instanceof String) {
+ name = DefaultFactories.NAMES.createLocalName(null, (String)
value);
+ } else if (value instanceof GenericName) {
+ name = (GenericName) value;
+ } else {
+ throw illegalPropertyType(properties, NAME_KEY, value);
+ }
+ definition = Types.toInternationalString(properties, DEFINITION_KEY );
+ designation = Types.toInternationalString(properties, DESIGNATION_KEY);
+ description = Types.toInternationalString(properties, DESCRIPTION_KEY);
+ }
+
+ /**
+ * Returns the exception to be thrown when a property is of illegal type.
+ */
+ private static IllegalArgumentException illegalPropertyType(
+ final Map<String,?> properties, final String key, final Object
value)
+ {
+ return new IllegalArgumentException(Errors.getResources(properties)
+ .getString(Errors.Keys.IllegalPropertyClass_2, key,
value.getClass()));
}
/**
@@ -74,13 +210,42 @@ public class AbstractIdentifiedType impl
}
/**
+ * Returns a concise definition of the element.
+ *
+ * @return Concise definition of the element.
+ */
+ public InternationalString getDefinition() {
+ return definition;
+ }
+
+ /**
+ * Returns a natural language designator for the element.
+ * This can be used as an alternative to the {@linkplain #getName()} in
user interfaces.
+ *
+ * @return Natural language designator for the element.
+ */
+ public InternationalString getDesignation() {
+ return designation;
+ }
+
+ /**
+ * Returns optional information beyond that required for concise
definition of the element.
+ * The description may assist in understanding the element scope and
application.
+ *
+ * @return Information beyond that required for concise definition of the
element, or {@code null} if none.
+ */
+ public InternationalString getDescription() {
+ return description;
+ }
+
+ /**
* Returns a hash code value for this type.
*
* @return The hash code for this type.
*/
@Override
public int hashCode() {
- return Objects.hashCode(name);
+ return Objects.hash(name, definition, designation, description);
}
/**
@@ -92,7 +257,11 @@ public class AbstractIdentifiedType impl
@Override
public boolean equals(final Object obj) {
if (obj != null && getClass() != obj.getClass()) {
- return Objects.equals(name, ((AbstractIdentifiedType) obj).name);
+ final AbstractIdentifiedType that = (AbstractIdentifiedType) obj;
+ return Objects.equals(name, that.name) &&
+ Objects.equals(definition, that.definition) &&
+ Objects.equals(designation, that.designation) &&
+ Objects.equals(description, that.description);
}
return false;
}
Modified:
sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAttributeType.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAttributeType.java?rev=1574852&r1=1574851&r2=1574852&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAttributeType.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAttributeType.java
[UTF-8] Thu Mar 6 12:08:08 2014
@@ -16,7 +16,7 @@
*/
package org.apache.sis.feature;
-import org.opengis.util.GenericName;
+import java.util.Map;
import org.apache.sis.measure.Range;
import org.apache.sis.util.Classes;
import org.apache.sis.util.Numbers;
@@ -31,6 +31,9 @@ import java.util.Objects;
/**
* Definition of an attribute in a feature type.
+ * The name of attribute type is mandatory. The name {@linkplain
org.apache.sis.util.iso.AbstractName#scope() scope}
+ * is typically the name of the {@linkplain DefaultFeatureType feature type}
containing this attribute, but this is
+ * not mandatory. The scope could also be defined by the ontology for example.
*
* <div class="note"><b>Note:</b>
* Compared to the Java language, {@code AttributeType} is equivalent to
{@link java.lang.reflect.Field}
@@ -41,6 +44,8 @@ import java.util.Objects;
* When such interface will be available, most references to {@code
DefaultAttributeType} in the API
* will be replaced by references to the {@code AttributeType} interface.</div>
*
+ * @param <T> The value type.
+ *
* @author Martin Desruisseaux (Geomatys)
* @since 0.4
* @version 0.4
@@ -90,7 +95,37 @@ public class DefaultAttributeType<T> ext
private final int minimumOccurs, maximumOccurs;
/**
- * Creates an attribute type of the given name.
+ * Constructs an attribute type from the given properties. The properties
map is given unchanged to
+ * the {@linkplain AbstractIdentifiedType#AbstractIdentifiedType(Map)
super-class constructor}.
+ * The following table is a reminder of main (not all) properties:
+ *
+ * <table class="sis">
+ * <tr>
+ * <th>Property name</th>
+ * <th>Value type</th>
+ * <th>Returned by</th>
+ * </tr>
+ * <tr>
+ * <td>{@value
org.apache.sis.feature.AbstractIdentifiedType#NAME_KEY}</td>
+ * <td>{@link org.opengis.util.GenericName} or {@link String}</td>
+ * <td>{@link #getName()}</td>
+ * </tr>
+ * <tr>
+ * <td>{@value
org.apache.sis.feature.AbstractIdentifiedType#DEFINITION_KEY}</td>
+ * <td>{@link org.opengis.util.InternationalString} or {@link
String}</td>
+ * <td>{@link #getDefinition()}</td>
+ * </tr>
+ * <tr>
+ * <td>{@value
org.apache.sis.feature.AbstractIdentifiedType#DESIGNATION_KEY}</td>
+ * <td>{@link org.opengis.util.InternationalString} or {@link
String}</td>
+ * <td>{@link #getDesignation()}</td>
+ * </tr>
+ * <tr>
+ * <td>{@value
org.apache.sis.feature.AbstractIdentifiedType#DESCRIPTION_KEY}</td>
+ * <td>{@link org.opengis.util.InternationalString} or {@link
String}</td>
+ * <td>{@link #getDescription()}</td>
+ * </tr>
+ * </table>
*
* {@section Domain of attribute values}
* If {@code valueDomain} argument is non-null, then it shall comply to
the following conditions:
@@ -108,7 +143,7 @@ public class DefaultAttributeType<T> ext
* </li>
* </ul>
*
- * @param name The name of this attribute type.
+ * @param properties The name and other properties to be given to this
attribute type.
* @param valueClass The type of attribute values.
* @param valueDomain The minimum value, maximum value and unit of
measurement, or {@code null} if none.
* @param defaultValue The default value for the attribute, or {@code
null} if none.
@@ -116,10 +151,10 @@ public class DefaultAttributeType<T> ext
* @param maximumOccurs The maximum number of occurrences of the property
within its containing entity,
* or {@link Integer#MAX_VALUE} if none.
*/
- public DefaultAttributeType(final GenericName name, final Class<T>
valueClass, final Range<?> valueDomain,
+ public DefaultAttributeType(final Map<String,?> properties, final Class<T>
valueClass, final Range<?> valueDomain,
final T defaultValue, final int minimumOccurs, final int
maximumOccurs)
{
- super(name);
+ super(properties);
ensureNonNull("valueClass", valueClass);
ensureCanCast("defaultValue", valueClass, defaultValue);
if (minimumOccurs < 0 || minimumOccurs > maximumOccurs) {
@@ -224,6 +259,9 @@ public class DefaultAttributeType<T> ext
*/
@Override
public boolean equals(final Object obj) {
+ if (obj == this) {
+ return true;
+ }
if (super.equals(obj)) {
final DefaultAttributeType<?> that = (DefaultAttributeType<?>) obj;
return valueClass == that.valueClass &&
Modified:
sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java?rev=1574852&r1=1574851&r2=1574852&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
[UTF-8] Thu Mar 6 12:08:08 2014
@@ -16,7 +16,7 @@
*/
package org.apache.sis.feature;
-import org.opengis.util.GenericName;
+import java.util.Map;
/**
@@ -39,11 +39,41 @@ import org.opengis.util.GenericName;
*/
public class DefaultFeatureType extends AbstractIdentifiedType {
/**
- * Creates a feature type of the given name.
+ * Constructs a feature type from the given properties. The properties map
is given unchanged to
+ * the {@linkplain AbstractIdentifiedType#AbstractIdentifiedType(Map)
super-class constructor}.
+ * The following table is a reminder of main (not all) properties:
*
- * @param name The name of this feature type.
+ * <table class="sis">
+ * <tr>
+ * <th>Property name</th>
+ * <th>Value type</th>
+ * <th>Returned by</th>
+ * </tr>
+ * <tr>
+ * <td>{@value
org.apache.sis.feature.AbstractIdentifiedType#NAME_KEY}</td>
+ * <td>{@link org.opengis.util.GenericName} or {@link String}</td>
+ * <td>{@link #getName()}</td>
+ * </tr>
+ * <tr>
+ * <td>{@value
org.apache.sis.feature.AbstractIdentifiedType#DEFINITION_KEY}</td>
+ * <td>{@link org.opengis.util.InternationalString} or {@link
String}</td>
+ * <td>{@link #getDefinition()}</td>
+ * </tr>
+ * <tr>
+ * <td>{@value
org.apache.sis.feature.AbstractIdentifiedType#DESIGNATION_KEY}</td>
+ * <td>{@link org.opengis.util.InternationalString} or {@link
String}</td>
+ * <td>{@link #getDesignation()}</td>
+ * </tr>
+ * <tr>
+ * <td>{@value
org.apache.sis.feature.AbstractIdentifiedType#DESCRIPTION_KEY}</td>
+ * <td>{@link org.opengis.util.InternationalString} or {@link
String}</td>
+ * <td>{@link #getDescription()}</td>
+ * </tr>
+ * </table>
+ *
+ * @param properties The name and other properties to be given to this
feature type.
*/
- public DefaultFeatureType(final GenericName name) {
- super(name);
+ public DefaultFeatureType(final Map<String,?> properties) {
+ super(properties);
}
}