Search in sources :

Example 21 with GeneralParameterDescriptor

use of org.opengis.parameter.GeneralParameterDescriptor in project sis by apache.

the class DefaultParameterValueGroup method setValues.

/**
 * Appends all parameter values. In this process, we may need to update the descriptor of some values
 * if those descriptors changed as a result of the above merge process.
 *
 * @param parameters   The parameters to add, or {@code null} for {@link #values}.
 * @param replacements The replacements to apply in the {@code GeneralParameterValue} instances.
 * @param addTo        Where to store the new values.
 */
@SuppressWarnings({ "unchecked", "AssignmentToCollectionOrArrayFieldFromParameter" })
private void setValues(GeneralParameterValue[] parameters, final Map<GeneralParameterDescriptor, GeneralParameterDescriptor> replacements, final ParameterValueList addTo) {
    if (parameters == null) {
        parameters = values.toArray();
    }
    for (final GeneralParameterValue p : parameters) {
        final GeneralParameterDescriptor replacement = replacements.get(p.getDescriptor());
        if (replacement != null) {
            if (p instanceof DefaultParameterValue<?>) {
                ((DefaultParameterValue<?>) p).setDescriptor((ParameterDescriptor) replacement);
            } else if (p instanceof DefaultParameterValueGroup) {
                ((DefaultParameterValueGroup) p).setValues(null, replacements, new ParameterValueList((ParameterDescriptorGroup) replacement));
            }
        }
        addTo.add(p);
    }
    values = addTo;
}
Also used : GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor)

Example 22 with GeneralParameterDescriptor

use of org.opengis.parameter.GeneralParameterDescriptor in project sis by apache.

the class DefaultParameterValueGroup method addGroup.

/**
 * Creates a new subgroup of the specified name, and adds it to the list of subgroups.
 * The argument shall be the name of a {@linkplain DefaultParameterDescriptorGroup descriptor group}
 * which is a child of this group.
 *
 * <div class="note"><b>API note:</b>
 * There is no {@code removeGroup(String)} method. To remove a group, users shall inspect the
 * {@link #values()} list, decide which occurrences to remove if there is many of them for the
 * same name, and whether to iterate recursively into sub-groups or not.</div>
 *
 * @param  name  the name of the parameter group to create.
 * @return a newly created parameter group for the given name.
 * @throws ParameterNotFoundException if no descriptor was found for the given name.
 * @throws InvalidParameterCardinalityException if this parameter group already contains the
 *         {@linkplain ParameterDescriptorGroup#getMaximumOccurs() maximum number of occurrences}
 *         of subgroups of the given name.
 */
@Override
public ParameterValueGroup addGroup(final String name) throws ParameterNotFoundException, InvalidParameterCardinalityException {
    // Protect against accidental changes.
    final ParameterValueList values = this.values;
    final ParameterDescriptorGroup descriptor = values.descriptor;
    final GeneralParameterDescriptor child = descriptor.descriptor(name);
    if (!(child instanceof ParameterDescriptorGroup)) {
        throw new ParameterNotFoundException(Resources.format(Resources.Keys.ParameterNotFound_2, descriptor.getName(), name), name);
    }
    final ParameterValueGroup value = ((ParameterDescriptorGroup) child).createValue();
    values.add(value);
    return value;
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ParameterDescriptorGroup(org.opengis.parameter.ParameterDescriptorGroup) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) ParameterNotFoundException(org.opengis.parameter.ParameterNotFoundException)

Example 23 with GeneralParameterDescriptor

use of org.opengis.parameter.GeneralParameterDescriptor in project sis by apache.

the class GeoKeysTest method verifyParameterNames.

/**
 * Verifies that parameter names registered in the {@link org.apache.sis.internal.referencing.provider} package
 * match the name of fields listed in {@link GeoKeys}.
 */
@Test
@DependsOnMethod("testName")
public void verifyParameterNames() {
    final MathTransformFactory factory = DefaultFactories.forBuildin(MathTransformFactory.class);
    for (final OperationMethod method : factory.getAvailableMethods(SingleOperation.class)) {
        for (final GeneralParameterDescriptor param : method.getParameters().descriptors()) {
            final Identifier identifier = IdentifiedObjects.getIdentifier(param, Citations.GEOTIFF);
            final Set<String> names = IdentifiedObjects.getNames(param, Citations.GEOTIFF);
            /*
                 * If there is no GeoTIFF identifiers, we should have no GeoTIFF name neither.
                 */
            assertEquals(param.getName().getCode(), identifier == null, names.isEmpty());
            if (identifier != null) {
                final int code = Short.parseShort(identifier.getCode());
                for (final String name : names) {
                    assertEquals(name, code(name), code);
                }
            }
        }
    }
}
Also used : Identifier(org.opengis.metadata.Identifier) MathTransformFactory(org.opengis.referencing.operation.MathTransformFactory) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) OperationMethod(org.opengis.referencing.operation.OperationMethod) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 24 with GeneralParameterDescriptor

