use of org.opengis.parameter.ParameterDescriptorGroup in project sis by apache.
the class DefaultOperationMethod method updateDescriptors.
/**
* Invoked by {@link AbstractSingleOperation} for completing the parameter descriptor.
*/
final void updateDescriptors(final GeneralParameterDescriptor[] descriptors) {
final ParameterDescriptorGroup previous = parameters;
parameters = new DefaultParameterDescriptorGroup(IdentifiedObjects.getProperties(previous), previous.getMinimumOccurs(), previous.getMaximumOccurs(), descriptors);
}
use of org.opengis.parameter.ParameterDescriptorGroup 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);
}
use of org.opengis.parameter.ParameterDescriptorGroup in project sis by apache.
the class CC_OperationMethod method store.
/**
* Stores the given {@code parameters} into the given {@code addTo} collection.
* This method copies only the <em>references</em> if possible. However is some
* cases the values may need to be copied in new parameter instances.
*
* <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 parameters the parameters to add to the {@code addTo} collection.
* @param addTo where to store the {@code parameters}.
* @param replacements the replacements to apply in the {@code GeneralParameterValue} instances.
*/
public static void store(final GeneralParameterValue[] parameters, final Collection<GeneralParameterValue> addTo, final Map<GeneralParameterDescriptor, GeneralParameterDescriptor> replacements) {
for (GeneralParameterValue p : parameters) {
final GeneralParameterDescriptor replacement = replacements.get(p.getDescriptor());
if (replacement != null) {
if (p instanceof ParameterValue<?>) {
final ParameterValue<?> source = (ParameterValue<?>) p;
final ParameterValue<?> target = new DefaultParameterValue<>((ParameterDescriptor<?>) replacement);
final Object value = source.getValue();
final Unit<?> unit = source.getUnit();
if (unit == null) {
target.setValue(value);
} else if (value instanceof double[]) {
target.setValue((double[]) value, unit);
} else {
target.setValue(((Number) value).doubleValue(), unit);
}
p = target;
} else if (p instanceof ParameterValueGroup) {
final ParameterValueGroup source = (ParameterValueGroup) p;
final ParameterValueGroup target = new DefaultParameterValueGroup((ParameterDescriptorGroup) replacement);
final Collection<GeneralParameterValue> values = source.values();
store(values.toArray(new GeneralParameterValue[values.size()]), target.values(), replacements);
p = target;
}
}
addTo.add(p);
}
}
use of org.opengis.parameter.ParameterDescriptorGroup in project sis by apache.
the class ProvidersTest method ensureParameterUniqueness.
/**
* Ensures that every parameter instance is unique. Actually this test is not strong requirement.
* This is only for sharing existing resources by avoiding unnecessary objects duplication.
*
* @throws ReflectiveOperationException if the instantiation of a service provider failed.
*/
@Test
public void ensureParameterUniqueness() throws ReflectiveOperationException {
final Map<GeneralParameterDescriptor, String> groupNames = new IdentityHashMap<>();
final Map<GeneralParameterDescriptor, GeneralParameterDescriptor> parameters = new HashMap<>();
final Map<Object, Object> namesAndIdentifiers = new HashMap<>();
for (final Class<?> c : methods()) {
final OperationMethod method = (OperationMethod) c.newInstance();
final ParameterDescriptorGroup group = method.getParameters();
final String operationName = group.getName().getCode();
for (final GeneralParameterDescriptor param : group.descriptors()) {
assertFalse("Parameter declared twice in the same group.", operationName.equals(groupNames.put(param, operationName)));
/*
* Ensure uniqueness of the parameter descriptor as a whole.
*/
final Identifier name = param.getName();
Object existing = parameters.put(param, param);
if (existing != null && existing != param) {
fail("Parameter “" + name.getCode() + "” defined in “" + operationName + '”' + " was already defined in “" + groupNames.get(existing) + "”." + " The same instance could be shared.");
}
/*
* Ensure uniqueness of each name and identifier.
*/
existing = namesAndIdentifiers.put(name, name);
if (existing != null && existing != name) {
fail("The name of parameter “" + name.getCode() + "” defined in “" + operationName + '”' + " was already defined elsewhere. The same instance could be shared.");
}
for (final GenericName alias : param.getAlias()) {
existing = namesAndIdentifiers.put(alias, alias);
if (existing != null && existing != alias) {
fail("Alias “" + alias + "” of parameter “" + name.getCode() + "” defined in “" + operationName + '”' + " was already defined elsewhere. The same instance could be shared.");
}
}
for (final Identifier id : param.getIdentifiers()) {
existing = namesAndIdentifiers.put(id, id);
if (existing != null && existing != id) {
fail("Identifier “" + id + "” of parameter “" + name.getCode() + "” defined in “" + operationName + '”' + " was already defined elsewhere. The same instance could be shared.");
}
}
}
}
}
use of org.opengis.parameter.ParameterDescriptorGroup in project sis by apache.
the class SingleOperationMarshallingTest method createMercatorMethod.
/**
* Creates the test operation method.
*/
private static DefaultOperationMethod createMercatorMethod() {
final ParameterBuilder builder = new ParameterBuilder();
builder.setCodeSpace(EPSG, "EPSG").setRequired(true);
ParameterDescriptor<?>[] parameters = { builder.addIdentifier("8801").addName("Latitude of natural origin").create(0, Units.DEGREE), builder.addIdentifier("8802").addName("Longitude of natural origin").create(0, Units.DEGREE) // There is more parameters for a Mercator projection, but 2 is enough for this test.
};
builder.addName(null, "Mercator (1SP)");
final ParameterDescriptorGroup descriptor = builder.createGroup(parameters);
final Map<String, Object> properties = new HashMap<>(4);
properties.put(DefaultOperationMethod.NAME_KEY, descriptor.getName());
properties.put(DefaultOperationMethod.FORMULA_KEY, new DefaultFormula("See EPSG guide."));
return new DefaultOperationMethod(properties, 2, 2, descriptor);
}
Aggregations