Search in sources :

Example 11 with DefaultParameterDescriptorGroup

use of org.apache.sis.parameter.DefaultParameterDescriptorGroup in project sis by apache.

the class CC_OperationMethod method group.

/**
 * Wraps the given descriptors in a descriptor group of the given name. If the given name can be matched
 * to the name of one of the predefined operation method, then the predefined parameters will be used.
 *
 * <p>We try to use predefined parameters if possible because they contain information, especially the
 * {@link org.opengis.parameter.ParameterDescriptor#getValueClass()} property, which are not available
 * in the GML document.</p>
 *
 * <div class="note"><b>Note:</b>
 * this code is defined in this {@code CC_OperationMethod} class instead than in the
 * {@link DefaultOperationMethod} class in the hope to reduce the amount of code processed
 * by the JVM in the common case where JAXB (un)marshalling is not needed.</div>
 *
 * @param  name         the operation method name, to be also given to the descriptor group.
 * @param  descriptors  the parameter descriptors to wrap in a group. This array will be modified in-place.
 * @return a parameter group containing at least the given descriptors, or equivalent descriptors.
 */
public static ParameterDescriptorGroup group(final Identifier name, final GeneralParameterDescriptor[] descriptors) {
    OperationMethod method;
    try {
        method = CoordinateOperations.factory().getOperationMethod(name.getCode());
    } catch (FactoryException e) {
        // Use DefaultOperationMethod as the source class because it is the first public class in callers.
        Context.warningOccured(Context.current(), DefaultOperationMethod.class, "setDescriptors", e, true);
        method = null;
    }
    final Map<String, ?> properties = Collections.singletonMap(ParameterDescriptorGroup.NAME_KEY, name);
    if (method != null) {
        /*
             * Verify that the pre-defined operation method contains at least all the parameters specified by
             * the 'descriptors' array. If this is the case, then the pre-defined parameters will be used in
             * replacement of the given ones.
             */
        final ParameterDescriptorGroup parameters = method.getParameters();
        return CC_GeneralOperationParameter.merge(DefaultOperationMethod.class, properties, IdentifiedObjects.getProperties(parameters), 1, 1, descriptors, parameters, true);
    }
    return new DefaultParameterDescriptorGroup(properties, 1, 1, descriptors);
}
Also used : DefaultParameterDescriptorGroup(org.apache.sis.parameter.DefaultParameterDescriptorGroup) FactoryException(org.opengis.util.FactoryException) ParameterDescriptorGroup(org.opengis.parameter.ParameterDescriptorGroup) DefaultParameterDescriptorGroup(org.apache.sis.parameter.DefaultParameterDescriptorGroup) DefaultOperationMethod(org.apache.sis.referencing.operation.DefaultOperationMethod) DefaultOperationMethod(org.apache.sis.referencing.operation.DefaultOperationMethod) OperationMethod(org.opengis.referencing.operation.OperationMethod)

Aggregations

DefaultParameterDescriptorGroup (org.apache.sis.parameter.DefaultParameterDescriptorGroup)11 ParameterDescriptorGroup (org.opengis.parameter.ParameterDescriptorGroup)9 HashMap (java.util.HashMap)5 GeneralParameterDescriptor (org.opengis.parameter.GeneralParameterDescriptor)5 DependsOnMethod (org.apache.sis.test.DependsOnMethod)4 Test (org.junit.Test)4 DefaultOperationMethod (org.apache.sis.referencing.operation.DefaultOperationMethod)3 CorruptedObjectException (org.apache.sis.util.CorruptedObjectException)2 ParameterDescriptor (org.opengis.parameter.ParameterDescriptor)2 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 ImmutableIdentifier (org.apache.sis.metadata.iso.ImmutableIdentifier)1 DefaultCitation (org.apache.sis.metadata.iso.citation.DefaultCitation)1 DefaultParameterDescriptor (org.apache.sis.parameter.DefaultParameterDescriptor)1 AbstractIdentifiedObject (org.apache.sis.referencing.AbstractIdentifiedObject)1 SimpleInternationalString (org.apache.sis.util.iso.SimpleInternationalString)1 ParameterNotFoundException (org.opengis.parameter.ParameterNotFoundException)1 IdentifiedObject (org.opengis.referencing.IdentifiedObject)1