Search in sources :

Example 1 with MemberName

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

the class GO_GenericName method getValue.

/**
 * Returns the {@code LocalName} or {@code ScopedName} to marshal. Returns {@code null} if the name
 * is a {@link TypeName} or a {@link MemberName}, in order to use {@link #getName()} instead.
 * Example:
 *
 * {@preformat xml
 *   <gml:alias>
 *     <gco:LocalName codeSpace=\"A code space\">A name in a scope</gco:LocalName>
 *   </gml:alias>
 * }
 *
 * @return the code for the current name, or {@code null} if none.
 */
@XmlElementRef
public final NameValue getValue() {
    final GenericName name = this.name;
    final NameValue code;
    if (name instanceof LocalName) {
        if (name instanceof TypeName || name instanceof MemberName) {
            return null;
        } else if (FilterByVersion.LEGACY_METADATA.accept()) {
            code = new NameValue.Local();
        } else {
            // ISO 19115-3:2016 does not seem to define gco:LocalName anymore.
            code = new NameValue.Scoped();
        }
    } else if (name instanceof ScopedName) {
        code = new NameValue.Scoped();
    } else {
        return null;
    }
    code.setName(name);
    return code;
}
Also used : GenericName(org.opengis.util.GenericName) DefaultTypeName(org.apache.sis.util.iso.DefaultTypeName) TypeName(org.opengis.util.TypeName) ScopedName(org.opengis.util.ScopedName) DefaultMemberName(org.apache.sis.util.iso.DefaultMemberName) MemberName(org.opengis.util.MemberName) LocalName(org.opengis.util.LocalName) DefaultLocalName(org.apache.sis.util.iso.DefaultLocalName) XmlElementRef(javax.xml.bind.annotation.XmlElementRef)

Example 2 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 3 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 4 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)

Example 5 with MemberName

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

the class DefaultLocalName method castOrCopy.

/**
 * Returns a SIS local name implementation with the values of the given arbitrary implementation.
 * This method performs the first applicable action in the following choices:
 *
 * <ul>
 *   <li>If the given object is {@code null}, then this method returns {@code null}.</li>
 *   <li>Otherwise if the given object is an instance of {@link MemberName} or {@link TypeName},
 *       then this method delegates to {@code castOrCopy(…)} method of the corresponding subclass.</li>
 *   <li>Otherwise if the given object is already an instance of {@code DefaultLocalName},
 *       then it is returned unchanged.</li>
 *   <li>Otherwise a new {@code DefaultLocalName} instance is created
 *       with the same values than the given name.</li>
 * </ul>
 *
 * @param  object  the object to get as a SIS implementation, or {@code null} if none.
 * @return a SIS implementation containing the values of the given object (may be the
 *         given object itself), or {@code null} if the argument was null.
 */
public static DefaultLocalName castOrCopy(final LocalName object) {
    if (object instanceof MemberName) {
        return DefaultMemberName.castOrCopy((MemberName) object);
    }
    if (object instanceof TypeName) {
        return DefaultTypeName.castOrCopy((TypeName) object);
    }
    if (object == null || object instanceof DefaultLocalName) {
        return (DefaultLocalName) object;
    }
    final NameSpace scope = object.scope();
    final InternationalString name = object.toInternationalString();
    if (scope instanceof DefaultNameSpace) {
        // May return a cached instance.
        return ((DefaultNameSpace) scope).local(name, null);
    } else {
        return new DefaultLocalName(scope, name);
    }
}
Also used : TypeName(org.opengis.util.TypeName) InternationalString(org.opengis.util.InternationalString) NameSpace(org.opengis.util.NameSpace) 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