Package org.opengis.parameter

Examples of org.opengis.parameter.GeneralParameterDescriptor


        ArgumentChecks.ensureNonNull("name", name);
        final ParameterValueList values = this.values; // Protect against accidental changes.
        final List<ParameterValueGroup> groups = new ArrayList<ParameterValueGroup>(4);
        final int size = values.size();
        for (int i=0; i<size; i++) {
            final GeneralParameterDescriptor descriptor = values.descriptor(i);
            if (descriptor instanceof ParameterDescriptorGroup) {
                if (isHeuristicMatchForName(descriptor, name)) {
                    groups.add((ParameterValueGroup) values.get(i));
                }
            }
        }
        /*
         * No groups were found. Check if the group actually exists (i.e. is declared in the
         * descriptor). If it doesn't exists, then an exception is thrown. If it exists (i.e.
         * it is simply an optional group not yet defined), then returns an empty list.
         */
        if (groups.isEmpty()) {
            final ParameterDescriptorGroup descriptor = values.descriptor;
            if (!(descriptor.descriptor(name) instanceof ParameterDescriptorGroup)) {
                throw new ParameterNotFoundException(Errors.format(
                        Errors.Keys.ParameterNotFound_2, descriptor.getName(), name), name);
            }
        }
        return groups;
    }
