Search in sources :

Example 26 with GenericName

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

the class FeatureTypeBuilder method initialize.

/**
 * Initializes this builder to the value of the given type.
 * The caller is responsible to invoke {@link #clear()} (if needed) before this method.
 */
private void initialize(final DefaultFeatureType template) {
    super.initialize(template);
    feature = template;
    isAbstract = template.isAbstract();
    superTypes.addAll(template.getSuperTypes());
    /*
         * For each attribute and association, wrap those properties in a builder.
         * For each operation, wrap them in pseudo-builder only if the operation
         * is not one of the operations automatically generated by this builder.
         */
    final Map<String, Set<AttributeRole>> propertyRoles = new HashMap<>();
    for (final AbstractIdentifiedType property : template.getProperties(false)) {
        PropertyTypeBuilder builder;
        if (property instanceof DefaultAttributeType<?>) {
            builder = new AttributeTypeBuilder<>(this, (DefaultAttributeType<?>) property);
        } else if (property instanceof DefaultAssociationRole) {
            builder = new AssociationRoleBuilder(this, (DefaultAssociationRole) property);
        } else {
            // Do not create OperationWrapper now - see below.
            builder = null;
        }
        /*
             * If the property name is one of our (Apache SIS specific) conventional names, try to reconstitute
             * the attribute roles that caused FeatureTypeBuilder to produce such property. Those roles usually
             * need to be applied on the source properties used for calculating the current property. There is
             * usually at most one role for each source property, but we nevertheless allow an arbitrary amount.
             */
        final AttributeRole role;
        final GenericName name = property.getName();
        if (AttributeConvention.IDENTIFIER_PROPERTY.equals(name)) {
            role = AttributeRole.IDENTIFIER_COMPONENT;
        } else if (AttributeConvention.GEOMETRY_PROPERTY.equals(name)) {
            role = AttributeRole.DEFAULT_GEOMETRY;
        } else if (AttributeConvention.ENVELOPE_PROPERTY.equals(name)) {
            // If "sis:envelope" is an operation, skip it completely.
            // It will be recreated if a default geometry exists.
            role = null;
        } else {
            if (builder == null) {
                // For all unknown operation, wrap as-is.
                builder = new OperationWrapper(this, property);
            }
            role = null;
        }
        if (role != null) {
            final Set<AttributeRole> rc = Collections.singleton(role);
            if (property instanceof AbstractOperation) {
                for (final String dependency : ((AbstractOperation) property).getDependencies()) {
                    propertyRoles.merge(dependency, rc, AttributeRole::merge);
                }
            } else {
                propertyRoles.merge(name.toString(), rc, AttributeRole::merge);
            }
        }
        if (builder != null) {
            properties.add(builder);
        }
    }
    /*
         * At this point we finished to collect information about the attribute roles.
         * Now assign those roles to the attribute builders. Note that some roles may
         * be ignored if we didn't found a suitable builder. The roles inference done
         * in this constructor is only a "best effort".
         */
    if (!propertyRoles.isEmpty()) {
        for (final Map.Entry<String, Set<AttributeRole>> entry : propertyRoles.entrySet()) {
            final PropertyTypeBuilder property = forName(properties, entry.getKey());
            if (property instanceof AttributeTypeBuilder<?>) {
                ((AttributeTypeBuilder<?>) property).roles().addAll(entry.getValue());
            }
        }
    }
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) AbstractIdentifiedType(org.apache.sis.feature.AbstractIdentifiedType) GenericName(org.opengis.util.GenericName) DefaultAssociationRole(org.apache.sis.feature.DefaultAssociationRole) AbstractOperation(org.apache.sis.feature.AbstractOperation) DefaultAttributeType(org.apache.sis.feature.DefaultAttributeType) HashMap(java.util.HashMap) Map(java.util.Map)

Example 27 with GenericName

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

the class Validator method addViolationReport.

/**
 * Adds a report for a constraint violation. If the given {@code report} is {@code null}, then this method creates
 * a new {@link DefaultDomainConsistency} instance with the measure identification set to the property name.
 *
 * <div class="note"><b>Note:</b>
 * setting {@code measureIdentification} to the property name may look like a departure from ISO intent,
 * since the former should be an identification of the <em>quality measurement</em> rather then the measure itself.
 * (setting {@code measureDescription} to {@code type.getDescription()} would probably be wrong for that reason).
 * However {@code measureIdentification} is only an identifier, not a full description of the quality measurement
 * We are not strictly forbidden to use the same identifier for both the quality measurement than the measurement
 * itself. However strictly speaking, maybe we should use a different scope.</div>
 *
 * @param  report       where to add the result, or {@code null} if not yet created.
 * @param  type         description of the property for which a constraint violation has been found.
 * @param  explanation  explanation of the constraint violation.
 * @return the {@code report}, or a new report if {@code report} was null.
 */
