Search in sources :

Example 1 with TypeName

use of org.opengis.util.TypeName 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 TypeName

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

the class NameMarshallingTest method testTypeName.

/**
 * Tests XML of a {@link TypeName}.
 *
 * @throws JAXBException if (un)marshalling failed.
 */
@Test
public void testTypeName() throws JAXBException {
    final NameFactory factory = DefaultFactories.forBuildin(NameFactory.class);
    final TypeName name = factory.createTypeName(null, "An other local name");
    assertEquals("An other local name", name.toString());
    final String expected = "<gml:IO_IdentifiedObject xmlns:gml=\"" + Namespaces.GML + '"' + " xmlns:gco=\"" + LegacyNamespaces.GCO + "\">\n" + "  <gml:alias>\n" + "    <gco:TypeName>\n" + "      <gco:aName>\n" + "        <gco:CharacterString>An other local name</gco:CharacterString>\n" + "      </gco:aName>\n" + "    </gco:TypeName>\n" + "  </gml:alias>\n" + "</gml:IO_IdentifiedObject>\n";
    final String actual = marshal(name);
    assertXmlEquals(expected, actual, "xmlns:*");
    assertEquals(name, unmarshal(expected));
}
Also used : TypeName(org.opengis.util.TypeName) NameFactory(org.opengis.util.NameFactory) Test(org.junit.Test)

Example 3 with TypeName

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

the class NamesTest method testClassFromOGC.

/**
 * Tests {@link Names#toClass(TypeName)} with a name in the {@code "OGC"} scope.
 * If the name is not recognized, then {@code toClass(TypeName)} is expected to throw an exception.
 */
@Test
public void testClassFromOGC() {
    final DefaultNameFactory factory = DefaultFactories.forBuildin(NameFactory.class, DefaultNameFactory.class);
    final TypeName type = factory.toTypeName(String.class);
    assertEquals("OGC:CharacterString", type.toFullyQualifiedName().toString());
    assertValueClassEquals(String.class, type);
    assertValueClassEquals(Double.class, new DefaultTypeName(type.scope(), "Real"));
    assertValueClassEquals(InternationalString.class, new DefaultTypeName(type.scope(), "FreeText"));
    assertValueClassEquals(UnknownNameException.class, new DefaultTypeName(type.scope(), "Dummy"));
}
Also used : TypeName(org.opengis.util.TypeName) Test(org.junit.Test)

Example 4 with TypeName

use of org.opengis.util.TypeName 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)

Example 5 with TypeName

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

the class DefaultRecordSchema method createRecordType.

/**
 * Creates a new record type of the given name, which will contains the given members.
 * Members are declared in iteration order.
 *
 * @param  typeName  the record type name.
 * @param  members   the name of each record member, together with the expected value types.
 * @return a record type of the given name and members.
 * @throws IllegalArgumentException if a record already exists for the given name but with different members.
 */
public RecordType createRecordType(final CharSequence typeName, final Map<CharSequence, Class<?>> members) throws IllegalArgumentException {
    ArgumentChecks.ensureNonNull("typeName", typeName);
    ArgumentChecks.ensureNonNull("members", members);
    final TypeName name = nameFactory.createTypeName(namespace, typeName);
    final Map<CharSequence, Type> memberTypes = ObjectConverters.derivedValues(members, CharSequence.class, toTypes);
    RecordType record;
    synchronized (description) {
        record = description.get(typeName);
        if (record == null) {
            record = new DefaultRecordType(name, this, memberTypes, nameFactory);
            description.put(name, record);
            return record;
        }
    }
    /*
         * If a record type already exists for the given name, verify that it contains the same members.
         */
    final Iterator<Map.Entry<CharSequence, Class<?>>> it1 = members.entrySet().iterator();
    final Iterator<Map.Entry<MemberName, Type>> it2 = record.getMemberTypes().entrySet().iterator();
    boolean hasNext;
    while ((hasNext = it1.hasNext()) == it2.hasNext()) {
        if (!hasNext) {
            // Finished comparison successfully.
            return record;
        }
        final Map.Entry<CharSequence, Class<?>> e1 = it1.next();
        final Map.Entry<MemberName, Type> e2 = it2.next();
        if (!e2.getKey().tip().toString().equals(e1.toString())) {
            // Member names differ.
            break;
        }
        if (!((SimpleAttributeType) e2.getValue()).getValueClass().equals(e1.getValue())) {
            // Value classes differ.
            break;
        }
    }
    throw new IllegalArgumentException(Errors.format(Errors.Keys.RecordAlreadyDefined_2, getSchemaName(), typeName));
}
Also used : TypeName(org.opengis.util.TypeName) SimpleAttributeType(org.apache.sis.internal.simple.SimpleAttributeType) SimpleAttributeType(org.apache.sis.internal.simple.SimpleAttributeType) Type(org.opengis.util.Type) RecordType(org.opengis.util.RecordType) RecordType(org.opengis.util.RecordType) MemberName(org.opengis.util.MemberName) WeakValueHashMap(org.apache.sis.util.collection.WeakValueHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Aggregations

TypeName (org.opengis.util.TypeName)9 Test (org.junit.Test)3 MemberName (org.opengis.util.MemberName)3 Map (java.util.Map)2 SimpleAttributeType (org.apache.sis.internal.simple.SimpleAttributeType)2 InternationalString (org.opengis.util.InternationalString)2 NameSpace (org.opengis.util.NameSpace)2 RecordType (org.opengis.util.RecordType)2 Type (org.opengis.util.Type)2 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 XmlElementRef (javax.xml.bind.annotation.XmlElementRef)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 GenericName (org.opengis.util.GenericName)1 LocalName (org.opengis.util.LocalName)1