Ejemplo n.º 1
0
        /// <summary>
        /// Parse a level name string into a Level.
        /// <para>
        /// The argument string may consist of either a level name
        /// or an integer value.
        /// </para>
        /// <para>
        /// For example:
        /// <ul>
        /// <li>     "SEVERE"
        /// <li>     "1000"
        /// </ul>
        ///
        /// </para>
        /// </summary>
        /// <param name="name">   string to be parsed </param>
        /// <exception cref="NullPointerException"> if the name is null </exception>
        /// <exception cref="IllegalArgumentException"> if the value is not valid.
        /// Valid values are integers between <CODE>Integer.MIN_VALUE</CODE>
        /// and <CODE>Integer.MAX_VALUE</CODE>, and all known level names.
        /// Known names are the levels defined by this class (e.g., <CODE>FINE</CODE>,
        /// <CODE>FINER</CODE>, <CODE>FINEST</CODE>), or created by this class with
        /// appropriate package access, or new levels defined or created
        /// by subclasses.
        /// </exception>
        /// <returns> The parsed value. Passing an integer that corresponds to a known name
        /// (e.g., 700) will return the associated name (e.g., <CODE>CONFIG</CODE>).
        /// Passing an integer that does not (e.g., 1) will return a new level name
        /// initialized to that value. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static synchronized Level parse(String name) throws IllegalArgumentException
        public static Level Parse(String name)
        {
            lock (typeof(Level))
            {
                // Check that name is not null.
                name.Length();

                KnownLevel level;

                // Look for a known Level with the given non-localized name.
                level = KnownLevel.FindByName(name);
                if (level != null)
                {
                    return(level.LevelObject);
                }

                // Now, check if the given name is an integer.  If so,
                // first look for a Level with the given value and then
                // if necessary create one.
                try
                {
                    int x = Convert.ToInt32(name);
                    level = KnownLevel.FindByValue(x);
                    if (level == null)
                    {
                        // add new Level
                        Level levelObject = new Level(name, x);
                        level = KnownLevel.FindByValue(x);
                    }
                    return(level.LevelObject);
                }
                catch (NumberFormatException)
                {
                    // Not an integer.
                    // Drop through.
                }

                // Finally, look for a known level with the given localized name,
                // in the current default locale.
                // This is relatively expensive, but not excessively so.
                level = KnownLevel.FindByLocalizedLevelName(name);
                if (level != null)
                {
                    return(level.LevelObject);
                }

                // OK, we've tried everything and failed
                throw new IllegalArgumentException("Bad level \"" + name + "\"");
            }
        }
Ejemplo n.º 2
0
        // Serialization magic to prevent "doppelgangers".
        // This is a performance optimization.
        private Object ReadResolve()
        {
            KnownLevel o = KnownLevel.Matches(this);

            if (o != null)
            {
                return(o.LevelObject);
            }

            // Woops.  Whoever sent us this object knows
            // about a new log level.  Add it to our list.
            Level level = new Level(this.Name_Renamed, this.Value, this.ResourceBundleName_Renamed);

            return(level);
        }
Ejemplo n.º 3
0
 // private constructor to specify whether this instance should be added
 // to the KnownLevel list from which Level.parse method does its look up
 private Level(String name, int value, String resourceBundleName, bool visible)
 {
     if (name == null)
     {
         throw new NullPointerException();
     }
     this.Name_Renamed = name;
     this.Value        = value;
     this.ResourceBundleName_Renamed = resourceBundleName;
     this.LocalizedLevelName_Renamed = resourceBundleName == null ? name : null;
     this.CachedLocale = null;
     if (visible)
     {
         KnownLevel.Add(this);
     }
 }
Ejemplo n.º 4
0
        // Returns a mirrored Level object that matches the given name as
        // specified in the Level.parse method.  Returns null if not found.
        //
        // It returns the same Level object as the one returned by Level.parse
        // method if the given name is a non-localized name or integer.
        //
        // If the name is a localized name, findLevel and parse method may
        // return a different level value if there is a custom Level subclass
        // that overrides Level.getLocalizedName() to return a different string
        // than what's returned by the default implementation.
        //
        internal static Level FindLevel(String name)
        {
            if (name == null)
            {
                throw new NullPointerException();
            }

            KnownLevel level;

            // Look for a known Level with the given non-localized name.
            level = KnownLevel.FindByName(name);
            if (level != null)
            {
                return(level.MirroredLevel);
            }

            // Now, check if the given name is an integer.  If so,
            // first look for a Level with the given value and then
            // if necessary create one.
            try
            {
                int x = Convert.ToInt32(name);
                level = KnownLevel.FindByValue(x);
                if (level == null)
                {
                    // add new Level
                    Level levelObject = new Level(name, x);
                    level = KnownLevel.FindByValue(x);
                }
                return(level.MirroredLevel);
            }
            catch (NumberFormatException)
            {
                // Not an integer.
                // Drop through.
            }

            level = KnownLevel.FindByLocalizedLevelName(name);
            if (level != null)
            {
                return(level.MirroredLevel);
            }

            return(null);
        }
Ejemplo n.º 5
0
            internal static void Add(Level l)
            {
                lock (typeof(KnownLevel))
                {
                    // the mirroredLevel object is always added to the list
                    // before the custom Level instance
                    KnownLevel         o    = new KnownLevel(l);
                    IList <KnownLevel> list = NameToLevels[l.Name_Renamed];
                    if (list == null)
                    {
                        list = new List <>();
                        NameToLevels[l.Name_Renamed] = list;
                    }
                    list.Add(o);

                    list = IntToLevels[l.Value];
                    if (list == null)
                    {
                        list = new List <>();
                        IntToLevels[l.Value] = list;
                    }
                    list.Add(o);
                }
            }