Exemplo n.º 1
0
 /// <summary>
 /// Registers the provider.
 /// </summary>
 /// <param name="provider">  the provider to register, not null </param>
 /// <exception cref="ZoneRulesException"> if unable to complete the registration </exception>
 private static void RegisterProvider0(ZoneRulesProvider provider)
 {
     foreach (String zoneId in provider.ProvideZoneIds())
     {
         Objects.RequireNonNull(zoneId, "zoneId");
         ZoneRulesProvider old = ZONES.PutIfAbsent(zoneId, provider);
         if (old != null)
         {
             throw new ZoneRulesException("Unable to register zone as one already registered with that ID: " + zoneId + ", currently loading from provider: " + provider);
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the provider for the zone ID.
        /// </summary>
        /// <param name="zoneId">  the zone ID as defined by {@code ZoneId}, not null </param>
        /// <returns> the provider, not null </returns>
        /// <exception cref="ZoneRulesException"> if the zone ID is unknown </exception>
        private static ZoneRulesProvider GetProvider(String zoneId)
        {
            ZoneRulesProvider provider = ZONES[zoneId];

            if (provider == null)
            {
                if (ZONES.Count == 0)
                {
                    throw new ZoneRulesException("No time-zone data files registered");
                }
                throw new ZoneRulesException("Unknown time-zone ID: " + zoneId);
            }
            return(provider);
        }
Exemplo n.º 3
0
            public virtual Object Run()
            {
                String prop = System.getProperty("java.time.zone.DefaultZoneRulesProvider");

                if (prop != null)
                {
                    try
                    {
                        Class             c        = Class.ForName(prop, true, ClassLoader.SystemClassLoader);
                        ZoneRulesProvider provider = typeof(ZoneRulesProvider).cast(c.NewInstance());
                        RegisterProvider(provider);
                        Loaded.Add(provider);
                    }
                    catch (Exception x)
                    {
                        throw new Error(x);
                    }
                }
                else
                {
                    RegisterProvider(new TzdbZoneRulesProvider());
                }
                return(null);
            }
Exemplo n.º 4
0
 //-------------------------------------------------------------------------
 /// <summary>
 /// Registers a zone rules provider.
 /// <para>
 /// This adds a new provider to those currently available.
 /// A provider supplies rules for one or more zone IDs.
 /// A provider cannot be registered if it supplies a zone ID that has already been
 /// registered. See the notes on time-zone IDs in <seealso cref="ZoneId"/>, especially
 /// the section on using the concept of a "group" to make IDs unique.
 /// </para>
 /// <para>
 /// To ensure the integrity of time-zones already created, there is no way
 /// to deregister providers.
 ///
 /// </para>
 /// </summary>
 /// <param name="provider">  the provider to register, not null </param>
 /// <exception cref="ZoneRulesException"> if a zone ID is already registered </exception>
 public static void RegisterProvider(ZoneRulesProvider provider)
 {
     Objects.RequireNonNull(provider, "provider");
     RegisterProvider0(provider);
     PROVIDERS.Add(provider);
 }