Author: desruisseaux
Date: Mon Jun 24 13:14:18 2013
New Revision: 1496026
URL: http://svn.apache.org/r1496026
Log:
Provides a real implementation for the automatically generated skeleton provided in the previous
commit.
Modified:
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultRecordType.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultRecordType.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultRecordType.java?rev=1496026&r1=1496025&r2=1496026&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultRecordType.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultRecordType.java
[UTF-8] Mon Jun 24 13:14:18 2013
@@ -16,48 +16,181 @@
*/
package org.apache.sis.util.iso;
-import java.util.Map;
import java.util.Set;
+import java.util.Map;
+import java.util.LinkedHashMap;
import org.opengis.util.Type;
import org.opengis.util.TypeName;
import org.opengis.util.MemberName;
import org.opengis.util.Record;
import org.opengis.util.RecordType;
import org.opengis.util.RecordSchema;
+import org.apache.sis.util.ArgumentChecks;
+import org.apache.sis.internal.util.CollectionsExt;
+import org.apache.sis.util.resources.Errors;
/**
- * Auto-generated by NetBeans.
+ * An immutable definition of the type of a {@linkplain DefaultRecord record}.
+ * A {@code RecordType} is identified by a {@linkplain #getTypeName() type name} and contains
an
+ * arbitrary amount of {@linkplain #getMembers() members} as (<var>name</var>,
<var>type</var>) pairs.
+ * A {@code RecordType} may therefore contain another {@code RecordType} as a member.
+ *
+ * {@section Comparison with Java reflection}
+ * {@code RecordType} instances can be though as equivalent to instances of the Java {@link
Class} class.
+ * The set of members in a {@code RecordType} can be though as equivalent to the set of fields
in a class.
+ *
+ * @author Martin Desruisseaux (IRD, Geomatys)
+ * @since 0.3
+ * @version 0.3
+ * @module
*/
public class DefaultRecordType implements RecordType {
-
+ /**
+ * The name that identifies this record type.
+ *
+ * @see #getTypeName()
+ */
+ private final TypeName typeName;
+
+ /**
+ * The schema that contains this record type.
+ *
+ * @see #getContainer()
+ */
+ private final RecordSchema container;
+
+ /**
+ * The dictionary of (<var>name</var>, <var>type</var>) pairs.
+ *
+ * @see #getMembers()
+ * @see #getMemberTypes()
+ */
+ private final Map<MemberName,Type> memberTypes;
+
+ /**
+ * Creates a new record.
+ *
+ * @param typeName The name that identifies this record type.
+ * @param container The schema that contains this record type.
+ * @param memberTypes The name of the members to be included in this record type.
+ */
+ public DefaultRecordType(final TypeName typeName, final RecordSchema container, Map<MemberName,Type>
memberTypes) {
+ ArgumentChecks.ensureNonNull("typeName", typeName);
+ ArgumentChecks.ensureNonNull("container", container);
+ ArgumentChecks.ensureNonNull("memberTypes", memberTypes);
+ memberTypes = new LinkedHashMap<>(memberTypes);
+ memberTypes.remove(null);
+ for (final Map.Entry<MemberName,Type> entry : memberTypes.entrySet()) {
+ final MemberName name = entry.getKey();
+ final Type type = entry.getValue();
+ if (type == null || !name.getAttributeType().equals(type.getTypeName())) {
+ throw new IllegalArgumentException(Errors.format(Errors.Keys.IllegalMemberType_2,
name, type));
+ }
+ }
+ this.typeName = typeName;
+ this.container = container;
+ this.memberTypes = CollectionsExt.unmodifiableOrCopy(memberTypes);
+ }
+
+ /**
+ * Returns the name that identifies this record type. If this {@code RecordType} is contained
in a
+ * {@linkplain DefaultRecordSchema record schema}, then the record type name shall be
valid in the
+ * {@linkplain DefaultNameSpace name space} of the record schema:
+ *
+ * {@preformat java
+ * NameSpace namespace = getContainer().getSchemaName().scope()
+ * }
+ *
+ * {@section Comparison with Java reflection}
+ * If we think about this {@code RecordType} as equivalent to a {@code Class} instance,
+ * then this method can be think as the equivalent of the Java {@link Class#getName()}
method.
+ *
+ * @return The name that identifies this record type.
+ */
@Override
public TypeName getTypeName() {
- throw new UnsupportedOperationException();
+ return typeName;
}
+ /**
+ * Returns the schema that contains this record type.
+ *
+ * @return The schema that contains this record type.
+ */
@Override
public RecordSchema getContainer() {
- throw new UnsupportedOperationException();
+ return container;
}
+ /**
+ * Returns the dictionary of all (<var>name</var>, <var>type</var>)
pairs in this record type.
+ * The returned map is unmodifiable.
+ *
+ * {@section Comparison with Java reflection}
+ * If we think about this {@code RecordType} as equivalent to a {@code Class} instance,
then
+ * this method can be though as the related to the Java {@link Class#getFields()} method.
+ *
+ * @return The dictionary of (<var>name</var>, <var>type</var>)
pairs, or an empty map if none.
+ */
@Override
public Map<MemberName, Type> getMemberTypes() {
- throw new UnsupportedOperationException();
+ return memberTypes;
}
+ /**
+ * Returns the set of attribute names defined in this {@code RecordType}'s dictionary.
+ * This method is functionally equivalent to:
+ *
+ * {@preformat java
+ * getMemberTypes().keySet();
+ * }
+ *
+ * @return The set of attribute names, or an empty set if none.
+ */
@Override
public Set<MemberName> getMembers() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public TypeName locate(MemberName mn) {
- throw new UnsupportedOperationException();
+ return memberTypes.keySet();
}
+ /**
+ * Returns the type associated to the given attribute name, or {@code null} if none.
+ * This method is functionally equivalent to:
+ *
+ * {@preformat java
+ * getMemberTypes().get(name);
+ * }
+ *
+ * {@section Comparison with Java reflection}
+ * If we think about this {@code RecordType} as equivalent to a {@code Class} instance,
then
+ * this method can be though as related to the Java {@link Class#getField(String)} method.
+ *
+ * @param memberName The attribute name for which to get the associated type name.
+ * @return The associated type name, or {@code null} if none.
+ */
+ @Override
+ public TypeName locate(final MemberName memberName) {
+ final Type type = memberTypes.get(memberName);
+ return (type != null) ? type.getTypeName() : null;
+ }
+
+ /**
+ * Determines if the given record is compatible with this record type. This method returns
{@code true}
+ * if the given {@code record} argument is non-null and the following condition holds:
+ *
+ * {@preformat java
+ * Set<MemberName> attributeNames = record.getAttributes().keySet();
+ * boolean isInstance = getMembers().containsAll(attributeNames);
+ * }
+ *
+ * {@note We do not require that {@code record.getRecordType() == this} in order to allow
record
+ * "sub-types" to define additional fields, in a way similar to Java sub-classing.}
+ *
+ * @param record The record to test for compatibility.
+ * @return {@code true} if the given record is compatible with this {@code RecordType}.
+ */
@Override
- public boolean isInstance(Record record) {
- throw new UnsupportedOperationException();
+ public boolean isInstance(final Record record) {
+ return (record != null) && getMembers().containsAll(record.getAttributes().keySet());
}
}
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java?rev=1496026&r1=1496025&r2=1496026&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] Mon Jun 24 13:14:18 2013
@@ -216,6 +216,11 @@ public final class Errors extends Indexe
public static final int IllegalLanguageCode_1 = 12;
/**
+ * Member “{0}” can not be associated to type “{1}”.
+ */
+ public static final int IllegalMemberType_2 = 106;
+
+ /**
* Option ‘{0}’ can not take the “{1}” value.
*/
public static final int IllegalOptionValue_2 = 101;
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties?rev=1496026&r1=1496025&r2=1496026&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] Mon Jun 24 13:14:18 2013
@@ -54,6 +54,7 @@ IllegalBitsPattern_1 = Illega
IllegalClass_2 = Class \u2018{1}\u2019 is illegal. It must be \u2018{0}\u2019
or a derived class.
IllegalFormatPatternForClass_2 = The \u201c{1}\u201d pattern can not be applied to formating
of objects of type \u2018{0}\u2019.
IllegalLanguageCode_1 = The \u201c{0}\u201d language is not recognized.
+IllegalMemberType_2 = Member \u201c{0}\u201d can not be associated to type \u201c{1}\u201d.
IllegalOrdinateRange_3 = The [{0} \u2026 {1}] range of ordinate values is not valid
for the \u201c{2}\u201d axis.
IllegalPropertyClass_2 = Property \u2018{0}\u2019 can be associated to an instance
of \u2018{1}\u2019.
IllegalRange_2 = Range [{0} \u2026 {1}] is not valid.
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties?rev=1496026&r1=1496025&r2=1496026&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] Mon Jun 24 13:14:18 2013
@@ -44,6 +44,7 @@ IllegalBitsPattern_1 = Patter
IllegalClass_2 = La classe \u2018{1}\u2019 est ill\u00e9gale. Il doit s\u2019agir
d\u2019une classe \u2018{0}\u2019 ou d\u00e9riv\u00e9e.
IllegalFormatPatternForClass_2 = Le mod\u00e8le \u201c{1}\u201d ne peut pas \u00eatre appliqu\u00e9
au formatage d\u2019objets de type \u2018{0}\u2019.
IllegalLanguageCode_1 = Le code de langue \u201c{0}\u201d n\u2019est pas reconnu.
+IllegalMemberType_2 = Le membre \u201c{0}\u201d ne peut pas \u00eatre associ\u00e9
au type \u201c{1}\u201d.
IllegalOrdinateRange_3 = La plage de valeurs de coordonn\u00e9es [{1} \u2026 {2}]
n\u2019est pas valide pour l\u2019axe \u201c{0}\u201d.
IllegalPropertyClass_2 = La propri\u00e9t\u00e9 \u2018{0}\u2019 ne peut pas \u00eatre
associ\u00e9e \u00e0 une valeur de type \u2018{1}\u2019.
IllegalRange_2 = La plage [{0} \u2026 {1}] n\u2019est pas valide.
|