Package org.opengis.parameter

Examples of org.opengis.parameter.InvalidParameterValueException


            key=   VERSION_KEY; this.version   = (String)              (value = version);
            key= CODESPACE_KEY; this.codeSpace = (String)              (value = codeSpace);
            key= AUTHORITY_KEY; this.authority = (Citation)            (value = authority);
            key=   REMARKS_KEY; this.remarks   = (InternationalString) (value = remarks);
        } catch (ClassCastException exception) {
            final InvalidParameterValueException e = new InvalidParameterValueException(
                    Errors.format(Errors.Keys.IllegalArgumentValue_2, key, value), key, value);
            e.initCause(exception);
            throw e;
        }
        if (code == null) {
            throw new IllegalArgumentException(Errors.format(Errors.Keys.MissingValueForProperty_1, CODE_KEY));
        }
View Full Code Here


        Object convertedValue = value;
        if (unit != null) {
            final Unit<?> def = descriptor.getUnit();
            if (def == null) {
                final String name = getName(descriptor);
                throw new InvalidParameterValueException(Errors.format(Errors.Keys.UnitlessParameter_1, name), name, unit);
            }
            if (!unit.equals(def)) {
                final short expectedID = getUnitMessageID(def);
                if (getUnitMessageID(unit) != expectedID) {
                    throw new IllegalArgumentException(Errors.format(expectedID, unit));
                }
                /*
                 * Verify the type of the user's value before to perform the unit conversion,
                 * because the conversion will create a new object not necessarily of the same type.
                 */
                if (value != null) {
                    if (!valueClass.isInstance(value)) {
                        final String name = getName(descriptor);
                        throw new InvalidParameterValueException(
                                Errors.format(Errors.Keys.IllegalParameterValueClass_3,
                                name, valueClass, value.getClass()), name, value);
                    }
                    /*
                     * From this point we will perform the actual unit conversion. The value may be either
                     * a Number instance, or an array of numbers (typically an array of type double[]). In
                     * the array case, we will store the converted values in a new array of the same type.
                     */
                    try {
                        converter = unit.getConverterToAny(def);
                    } catch (ConversionException e) {
                        throw new IllegalArgumentException(Errors.format(Errors.Keys.IncompatibleUnits_2, unit, def), e);
                    }
                    Class<?> componentType = valueClass.getComponentType();
                    if (componentType == null) {
                        /*
                         * Usual case where the value is not an array. Convert the value directly.
                         * Note that the value can only be a number because the unit is associated
                         * to MeasurementRange, which accepts only numbers.
                         */
                        Number n = converter.convert(((Number) value).doubleValue());
                        try {
                            convertedValue = Numbers.cast(n, (Class<? extends Number>) valueClass);
                        } catch (IllegalArgumentException e) {
                            throw new InvalidParameterValueException(e.getLocalizedMessage(), getName(descriptor), value);
                        }
                    } else {
                        /*
                         * The value is an array. Creates a new array and store the converted values
                         * using Array reflection.
                         */
                        final int length = Array.getLength(value);
                        convertedValue = Array.newInstance(componentType, length);
                        componentType = Numbers.primitiveToWrapper(componentType);
                        for (int i=0; i<length; i++) {
                            Number n = (Number) Array.get(value, i);
                            n = converter.convert(n.doubleValue()); // Value in units that we can compare.
                            try {
                                n = Numbers.cast(n, (Class<? extends Number>) componentType);
                            } catch (IllegalArgumentException e) {
                                throw new InvalidParameterValueException(e.getLocalizedMessage(),
                                        getName(descriptor) + '[' + i + ']', value);
                            }
                            Array.set(convertedValue, i, n);
                        }
                    }
                }
            }
        }
        /*
         * At this point the user's value has been fully converted to the unit of measurement specified
         * by the ParameterDescriptor. Now compares the converted value to the restricting given by the
         * descriptor (set of valid values and range of value domain).
         */
        if (convertedValue != null) {
            final Verifier error;
            final Set<T> validValues = descriptor.getValidValues();
            if (descriptor instanceof DefaultParameterDescriptor<?>) {
                error = ensureValidValue(valueClass, validValues,
                        ((DefaultParameterDescriptor<?>) descriptor).getValueDomain(), convertedValue);
            } else {
                error = ensureValidValue(valueClass, validValues,
                        descriptor.getMinimumValue(), descriptor.getMaximumValue(), convertedValue);
            }
            if (error != null) {
                error.convertRange(converter);
                final String name = getName(descriptor);
                throw new InvalidParameterValueException(error.message(null, name, value), name, value);
            }
        }
        return (T) convertedValue;
    }