use of org.opengis.parameter.GeneralParameterDescriptor in project sis by apache.

the class AbstractOperation method defaultFormula.

/**
 * Default implementation of {@link #formatResultFormula(Appendable)},
 * to be used also for operations that are not instance of {@link AbstractOperation}.
 */
static void defaultFormula(final ParameterDescriptorGroup parameters, final Appendable buffer) throws IOException {
    buffer.append(parameters != null ? name(parameters.getName()) : "operation").append('(');
    if (parameters != null) {
        boolean hasMore = false;
        for (GeneralParameterDescriptor p : parameters.descriptors()) {
            if (p != null) {
                if (hasMore)
                    buffer.append(", ");
                buffer.append(name(p.getName()));
                hasMore = true;
            }
        }
    }
    buffer.append(')');
}
Also used : GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor)

Example 25 with GeneralParameterDescriptor

use of org.opengis.parameter.GeneralParameterDescriptor in project sis by apache.

the class AbstractSingleOperation method setParameters.

/**
 * Invoked by JAXB for setting the unmarshalled parameters.
 * This method wraps the given parameters in a {@link ParameterValueGroup},
 * unless the given descriptors was already a {@code ParameterValueGroup}.
 *
 * @see DefaultOperationMethod#setDescriptors
 */
private void setParameters(final GeneralParameterValue[] values) {
    if (parameters == null) {
        if (!(method instanceof DefaultOperationMethod)) {
            // May be a non-null proxy if defined only by xlink:href.
            throw new IllegalStateException(Errors.format(Errors.Keys.MissingValueForProperty_1, "method"));
        }
        /*
             * The descriptors in the <gml:method> element do not know the class of parameter value
             * (String, Integer, Double, double[], etc.) because this information is not part of GML.
             * But this information is available to descriptors in the <gml:parameterValue> elements
             * because Apache SIS infers the type from the actual parameter value. The 'merge' method
             * below puts those information together.
             */
        final Map<GeneralParameterDescriptor, GeneralParameterDescriptor> replacements = new IdentityHashMap<>(4);
        final GeneralParameterDescriptor[] merged = CC_OperationParameterGroup.merge(method.getParameters().descriptors(), Parameters.getDescriptors(values), replacements);
        /*
             * Sometime Apache SIS recognizes the OperationMethod as one of its build-in methods and use the
             * build-in parameters. In such cases the unmarshalled ParameterDescriptorGroup can be used as-in.
             * But if the above 'merge' method has changed any parameter descriptor, then we will need to create
             * a new ParameterDescriptorGroup with the new descriptors.
             */
        for (int i = 0; i < merged.length; i++) {
            if (merged[i] != values[i].getDescriptor()) {
                ((DefaultOperationMethod) method).updateDescriptors(merged);
                // At this point, method.getParameters() may have changed.
                break;
            }
        }
        /*
             * Sometime the descriptors associated to ParameterValues need to be updated, for example because
             * the descriptors in OperationMethod contain more information (remarks, etc.). Those updates, if
             * needed, are applied on-the-fly by the copy operation below, using the information provided by
             * the 'replacements' map.
             */
        parameters = new DefaultParameterValueGroup(method.getParameters());
        CC_OperationMethod.store(values, parameters.values(), replacements);
        parameters = Parameters.unmodifiable(parameters);
    } else {
        MetadataUtilities.propertyAlreadySet(AbstractSingleOperation.class, "setParameters", "parameterValue");
    }
}
Also used : IdentityHashMap(java.util.IdentityHashMap) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) DefaultParameterValueGroup(org.apache.sis.parameter.DefaultParameterValueGroup)

Aggregations

GeneralParameterDescriptor (org.opengis.parameter.GeneralParameterDescriptor)30 ParameterDescriptorGroup (org.opengis.parameter.ParameterDescriptorGroup)12 Test (org.junit.Test)10 DefaultParameterDescriptorGroup (org.apache.sis.parameter.DefaultParameterDescriptorGroup)8 DependsOnMethod (org.apache.sis.test.DependsOnMethod)8 ParameterNotFoundException (org.opengis.parameter.ParameterNotFoundException)6 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)6 HashMap (java.util.HashMap)5 Identifier (org.opengis.metadata.Identifier)5 GeneralParameterValue (org.opengis.parameter.GeneralParameterValue)5 ParameterDescriptor (org.opengis.parameter.ParameterDescriptor)4 IdentityHashMap (java.util.IdentityHashMap)3 OperationMethod (org.opengis.referencing.operation.OperationMethod)3 ArrayList (java.util.ArrayList)2 DefaultParameterValueGroup (org.apache.sis.parameter.DefaultParameterValueGroup)2 CorruptedObjectException (org.apache.sis.util.CorruptedObjectException)2 InvalidParameterNameException (org.opengis.parameter.InvalidParameterNameException)2 ParameterValue (org.opengis.parameter.ParameterValue)2 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1