/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
/*
*
*
*
*
*
* Copyright (c) 2009-2012, Stephen Colebourne & Michael Nascimento Santos
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of JSR-310 nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package java.time.zone;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.NavigableMap;
import java.util.Objects;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CopyOnWriteArrayList;
/**
* Provider of time-zone rules to the system.
*
* This class manages the configuration of time-zone rules.
* The static methods provide the public API that can be used to manage the providers.
* The abstract methods provide the SPI that allows rules to be provided.
*
* ZoneRulesProvider may be installed in an instance of the Java Platform as
* extension classes, that is, jar files placed into any of the usual extension
* directories. Installed providers are loaded using the service-provider loading
* facility defined by the {@link ServiceLoader} class. A ZoneRulesProvider
* identifies itself with a provider configuration file named
* {@code java.time.zone.ZoneRulesProvider} in the resource directory
* {@code META-INF/services}. The file should contain a line that specifies the
* fully qualified concrete zonerules-provider class name.
* Providers may also be made available by adding them to the class path or by
* registering themselves via {@link #registerProvider} method.
*
* The Java virtual machine has a default provider that provides zone rules
* for the time-zones defined by IANA Time Zone Database (TZDB). If the system
* property {@code java.time.zone.DefaultZoneRulesProvider} is defined then
* it is taken to be the fully-qualified name of a concrete ZoneRulesProvider
* class to be loaded as the default provider, using the system class loader.
* If this system property is not defined, a system-default provider will be
* loaded to serve as the default provider.
*
* Rules are looked up primarily by zone ID, as used by {@link ZoneId}.
* Only zone region IDs may be used, zone offset IDs are not used here.
*
* Time-zone rules are political, thus the data can change at any time.
* Each provider will provide the latest rules for each zone ID, but they
* may also provide the history of how the rules changed.
*
* @implSpec
* This interface is a service provider that can be called by multiple threads.
* Implementations must be immutable and thread-safe.
*
* Providers must ensure that once a rule has been seen by the application, the
* rule must continue to be available.
*
* Providers are encouraged to implement a meaningful {@code toString} method.
*
* Many systems would like to update time-zone rules dynamically without stopping the JVM.
* When examined in detail, this is a complex problem.
* Providers may choose to handle dynamic updates, however the default provider does not.
*
* @since 1.8
*/
public abstract class ZoneRulesProvider {
/**
* The set of loaded providers.
*/
private static final CopyOnWriteArrayList PROVIDERS = new CopyOnWriteArrayList<>();
/**
* The lookup from zone ID to provider.
*/
private static final ConcurrentMap ZONES = new ConcurrentHashMap<>(512, 0.75f, 2);
static {
// if the property java.time.zone.DefaultZoneRulesProvider is
// set then its value is the class name of the default provider
final List loaded = new ArrayList<>();
AccessController.doPrivileged(new PrivilegedAction