sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1469077 - in /sis/branches/JDK7/sis-metadata/src: main/java/org/apache/sis/metadata/ test/java/org/apache/sis/metadata/ test/java/org/apache/sis/test/suite/
Date Wed, 17 Apr 2013 21:32:06 GMT
Author: desruisseaux
Date: Wed Apr 17 21:32:05 2013
New Revision: 1469077

URL: http://svn.apache.org/r1469077
Log:
Refactored PropertyDescriptor as an implementation of ExtendedElementInformation instead of
PropertyDescriptor (SIS-80).

Added:
    sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyInformation.java
      - copied, changed from r1468921, sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyDescriptor.java
    sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyInformationTest.java
      - copied, changed from r1468921, sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyDescriptorTest.java
Removed:
    sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyDescriptor.java
    sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyDescriptorTest.java
Modified:
    sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
    sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyAccessorTest.java
    sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java

Modified: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java?rev=1469077&r1=1469076&r2=1469077&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
[UTF-8] Wed Apr 17 21:32:05 2013
@@ -30,7 +30,7 @@ import java.lang.reflect.InvocationTarge
 import net.jcip.annotations.ThreadSafe;
 import org.opengis.annotation.UML;
 import org.opengis.metadata.citation.Citation;
-import org.opengis.parameter.ParameterDescriptor;
+import org.opengis.metadata.ExtendedElementInformation;
 import org.apache.sis.measure.ValueRange;
 import org.apache.sis.util.Classes;
 import org.apache.sis.util.Numbers;