View Full Code Here


    public ParameterValueGroup addGroup(final String name)
            throws ParameterNotFoundException, InvalidParameterCardinalityException
    {
        final ParameterValueList values = this.values; // Protect against accidental changes.
        final ParameterDescriptorGroup descriptor = values.descriptor;
        final GeneralParameterDescriptor child = descriptor.descriptor(name);
        if (!(child instanceof ParameterDescriptorGroup)) {
            throw new ParameterNotFoundException(Errors.format(
                    Errors.Keys.ParameterNotFound_2, descriptor.getName(), name), name);
        }
        final ParameterValueGroup value = ((ParameterDescriptorGroup) child).createValue();
View Full Code Here

    @Override
    public GeneralParameterValue set(final int index, final GeneralParameterValue parameter) {
        ArgumentChecks.ensureValidIndex(size, index);
        final GeneralParameterValue value = values[index];
        ArgumentChecks.ensureNonNull("parameter", parameter);
        final GeneralParameterDescriptor desc = parameter.getDescriptor();
        if (!value.getDescriptor().equals(desc)) {
            ensureDescriptorExists(desc);
            ensureCanRemove(desc);
            ensureCanAdd(desc);
        }
View Full Code Here

     *         than allowed by {@code maximumOccurs}.
     */
    @Override
    public boolean add(final GeneralParameterValue parameter) {
        ArgumentChecks.ensureNonNull("parameter", parameter);
        final GeneralParameterDescriptor desc = parameter.getDescriptor();
        ensureDescriptorExists(desc);
        /*
         * If we had an uninitialized parameter (a parameter created by the DefaultParameterValueGroup constructor
         * and never been queried or set by the user), then the given parameter will replace the uninitialized.
         * The intend is to allow users to set its own parameters by a call to group.values().addAll(myParam).
         * Otherwise the given parameter will be added, in which case we need to check the cardinality.
         */
        final ReferenceIdentifier name = desc.getName();
        int count = 0;
        for (int i=0; i<size; i++) {
            final GeneralParameterValue value = values[i];
            if (name.equals(value.getDescriptor().getName())) {
                if (value instanceof UninitializedParameter) {
                    values[i] = parameter;
                    return true;
                }
                count++;
            }
        }
        if (count >= desc.getMaximumOccurs()) {
            throw new InvalidParameterCardinalityException(Errors.format(
                    Errors.Keys.TooManyOccurrences_2, count, name), name.getCode());
        }
        addUnchecked(parameter);
        modCount++;
View Full Code Here

        final ParameterValueList values = this.values; // Protect against accidental changes.

        // Quick search for an exact match.
        final int size = values.size();
        for (int i=0; i<size; i++) {
            final GeneralParameterDescriptor descriptor = values.descriptor(i);
            if (descriptor instanceof ParameterDescriptor<?>) {
                if (name.equals(descriptor.getName().toString())) {
                    return (ParameterValue<?>) values.get(i);
                }
            }
        }
        // More costly search before to give up.
        int fallback = -1, ambiguity = -1;
        for (int i=0; i<size; i++) {
            final GeneralParameterDescriptor descriptor = values.descriptor(i);
            if (descriptor instanceof ParameterDescriptor<?>) {
                if (isHeuristicMatchForName(descriptor, name)) {
                    if (fallback < 0) {
                        fallback = i;
                    } else {
                        ambiguity = i;
                    }
                }
            }
        }
        if (fallback >= 0) {
            if (ambiguity < 0) {
                return (ParameterValue<?>) values.get(fallback);
            }
            throw new ParameterNotFoundException(Errors.format(Errors.Keys.AmbiguousName_3,
                    values.descriptor(fallback).getName(), values.descriptor(ambiguity).getName(), name), name);
        }
        /*
         * No existing parameter found. The parameter may be optional. Check if a descriptor exists.
         * If such a descriptor is found, create the parameter, add it to the values list and returns it.
         */
        final GeneralParameterDescriptor descriptor = values.descriptor.descriptor(name);
        if (descriptor instanceof ParameterDescriptor<?> && descriptor.getMaximumOccurs() != 0) {
            final ParameterValue<?> value = ((ParameterDescriptor<?>) descriptor).createValue();
            values.addUnchecked(value);
            return value;
        }
        throw new ParameterNotFoundException(Errors.format(Errors.Keys.ParameterNotFound_2,
View Full Code Here

            if (name.equals(param.getName().getCode())) {
                return param;
            }
        }
        // More costly search before to give up.
        GeneralParameterDescriptor fallback = null, ambiguity = null;
        for (final GeneralParameterDescriptor param : descriptors) {
            if (IdentifiedObjects.isHeuristicMatchForName(param, name)) {
                if (fallback == null) {
                    fallback = param;
                } else {
                    ambiguity = param;
                }
            }
        }
        if (fallback != null && ambiguity == null) {
            return fallback;
        }
        throw new ParameterNotFoundException(ambiguity != null
                ? Errors.format(Errors.Keys.AmbiguousName_3, fallback.getName(), ambiguity.getName(), name)
                : Errors.format(Errors.Keys.ParameterNotFound_2, getName(), name), name);
    }
View Full Code Here

        /*
         * Count the parameters occurences.
         */
        for (int i=0; i<values.length; i++) {
            ensureNonNull("values", values, i);
            final GeneralParameterDescriptor descriptor = values[i].getDescriptor();
            final int[] count = occurences.get(descriptor);
            if (count == null) {
                final String name = getName(descriptor);
                throw new InvalidParameterTypeException(Errors.format(
                          ErrorKeys.ILLEGAL_DESCRIPTOR_FOR_PARAMETER_$1, name), name);
            }
            count[0]++;
        }
        /*
         * Now check if the occurences are in the expected ranges.
         */
        for (final Map.Entry<GeneralParameterDescriptor,int[]> entry : occurences.entrySet()) {
            final GeneralParameterDescriptor descriptor = entry.getKey();
            final int count = entry.getValue()[0];
            final int min   = descriptor.getMinimumOccurs();
            final int max   = descriptor.getMaximumOccurs();
            if (!(count>=min && count<=max)) {
                final String name = getName(descriptor);
                throw new InvalidParameterCardinalityException(Errors.format(
                          ErrorKeys.ILLEGAL_OCCURS_FOR_PARAMETER_$4, name, count, min, max), name);
            }
View Full Code Here

         * No groups were found. Check if the group actually exists (i.e. is declared in the
         * descriptor). If it doesn't exists, then an exception is thrown. If it exists (i.e.
         * it is simply an optional group not yet defined), then returns an empty list.
         */
        if (groups.isEmpty()) {
            final GeneralParameterDescriptor check =
                    ((ParameterDescriptorGroup) descriptor).descriptor(name);
            if (!(check instanceof ParameterDescriptorGroup)) {
                throw new ParameterNotFoundException(Errors.format(
                          ErrorKeys.MISSING_PARAMETER_$1, name), name);
            }
View Full Code Here

     *         of subgroups of the given name.
     */
    public ParameterValueGroup addGroup(String name)
            throws ParameterNotFoundException, InvalidParameterCardinalityException
    {
        final GeneralParameterDescriptor check =
                ((ParameterDescriptorGroup) descriptor).descriptor(name);
        if (!(check instanceof ParameterDescriptorGroup)) {
            throw new ParameterNotFoundException(Errors.format(
                      ErrorKeys.MISSING_PARAMETER_$1, name), name);
        }
        int count = 0;
        for (final Iterator it=values.iterator(); it.hasNext();) {
            final GeneralParameterValue value = (GeneralParameterValue) it.next();
            if (AbstractIdentifiedObject.nameMatches(value.getDescriptor(), name)) {
                count++;
            }
        }
        if (count >= check.getMaximumOccurs()) {
            throw new InvalidParameterCardinalityException(Errors.format(
                      ErrorKeys.TOO_MANY_OCCURENCES_$2, name, count), name);
        }
        final ParameterValueGroup value = ((ParameterDescriptorGroup) check).createValue();
        values.add(value);
View Full Code Here

        List<Object> deferredGroups = null;
        final Object[] array1 = new Object[1];
        final Collection<?> elements = (values!=null) ? values.values() : group.descriptors();
        for (final Object element : elements) {
            final GeneralParameterValue      generalValue;
            final GeneralParameterDescriptor generalDescriptor;
            if (values != null) {
                generalValue = (GeneralParameterValue) element;
                generalDescriptor = generalValue.getDescriptor();
            } else {
                generalValue = null;
                generalDescriptor = (GeneralParameterDescriptor) element;
            }
            /*
             * If the current element is a group, we will format it later (after
             * all ordinary elements) in order avoid breaking the table layout.
             */
            if (generalDescriptor instanceof ParameterDescriptorGroup) {
                if (deferredGroups == null) {
                    deferredGroups = new ArrayList<Object>();
                }
                deferredGroups.add(element);
                continue;
            }
            /*
             * Format the element name, including all alias (if any).
             * Each alias will be formatted on its own line.
             */
            final Identifier identifier = generalDescriptor.getName();
            table.write(identifier.getCode());
            alias = generalDescriptor.getAlias();
            if (alias != null) {
                for (final GenericName a : alias) {
                    if (!identifier.equals(a)) {
                        table.write(lineSeparator);
                        table.write(a.tip().toInternationalString().toString(locale));
View Full Code Here

TOP

Related Classes of org.opengis.parameter.GeneralParameterDescriptor

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.