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;
}
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;
}
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);
}
}
}
}
}
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(')');
}
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");
}
}
Aggregations