Package com.sun.mail.util.logging
Class LogManagerProperties
- java.lang.Object
-
- java.util.Dictionary<K,V>
-
- java.util.Hashtable<java.lang.Object,java.lang.Object>
-
- java.util.Properties
-
- com.sun.mail.util.logging.LogManagerProperties
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.util.Map<java.lang.Object,java.lang.Object>
final class LogManagerProperties extends java.util.PropertiesAn adapter class to allow the Mail API to access the LogManager properties. The LogManager properties are treated as the root of all properties. First, the parent properties are searched. If no value is found, then, the LogManager is searched with prefix value. If not found, then, just the key itself is searched in the LogManager. If a value is found in the LogManager it is then copied to this properties object with no key prefix. If no value is found in the LogManager or the parent properties, then this properties object is searched only by passing the key value.This class also emulates the LogManager functions for creating new objects from string class names. This is to support initial setup of objects such as log filters, formatters, error managers, etc.
This class should never be exposed outside of this package. Keep this class package private (default access).
- Since:
- JavaMail 1.4.3
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.ObjectLOG_MANAGERCaches the LogManager or Properties so we only read the configuration once.private static java.lang.reflect.MethodLR_GET_INSTANTHolds the method used to get the LogRecord instant if running on JDK 9 or later.private java.lang.StringprefixThe namespace prefix to search LogManager and defaults.private static java.lang.String[]REFLECT_NAMESCaches the read only reflection class names string array.private static longserialVersionUIDGenerated serial id.private static java.lang.reflect.MethodZDT_OF_INSTANTHolds the method used to convert and instant to a zoned date time if running on JDK 9 later.private static java.lang.reflect.MethodZI_SYSTEM_DEFAULTHolds the method used to get the default time zone if running on JDK 9 or later.
-
Constructor Summary
Constructors Constructor Description LogManagerProperties(java.util.Properties parent, java.lang.String prefix)Creates a log manager properties object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static voidcheckLoggingAccess()Check that the current context is trusted to modify the logging configuration when the LogManager is not present.(package private) static voidcheckLogManagerAccess()Check that the current context is trusted to modify the logging configuration.java.lang.Objectclone()Returns a properties object that contains a snapshot of the current state.booleancontainsKey(java.lang.Object key)Required to work with PropUtil.booleanequals(java.lang.Object o)It is assumed that this method will never be called.private java.util.PropertiesexportCopy(java.util.Properties parent)Creates a public snapshot of this properties object using the given parent properties.private static java.lang.Class<?>findClass(java.lang.String name)This code is modified from the LogManager, which explictly states searching the system class loader first, then the context class loader.(package private) static java.lang.StringfromLogManager(java.lang.String name)Gets LogManger property for the running JVM.java.lang.Objectget(java.lang.Object key)Required to work with PropUtil.private static java.lang.ClassLoader[]getClassLoaders()Gets the class loaders using elevated privileges.(package private) static java.lang.StringgetLocalHost(java.lang.Object s)Gets the local host name from the given service.java.lang.StringgetProperty(java.lang.String key)Searches defaults, then searches the log manager if available or the system properties by the prefix property, and then by the key itself.java.lang.StringgetProperty(java.lang.String key, java.lang.String def)Calls getProperty directly.(package private) static java.lang.Comparable<?>getZonedDateTime(java.util.logging.LogRecord record)Gets the ZonedDateTime from the given log record.inthashCode()It is assumed that this method will never be called.(package private) static booleanhasLogManager()Determines if access to thejava.util.logging.LogManagerclass is restricted by the class loader.(package private) static booleanisReflectionClass(java.lang.String name)Determines if the given class name is a reflection class name responsible for invoking methods and or constructors.(package private) static booleanisStaticUtilityClass(java.lang.String name)Determines if the given class name identifies a utility class.private static java.lang.ObjectloadLogManager()Get the LogManager or loads a Properties object to use as the LogManager.(package private) static java.util.Comparator<? super java.util.logging.LogRecord>newComparator(java.lang.String name)Creates a new log record comparator from the given class name.(package private) static java.util.logging.ErrorManagernewErrorManager(java.lang.String name)Creates a new error manager from the given class name.(package private) static java.util.logging.FilternewFilter(java.lang.String name)Creates a new filter from the given class name.(package private) static java.util.logging.FormatternewFormatter(java.lang.String name)Creates a new formatter from the given class name.(package private) static <T> TnewObjectFrom(java.lang.String name, java.lang.Class<T> type)Creates a new object from the given class name.private static java.lang.ExceptionparamOrError(java.lang.reflect.InvocationTargetException ite)Returns the given exception or throws the escaping cause.(package private) static longparseDurationToMillis(java.lang.CharSequence value)Used to parse an ISO-8601 duration format ofPnDTnHnMn.nS.private java.lang.ObjectpreWrite(java.lang.Object key)Called before a write operation of a key.java.util.Enumeration<?>propertyNames()It is assumed that this method will never be called.java.lang.Objectput(java.lang.Object key, java.lang.Object value)Required to work with PropUtil.private static java.util.PropertiesreadConfiguration()Create a properties object from the default logging configuration file.private static java.lang.String[]reflectionClassNames()Determines all of the reflection class names used to invoke methods.java.lang.Objectremove(java.lang.Object key)Required to work with PropUtil.(package private) static <T> java.util.Comparator<T>reverseOrder(java.util.Comparator<T> c)Returns a comparator that imposes the reverse ordering of the specifiedComparator.java.lang.ObjectsetProperty(java.lang.String key, java.lang.String value)Calls the put method directly.(package private) static java.lang.StringtoLanguageTag(java.util.Locale locale)Converts a locale to a language tag.private static java.lang.Class<?>tryLoad(java.lang.String name, java.lang.ClassLoader l)Loads a class using the given loader or the class loader of this class.private static java.lang.reflect.InvocationTargetExceptionwrapOrThrow(java.lang.ExceptionInInitializerError eiie)Throws the given error if the cause is an error otherwise the given error is wrapped.private java.lang.ObjectwriteReplace()It is assumed that this method will never be called.-
Methods inherited from class java.util.Properties
clear, compute, computeIfAbsent, computeIfPresent, contains, containsValue, elements, entrySet, forEach, getOrDefault, isEmpty, keys, keySet, list, list, load, load, loadFromXML, merge, putAll, putIfAbsent, rehash, remove, replace, replace, replaceAll, save, size, store, store, storeToXML, storeToXML, storeToXML, stringPropertyNames, toString, values
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Generated serial id.- See Also:
- Constant Field Values
-
LR_GET_INSTANT
private static final java.lang.reflect.Method LR_GET_INSTANT
Holds the method used to get the LogRecord instant if running on JDK 9 or later.
-
ZI_SYSTEM_DEFAULT
private static final java.lang.reflect.Method ZI_SYSTEM_DEFAULT
Holds the method used to get the default time zone if running on JDK 9 or later.
-
ZDT_OF_INSTANT
private static final java.lang.reflect.Method ZDT_OF_INSTANT
Holds the method used to convert and instant to a zoned date time if running on JDK 9 later.
-
REFLECT_NAMES
private static volatile java.lang.String[] REFLECT_NAMES
Caches the read only reflection class names string array. Declared volatile for safe publishing only. The VO_VOLATILE_REFERENCE_TO_ARRAY warning is a false positive.
-
LOG_MANAGER
private static final java.lang.Object LOG_MANAGER
Caches the LogManager or Properties so we only read the configuration once.
-
prefix
private final java.lang.String prefix
The namespace prefix to search LogManager and defaults.
-
-
Constructor Detail
-
LogManagerProperties
LogManagerProperties(java.util.Properties parent, java.lang.String prefix)Creates a log manager properties object.- Parameters:
parent- the parent properties.prefix- the namespace prefix.- Throws:
java.lang.NullPointerException- if prefix or parent is null.
-
-
Method Detail
-
loadLogManager
private static java.lang.Object loadLogManager()
Get the LogManager or loads a Properties object to use as the LogManager.- Returns:
- the LogManager or a loaded Properties object.
- Since:
- JavaMail 1.5.3
-
readConfiguration
private static java.util.Properties readConfiguration()
Create a properties object from the default logging configuration file. Since the LogManager is not available in restricted environments, only the default configuration is applicable.- Returns:
- a properties object loaded with the default configuration.
- Since:
- JavaMail 1.5.3
-
fromLogManager
static java.lang.String fromLogManager(java.lang.String name)
Gets LogManger property for the running JVM. If the LogManager doesn't exist then the default LogManger properties are used.- Parameters:
name- the property name.- Returns:
- the LogManager.
- Throws:
java.lang.NullPointerException- if the given name is null.- Since:
- JavaMail 1.5.3
-
checkLogManagerAccess
static void checkLogManagerAccess()
Check that the current context is trusted to modify the logging configuration. This requires LoggingPermission("control").- Throws:
java.lang.SecurityException- if a security manager exists and the caller does not haveLoggingPermission("control").- Since:
- JavaMail 1.5.3
-
checkLoggingAccess
private static void checkLoggingAccess()
Check that the current context is trusted to modify the logging configuration when the LogManager is not present. This requires LoggingPermission("control").- Throws:
java.lang.SecurityException- if a security manager exists and the caller does not haveLoggingPermission("control").- Since:
- JavaMail 1.5.3
-
hasLogManager
static boolean hasLogManager()
Determines if access to thejava.util.logging.LogManagerclass is restricted by the class loader.- Returns:
- true if a LogManager is present.
- Since:
- JavaMail 1.5.3
-
getZonedDateTime
static java.lang.Comparable<?> getZonedDateTime(java.util.logging.LogRecord record)
Gets the ZonedDateTime from the given log record.- Parameters:
record- used to generate the zoned date time.- Returns:
- null if LogRecord doesn't support nanoseconds otherwise a new zoned date time is returned.
- Throws:
java.lang.NullPointerException- if record is null.- Since:
- JavaMail 1.5.6
-
getLocalHost
static java.lang.String getLocalHost(java.lang.Object s) throws java.lang.ExceptionGets the local host name from the given service.- Parameters:
s- the service to examine.- Returns:
- the local host name or null.
- Throws:
java.lang.IllegalAccessException- if the method is inaccessible.java.lang.reflect.InvocationTargetException- if the method throws an exception.java.lang.LinkageError- if the linkage fails.java.lang.NullPointerException- if the given service is null.java.lang.ExceptionInInitializerError- if the static initializer fails.java.lang.Exception- if there is a problem.java.lang.NoSuchMethodException- if the given service does not have a method to get the local host name as a string.java.lang.SecurityException- if unable to inspect properties of object.- Since:
- JavaMail 1.5.3
-
parseDurationToMillis
static long parseDurationToMillis(java.lang.CharSequence value) throws java.lang.ExceptionUsed to parse an ISO-8601 duration format ofPnDTnHnMn.nS.- Parameters:
value- an ISO-8601 duration character sequence.- Returns:
- the number of milliseconds parsed from the duration.
- Throws:
java.lang.ClassNotFoundException- if the java.time classes are not present.java.lang.IllegalAccessException- if the method is inaccessible.java.lang.reflect.InvocationTargetException- if the method throws an exception.java.lang.LinkageError- if the linkage fails.java.lang.NullPointerException- if the given duration is null.java.lang.ExceptionInInitializerError- if the static initializer fails.java.lang.Exception- if there is a problem.java.lang.NoSuchMethodException- if the correct time methods are missing.java.lang.SecurityException- if reflective access to the java.time classes are not allowed.- Since:
- JavaMail 1.5.5
-
toLanguageTag
static java.lang.String toLanguageTag(java.util.Locale locale)
Converts a locale to a language tag.- Parameters:
locale- the locale to convert.- Returns:
- the language tag.
- Throws:
java.lang.NullPointerException- if the given locale is null.- Since:
- JavaMail 1.4.5
-
newFilter
static java.util.logging.Filter newFilter(java.lang.String name) throws java.lang.ExceptionCreates a new filter from the given class name.- Parameters:
name- the fully qualified class name.- Returns:
- a new filter.
- Throws:
java.lang.ClassCastException- if class name does not match the type.java.lang.ClassNotFoundException- if the class name was not found.java.lang.IllegalAccessException- if the constructor is inaccessible.java.lang.InstantiationException- if the given class name is abstract.java.lang.reflect.InvocationTargetException- if the constructor throws an exception.java.lang.LinkageError- if the linkage fails.java.lang.ExceptionInInitializerError- if the static initializer fails.java.lang.Exception- to match the error method of the ErrorManager.java.lang.NoSuchMethodException- if the class name does not have a no argument constructor.- Since:
- JavaMail 1.4.5
-
newFormatter
static java.util.logging.Formatter newFormatter(java.lang.String name) throws java.lang.ExceptionCreates a new formatter from the given class name.- Parameters:
name- the fully qualified class name.- Returns:
- a new formatter.
- Throws:
java.lang.ClassCastException- if class name does not match the type.java.lang.ClassNotFoundException- if the class name was not found.java.lang.IllegalAccessException- if the constructor is inaccessible.java.lang.InstantiationException- if the given class name is abstract.java.lang.reflect.InvocationTargetException- if the constructor throws an exception.java.lang.LinkageError- if the linkage fails.java.lang.ExceptionInInitializerError- if the static initializer fails.java.lang.Exception- to match the error method of the ErrorManager.java.lang.NoSuchMethodException- if the class name does not have a no argument constructor.- Since:
- JavaMail 1.4.5
-
newComparator
static java.util.Comparator<? super java.util.logging.LogRecord> newComparator(java.lang.String name) throws java.lang.ExceptionCreates a new log record comparator from the given class name.- Parameters:
name- the fully qualified class name.- Returns:
- a new comparator.
- Throws:
java.lang.ClassCastException- if class name does not match the type.java.lang.ClassNotFoundException- if the class name was not found.java.lang.IllegalAccessException- if the constructor is inaccessible.java.lang.InstantiationException- if the given class name is abstract.java.lang.reflect.InvocationTargetException- if the constructor throws an exception.java.lang.LinkageError- if the linkage fails.java.lang.ExceptionInInitializerError- if the static initializer fails.java.lang.Exception- to match the error method of the ErrorManager.java.lang.NoSuchMethodException- if the class name does not have a no argument constructor.- Since:
- JavaMail 1.4.5
- See Also:
LogRecord
-
reverseOrder
static <T> java.util.Comparator<T> reverseOrder(java.util.Comparator<T> c)
Returns a comparator that imposes the reverse ordering of the specifiedComparator. If the given comparator declares a public reverseOrder method that method is called first and the return value is used. If that method is not declared or the caller does not have access then a comparator wrapping the given comparator is returned.- Type Parameters:
T- the element type to be compared- Parameters:
c- a comparator whose ordering is to be reversed by the returned comparator- Returns:
- A comparator that imposes the reverse ordering of the specified comparator.
- Throws:
java.lang.NullPointerException- if the given comparator is null.- Since:
- JavaMail 1.5.0
-
newErrorManager
static java.util.logging.ErrorManager newErrorManager(java.lang.String name) throws java.lang.ExceptionCreates a new error manager from the given class name.- Parameters:
name- the fully qualified class name.- Returns:
- a new error manager.
- Throws:
java.lang.ClassCastException- if class name does not match the type.java.lang.ClassNotFoundException- if the class name was not found.java.lang.IllegalAccessException- if the constructor is inaccessible.java.lang.InstantiationException- if the given class name is abstract.java.lang.reflect.InvocationTargetException- if the constructor throws an exception.java.lang.LinkageError- if the linkage fails.java.lang.ExceptionInInitializerError- if the static initializer fails.java.lang.Exception- to match the error method of the ErrorManager.java.lang.NoSuchMethodException- if the class name does not have a no argument constructor.- Since:
- JavaMail 1.4.5
-
isStaticUtilityClass
static boolean isStaticUtilityClass(java.lang.String name) throws java.lang.ExceptionDetermines if the given class name identifies a utility class.- Parameters:
name- the fully qualified class name.- Returns:
- true if the given class name
- Throws:
java.lang.ClassNotFoundException- if the class name was not found.java.lang.IllegalAccessException- if the constructor is inaccessible.java.lang.LinkageError- if the linkage fails.java.lang.ExceptionInInitializerError- if the static initializer fails.java.lang.Exception- to match the error method of the ErrorManager.java.lang.SecurityException- if unable to inspect properties of class.- Since:
- JavaMail 1.5.2
-
isReflectionClass
static boolean isReflectionClass(java.lang.String name) throws java.lang.ExceptionDetermines if the given class name is a reflection class name responsible for invoking methods and or constructors.- Parameters:
name- the fully qualified class name.- Returns:
- true if the given class name
- Throws:
java.lang.ClassNotFoundException- if the class name was not found.java.lang.IllegalAccessException- if the constructor is inaccessible.java.lang.LinkageError- if the linkage fails.java.lang.ExceptionInInitializerError- if the static initializer fails.java.lang.Exception- to match the error method of the ErrorManager.java.lang.SecurityException- if unable to inspect properties of class.- Since:
- JavaMail 1.5.2
-
reflectionClassNames
private static java.lang.String[] reflectionClassNames() throws java.lang.ExceptionDetermines all of the reflection class names used to invoke methods. This method performs indirect and direct calls on a throwable to capture the standard class names and the implementation class names.- Returns:
- a string array containing the fully qualified class names.
- Throws:
java.lang.Exception- if there is a problem.
-
newObjectFrom
static <T> T newObjectFrom(java.lang.String name, java.lang.Class<T> type) throws java.lang.ExceptionCreates a new object from the given class name.- Type Parameters:
T- The generic class type.- Parameters:
name- the fully qualified class name.type- the assignable type for the given name.- Returns:
- a new object assignable to the given type.
- Throws:
java.lang.ClassCastException- if class name does not match the type.java.lang.ClassNotFoundException- if the class name was not found.java.lang.IllegalAccessException- if the constructor is inaccessible.java.lang.InstantiationException- if the given class name is abstract.java.lang.reflect.InvocationTargetException- if the constructor throws an exception.java.lang.LinkageError- if the linkage fails.java.lang.ExceptionInInitializerError- if the static initializer fails.java.lang.Exception- to match the error method of the ErrorManager.java.lang.NoSuchMethodException- if the class name does not have a no argument constructor.- Since:
- JavaMail 1.4.5
-
paramOrError
private static java.lang.Exception paramOrError(java.lang.reflect.InvocationTargetException ite)
Returns the given exception or throws the escaping cause.- Parameters:
ite- any invocation target.- Returns:
- the exception.
- Throws:
java.lang.VirtualMachineError- if present as cause.java.lang.ThreadDeath- if present as cause.- Since:
- JavaMail 1.4.5
-
wrapOrThrow
private static java.lang.reflect.InvocationTargetException wrapOrThrow(java.lang.ExceptionInInitializerError eiie)
Throws the given error if the cause is an error otherwise the given error is wrapped.- Parameters:
eiie- the error.- Returns:
- an InvocationTargetException.
- Since:
- JavaMail 1.5.0
-
findClass
private static java.lang.Class<?> findClass(java.lang.String name) throws java.lang.ClassNotFoundExceptionThis code is modified from the LogManager, which explictly states searching the system class loader first, then the context class loader. There is resistance (compatibility) to change this behavior to simply searching the context class loader.- Parameters:
name- full class name- Returns:
- the class.
- Throws:
java.lang.LinkageError- if the linkage fails.java.lang.ClassNotFoundException- if the class name was not found.java.lang.ExceptionInInitializerError- if static initializer fails.
-
tryLoad
private static java.lang.Class<?> tryLoad(java.lang.String name, java.lang.ClassLoader l) throws java.lang.ClassNotFoundExceptionLoads a class using the given loader or the class loader of this class.- Parameters:
name- the class name.l- any class loader or null.- Returns:
- the raw class.
- Throws:
java.lang.ClassNotFoundException- if not found.
-
getClassLoaders
private static java.lang.ClassLoader[] getClassLoaders()
Gets the class loaders using elevated privileges.- Returns:
- any array of class loaders. Indexes may be null.
-
clone
public java.lang.Object clone()
Returns a properties object that contains a snapshot of the current state. This method violates the clone contract so that no instances of LogManagerProperties is exported for public use.- Overrides:
clonein classjava.util.Properties- Returns:
- the snapshot.
- Since:
- JavaMail 1.4.4
-
getProperty
public java.lang.String getProperty(java.lang.String key)
Searches defaults, then searches the log manager if available or the system properties by the prefix property, and then by the key itself.- Overrides:
getPropertyin classjava.util.Properties- Parameters:
key- a non null key.- Returns:
- the value for that key.
-
getProperty
public java.lang.String getProperty(java.lang.String key, java.lang.String def)Calls getProperty directly. If getProperty returns null the default value is returned.- Overrides:
getPropertyin classjava.util.Properties- Parameters:
key- a key to search for.def- the default value to use if not found.- Returns:
- the value for the key.
- Since:
- JavaMail 1.4.4
-
get
public java.lang.Object get(java.lang.Object key)
Required to work with PropUtil. Calls getProperty directly if the given key is a string. Otherwise, performs a get operation on the defaults followed by the normal hash table get.- Specified by:
getin interfacejava.util.Map<java.lang.Object,java.lang.Object>- Overrides:
getin classjava.util.Properties- Parameters:
key- any key.- Returns:
- the value for the key or null.
- Since:
- JavaMail 1.4.5
-
put
public java.lang.Object put(java.lang.Object key, java.lang.Object value)Required to work with PropUtil. An updated copy of the key is fetched from the log manager if the key doesn't exist in this properties.- Specified by:
putin interfacejava.util.Map<java.lang.Object,java.lang.Object>- Overrides:
putin classjava.util.Properties- Parameters:
key- any key.- Returns:
- the value for the key or the default value for the key.
- Since:
- JavaMail 1.4.5
-
setProperty
public java.lang.Object setProperty(java.lang.String key, java.lang.String value)Calls the put method directly.- Overrides:
setPropertyin classjava.util.Properties- Parameters:
key- any key.- Returns:
- the value for the key or the default value for the key.
- Since:
- JavaMail 1.4.5
-
containsKey
public boolean containsKey(java.lang.Object key)
Required to work with PropUtil. An updated copy of the key is fetched from the log manager prior to returning.- Specified by:
containsKeyin interfacejava.util.Map<java.lang.Object,java.lang.Object>- Overrides:
containsKeyin classjava.util.Properties- Parameters:
key- any key.- Returns:
- the value for the key or null.
- Since:
- JavaMail 1.4.5
-
remove
public java.lang.Object remove(java.lang.Object key)
Required to work with PropUtil. An updated copy of the key is fetched from the log manager if the key doesn't exist in this properties.- Specified by:
removein interfacejava.util.Map<java.lang.Object,java.lang.Object>- Overrides:
removein classjava.util.Properties- Parameters:
key- any key.- Returns:
- the value for the key or the default value for the key.
- Since:
- JavaMail 1.4.5
-
propertyNames
public java.util.Enumeration<?> propertyNames()
It is assumed that this method will never be called. No way to get the property names from LogManager.- Overrides:
propertyNamesin classjava.util.Properties- Returns:
- the property names
-
equals
public boolean equals(java.lang.Object o)
It is assumed that this method will never be called. The prefix value is not used for the equals method.- Specified by:
equalsin interfacejava.util.Map<java.lang.Object,java.lang.Object>- Overrides:
equalsin classjava.util.Properties- Parameters:
o- any object or null.- Returns:
- true if equal, otherwise false.
-
hashCode
public int hashCode()
It is assumed that this method will never be called. See equals.- Specified by:
hashCodein interfacejava.util.Map<java.lang.Object,java.lang.Object>- Overrides:
hashCodein classjava.util.Properties- Returns:
- the hash code.
-
preWrite
private java.lang.Object preWrite(java.lang.Object key)
Called before a write operation of a key. Caches a key read from the log manager in this properties object. The key is only cached if it is an instance of a String and this properties doesn't contain a copy of the key.- Parameters:
key- the key to search.- Returns:
- the default value for the key.
-
exportCopy
private java.util.Properties exportCopy(java.util.Properties parent)
Creates a public snapshot of this properties object using the given parent properties.- Parameters:
parent- the defaults to use with the snapshot.- Returns:
- the safe snapshot.
-
writeReplace
private java.lang.Object writeReplace() throws java.io.ObjectStreamExceptionIt is assumed that this method will never be called. We return a safe copy for export to avoid locking this properties object or the defaults during write.- Returns:
- the parent properties.
- Throws:
java.io.ObjectStreamException- if there is a problem.
-
-