View Full Code Here

        try {
            // Use 'unit' instead than 'getUnit()' despite class Javadoc claims because units are not expected
            // to be involved in this method. We just want the current unit setting to be unchanged.
            setValue(wrap(value, descriptor.getValueClass()), unit);
        } catch (IllegalArgumentException e) {
            throw new InvalidParameterValueException(e.getLocalizedMessage(), Verifier.getName(descriptor), value);
        }
    }
View Full Code Here

    @Override
    public void setValue(final double value, final Unit<?> unit) throws InvalidParameterValueException {
        try {
            setValue(wrap(value, descriptor.getValueClass()), unit);
        } catch (IllegalArgumentException e) {
            throw new InvalidParameterValueException(e.getLocalizedMessage(), Verifier.getName(descriptor), value);
        }
    }
View Full Code Here

        // Extraction of the sources from the parameters
        Object srcCoverages = parameters.parameter("sources").getValue();

        if (!(srcCoverages instanceof Collection) || ((Collection) srcCoverages).isEmpty()
                || !(((Collection) srcCoverages).iterator().next() instanceof GridCoverage2D)) {
            throw new InvalidParameterValueException(Errors.format(ErrorKeys.ILLEGAL_ARGUMENT_$1,
                    "sources"), "sources", srcCoverages);
        }
        // Collection of the sources to use
        Collection<GridCoverage2D> sourceCoverages = (Collection<GridCoverage2D>) srcCoverages;
        // ViewType object
View Full Code Here

     */
    protected static void ensureNonNull(final String name, final Object object)
            throws InvalidParameterValueException
    {
        if (object == null) {
            throw new InvalidParameterValueException(Errors.format(
                        ErrorKeys.NULL_ARGUMENT_$1, name), name, object);
        }
    }
View Full Code Here

            } else if (v instanceof Number) {
                target.setValue(((Number) v).doubleValue(), unit);
            } else if (v instanceof double[]) {
                target.setValue((double[]) v, unit);
            } else {
                throw new InvalidParameterValueException(Errors.format(
                          ErrorKeys.ILLEGAL_ARGUMENT_$2, name, v), name, v);
            }
        }
    }
View Full Code Here

            this.identifiers = asSet((ReferenceIdentifier[]) (value = identifiers));

            key = REMARKS_KEY;
            this.remarks = (InternationalString) (value = remarks);
        } catch (ClassCastException exception) {
            InvalidParameterValueException e = new InvalidParameterValueException(Errors.format(
                    ErrorKeys.ILLEGAL_ARGUMENT_$2, key, value), key, value);
            e.initCause(exception);
            throw e;
        }
        ensureNonNull(NAME_KEY, name);
        ensureNonNull(NAME_KEY, name.toString());
    }
View Full Code Here

     */
    protected static void ensureNonNull(final String name, final Object object)
            throws InvalidParameterValueException
    {
        if (object == null) {
            throw new InvalidParameterValueException(Errors.format(
                        ErrorKeys.NULL_ARGUMENT_$1, name), name, object);
        }
    }
View Full Code Here

     */
    protected static void ensureNonNull(final String name, final Object[] array, final int index)
            throws InvalidParameterValueException
    {
        if (array[index] == null) {
            throw new InvalidParameterValueException(Errors.format(
                        ErrorKeys.NULL_ARGUMENT_$1, name+'['+index+']'), name, array);
        }
    }
View Full Code Here

TOP

Related Classes of org.opengis.parameter.InvalidParameterValueException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.