public final void setProperty()

in endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/Pooled.java [306:419]


    public final void setProperty(String name, final Object value) throws PropertyException {
        try {
            switch (name) {
                case XML.LOCALE: {
                    locale = (value instanceof CharSequence) ? Locales.parse(value.toString()) : (Locale) value;
                    return;
                }
                case XML.TIMEZONE: {
                    if (value instanceof CharSequence) {
                        String id = value.toString();
                        try {
                            timezone = ZoneId.of(id);
                        } catch (DateTimeException e) {
                            timezone = TimeZone.getTimeZone(id).toZoneId();
                            if (timezone.getId().equals("GMT")) {
                                throw e;
                            }
                        }
                    } else {
                        timezone = (value instanceof TimeZone) ? ((TimeZone) value).toZoneId() : (ZoneId) value;
                    }
                    return;
                }
                case XML.SCHEMAS: {
                    final Map<?,?> map = (Map<?,?>) value;
                    Map<String,String> copy = null;
                    if (map != null) {
                        copy = new HashMap<>(4);
                        for (final String key : SCHEMA_KEYS) {
                            final Object schema = map.get(key);
                            if (schema != null) {
                                if (!(schema instanceof String)) {
                                    throw new PropertyException(Errors.format(Errors.Keys.IllegalPropertyValueClass_2,
                                            Strings.bracket(name, key), schema.getClass()));
                                }
                                copy.put(key, (String) schema);
                            }
                        }
                        copy = Map.copyOf(copy);
                    }
                    schemas = copy;
                    return;
                }
                case XML.GML_VERSION: {
                    versionGML = (value instanceof CharSequence) ? new Version(value.toString()) : (Version) value;
                    return;
                }
                case XML.METADATA_VERSION: {
                    versionMetadata = (value instanceof CharSequence) ? new Version(value.toString()) : (Version) value;
                    return;
                }
                case XML.RESOLVER: {
                    resolver = (ReferenceResolver) value;
                    return;
                }
                case XML.CONVERTER: {
                    converter = (ValueConverter) value;
                    return;
                }
                case XML.LENIENT_UNMARSHAL: {
                    if (value != null && ((value instanceof CharSequence) ?
                            Boolean.parseBoolean(value.toString()) : (Boolean) value))
                    {
                        bitMasks |= Context.LENIENT_UNMARSHAL;
                    } else {
                        bitMasks &= ~Context.LENIENT_UNMARSHAL;
                    }
                    return;
                }
                case XML.STRING_SUBSTITUTES: {
                    bitMasks &= ~(Context.SUBSTITUTE_LANGUAGE |
                                  Context.SUBSTITUTE_COUNTRY  |
                                  Context.SUBSTITUTE_FILENAME |
                                  Context.SUBSTITUTE_MIMETYPE);
                    if (value != null) {
                        for (final CharSequence substitute : (CharSequence[]) value) {
                            if (CharSequences.equalsIgnoreCase(substitute, "language")) {
                                bitMasks |= Context.SUBSTITUTE_LANGUAGE;
                            } else if (CharSequences.equalsIgnoreCase(substitute, "country")) {
                                bitMasks |= Context.SUBSTITUTE_COUNTRY;
                            } else if (CharSequences.equalsIgnoreCase(substitute, "filename")) {
                                bitMasks |= Context.SUBSTITUTE_FILENAME;
                            } else if (CharSequences.equalsIgnoreCase(substitute, "mimetype")) {
                                bitMasks |= Context.SUBSTITUTE_MIMETYPE;
                            }
                        }
                    }
                    return;
                }
                case XML.WARNING_FILTER: {
                    logFilter = (Filter) value;
                    return;
                }
                case TypeRegistration.ROOT_ADAPTERS: {
                    @SuppressWarnings("unchecked")
                    UnaryOperator<Object>[] c = (UnaryOperator<Object>[]) value;
                    rootAdapters = c;       // No clone for now because ROOT_ADAPTERS is not yet a public API.
                    return;
                }
            }
        } catch (RuntimeException e) {
            throw new PropertyException(Errors.format(
                    Errors.Keys.IllegalPropertyValueClass_2, name, value.getClass()), e);
        }
        /*
         * If we reach this point, the given name is not a SIS property. Try to handle
         * it as a (un)marshaller-specific property, after saving the previous value.
         */
        if (!initialProperties.containsKey(name) && initialProperties.put(name, getStandardProperty(name)) != null) {
            // Should never happen, unless on concurrent changes in a backgroung thread.
            throw new ConcurrentModificationException(name);
        }
        setStandardProperty(name, value);
    }