FileDocCategorySizeDatePackage
LogManagerProperties.javaAPI DocJavaMail 1.4.37590Tue Nov 17 10:38:12 GMT 2009com.sun.mail.util.logging

LogManagerProperties

public final class LogManagerProperties extends Properties
An 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 local properties and the parent properties are searched. If no value is found, then, the LogManager is searched with prefix value and finally, just the key itself is searched in the LogManager.

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).

author
Jason Mehrens
since
JavaMail 1.4.3

Fields Summary
private static final long
serialVersionUID
static final LogManager
manager
Caches the LogManager so we only read the config once.
private final String
prefix
Constructors Summary
LogManagerProperties(Properties parent, String prefix)
Creates a log manager properties object.

param
parent the parent properties.
param
prefix the namespace prefix.
throws
NullPointerException if prefix is null.

        super(parent);
        if(prefix == null) {
            throw new NullPointerException();
        }
        this.prefix = prefix;
    
Methods Summary
public booleanequals(java.lang.Object o)
It is assumed that this method will never be called. The prefix value is not used for the equals method.

param
o any object or null.
return
true if equal, otherwise false.

        if (o == null) {
            return false;
        }
        if (o == this) {
            return true;
        }
        if (o instanceof Properties == false) {
            return false;
        }
        assert false;
        return super.equals(o);
    
static final java.lang.ClassfindClass(java.lang.String name)
This code is modifed from the LogManager, which explictly states searching the system class loader first, then the context class loader. There is resistance (compatiblity) to change this behavior to simply searching the context class loader.

param
name full class name
return
the class.
throws
ClassNotFoundException if not found.


                                                          
           
        ClassLoader[] loaders = getClassLoaders();
        Class clazz;
        if (loaders[0] != null) {
            try {
                clazz = Class.forName(name, false, loaders[0]);
            } catch (ClassNotFoundException tryContext) {
                clazz = tryLoad(name, loaders[1]);
            }
        } else {
            clazz = tryLoad(name, loaders[1]);
        }
        return clazz;
    
private static java.lang.ClassLoader[]getClassLoaders()

        return (ClassLoader[]) AccessController.doPrivileged(new PrivilegedAction() {

            public Object run() {
                final ClassLoader[] loaders = new ClassLoader[2];
                try {
                    loaders[0] = ClassLoader.getSystemClassLoader();
                } catch (SecurityException ignore) {
                    loaders[0] = null;
                }

                try {
                    loaders[1] = Thread.currentThread().getContextClassLoader();
                } catch (SecurityException ignore) {
                    loaders[1] = null;
                }
                return loaders;
            }
        });
    
public java.lang.StringgetProperty(java.lang.String key)
Performs the super action, then searches the log manager by the prefix property, and then by the key itself.

param
key a non null key.
return
the value for that key.

        String value = super.getProperty(key);
        if (value == null && key.length() > 0) {
            value = manager.getProperty(prefix + '." + key);
            if (value == null) {
                value = manager.getProperty(key);
            }
        }
        return value;
    
public inthashCode()
It is assumed that this method will never be called. See equals.

return
the hash code.

        assert false;
        return super.hashCode();
    
public java.util.EnumerationpropertyNames()
It is assumed that this method will never be called. No way to get the property names from LogManager.

return
the property names

        assert false;
        return super.propertyNames();
    
private static java.lang.ClasstryLoad(java.lang.String name, java.lang.ClassLoader l)

        if (l != null) {
            return Class.forName(name, false, l);
        } else {
            return Class.forName(name);
        }
    
private synchronized java.lang.ObjectwriteReplace()
It is assumed that this method will never be called.

return
a new properties object copied from this one.
throws
ObjectStreamException if there is a problem.

        assert false;
        final Properties out = new Properties(defaults);
        if (!super.isEmpty()) { //should always be empty.
            out.putAll(this);
        }
        return out;