Search in sources :

Example 6 with MemberName

use of org.opengis.util.MemberName in project sis by apache.

the class ServiceParameterTest method create.

/**
 * Creates the parameter to use for testing purpose.
 *
 * @return the test parameter.
 */
public static ServiceParameter create() {
    final MemberName paramName = Names.createMemberName(null, null, "Version", String.class);
    final ServiceParameter param = new ServiceParameter();
    param.memberName = paramName;
    param.optionality = true;
    param.repeatability = false;
    return param;
}
Also used : MemberName(org.opengis.util.MemberName)

Example 7 with MemberName

use of org.opengis.util.MemberName in project sis by apache.

the class DefaultRecordSchemaTest method testCreateRecordType.

/**
 * Tests {@link DefaultRecordSchema#createRecordType(CharSequence, Map)}.
 */
@Test
public void testCreateRecordType() {
    final DefaultRecordSchema schema = new DefaultRecordSchema(null, null, "MySchema");
    final Map<CharSequence, Class<?>> members = new LinkedHashMap<>(8);
    assertNull(members.put("city", String.class));
    assertNull(members.put("latitude", Double.class));
    assertNull(members.put("longitude", Double.class));
    assertNull(members.put("population", Integer.class));
    final RecordType recordType = schema.createRecordType("MyRecordType", members);
    /*
         * Inspect properties.
         */
    assertSame("container", schema, recordType.getContainer());
    assertEquals("typeName", Names.createTypeName("MySchema", ":", "MyRecordType"), recordType.getTypeName());
    int count = 0;
    for (final Map.Entry<MemberName, Type> entry : recordType.getMemberTypes().entrySet()) {
        final String expectedName;
        final String expectedType;
        final Class<?> expectedClass;
        switch(count) {
            case 0:
                {
                    expectedName = "city";
                    expectedType = "OGC:CharacterString";
                    expectedClass = String.class;
                    break;
                }
            case 1:
                {
                    expectedName = "latitude";
                    expectedType = "OGC:Real";
                    expectedClass = Double.class;
                    break;
                }
            case 2:
                {
                    expectedName = "longitude";
                    expectedType = "OGC:Real";
                    expectedClass = Double.class;
                    break;
                }
            case 3:
                {
                    expectedName = "population";
                    expectedType = "OGC:Integer";
                    expectedClass = Integer.class;
                    break;
                }
            default:
                {
                    throw new AssertionError(count);
                }
        }
        final Type type = entry.getValue();
        assertEquals(expectedName, entry.getKey().toString());
        assertEquals(expectedType, type.getTypeName().toFullyQualifiedName().toString());
        assertEquals(expectedClass, ((SimpleAttributeType) type).getValueClass());
        count++;
    }
    /*
         * The DefaultRecordType(TypeName, RecordSchema, Map) constructor performs many argument checks, so
         * we use that constructor as a way to perform a final validation, especially regarding namespaces.
         */
    final DefaultRecordType copy = new DefaultRecordType(recordType.getTypeName(), recordType.getContainer(), recordType.getMemberTypes());
    assertEquals(recordType, copy);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) SimpleAttributeType(org.apache.sis.internal.simple.SimpleAttributeType) RecordType(org.opengis.util.RecordType) Type(org.opengis.util.Type) RecordType(org.opengis.util.RecordType) MemberName(org.opengis.util.MemberName) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.junit.Test)

Example 8 with MemberName

use of org.opengis.util.MemberName in project sis by apache.

the class MetadataBuilder method setBandIdentifier.

/**
 * Sets the number that uniquely identifies instances of bands of wavelengths on which a sensor operates.
 * This is a convenience method for {@link #setBandIdentifier(MemberName)} when the band is specified only
 * by a number.
 *
 * @param  sequenceIdentifier  the band number, or 0 or negative if none.
 */
public final void setBandIdentifier(final int sequenceIdentifier) {
    if (sequenceIdentifier > 0) {
        final boolean cached = (sequenceIdentifier <= BAND_NUMBERS.length);
        MemberName name = null;
        if (cached)
            synchronized (BAND_NUMBERS) {
                name = BAND_NUMBERS[sequenceIdentifier - 1];
            }
        if (name == null) {
            name = Names.createMemberName(null, null, String.valueOf(sequenceIdentifier), Integer.class);
            if (cached)
                synchronized (BAND_NUMBERS) {
                    /*
                     * No need to check if a value has been set concurrently because Names.createMemberName(…)
                     * already checked if an equal instance exists in the current JVM.
                     */
                    BAND_NUMBERS[sequenceIdentifier - 1] = name;
                }
        }
        setBandIdentifier(name);
    }
}
Also used : MemberName(org.opengis.util.MemberName)

Aggregations

MemberName (org.opengis.util.MemberName)8 RecordType (org.opengis.util.RecordType)4 Type (org.opengis.util.Type)4 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 SimpleAttributeType (org.apache.sis.internal.simple.SimpleAttributeType)3 TypeName (org.opengis.util.TypeName)3 InvalidObjectException (java.io.InvalidObjectException)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 XmlElementRef (javax.xml.bind.annotation.XmlElementRef)1 XmlType (javax.xml.bind.annotation.XmlType)1 WeakValueHashMap (org.apache.sis.util.collection.WeakValueHashMap)1 DefaultLocalName (org.apache.sis.util.iso.DefaultLocalName)1 DefaultMemberName (org.apache.sis.util.iso.DefaultMemberName)1 DefaultTypeName (org.apache.sis.util.iso.DefaultTypeName)1 Test (org.junit.Test)1 GenericName (org.opengis.util.GenericName)1 InternationalString (org.opengis.util.InternationalString)1 LocalName (org.opengis.util.LocalName)1