private AbstractElement addViolationReport(AbstractElement report, final AbstractIdentifiedType type, final InternationalString explanation) {
    if (report == null) {
        final GenericName name = type.getName();
        report = new DefaultDomainConsistency();
        // Do not invoke report.setMeasureDescription(type.getDescription()) - see above javadoc.
        report.setMeasureIdentification(name instanceof Identifier ? (Identifier) name : new NamedIdentifier(name));
        report.setEvaluationMethodType(EvaluationMethodType.DIRECT_INTERNAL);
        quality.getReports().add(report);
    }
    report.getResults().add(new DefaultConformanceResult(null, explanation, false));
    return report;
}
Also used : GenericName(org.opengis.util.GenericName) DefaultDomainConsistency(org.apache.sis.metadata.iso.quality.DefaultDomainConsistency) NamedIdentifier(org.apache.sis.referencing.NamedIdentifier) Identifier(org.opengis.metadata.Identifier) NamedIdentifier(org.apache.sis.referencing.NamedIdentifier) DefaultConformanceResult(org.apache.sis.metadata.iso.quality.DefaultConformanceResult)

Example 28 with GenericName

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

the class DefaultAssociationRoleTest method twinTown.

/**
 * Creates an association to a twin town. We arbitrarily fix the maximum number
 * of occurrences to 1, even if in reality some cities have many twin towns.
 *
 * @param  cyclic  {@code true} if in addition to the association from <var>A</var> to <var>B</var>,
 *                 we also want an association from <var>B</var> to <var>A</var>, thus creating a cycle.
 * @return the association to use for testing purpose.
 */
static DefaultAssociationRole twinTown(final boolean cyclic) {
    final Map<String, ?> properties = singletonMap(NAME_KEY, "twin town");
    if (cyclic) {
        final NameFactory factory = DefaultFactories.forBuildin(NameFactory.class);
        final GenericName valueType = factory.createTypeName(null, "Twin town");
        return new DefaultAssociationRole(properties, valueType, 0, 1);
    } else {
        final DefaultFeatureType valueType = DefaultFeatureTypeTest.city();
        return new DefaultAssociationRole(properties, valueType, 0, 1);
    }
}
Also used : GenericName(org.opengis.util.GenericName) NameFactory(org.opengis.util.NameFactory)

Example 29 with GenericName

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

the class DefaultAttributeTypeTest method testMandatorySingleton.

/**
 * Tests the creation of a simple {@link DefaultAttributeType} instance for a mandatory singleton.
 */
@Test
public void testMandatorySingleton() {
    final DefaultAttributeType<String> city = city();
    final GenericName name = city.getName();
    assertInstanceOf("city.name", LocalName.class, name);
    assertEquals("city.name", "city", name.toString());
    InternationalString p = city.getDesignation();
    assertNotNull("designation", p);
    assertEquals("designation", "City", p.toString(Locale.ENGLISH));
    assertEquals("designation", "Ville", p.toString(Locale.FRENCH));
    assertEquals("designation", "都市", p.toString(Locale.JAPANESE));
    p = city.getDefinition();
    assertEquals("definition", "The name of the city.", p.toString(Locale.ENGLISH));
    assertEquals("definition", "Le nom de la ville.", p.toString(Locale.FRENCH));
    assertEquals("definition", "都市の名前。", p.toString(Locale.JAPANESE));
    p = city.getDescription();
    assertEquals("description", "Some verbose description.", p.toString(Locale.ENGLISH));
    assertEquals("valueClass", String.class, city.getValueClass());
    assertEquals("defaultValue", "Utopia", city.getDefaultValue());
    assertEquals("minimumOccurs", 1, city.getMinimumOccurs());
    assertEquals("axnimumOccurs", 1, city.getMaximumOccurs());
}
Also used : GenericName(org.opengis.util.GenericName) InternationalString(org.opengis.util.InternationalString) InternationalString(org.opengis.util.InternationalString) Test(org.junit.Test)

Example 30 with GenericName

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

the class DefaultScopedNameTest method testUrnNamespace.

/**
 * Tests the creation of a scoped name in a new namespace.
 * The fully qualified name is {@code "urn:ogc:def:crs:epsg:4326"}.
 */
@Test
public void testUrnNamespace() {
    final String[] parsed = new String[] { "urn", "ogc", "def", "crs", "epsg", "4326" };
    GenericName name = new DefaultScopedName(null, Arrays.asList(parsed));
    assertSame(name, name.toFullyQualifiedName());
    assertEquals("urn:ogc:def:crs:epsg:4326", name.toString());
    assertNotSame(name, assertSerializedEquals(name));
    // GeoAPI tests.
    validate(name);
    for (int i = parsed.length; --i >= 0; ) {
        name = name.tip();
        validate(name);
        assertSame(parsed[i], name.toString());
        name = name.scope().name();
    }
}
Also used : GenericName(org.opengis.util.GenericName) Test(org.junit.Test)

Aggregations

GenericName (org.opengis.util.GenericName)46 Test (org.junit.Test)11 ReferenceIdentifier (org.opengis.referencing.ReferenceIdentifier)9 InternationalString (org.opengis.util.InternationalString)9 ArrayList (java.util.ArrayList)5 IdentifiedObject (org.opengis.referencing.IdentifiedObject)5 NameFactory (org.opengis.util.NameFactory)5 Identifier (org.opengis.metadata.Identifier)4 ScopedName (org.opengis.util.ScopedName)4 HashMap (java.util.HashMap)3 DependsOnMethod (org.apache.sis.test.DependsOnMethod)3 IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 Collection (java.util.Collection)2 IdentityHashMap (java.util.IdentityHashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 AbstractIdentifiedType (org.apache.sis.feature.AbstractIdentifiedType)2 NameToIdentifier (org.apache.sis.internal.metadata.NameToIdentifier)2 TableAppender (org.apache.sis.io.TableAppender)2