@@ -201,13 +201,13 @@ final class PropertyAccessor {
     private transient volatile ObjectConverter<?,?> converter;
 
     /**
-     * The property descriptions, including the name and restrictions on valid values.
+     * The property information, including the name and restrictions on valid values.
      * The array will be created when first needed. A {@code null} element means that
-     * the descriptor at that index has not yet been computed.
+     * the information at that index has not yet been computed.
      *
-     * @see #descriptor(int)
+     * @see #information(int)
      */
-    private transient ParameterDescriptor<?>[] descriptors;
+    private transient ExtendedElementInformation[] informations;
 
     /**
      * Creates a new property accessor for the specified metadata implementation.
@@ -538,26 +538,25 @@ final class PropertyAccessor {
     }
 
     /**
-     * Returns the descriptor for the property at the given index.
-     * The descriptor are created when first needed.
+     * Returns the information for the property at the given index.
+     * The information are created when first needed.
      *
-     * @param  index The index of the property for which to get the descriptor.
-     * @return The descriptor for the property at the given index,
+     * @param  index The index of the property for which to get the information.
+     * @return The information for the property at the given index,
      *         or {@code null} if the index is out of bounds.
      */
     @SuppressWarnings({"unchecked","rawtypes"})
-    final synchronized ParameterDescriptor<?> descriptor(final int index) {
-        ParameterDescriptor[] descriptors = this.descriptors;
-        if (descriptors == null) {
-            this.descriptors = descriptors = new PropertyDescriptor<?>[standardCount];
+    final synchronized ExtendedElementInformation information(final int index) {
+        ExtendedElementInformation[] informations = this.informations;
+        if (informations == null) {
+            this.informations = informations = new PropertyInformation<?>[standardCount];
         }
-        if (index < 0 || index >= descriptors.length) {
+        if (index < 0 || index >= informations.length) {
             return null;
         }
-        ParameterDescriptor<?> descriptor = descriptors[index];
-        if (descriptor == null) {
+        ExtendedElementInformation information = informations[index];
+        if (information == null) {
             final Class<?> elementType = elementTypes[index];
-            final Citation standard    = this.standard;
             final String   name        = name(index, KeyNamePolicy.UML_IDENTIFIER);
             final Method   getter      = getters[index];
             ValueRange range = null;
@@ -572,14 +571,10 @@ final class PropertyAccessor {
                     throw new AssertionError(error);
                 }
             }
-            if (range != null) {
-                descriptor = new PropertyDescriptor.Bounded(elementType, standard, name,
getter, range);
-            } else {
-                descriptor = new PropertyDescriptor<>(elementType, standard, name,
getter);
-            }
-            descriptors[index] = descriptor;
+            information = new PropertyInformation<>(standard, name, getter, elementType,
range);
+            informations[index] = information;
         }
-        return descriptor;
+        return information;
     }
 
     /**

Copied: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyInformation.java
(from r1468921, sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyDescriptor.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyInformation.java?p2=sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyInformation.java&p1=sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyDescriptor.java&r1=1468921&r2=1469077&rev=1469077&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyDescriptor.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyInformation.java
[UTF-8] Wed Apr 17 21:32:05 2013
@@ -16,52 +16,47 @@
  */
 package org.apache.sis.metadata;
 
-import java.util.Set;
 import java.util.Collection;
 import java.util.Collections;
 import java.lang.reflect.Method;
 import net.jcip.annotations.Immutable;
-import javax.measure.unit.Unit;
 import org.opengis.annotation.UML;
-import org.opengis.util.GenericName;
-import org.opengis.util.InternationalString;
+import org.opengis.metadata.Datatype;
+import org.opengis.metadata.Obligation;
 import org.opengis.metadata.citation.Citation;
-import org.opengis.parameter.ParameterValue;
-import org.opengis.parameter.ParameterDescriptor;
-import org.opengis.referencing.ReferenceIdentifier;
+import org.opengis.metadata.ExtendedElementInformation;
+import org.opengis.metadata.citation.ResponsibleParty;
+import org.opengis.util.CodeList;
+import org.opengis.util.InternationalString;
 import org.apache.sis.internal.simple.SimpleReferenceIdentifier;
-import org.apache.sis.measure.NumberRange;
 import org.apache.sis.measure.ValueRange;
 import org.apache.sis.util.iso.Types;
-
-// Related to JDK7
-import java.util.Objects;
+import org.apache.sis.util.Numbers;
+import org.apache.sis.util.collection.CheckedContainer;
 
 
 /**
  * Description of a metadata property inferred from Java reflection.
  * For a given metadata instances (typically an {@link AbstractMetadata} subclasses,
- * but other types are allowed), instances of {@code PropertyDescriptor} are obtained
- * indirectly by the {@link MetadataStandard#asDescriptorMap(Object, KeyNamePolicy,
- * ValueExistencePolicy)} method.
+ * but other types are allowed), instances of {@code PropertyInformation} are obtained
+ * indirectly by the {@link MetadataStandard#getElementInformation(Object, KeyNamePolicy)}
method.
  *
  * @param <T> The value type, either the method return type if not a collection,
  *            or the type of elements in the collection otherwise.
  *
+ *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-3.05)
  * @version 0.3
  * @module
  *
- * @see MetadataStandard#asDescriptorMap(Object, KeyNamePolicy, ValueExistencePolicy)
+ * @see MetadataStandard#getElementInformation(Object, KeyNamePolicy)
  * @see <a href="https://issues.apache.org/jira/browse/SIS-80">SIS-80</a>
- *
- * @todo Implementing {@code ParameterDescriptor} is not really appropriate since metadata
properties
- *       are not parameters. Implementing {@link org.opengis.feature.type.PropertyDescriptor}
would
- *       be better, but the later is not yet part of GeoAPI standard and needs cleaning.
See SIS-80.
  */
 @Immutable
-class PropertyDescriptor<T> extends SimpleReferenceIdentifier implements ParameterDescriptor<T>
{
+final class PropertyInformation<T> extends SimpleReferenceIdentifier
+        implements ExtendedElementInformation, CheckedContainer<T>
+{
     /**
      * For cross-versions compatibility.
      */
@@ -70,258 +65,240 @@ class PropertyDescriptor<T> extends Simp
     /**
      * The interface which contain this property.
      *
-     * @see #getCodeSpace()
+     * @see #getParentEntity()
      */
-    final Class<?> container;
+    private final Class<?> parent;
 
     /**
      * The value type, either the method return type if not a collection,
      * or the type of elements in the collection otherwise.
      *
-     * @see #getValueClass()
+     * @see #getDataType()
+     * @see #getElementType()
      */
     private final Class<T> elementType;
 
     /**
-     * Minimal and maximal occurrences of this property, packed as below:
-     *
-     * <ul>
-     *   <li>Rightmost bit encodes the minimal occurrence.</li>
-     *   <li>All other bits encode the maximal occurrence.</li>
-     * </ul>
+     * The minimum number of occurrences.
+     * A {@code minimumOccurs} value of -1 means that the property is conditional,
+     * i.e. the actual {@code minimumOccurs} value can either 0 or 1 depending on
+     * the value of another property.
      *
-     * @see #getMinimumOccurs()
-     * @see #getMaximumOccurs()
+     * @see #getObligation()
      */
-    private final byte cardinality;
+    private final byte minimumOccurs;
 
     /**
-     * Specialization of {@link PropertyDescriptor} when the range of legal values is
-     * specified by a {@link ValueRange} annotation. Those values must be numeric.
+     * The maximum number of occurrences as an unsigned number.
+     * Value 255 (or -1 as a signed number) shall be understood as {@link Integer#MAX_VALUE}.
      *
-     * <p>Bounded properties are represented by a different class because the requirement
-     * for numerical values put additional constraints on the {@code <T>} parameterized
type,
-     * and because bounded properties are relatively rare so we can avoid to carry a null
-     * range fields for the properties that don't need it.</p>
-     *
-     * @param <T> The numeric value type.
+     * @see #getMaximumOccurrence()
      */
-    static final class Bounded<T extends Number & Comparable<T>> extends
PropertyDescriptor<T> {
-        /** For cross versions compatibility. */
-        private static final long serialVersionUID = 2066938309308576985L;
-
-        /** The range of valid values. */
-        private final NumberRange<T> range;
-
-        /** Creates a new descriptor for the given range of values. */
-        Bounded(final Class<T> type, final Citation standard,
-                final String property, final Method getter, final ValueRange range)
-        {
-            super(type, standard, property, getter);
-            this.range = new NumberRange<>(type, range);
-        }
-
-        /** Returns the minimum parameter value, assumed inclusive. */
-        @Override
-        public Comparable<T> getMinimumValue() {
-            return range.getMinValue();
-        }
-
-        /** Returns the maximum parameter value, assumed inclusive. */
-        @Override
-        public Comparable<T> getMaximumValue() {
-            return range.getMaxValue();
-        }
-
-        /** Compares the given object for equality. */
-        @Override
-        public boolean equals(final Object obj) {
-            if (super.equals(obj)) {
-                return Objects.equals(range, ((Bounded) obj).range);
-            }
-            return false;
-        }
-    }
+    private final byte maximumOccurs;
 
     /**
-     * Creates a new {@code PropertyDescriptor} instance from the annotations on the given
-     * getter method. If there is no restriction, then this method returns {@code null}.
+     * Creates a new {@code PropertyInformation} instance from the annotations on the given
+     * getter method.
      *
-     * @param  elementType The value type, either the method return type if not a collection,
-     *                     or the type of elements in the collection otherwise.
      * @param  standard    The international standard that define the property, or {@code
null} if none.
-     * @param  property    The property name as defined by the international {@linkplain
#standard}.
+     * @param  property    The property name as defined by the international {@code standard}.
      * @param  getter      The getter method defined in the interface.
+     * @param  elementType The value type, either the method return type if not a collection,
+     *                     or the type of elements in the collection otherwise.
+     * @param  valueRange  The range of valid values, or {@code null} if none. This information
is associated to the
+     *                     implementation method rather than the interface one, because it
is specific to SIS.
      */
     @SuppressWarnings({"unchecked","rawtypes"})
-    PropertyDescriptor(final Class<T> elementType, final Citation standard, final String
property, final Method getter) {
+    PropertyInformation(final Citation standard, final String property, final Method getter,
+            final Class<T> elementType, final ValueRange range)
+    {
         super(standard, property);
-        container = getter.getDeclaringClass();
+        parent = getter.getDeclaringClass();
         this.elementType = elementType;
         final UML uml = getter.getAnnotation(UML.class);
-        byte cardinality = 2; // minOccurs = 0, maxOccurs = 1;
+        byte minimumOccurs = 0;
+        byte maximumOccurs = 1;
         if (uml != null) {
             switch (uml.obligation()) {
-                case MANDATORY:      cardinality = 3; break;  // minOccurs = 1, maxOccurs
= 1;
-                case FORBIDDEN: this.cardinality = 0; return; // minOccurs = 0, maxOccurs
= 0;
+                case MANDATORY:   minimumOccurs =  1; break;
+                case FORBIDDEN:   maximumOccurs =  0; break;
+                case CONDITIONAL: minimumOccurs = -1; break;
             }
         }
-        final Class<?> c = getter.getReturnType();
-        if (c.isArray() || Collection.class.isAssignableFrom(c)) {
-            cardinality |= 0xFE; // Set all bits except the rightmost one, which is left
unchanged.
+        if (maximumOccurs != 0) {
+            final Class<?> c = getter.getReturnType();
+            if (c.isArray() || Collection.class.isAssignableFrom(c)) {
+                maximumOccurs = -1;
+            }
         }
-        this.cardinality = cardinality;
+        this.minimumOccurs = minimumOccurs;
+        this.maximumOccurs = maximumOccurs;
+        // TODO: store the range.
     }
 
     /**
-     * Returns the primary name by which this object is identified.
-     * This is fixed to {@code this} for more efficient storage of
-     * potentially large amount of {@code PropertyDescriptor}s.
-     *
-     * <p>Users invoke this method in order to get access to the {@link #getCode()},
-     * {@link #getCodeSpace()}, {@link #getVersion()} and {@link #getAuthority()} methods.</p>
+     * Returns the primary name by which this metadata element is identified.
      */
     @Override
-    public final ReferenceIdentifier getName() {
-        return this;
+    public String getName() {
+        return code;
     }
 
     /**
      * Returns the ISO name of the class containing the property,
      * or the simple class name if the ISO name is undefined.
+     *
+     * @see #getParentEntity()
      */
     @Override
     public final String getCodeSpace() {
-        String codespace = Types.getStandardName(container);
+        String codespace = Types.getStandardName(parent);
         if (codespace == null) {
-            codespace = container.getSimpleName();
+            codespace = parent.getSimpleName();
         }
         return codespace;
     }
 
     /**
-     * An identifier which references elsewhere the object's defining information.
-     * The current implementation returns an empty set.
+     * Unconditionally returns {@code null}.
+     *
+     * @deprecated This property was defined in the 2003 edition of ISO 19115,
+     *             but has been removed in the 2013 edition.
      */
     @Override
-    public final Set<ReferenceIdentifier> getIdentifiers() {
-        return Collections.emptySet();
+    @Deprecated
+    public String getShortName() {
+        return null;
     }
 
     /**
-     * An alternative name by which this object is identified.
-     * The current implementation returns an empty set.
+     * Unconditionally returns {@code null}.
      *
-     * <p>Future implementation may return the JavaBeans property name,
-     * if different than the ISO name.</p>
+     * @deprecated This property was defined in the 2003 edition of ISO 19115,
+     *             but has been removed in the 2013 edition.
      */
     @Override
-    public final Collection<GenericName> getAlias() {
-        return Collections.emptySet();
+    @Deprecated
+    public Integer getDomainCode() {
+        return null;
     }
 
     /**
-     * Returns comments about this property, or {@code null} if none.
+     * Returns the definition of this property, or {@code null} if none.
      */
     @Override
-    public final InternationalString getRemarks() {
-        return Types.getDescription(container, code);
+    public final InternationalString getDefinition() {
+        return Types.getDescription(parent, code);
     }
 
     /**
-     * Returns the class that describe the type of the parameter.
-     * This is the type given at construction time.
+     * Returns the obligation of the element.
      */
     @Override
-    public final Class<T> getValueClass() {
-        return elementType;
+    public Obligation getObligation() {
+        switch (minimumOccurs) {
+            case -1: return Obligation.CONDITIONAL;
+            case  0: return Obligation.OPTIONAL;
+            default: return Obligation.MANDATORY;
+        }
     }
 
     /**
-     * Returns the default value for the parameter, or {@code null} if none.
-     * Current implementation unconditionally return {@code null}.
+     * Returns the condition under which the extended element is mandatory.
+     * Current implementation always return {@code null}, since the condition
+     * is not yet documented programmatically.
      */
     @Override
-    public final T getDefaultValue() {
+    public InternationalString getCondition() {
         return null;
     }
 
     /**
-     * Returns the minimum parameter value, or {@code null} if none.
-     * The {@link ValueRange#minimum()} value is assumed inclusive
-     * (this is not verified).
+     * Returns the kind of value provided in the extended element.
+     * This is a generic code that describe the element type.
+     * For more accurate information, see {@link #getElementType()}.
      */
     @Override
-    public Comparable<T> getMinimumValue() {
-        return null;
+    public Datatype getDataType() {
+        if (CharSequence.class.isAssignableFrom(elementType)) return Datatype.CHARACTER_STRING;
+        if (CodeList    .class.isAssignableFrom(elementType)) return Datatype.CODE_LIST;
+        if (Enum        .class.isAssignableFrom(elementType)) return Datatype.ENUMERATION;
+        if (Numbers.isInteger(elementType)) {
+            return Datatype.INTEGER;
+        }
+        // TODO: check the org.opengis.annotation.Classifier annotation here.
+        return Datatype.TYPE_CLASS;
     }
 
     /**
-     * Returns the minimum parameter value, or {@code null} if none.
-     * The {@link ValueRange#maximum()} value is assumed inclusive
-     * (this is not verified).
+     * Returns the case type of values to be stored in the property.
+     * If the property type is an array or a collection, then this method
+     * returns the type of elements in the array or collection.
      */
     @Override
-    public Comparable<T> getMaximumValue() {
-        return null;
+    public Class<T> getElementType() {
+        return elementType;
     }
 
     /**
-     * Returns the set of allowed values when these are restricted to some finite set.
-     * The default implementation returns {@code null} since there is no restriction even
-     * on code list (we can not return the set of all code list elements since this list
-     * may growth at runtime).
-     *
-     * However if we want to restrict the set of applicable code list values, we can do
-     * that here using {@link org.apache.sis.util.collection.CodeListSet}.
+     * Returns the maximum number of times that values are required.
+     * This method returns 0 if the property is forbidden, {@link Integer#MAX_VALUE}
+     * if the property is an array or a collection, or 1 otherwise.
      */
     @Override
-    public final Set<T> getValidValues() {
-        return null;
+    public Integer getMaximumOccurrence() {
+        final int n = maximumOccurs & 0xFF;
+        return (n == 0xFF) ? Integer.MAX_VALUE : n;
     }
 
     /**
-     * Returns the unit of measurement. The current implementation returns {@code null}.
+     * Returns valid values that can be assigned to the extended element, or {@code null}
if none.
      */
     @Override
-    public final Unit<?> getUnit() {
-        return null;
+    public InternationalString getDomainValue() {
+        return null; // TODO: A NumberRange subclass implementing InternationalString?
     }
 
     /**
-     * Returns the minimum number of times that values are required.
-     * This method returns 1 if the property is mandatory, or 0 otherwise.
+     * Returns the name of the metadata entity under which this metadata element may appear.
+     * The name may be standard metadata element or other extended metadata element.
+     *
+     * @see #getCodeSpace()
      */
     @Override
-    public final int getMinimumOccurs() {
-        return cardinality & 1;
+    public Collection<String> getParentEntity() {
+        return Collections.singleton(getCodeSpace());
     }
 
     /**
-     * Returns the maximum number of times that values are required.
-     * This method returns 0 if the property is forbidden, {@link Integer#MAX_VALUE}
-     * if the property is an array or a collection, or 1 otherwise.
+     * Specifies how the extended element relates to other existing elements and entities.
+     * The current implementation always return {@code null}.
+     */
+    @Override
+    public InternationalString getRule() {
+        return null;
+    }
+
+    /**
+     * Unconditionally returns an empty list.
      */
     @Override
-    public final int getMaximumOccurs() {
-        // The cast to (int) propagate the sign bit on all bytes.
-        // Using unsigned shift, the 1111…111_ bit pattern become
-        // 0111…1111, which is Integer.MAX_VALUE.
-        return ((int) cardinality) >>> 1;
+    public Collection<InternationalString> getRationales() {
+        return Collections.emptyList();
     }
 
     /**
-     * Unsupported operation.
+     * Returns the name of the person or organization creating the element.
      */
     @Override
-    public final ParameterValue<T> createValue() {
-        throw new UnsupportedOperationException();
+    public Collection<? extends ResponsibleParty> getSources() {
+        return authority.getCitedResponsibleParties();
     }
 
     /**
-     * Compares the given object with this descriptor for equality.
+     * Compares the given object with this element information for equality.
      *
-     * @param  obj The object to compare with this descriptor for equality.
+     * @param  obj The object to compare with this element information for equality.
      * @return {@code true} if both objects are equal.
      */
     @Override
@@ -330,10 +307,11 @@ class PropertyDescriptor<T> extends Simp
             return true;
         }
         if (super.equals(obj)) {
-            final PropertyDescriptor<?> that = (PropertyDescriptor<?>) obj;
-            return this.container   == that.container   &&
-                   this.elementType == that.elementType &&
-                   this.cardinality == that.cardinality;
+            final PropertyInformation<?> that = (PropertyInformation<?>) obj;
+            return this.parent        == that.parent        &&
+                   this.elementType   == that.elementType   &&
+                   this.minimumOccurs == that.minimumOccurs &&
+                   this.maximumOccurs == that.maximumOccurs;
 
         }
         return false;
@@ -346,6 +324,6 @@ class PropertyDescriptor<T> extends Simp
      */
     @Override
     public final int hashCode() {
-        return (container.hashCode() + 31 * code.hashCode()) ^ (int) serialVersionUID;
+        return (parent.hashCode() + 31 * code.hashCode()) ^ (int) serialVersionUID;
     }
 }

Modified: sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyAccessorTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyAccessorTest.java?rev=1469077&r1=1469076&r2=1469077&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyAccessorTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyAccessorTest.java
[UTF-8] Wed Apr 17 21:32:05 2013
@@ -69,7 +69,7 @@ import static org.apache.sis.test.TestUt
  * @version 0.3
  * @module
  */
-@DependsOn(PropertyDescriptorTest.class)
+@DependsOn(PropertyInformationTest.class)
 public final strictfp class PropertyAccessorTest extends TestCase {
     /**
      * Creates a new property accessor for the {@link DefaultCitation} class.
@@ -191,10 +191,10 @@ public final strictfp class PropertyAcce
      */
     @Test
     @DependsOnMethod("testConstructor")
-    public void testDescriptor() {
+    public void testInformation() {
         final PropertyAccessor accessor = createPropertyAccessor();
-        PropertyDescriptorTest.validateTitle           (accessor.descriptor(accessor.indexOf("title",
           true)));
-        PropertyDescriptorTest.validatePresentationForm(accessor.descriptor(accessor.indexOf("presentationForm",
true)));
+        PropertyInformationTest.validateTitle           (accessor.information(accessor.indexOf("title",
           true)));
+        PropertyInformationTest.validatePresentationForm(accessor.information(accessor.indexOf("presentationForm",
true)));
     }
 
     /**

Copied: sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyInformationTest.java
(from r1468921, sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyDescriptorTest.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyInformationTest.java?p2=sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyInformationTest.java&p1=sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyDescriptorTest.java&r1=1468921&r2=1469077&rev=1469077&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyDescriptorTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyInformationTest.java
[UTF-8] Wed Apr 17 21:32:05 2013
@@ -18,38 +18,43 @@ package org.apache.sis.metadata;
 
 import java.util.Locale;
 import org.opengis.util.InternationalString;
-import org.opengis.parameter.ParameterDescriptor;
+import org.opengis.metadata.Datatype;
+import org.opengis.metadata.Obligation;
+import org.opengis.metadata.Identifier;
 import org.opengis.metadata.citation.Citation;
 import org.opengis.metadata.citation.PresentationForm;
+import org.opengis.metadata.ExtendedElementInformation;
 import org.apache.sis.metadata.iso.citation.HardCodedCitations;
+import org.apache.sis.util.collection.CheckedContainer;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
 import static org.apache.sis.test.Assert.*;
+import static org.apache.sis.test.TestUtilities.getSingleton;
 
 
 /**
- * Tests {@link PropertyDescriptor}.
+ * Tests {@link PropertyInformation}.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
  * @version 0.3
  * @module
  */
-public final strictfp class PropertyDescriptorTest extends TestCase {
+public final strictfp class PropertyInformationTest extends TestCase {
     /**
-     * Creates a property descriptor instance for the given method of the {@link Citation}
interface.
+     * Creates a property information instance for the given method of the {@link Citation}
interface.
      *
      * @param  elementType The type of elements returned by the given method.
      * @param  method      The name of the method.
      * @param  property    The ISO 19115 name of the property.
      * @throws NoSuchMethodException If the {@code method} name is invalid.
      */
-    private static <T> PropertyDescriptor<T> create(final Class<T> elementType,
final String method,
+    private static <T> PropertyInformation<T> create(final Class<T> elementType,
final String method,
             final String property) throws NoSuchMethodException
     {
-        return new PropertyDescriptor<>(elementType, HardCodedCitations.ISO_19115,
property,
-                Citation.class.getMethod(method));
+        return new PropertyInformation<>(HardCodedCitations.ISO_19115, property,
+                Citation.class.getMethod(method), elementType, null);
     }
 
     /**
@@ -64,20 +69,23 @@ public final strictfp class PropertyDesc
     }
 
     /**
-     * Validates a descriptor for {@link Citation#getTitle()}.
-     * This is validation code to be shared with {@link PropertyAccessorTest#testDescriptor()}.
+     * Validates a property information for {@link Citation#getTitle()}.
+     * This is validation code to be shared with {@link PropertyAccessorTest#testInformation()}.
      */
-    static void validateTitle(final ParameterDescriptor<?> descriptor) {
-        assertEquals("ISO 19115",   descriptor.getName().getAuthority().getTitle().toString());
-        assertEquals("CI_Citation", descriptor.getName().getCodeSpace());
-        assertEquals("title",       descriptor.getName().getCode());
-        final InternationalString remarks = descriptor.getRemarks();
-        assertEquals("Name by which the cited resource is known.", remarks.toString(Locale.ENGLISH));
+    static void validateTitle(final ExtendedElementInformation information) {
+        assertInstanceOf("SIS-specific", Identifier.class, information);
+        assertEquals("ISO 19115",   ((Identifier) information).getAuthority().getTitle().toString());
+        assertEquals("CI_Citation", getSingleton(information.getParentEntity()));
+        assertEquals("title",       information.getName());
+        final InternationalString definition = information.getDefinition();
+        assertEquals("Name by which the cited resource is known.", definition.toString(Locale.ENGLISH));
         // Test other locale here, if any.
 
-        assertEquals(InternationalString.class, descriptor.getValueClass());
-        assertEquals(1, descriptor.getMinimumOccurs());
-        assertEquals(1, descriptor.getMaximumOccurs());
+        assertInstanceOf("SIS-specific", CheckedContainer.class, information);
+        assertEquals(InternationalString.class, ((CheckedContainer<?>) information).getElementType());
+        assertEquals(Datatype.CHARACTER_STRING, information.getDataType());
+        assertEquals(Obligation.MANDATORY, information.getObligation());
+        assertEquals(Integer.valueOf(1), information.getMaximumOccurrence());
     }
 
     /**
@@ -92,20 +100,23 @@ public final strictfp class PropertyDesc
     }
 
     /**
-     * Validates a descriptor for {@link Citation#getPresentationForms()}.
-     * This is validation code to be shared with {@link PropertyAccessorTest#testDescriptor()}.
+     * Validates information for {@link Citation#getPresentationForms()}.
+     * This is validation code to be shared with {@link PropertyAccessorTest#testInformation()}.
      */
-    static void validatePresentationForm(final ParameterDescriptor<?> descriptor) {
-        assertEquals("ISO 19115",        descriptor.getName().getAuthority().getTitle().toString());
-        assertEquals("CI_Citation",      descriptor.getName().getCodeSpace());
-        assertEquals("presentationForm", descriptor.getName().getCode());
-        final InternationalString remarks = descriptor.getRemarks();
-        assertEquals("Mode in which the resource is represented.", remarks.toString(Locale.ENGLISH));
+    static void validatePresentationForm(final ExtendedElementInformation information) {
+        assertInstanceOf("SIS-specific", Identifier.class, information);
+        assertEquals("ISO 19115",        ((Identifier) information).getAuthority().getTitle().toString());
+        assertEquals("CI_Citation",      getSingleton(information.getParentEntity()));
+        assertEquals("presentationForm", information.getName());
+        final InternationalString definition = information.getDefinition();
+        assertEquals("Mode in which the resource is represented.", definition.toString(Locale.ENGLISH));
         // Test other locale here, if any.
 
-        assertEquals(PresentationForm.class, descriptor.getValueClass());
-        assertEquals(0, descriptor.getMinimumOccurs());
-        assertEquals(Integer.MAX_VALUE, descriptor.getMaximumOccurs());
+        assertInstanceOf("SIS-specific", CheckedContainer.class, information);
+        assertEquals(PresentationForm.class, ((CheckedContainer<?>) information).getElementType());
+        assertEquals(Datatype.CODE_LIST, information.getDataType());
+        assertEquals(Obligation.OPTIONAL, information.getObligation());
+        assertEquals(Integer.valueOf(Integer.MAX_VALUE), information.getMaximumOccurrence());
     }
 
     /**

Modified: sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java?rev=1469077&r1=1469076&r2=1469077&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
[UTF-8] Wed Apr 17 21:32:05 2013
@@ -30,7 +30,7 @@ import org.junit.runners.Suite;
  */
 @Suite.SuiteClasses({
     org.apache.sis.internal.metadata.MetadataUtilitiesTest.class,
-    org.apache.sis.metadata.PropertyDescriptorTest.class,
+    org.apache.sis.metadata.PropertyInformationTest.class,
     org.apache.sis.metadata.PropertyAccessorTest.class,
     org.apache.sis.metadata.MetadataStandardTest.class
 })



Mime
View raw message