1
0

Remove trailing spaces.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/logging/trunk@1432580 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Thomas Neidhart
2013-01-13 10:41:05 +00:00
parent 45182accb1
commit 81e90d14a3
15 changed files with 480 additions and 549 deletions

View File

@@ -5,12 +5,12 @@
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */

View File

@@ -5,15 +5,15 @@
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.commons.logging; package org.apache.commons.logging;

View File

@@ -5,15 +5,15 @@
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.commons.logging; package org.apache.commons.logging;

View File

@@ -5,15 +5,15 @@
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.commons.logging; package org.apache.commons.logging;
@@ -52,7 +52,7 @@ public abstract class LogFactory {
// //
// It is important to keep code invoked via an AccessController to small // It is important to keep code invoked via an AccessController to small
// auditable blocks. Such code must carefully evaluate all user input // auditable blocks. Such code must carefully evaluate all user input
// (parameters, system properties, config file contents, etc). As an // (parameters, system properties, config file contents, etc). As an
// example, a Log implementation should not write to its logfile // example, a Log implementation should not write to its logfile
// with an AccessController anywhere in the call stack, otherwise an // with an AccessController anywhere in the call stack, otherwise an
// insecure application could configure the log implementation to write // insecure application could configure the log implementation to write
@@ -64,7 +64,7 @@ public abstract class LogFactory {
// to invoke that method and obtain data that it is not permitted to have. // to invoke that method and obtain data that it is not permitted to have.
// //
// Invoking user-supplied code with an AccessController set is not a major // Invoking user-supplied code with an AccessController set is not a major
// issue (eg invoking the constructor of the class specified by // issue (eg invoking the constructor of the class specified by
// HASHTABLE_IMPLEMENTATION_PROPERTY). That class will be in a different // HASHTABLE_IMPLEMENTATION_PROPERTY). That class will be in a different
// trust domain, and therefore must have permissions to do whatever it // trust domain, and therefore must have permissions to do whatever it
// is trying to do regardless of the permissions granted to JCL. There is // is trying to do regardless of the permissions granted to JCL. There is
@@ -76,21 +76,21 @@ public abstract class LogFactory {
// ----------------------------------------------------- Manifest Constants // ----------------------------------------------------- Manifest Constants
/** /**
* The name (<code>priority</code>) of the key in the config file used to * The name (<code>priority</code>) of the key in the config file used to
* specify the priority of that particular config file. The associated value * specify the priority of that particular config file. The associated value
* is a floating-point number; higher values take priority over lower values. * is a floating-point number; higher values take priority over lower values.
*/ */
public static final String PRIORITY_KEY = "priority"; public static final String PRIORITY_KEY = "priority";
/** /**
* The name (<code>use_tccl</code>) of the key in the config file used * The name (<code>use_tccl</code>) of the key in the config file used
* to specify whether logging classes should be loaded via the thread * to specify whether logging classes should be loaded via the thread
* context class loader (TCCL), or not. By default, the TCCL is used. * context class loader (TCCL), or not. By default, the TCCL is used.
*/ */
public static final String TCCL_KEY = "use_tccl"; public static final String TCCL_KEY = "use_tccl";
/** /**
* The name (<code>org.apache.commons.logging.LogFactory</code>) of the property * The name (<code>org.apache.commons.logging.LogFactory</code>) of the property
* used to identify the LogFactory implementation * used to identify the LogFactory implementation
* class name. This can be used as a system property, or as an entry in a * class name. This can be used as a system property, or as an entry in a
* configuration properties file. * configuration properties file.
@@ -116,10 +116,10 @@ public abstract class LogFactory {
"META-INF/services/org.apache.commons.logging.LogFactory"; "META-INF/services/org.apache.commons.logging.LogFactory";
/** /**
* The name (<code>org.apache.commons.logging.diagnostics.dest</code>) * The name (<code>org.apache.commons.logging.diagnostics.dest</code>)
* of the property used to enable internal commons-logging * of the property used to enable internal commons-logging
* diagnostic output, in order to get information on what logging * diagnostic output, in order to get information on what logging
* implementations are being discovered, what classloaders they * implementations are being discovered, what classloaders they
* are loaded through, etc. * are loaded through, etc.
* <p> * <p>
* If a system property of this name is set then the value is * If a system property of this name is set then the value is
@@ -139,17 +139,17 @@ public abstract class LogFactory {
* interesting events will be written to the specified object. * interesting events will be written to the specified object.
*/ */
private static PrintStream diagnosticsStream = null; private static PrintStream diagnosticsStream = null;
/** /**
* A string that gets prefixed to every message output by the * A string that gets prefixed to every message output by the
* logDiagnostic method, so that users can clearly see which * logDiagnostic method, so that users can clearly see which
* LogFactory class is generating the output. * LogFactory class is generating the output.
*/ */
private static final String diagnosticPrefix; private static final String diagnosticPrefix;
/** /**
* <p>Setting this system property * <p>Setting this system property
* (<code>org.apache.commons.logging.LogFactory.HashtableImpl</code>) * (<code>org.apache.commons.logging.LogFactory.HashtableImpl</code>)
* value allows the <code>Hashtable</code> used to store * value allows the <code>Hashtable</code> used to store
* classloaders to be substituted by an alternative implementation. * classloaders to be substituted by an alternative implementation.
* </p> * </p>
@@ -162,13 +162,13 @@ public abstract class LogFactory {
* </p> * </p>
* <p> * <p>
* <strong>Usage:</strong> Set this property when Java is invoked * <strong>Usage:</strong> Set this property when Java is invoked
* and <code>LogFactory</code> will attempt to load a new instance * and <code>LogFactory</code> will attempt to load a new instance
* of the given implementation class. * of the given implementation class.
* For example, running the following ant scriplet: * For example, running the following ant scriplet:
* <code><pre> * <code><pre>
* &lt;java classname="${test.runner}" fork="yes" failonerror="${test.failonerror}"&gt; * &lt;java classname="${test.runner}" fork="yes" failonerror="${test.failonerror}"&gt;
* ... * ...
* &lt;sysproperty * &lt;sysproperty
* key="org.apache.commons.logging.LogFactory.HashtableImpl" * key="org.apache.commons.logging.LogFactory.HashtableImpl"
* value="org.apache.commons.logging.AltHashtable"/&gt; * value="org.apache.commons.logging.AltHashtable"/&gt;
* &lt;/java&gt; * &lt;/java&gt;
@@ -187,7 +187,7 @@ public abstract class LogFactory {
"org.apache.commons.logging.LogFactory.HashtableImpl"; "org.apache.commons.logging.LogFactory.HashtableImpl";
/** Name used to load the weak hashtable implementation by names */ /** Name used to load the weak hashtable implementation by names */
private static final String WEAK_HASHTABLE_CLASSNAME = private static final String WEAK_HASHTABLE_CLASSNAME =
"org.apache.commons.logging.impl.WeakHashtable"; "org.apache.commons.logging.impl.WeakHashtable";
/** /**
@@ -198,7 +198,7 @@ public abstract class LogFactory {
* cache it here. * cache it here.
*/ */
private static final ClassLoader thisClassLoader; private static final ClassLoader thisClassLoader;
// ----------------------------------------------------------- Constructors // ----------------------------------------------------------- Constructors
/** /**
@@ -206,7 +206,7 @@ public abstract class LogFactory {
*/ */
protected LogFactory() { protected LogFactory() {
} }
// --------------------------------------------------------- Public Methods // --------------------------------------------------------- Public Methods
/** /**
@@ -291,7 +291,7 @@ public abstract class LogFactory {
* the <code>ClassLoader</code> with which it was created. * the <code>ClassLoader</code> with which it was created.
*/ */
protected static Hashtable factories = null; protected static Hashtable factories = null;
/** /**
* Previously constructed <code>LogFactory</code> instance as in the * Previously constructed <code>LogFactory</code> instance as in the
* <code>factories</code> map, but for the case where * <code>factories</code> map, but for the case where
@@ -320,7 +320,7 @@ public abstract class LogFactory {
* arbitrary Hashtable implementation name. * arbitrary Hashtable implementation name.
* <p> * <p>
* Note that the correct way to ensure no memory leaks occur is to ensure * Note that the correct way to ensure no memory leaks occur is to ensure
* that LogFactory.release(contextClassLoader) is called whenever a * that LogFactory.release(contextClassLoader) is called whenever a
* webapp is undeployed. * webapp is undeployed.
*/ */
private static final Hashtable createFactoryStore() { private static final Hashtable createFactoryStore() {
@@ -340,7 +340,6 @@ public abstract class LogFactory {
try { try {
Class implementationClass = Class.forName(storeImplementationClass); Class implementationClass = Class.forName(storeImplementationClass);
result = (Hashtable) implementationClass.newInstance(); result = (Hashtable) implementationClass.newInstance();
} catch (Throwable t) { } catch (Throwable t) {
// ignore // ignore
if (!WEAK_HASHTABLE_CLASSNAME.equals(storeImplementationClass)) { if (!WEAK_HASHTABLE_CLASSNAME.equals(storeImplementationClass)) {
@@ -365,10 +364,10 @@ public abstract class LogFactory {
/** Utility method to safely trim a string. */ /** Utility method to safely trim a string. */
private static String trim(String src) { private static String trim(String src) {
if (src == null) { if (src == null) {
return null; return null;
} }
return src.trim(); return src.trim();
} }
/** /**
@@ -394,9 +393,9 @@ public abstract class LogFactory {
* properties defined in this file will be set as configuration attributes * properties defined in this file will be set as configuration attributes
* on the corresponding <code>LogFactory</code> instance. * on the corresponding <code>LogFactory</code> instance.
* <p> * <p>
* <em>NOTE</em> - In a multi-threaded environment it is possible * <em>NOTE</em> - In a multi-threaded environment it is possible
* that two different instances will be returned for the same * that two different instances will be returned for the same
* classloader environment. * classloader environment.
* *
* @throws LogConfigurationException if the implementation class is not * @throws LogConfigurationException if the implementation class is not
* available or cannot be instantiated. * available or cannot be instantiated.
@@ -422,8 +421,8 @@ public abstract class LogFactory {
if (isDiagnosticsEnabled()) { if (isDiagnosticsEnabled()) {
logDiagnostic( logDiagnostic(
"[LOOKUP] LogFactory implementation requested for the first time for context classloader " "[LOOKUP] LogFactory implementation requested for the first time for context classloader " +
+ objectId(contextClassLoader)); objectId(contextClassLoader));
logHierarchy("[LOOKUP] ", contextClassLoader); logHierarchy("[LOOKUP] ", contextClassLoader);
} }
@@ -434,7 +433,7 @@ public abstract class LogFactory {
// property may also control which LogFactory concrete subclass is // property may also control which LogFactory concrete subclass is
// used, but only if other discovery mechanisms fail.. // used, but only if other discovery mechanisms fail..
// //
// As the properties file (if it exists) will be used one way or // As the properties file (if it exists) will be used one way or
// another in the end we may as well look for it first. // another in the end we may as well look for it first.
Properties props = getConfigurationFile(contextClassLoader, FACTORY_PROPERTIES); Properties props = getConfigurationFile(contextClassLoader, FACTORY_PROPERTIES);
@@ -455,7 +454,7 @@ public abstract class LogFactory {
// own logging implementations. It also means that it is up to the // own logging implementations. It also means that it is up to the
// implementation whether to load library-specific config files // implementation whether to load library-specific config files
// from the TCCL or not. // from the TCCL or not.
baseClassLoader = thisClassLoader; baseClassLoader = thisClassLoader;
} }
} }
} }
@@ -463,35 +462,28 @@ public abstract class LogFactory {
// Determine which concrete LogFactory subclass to use. // Determine which concrete LogFactory subclass to use.
// First, try a global system property // First, try a global system property
if (isDiagnosticsEnabled()) { if (isDiagnosticsEnabled()) {
logDiagnostic( logDiagnostic("[LOOKUP] Looking for system property [" + FACTORY_PROPERTY +
"[LOOKUP] Looking for system property [" + FACTORY_PROPERTY "] to define the LogFactory subclass to use...");
+ "] to define the LogFactory subclass to use...");
} }
try { try {
String factoryClass = getSystemProperty(FACTORY_PROPERTY, null); String factoryClass = getSystemProperty(FACTORY_PROPERTY, null);
if (factoryClass != null) { if (factoryClass != null) {
if (isDiagnosticsEnabled()) { if (isDiagnosticsEnabled()) {
logDiagnostic( logDiagnostic("[LOOKUP] Creating an instance of LogFactory class '" + factoryClass +
"[LOOKUP] Creating an instance of LogFactory class '" + factoryClass "' as specified by system property " + FACTORY_PROPERTY);
+ "' as specified by system property " + FACTORY_PROPERTY);
} }
factory = newFactory(factoryClass, baseClassLoader, contextClassLoader); factory = newFactory(factoryClass, baseClassLoader, contextClassLoader);
} else { } else {
if (isDiagnosticsEnabled()) { if (isDiagnosticsEnabled()) {
logDiagnostic( logDiagnostic("[LOOKUP] No system property [" + FACTORY_PROPERTY + "] defined.");
"[LOOKUP] No system property [" + FACTORY_PROPERTY
+ "] defined.");
} }
} }
} catch (SecurityException e) { } catch (SecurityException e) {
if (isDiagnosticsEnabled()) { if (isDiagnosticsEnabled()) {
logDiagnostic( logDiagnostic("[LOOKUP] A security exception occurred while trying to create an" +
"[LOOKUP] A security exception occurred while trying to create an" " instance of the custom factory class" + ": [" + trim(e.getMessage()) +
+ " instance of the custom factory class" "]. Trying alternative implementations...");
+ ": [" + trim(e.getMessage())
+ "]. Trying alternative implementations...");
} }
// ignore // ignore
} catch(RuntimeException e) { } catch(RuntimeException e) {
@@ -501,11 +493,9 @@ public abstract class LogFactory {
// One possible exception that can occur here is a ClassCastException when // One possible exception that can occur here is a ClassCastException when
// the specified class wasn't castable to this LogFactory type. // the specified class wasn't castable to this LogFactory type.
if (isDiagnosticsEnabled()) { if (isDiagnosticsEnabled()) {
logDiagnostic( logDiagnostic("[LOOKUP] An exception occurred while trying to create an" +
"[LOOKUP] An exception occurred while trying to create an" " instance of the custom factory class" + ": [" + trim(e.getMessage()) +
+ " instance of the custom factory class" "] as specified by a system property.");
+ ": [" + trim(e.getMessage())
+ "] as specified by a system property.");
} }
throw e; throw e;
} }
@@ -513,14 +503,13 @@ public abstract class LogFactory {
// Second, try to find a service by using the JDK1.3 class // Second, try to find a service by using the JDK1.3 class
// discovery mechanism, which involves putting a file with the name // discovery mechanism, which involves putting a file with the name
// of an interface class in the META-INF/services directory, where the // of an interface class in the META-INF/services directory, where the
// contents of the file is a single line specifying a concrete class // contents of the file is a single line specifying a concrete class
// that implements the desired interface. // that implements the desired interface.
if (factory == null) { if (factory == null) {
if (isDiagnosticsEnabled()) { if (isDiagnosticsEnabled()) {
logDiagnostic( logDiagnostic("[LOOKUP] Looking for a resource file of name [" + SERVICE_ID +
"[LOOKUP] Looking for a resource file of name [" + SERVICE_ID "] to define the LogFactory subclass to use...");
+ "] to define the LogFactory subclass to use...");
} }
try { try {
InputStream is = getResourceAsStream(contextClassLoader, InputStream is = getResourceAsStream(contextClassLoader,
@@ -542,20 +531,16 @@ public abstract class LogFactory {
if (factoryClassName != null && if (factoryClassName != null &&
! "".equals(factoryClassName)) { ! "".equals(factoryClassName)) {
if (isDiagnosticsEnabled()) { if (isDiagnosticsEnabled()) {
logDiagnostic( logDiagnostic("[LOOKUP] Creating an instance of LogFactory class " + factoryClassName +
"[LOOKUP] Creating an instance of LogFactory class " + factoryClassName " as specified by file '" + SERVICE_ID +
+ " as specified by file '" + SERVICE_ID "' which was present in the path of the context classloader.");
+ "' which was present in the path of the context"
+ " classloader.");
} }
factory = newFactory(factoryClassName, baseClassLoader, contextClassLoader ); factory = newFactory(factoryClassName, baseClassLoader, contextClassLoader );
} }
} else { } else {
// is == null // is == null
if (isDiagnosticsEnabled()) { if (isDiagnosticsEnabled()) {
logDiagnostic( logDiagnostic("[LOOKUP] No resource file with name '" + SERVICE_ID + "' found.");
"[LOOKUP] No resource file with name '" + SERVICE_ID
+ "' found.");
} }
} }
} catch( Exception ex ) { } catch( Exception ex ) {
@@ -760,7 +745,7 @@ public abstract class LogFactory {
* Even when using an AccessController, however, this method can still * Even when using an AccessController, however, this method can still
* throw SecurityException. Commons-logging basically relies on the * throw SecurityException. Commons-logging basically relies on the
* ability to access classloaders, ie a policy that forbids all * ability to access classloaders, ie a policy that forbids all
* classloader access will also prevent commons-logging from working: * classloader access will also prevent commons-logging from working:
* currently this method will throw an exception preventing the entire app * currently this method will throw an exception preventing the entire app
* from starting up. Maybe it would be good to detect this situation and * from starting up. Maybe it would be good to detect this situation and
* just disable all commons-logging? Not high priority though - as stated * just disable all commons-logging? Not high priority though - as stated
@@ -770,7 +755,7 @@ public abstract class LogFactory {
* technically be a security flaw anyway; untrusted code that has access * technically be a security flaw anyway; untrusted code that has access
* to a trusted JCL library could use it to fetch the classloader for * to a trusted JCL library could use it to fetch the classloader for
* a class even when forbidden to do so directly. * a class even when forbidden to do so directly.
* *
* @since 1.1 * @since 1.1
*/ */
protected static ClassLoader getClassLoader(Class clazz) { protected static ClassLoader getClassLoader(Class clazz) {
@@ -797,13 +782,13 @@ public abstract class LogFactory {
* an AccessController. User code wishing to obtain the context classloader * an AccessController. User code wishing to obtain the context classloader
* must invoke this method via AccessController.doPrivileged if it needs * must invoke this method via AccessController.doPrivileged if it needs
* support for that. * support for that.
* *
* @return the context classloader associated with the current thread, * @return the context classloader associated with the current thread,
* or null if security doesn't allow it. * or null if security doesn't allow it.
* *
* @throws LogConfigurationException if there was some weird error while * @throws LogConfigurationException if there was some weird error while
* attempting to get the context classloader. * attempting to get the context classloader.
* *
* @throws SecurityException if the current java security policy doesn't * @throws SecurityException if the current java security policy doesn't
* allow this class to access the context classloader. * allow this class to access the context classloader.
*/ */
@@ -821,13 +806,13 @@ public abstract class LogFactory {
* doesn't have such privileges. Without using an AccessController, the * doesn't have such privileges. Without using an AccessController, the
* the entire call stack must have the privilege before the call is * the entire call stack must have the privilege before the call is
* allowed. * allowed.
* *
* @return the context classloader associated with the current thread, * @return the context classloader associated with the current thread,
* or null if security doesn't allow it. * or null if security doesn't allow it.
* *
* @throws LogConfigurationException if there was some weird error while * @throws LogConfigurationException if there was some weird error while
* attempting to get the context classloader. * attempting to get the context classloader.
* *
* @throws SecurityException if the current java security policy doesn't * @throws SecurityException if the current java security policy doesn't
* allow this class to access the context classloader. * allow this class to access the context classloader.
*/ */
@@ -842,7 +827,7 @@ public abstract class LogFactory {
/** /**
* Return the thread context class loader if available; otherwise return * Return the thread context class loader if available; otherwise return
* null. * null.
* <p> * <p>
* Most/all code should call getContextClassLoaderInternal rather than * Most/all code should call getContextClassLoaderInternal rather than
* calling this method directly. * calling this method directly.
@@ -853,13 +838,13 @@ public abstract class LogFactory {
* Note that no internal logging is done within this method because * Note that no internal logging is done within this method because
* this method is called every time LogFactory.getLogger() is called, * this method is called every time LogFactory.getLogger() is called,
* and we don't want too much output generated here. * and we don't want too much output generated here.
* *
* @exception LogConfigurationException if a suitable class loader * @exception LogConfigurationException if a suitable class loader
* cannot be identified. * cannot be identified.
* *
* @exception SecurityException if the java security policy forbids * @exception SecurityException if the java security policy forbids
* access to the context classloader from one of the classes in the * access to the context classloader from one of the classes in the
* current call stack. * current call stack.
* @since 1.1 * @since 1.1
*/ */
protected static ClassLoader directGetContextClassLoader() protected static ClassLoader directGetContextClassLoader()
@@ -869,13 +854,11 @@ public abstract class LogFactory {
try { try {
// Are we running on a JDK 1.2 or later system? // Are we running on a JDK 1.2 or later system?
Method method = Thread.class.getMethod("getContextClassLoader", Method method = Thread.class.getMethod("getContextClassLoader", (Class[]) null);
(Class[]) null);
// Get the thread context class loader (if there is one) // Get the thread context class loader (if there is one)
try { try {
classLoader = (ClassLoader)method.invoke(Thread.currentThread(), classLoader = (ClassLoader)method.invoke(Thread.currentThread(), (Object[]) null);
(Object[]) null);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
throw new LogConfigurationException throw new LogConfigurationException
("Unexpected IllegalAccessException", e); ("Unexpected IllegalAccessException", e);
@@ -920,7 +903,6 @@ public abstract class LogFactory {
// + " classloader is the same as the class that loaded" // + " classloader is the same as the class that loaded"
// + " the concrete LogFactory class."); // + " the concrete LogFactory class.");
// } // }
} }
// Return the selected class loader // Return the selected class loader
@@ -936,7 +918,7 @@ public abstract class LogFactory {
* a distinct context classloader set. This parameter may be null * a distinct context classloader set. This parameter may be null
* in JDK1.1, and in embedded systems where jcl-using code is * in JDK1.1, and in embedded systems where jcl-using code is
* placed in the bootclasspath. * placed in the bootclasspath.
* *
* @return the factory associated with the specified classloader if * @return the factory associated with the specified classloader if
* one has previously been created, or null if this is the first time * one has previously been created, or null if this is the first time
* we have seen this particular classloader. * we have seen this particular classloader.
@@ -985,7 +967,7 @@ public abstract class LogFactory {
* (abstract) LogFactory. * (abstract) LogFactory.
* <p> * <p>
* <h2>ClassLoader conflicts</h2> * <h2>ClassLoader conflicts</h2>
* Note that there can be problems if the specified ClassLoader is not the * Note that there can be problems if the specified ClassLoader is not the
* same as the classloader that loaded this class, ie when loading a * same as the classloader that loaded this class, ie when loading a
* concrete LogFactory subclass via a context classloader. * concrete LogFactory subclass via a context classloader.
* <p> * <p>
@@ -1040,16 +1022,13 @@ public abstract class LogFactory {
if (result instanceof LogConfigurationException) { if (result instanceof LogConfigurationException) {
LogConfigurationException ex = (LogConfigurationException) result; LogConfigurationException ex = (LogConfigurationException) result;
if (isDiagnosticsEnabled()) { if (isDiagnosticsEnabled()) {
logDiagnostic( logDiagnostic("An error occurred while loading the factory class:" + ex.getMessage());
"An error occurred while loading the factory class:"
+ ex.getMessage());
} }
throw ex; throw ex;
} }
if (isDiagnosticsEnabled()) { if (isDiagnosticsEnabled()) {
logDiagnostic( logDiagnostic("Created object " + objectId(result) + " to manage classloader " +
"Created object " + objectId(result) objectId(contextClassLoader));
+ " to manage classloader " + objectId(contextClassLoader));
} }
return (LogFactory)result; return (LogFactory)result;
} }
@@ -1076,14 +1055,14 @@ public abstract class LogFactory {
/** /**
* Implements the operations described in the javadoc for newFactory. * Implements the operations described in the javadoc for newFactory.
* *
* @param factoryClass * @param factoryClass
* *
* @param classLoader used to load the specified factory class. This is * @param classLoader used to load the specified factory class. This is
* expected to be either the TCCL or the classloader which loaded this * expected to be either the TCCL or the classloader which loaded this
* class. Note that the classloader which loaded this class might be * class. Note that the classloader which loaded this class might be
* "null" (ie the bootloader) for embedded systems. * "null" (ie the bootloader) for embedded systems.
* *
* @return either a LogFactory object or a LogConfigurationException object. * @return either a LogFactory object or a LogConfigurationException object.
* @since 1.1 * @since 1.1
*/ */
@@ -1108,14 +1087,14 @@ public abstract class LogFactory {
} else { } else {
// //
// This indicates a problem with the ClassLoader tree. // This indicates a problem with the ClassLoader tree.
// An incompatible ClassLoader was used to load the // An incompatible ClassLoader was used to load the
// implementation. // implementation.
// As the same classes // As the same classes
// must be available in multiple class loaders, // must be available in multiple class loaders,
// it is very likely that multiple JCL jars are present. // it is very likely that multiple JCL jars are present.
// The most likely fix for this // The most likely fix for this
// problem is to remove the extra JCL jars from the // problem is to remove the extra JCL jars from the
// ClassLoader hierarchy. // ClassLoader hierarchy.
// //
if (isDiagnosticsEnabled()) { if (isDiagnosticsEnabled()) {
logDiagnostic( logDiagnostic(
@@ -1126,7 +1105,7 @@ public abstract class LogFactory {
logHierarchy("[BAD CL TREE] ", classLoader); logHierarchy("[BAD CL TREE] ", classLoader);
} }
} }
return (LogFactory) logFactoryClass.newInstance(); return (LogFactory) logFactoryClass.newInstance();
} catch (ClassNotFoundException ex) { } catch (ClassNotFoundException ex) {
@@ -1161,13 +1140,13 @@ public abstract class LogFactory {
// appropriate exception here. // appropriate exception here.
final boolean implementsLogFactory = implementsLogFactory(logFactoryClass); final boolean implementsLogFactory = implementsLogFactory(logFactoryClass);
// //
// Construct a good message: users may not actual expect that a custom implementation // Construct a good message: users may not actual expect that a custom implementation
// has been specified. Several well known containers use this mechanism to adapt JCL // has been specified. Several well known containers use this mechanism to adapt JCL
// to their native logging system. // to their native logging system.
// //
String msg = String msg =
"The application has specified that a custom LogFactory implementation should be used but " + "The application has specified that a custom LogFactory implementation should be used but " +
"Class '" + factoryClass + "' cannot be converted to '" "Class '" + factoryClass + "' cannot be converted to '"
+ LogFactory.class.getName() + "'. "; + LogFactory.class.getName() + "'. ";
@@ -1182,14 +1161,14 @@ public abstract class LogFactory {
msg = msg + "Please check the custom implementation. "; msg = msg + "Please check the custom implementation. ";
} }
msg = msg + "Help can be found @http://commons.apache.org/logging/troubleshooting.html."; msg = msg + "Help can be found @http://commons.apache.org/logging/troubleshooting.html.";
if (isDiagnosticsEnabled()) { if (isDiagnosticsEnabled()) {
logDiagnostic(msg); logDiagnostic(msg);
} }
throw new ClassCastException(msg); throw new ClassCastException(msg);
} }
// Ignore exception, continue. Presumably the classloader was the // Ignore exception, continue. Presumably the classloader was the
// TCCL; the code below will try to load the class via thisClassLoader. // TCCL; the code below will try to load the class via thisClassLoader.
// This will handle the case where the original calling class is in // This will handle the case where the original calling class is in
@@ -1212,7 +1191,7 @@ public abstract class LogFactory {
* to LogFactory.class.getClassLoader().load(name), ie we ignore * to LogFactory.class.getClassLoader().load(name), ie we ignore
* the classloader parameter the caller passed, and fall back * the classloader parameter the caller passed, and fall back
* to trying the classloader associated with this class. See the * to trying the classloader associated with this class. See the
* javadoc for the newFactory method for more info on the * javadoc for the newFactory method for more info on the
* consequences of this. * consequences of this.
* *
* Notes: * Notes:
@@ -1223,7 +1202,7 @@ public abstract class LogFactory {
// to be generated/caught & recast properly. // to be generated/caught & recast properly.
if (isDiagnosticsEnabled()) { if (isDiagnosticsEnabled()) {
logDiagnostic( logDiagnostic(
"Unable to load factory class via classloader " "Unable to load factory class via classloader "
+ objectId(classLoader) + objectId(classLoader)
+ " - trying the classloader associated with this LogFactory."); + " - trying the classloader associated with this LogFactory.");
} }
@@ -1234,9 +1213,7 @@ public abstract class LogFactory {
if (isDiagnosticsEnabled()) { if (isDiagnosticsEnabled()) {
logDiagnostic("Unable to create LogFactory instance."); logDiagnostic("Unable to create LogFactory instance.");
} }
if (logFactoryClass != null if (logFactoryClass != null && !LogFactory.class.isAssignableFrom(logFactoryClass)) {
&& !LogFactory.class.isAssignableFrom(logFactoryClass)) {
return new LogConfigurationException( return new LogConfigurationException(
"The chosen LogFactory implementation does not extend LogFactory." "The chosen LogFactory implementation does not extend LogFactory."
+ " Please check your configuration.", + " Please check your configuration.",
@@ -1315,7 +1292,7 @@ public abstract class LogFactory {
/** /**
* Applets may run in an environment where accessing resources of a loader is * Applets may run in an environment where accessing resources of a loader is
* a secure operation, but where the commons-logging library has explicitly * a secure operation, but where the commons-logging library has explicitly
* been granted permission for that operation. In this case, we need to * been granted permission for that operation. In this case, we need to
* run the operation using an AccessController. * run the operation using an AccessController.
*/ */
private static InputStream getResourceAsStream(final ClassLoader loader, final String name) { private static InputStream getResourceAsStream(final ClassLoader loader, final String name) {
@@ -1345,7 +1322,7 @@ public abstract class LogFactory {
* If resources could not be listed for some reason, null is returned. * If resources could not be listed for some reason, null is returned.
*/ */
private static Enumeration getResources(final ClassLoader loader, final String name) { private static Enumeration getResources(final ClassLoader loader, final String name) {
PrivilegedAction action = PrivilegedAction action =
new PrivilegedAction() { new PrivilegedAction() {
public Object run() { public Object run() {
try { try {
@@ -1356,9 +1333,8 @@ public abstract class LogFactory {
} }
} catch(IOException e) { } catch(IOException e) {
if (isDiagnosticsEnabled()) { if (isDiagnosticsEnabled()) {
logDiagnostic( logDiagnostic("Exception while trying to find configuration file " +
"Exception while trying to find configuration file " name + ":" + e.getMessage());
+ name + ":" + e.getMessage());
} }
return null; return null;
} catch(NoSuchMethodError e) { } catch(NoSuchMethodError e) {
@@ -1382,7 +1358,7 @@ public abstract class LogFactory {
* {@code Null} is returned if the URL cannot be opened. * {@code Null} is returned if the URL cannot be opened.
*/ */
private static Properties getProperties(final URL url) { private static Properties getProperties(final URL url) {
PrivilegedAction action = PrivilegedAction action =
new PrivilegedAction() { new PrivilegedAction() {
public Object run() { public Object run() {
InputStream stream = null; InputStream stream = null;
@@ -1431,7 +1407,7 @@ public abstract class LogFactory {
* null is returned. If more than one is found, then the file with the greatest * null is returned. If more than one is found, then the file with the greatest
* value for its PRIORITY property is returned. If multiple files have the * value for its PRIORITY property is returned. If multiple files have the
* same PRIORITY value then the first in the classpath is returned. * same PRIORITY value then the first in the classpath is returned.
* <p> * <p>
* This differs from the 1.0.x releases; those always use the first one found. * This differs from the 1.0.x releases; those always use the first one found.
* However as the priority is a new field, this change is backwards compatible. * However as the priority is a new field, this change is backwards compatible.
* <p> * <p>
@@ -1440,7 +1416,7 @@ public abstract class LogFactory {
* file in a shared classpath location with a priority > 0; this overrides any * file in a shared classpath location with a priority > 0; this overrides any
* commons-logging.properties files without priorities which are in the * commons-logging.properties files without priorities which are in the
* webapps. Webapps can also use explicit priorities to override a configuration * webapps. Webapps can also use explicit priorities to override a configuration
* file in the shared classpath if needed. * file in the shared classpath if needed.
*/ */
private static final Properties getConfigurationFile(ClassLoader classLoader, String fileName) { private static final Properties getConfigurationFile(ClassLoader classLoader, String fileName) {
Properties props = null; Properties props = null;
@@ -1452,14 +1428,14 @@ public abstract class LogFactory {
if (urls == null) { if (urls == null) {
return null; return null;
} }
while (urls.hasMoreElements()) { while (urls.hasMoreElements()) {
URL url = (URL) urls.nextElement(); URL url = (URL) urls.nextElement();
Properties newProps = getProperties(url); Properties newProps = getProperties(url);
if (newProps != null) { if (newProps != null) {
if (props == null) { if (props == null) {
propsUrl = url; propsUrl = url;
props = newProps; props = newProps;
String priorityStr = props.getProperty(PRIORITY_KEY); String priorityStr = props.getProperty(PRIORITY_KEY);
priority = 0.0; priority = 0.0;
@@ -1470,7 +1446,7 @@ public abstract class LogFactory {
if (isDiagnosticsEnabled()) { if (isDiagnosticsEnabled()) {
logDiagnostic( logDiagnostic(
"[LOOKUP] Properties file found at '" + url + "'" "[LOOKUP] Properties file found at '" + url + "'"
+ " with priority " + priority); + " with priority " + priority);
} }
} else { } else {
String newPriorityStr = newProps.getProperty(PRIORITY_KEY); String newPriorityStr = newProps.getProperty(PRIORITY_KEY);
@@ -1483,12 +1459,12 @@ public abstract class LogFactory {
if (isDiagnosticsEnabled()) { if (isDiagnosticsEnabled()) {
logDiagnostic( logDiagnostic(
"[LOOKUP] Properties file at '" + url + "'" "[LOOKUP] Properties file at '" + url + "'"
+ " with priority " + newPriority + " with priority " + newPriority
+ " overrides file at '" + propsUrl + "'" + " overrides file at '" + propsUrl + "'"
+ " with priority " + priority); + " with priority " + priority);
} }
propsUrl = url; propsUrl = url;
props = newProps; props = newProps;
priority = newPriority; priority = newPriority;
} else { } else {
@@ -1512,13 +1488,9 @@ public abstract class LogFactory {
if (isDiagnosticsEnabled()) { if (isDiagnosticsEnabled()) {
if (props == null) { if (props == null) {
logDiagnostic( logDiagnostic("[LOOKUP] No properties file of name '" + fileName + "' found.");
"[LOOKUP] No properties file of name '" + fileName
+ "' found.");
} else { } else {
logDiagnostic( logDiagnostic("[LOOKUP] Properties file of name '" + fileName + "' found at '" + propsUrl + '"');
"[LOOKUP] Properties file of name '" + fileName
+ "' found at '" + propsUrl + '"');
} }
} }
@@ -1526,7 +1498,7 @@ public abstract class LogFactory {
} }
/** /**
* Read the specified system property, using an AccessController so that * Read the specified system property, using an AccessController so that
* the property can be read if JCL has been granted the appropriate * the property can be read if JCL has been granted the appropriate
* security rights even if the calling code has not. * security rights even if the calling code has not.
* <p> * <p>
@@ -1548,7 +1520,7 @@ public abstract class LogFactory {
* Determines whether the user wants internal diagnostic output. If so, * Determines whether the user wants internal diagnostic output. If so,
* returns an appropriate writer object. Users can enable diagnostic * returns an appropriate writer object. Users can enable diagnostic
* output by setting the system property named {@link #DIAGNOSTICS_DEST_PROPERTY} to * output by setting the system property named {@link #DIAGNOSTICS_DEST_PROPERTY} to
* a filename, or the special values STDOUT or STDERR. * a filename, or the special values STDOUT or STDERR.
*/ */
private static PrintStream initDiagnostics() { private static PrintStream initDiagnostics() {
String dest; String dest;
@@ -1584,7 +1556,7 @@ public abstract class LogFactory {
* <p> * <p>
* By the way, sorry for the incorrect grammar, but calling this method * By the way, sorry for the incorrect grammar, but calling this method
* areDiagnosticsEnabled just isn't java beans style. * areDiagnosticsEnabled just isn't java beans style.
* *
* @return true if calls to logDiagnostic will have any effect. * @return true if calls to logDiagnostic will have any effect.
* @since 1.1 * @since 1.1
*/ */
@@ -1607,7 +1579,7 @@ public abstract class LogFactory {
* Note that it is safe to call this method before initDiagnostics * Note that it is safe to call this method before initDiagnostics
* is called; any output will just be ignored (as isDiagnosticsEnabled * is called; any output will just be ignored (as isDiagnosticsEnabled
* will return false). * will return false).
* *
* @param msg is the diagnostic message to be output. * @param msg is the diagnostic message to be output.
*/ */
private static final void logDiagnostic(String msg) { private static final void logDiagnostic(String msg) {
@@ -1620,7 +1592,7 @@ public abstract class LogFactory {
/** /**
* Write the specified message to the internal logging destination. * Write the specified message to the internal logging destination.
* *
* @param msg is the diagnostic message to be output. * @param msg is the diagnostic message to be output.
* @since 1.1 * @since 1.1
*/ */
@@ -1639,12 +1611,12 @@ public abstract class LogFactory {
* classloader, then you may get the following output: * classloader, then you may get the following output:
* <pre> * <pre>
* Class com.acme.Foo was loaded via classloader 11111 * Class com.acme.Foo was loaded via classloader 11111
* ClassLoader tree: 11111 -> 22222 (SYSTEM) -> 33333 -> BOOT * ClassLoader tree: 11111 -> 22222 (SYSTEM) -> 33333 -> BOOT
* </pre> * </pre>
* <p> * <p>
* This method returns immediately if isDiagnosticsEnabled() * This method returns immediately if isDiagnosticsEnabled()
* returns false. * returns false.
* *
* @param clazz is the class whose classloader + tree are to be * @param clazz is the class whose classloader + tree are to be
* output. * output.
*/ */
@@ -1652,20 +1624,20 @@ public abstract class LogFactory {
if (!isDiagnosticsEnabled()) { if (!isDiagnosticsEnabled()) {
return; return;
} }
try { try {
// Deliberately use System.getProperty here instead of getSystemProperty; if // Deliberately use System.getProperty here instead of getSystemProperty; if
// the overall security policy for the calling application forbids access to // the overall security policy for the calling application forbids access to
// these variables then we do not want to output them to the diagnostic stream. // these variables then we do not want to output them to the diagnostic stream.
logDiagnostic("[ENV] Extension directories (java.ext.dir): " + System.getProperty("java.ext.dir")); logDiagnostic("[ENV] Extension directories (java.ext.dir): " + System.getProperty("java.ext.dir"));
logDiagnostic("[ENV] Application classpath (java.class.path): " + System.getProperty("java.class.path")); logDiagnostic("[ENV] Application classpath (java.class.path): " + System.getProperty("java.class.path"));
} catch(SecurityException ex) { } catch(SecurityException ex) {
logDiagnostic("[ENV] Security setting prevent interrogation of system classpaths."); logDiagnostic("[ENV] Security setting prevent interrogation of system classpaths.");
} }
String className = clazz.getName(); String className = clazz.getName();
ClassLoader classLoader; ClassLoader classLoader;
try { try {
classLoader = getClassLoader(clazz); classLoader = getClassLoader(clazz);
} catch(SecurityException ex) { } catch(SecurityException ex) {
@@ -1675,9 +1647,7 @@ public abstract class LogFactory {
return; return;
} }
logDiagnostic( logDiagnostic("[ENV] Class " + className + " was loaded via classloader " + objectId(classLoader));
"[ENV] Class " + className + " was loaded via classloader "
+ objectId(classLoader));
logHierarchy("[ENV] Ancestry of classloader which loaded " + className + " is ", classLoader); logHierarchy("[ENV] Ancestry of classloader which loaded " + className + " is ", classLoader);
} }
@@ -1685,7 +1655,7 @@ public abstract class LogFactory {
* Logs diagnostic messages about the given classloader * Logs diagnostic messages about the given classloader
* and it's hierarchy. The prefix is prepended to the message * and it's hierarchy. The prefix is prepended to the message
* and is intended to make it easier to understand the logs. * and is intended to make it easier to understand the logs.
* @param prefix * @param prefix
* @param classLoader * @param classLoader
*/ */
private static void logHierarchy(String prefix, ClassLoader classLoader) { private static void logHierarchy(String prefix, ClassLoader classLoader) {
@@ -1697,14 +1667,13 @@ public abstract class LogFactory {
final String classLoaderString = classLoader.toString(); final String classLoaderString = classLoader.toString();
logDiagnostic(prefix + objectId(classLoader) + " == '" + classLoaderString + "'"); logDiagnostic(prefix + objectId(classLoader) + " == '" + classLoaderString + "'");
} }
try { try {
systemClassLoader = ClassLoader.getSystemClassLoader(); systemClassLoader = ClassLoader.getSystemClassLoader();
} catch(SecurityException ex) { } catch(SecurityException ex) {
logDiagnostic( logDiagnostic(prefix + "Security forbids determining the system classloader.");
prefix + "Security forbids determining the system classloader.");
return; return;
} }
if (classLoader != null) { if (classLoader != null) {
StringBuffer buf = new StringBuffer(prefix + "ClassLoader tree:"); StringBuffer buf = new StringBuffer(prefix + "ClassLoader tree:");
for(;;) { for(;;) {
@@ -1737,7 +1706,7 @@ public abstract class LogFactory {
* The returned string is of form "classname@hashcode", ie is the same as * The returned string is of form "classname@hashcode", ie is the same as
* the return value of the Object.toString() method, but works even when * the return value of the Object.toString() method, but works even when
* the specified object's class has overidden the toString method. * the specified object's class has overidden the toString method.
* *
* @param o may be null. * @param o may be null.
* @return a string of form classname@hashcode, or "null" if param o is null. * @return a string of form classname@hashcode, or "null" if param o is null.
* @since 1.1 * @since 1.1
@@ -1753,7 +1722,7 @@ public abstract class LogFactory {
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Static initialiser block to perform initialisation at class load time. // Static initialiser block to perform initialisation at class load time.
// //
// We can't do this in the class constructor, as there are many // We can't do this in the class constructor, as there are many
// static methods on this class that can be called before any // static methods on this class that can be called before any
// LogFactory instances are created, and they depend upon this // LogFactory instances are created, and they depend upon this
// stuff having been set up. // stuff having been set up.
@@ -1778,7 +1747,7 @@ public abstract class LogFactory {
// ensure each logged message has a prefix of form // ensure each logged message has a prefix of form
// [LogFactory from classloader OID] // [LogFactory from classloader OID]
// //
// Note that this prefix should be kept consistent with that // Note that this prefix should be kept consistent with that
// in LogFactoryImpl. However here we don't need to output info // in LogFactoryImpl. However here we don't need to output info
// about the actual *instance* of LogFactory, as all methods that // about the actual *instance* of LogFactory, as all methods that
// output diagnostics from this class are static. // output diagnostics from this class are static.

View File

@@ -5,15 +5,15 @@
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.commons.logging; package org.apache.commons.logging;
@@ -201,7 +201,7 @@ public class LogSource {
* class can be found, this method will return a Log4JLogger if the log4j Logger * class can be found, this method will return a Log4JLogger if the log4j Logger
* class is available in the {@link LogSource}'s classpath, or a Jdk14Logger if we * class is available in the {@link LogSource}'s classpath, or a Jdk14Logger if we
* are on a JDK 1.4 or later system, or NoOpLog if neither of the above conditions is true. * are on a JDK 1.4 or later system, or NoOpLog if neither of the above conditions is true.
* *
* @param name the log name (or category) * @param name the log name (or category)
*/ */
static public Log makeNewLogInstance(String name) { static public Log makeNewLogInstance(String name) {

View File

@@ -5,15 +5,15 @@
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.commons.logging.impl; package org.apache.commons.logging.impl;
@@ -26,13 +26,13 @@ import org.apache.commons.logging.Log;
* <p> * <p>
* There are two ways in which this class can be used: * There are two ways in which this class can be used:
* <ul> * <ul>
* <li>the instance can be constructed with an Avalon logger * <li>the instance can be constructed with an Avalon logger
* (by calling {@link #AvalonLogger(Logger)}). In this case, it acts * (by calling {@link #AvalonLogger(Logger)}). In this case, it acts
* as a simple thin wrapping implementation over the logger. This is * as a simple thin wrapping implementation over the logger. This is
* particularly useful when using a property setter. * particularly useful when using a property setter.
* </li> * </li>
* <li>the {@link #setDefaultLogger} class property can be called which * <li>the {@link #setDefaultLogger} class property can be called which
* sets the ancestral Avalon logger for this class. Any <code>AvalonLogger</code> * sets the ancestral Avalon logger for this class. Any <code>AvalonLogger</code>
* instances created through the <code>LogFactory</code> mechanisms will output * instances created through the <code>LogFactory</code> mechanisms will output
* to child loggers of this <code>Logger</code>. * to child loggers of this <code>Logger</code>.
* </li> * </li>
@@ -43,7 +43,7 @@ import org.apache.commons.logging.Log;
* circumstances; there is no way to "reconnect" to an underlying Logger object on * circumstances; there is no way to "reconnect" to an underlying Logger object on
* deserialization if one was just passed in to the constructor of the original * deserialization if one was just passed in to the constructor of the original
* object. This class <i>was</i> marked Serializable in the 1.0.4 release of * object. This class <i>was</i> marked Serializable in the 1.0.4 release of
* commons-logging, but this never actually worked (a NullPointerException would * commons-logging, but this never actually worked (a NullPointerException would
* be thrown as soon as the deserialized object was used), so removing this marker * be thrown as soon as the deserialized object was used), so removing this marker
* is not considered to be an incompatible change. * is not considered to be an incompatible change.
* *
@@ -52,7 +52,7 @@ import org.apache.commons.logging.Log;
*/ */
public class AvalonLogger implements Log { public class AvalonLogger implements Log {
/** Ancestral Avalon logger. */ /** Ancestral Avalon logger. */
private static Logger defaultLogger = null; private static Logger defaultLogger = null;
/** Avalon logger used to perform log. */ /** Avalon logger used to perform log. */
private final transient Logger logger; private final transient Logger logger;
@@ -101,7 +101,7 @@ public class AvalonLogger implements Log {
/** /**
* Logs a message with <code>org.apache.avalon.framework.logger.Logger.debug</code>. * Logs a message with <code>org.apache.avalon.framework.logger.Logger.debug</code>.
* *
* @param message to log * @param message to log
* @param t log this cause * @param t log this cause
* @see org.apache.commons.logging.Log#debug(Object, Throwable) * @see org.apache.commons.logging.Log#debug(Object, Throwable)
@@ -114,7 +114,7 @@ public class AvalonLogger implements Log {
/** /**
* Logs a message with <code>org.apache.avalon.framework.logger.Logger.debug</code>. * Logs a message with <code>org.apache.avalon.framework.logger.Logger.debug</code>.
* *
* @param message to log. * @param message to log.
* @see org.apache.commons.logging.Log#debug(Object) * @see org.apache.commons.logging.Log#debug(Object)
*/ */
@@ -126,7 +126,7 @@ public class AvalonLogger implements Log {
/** /**
* Logs a message with <code>org.apache.avalon.framework.logger.Logger.error</code>. * Logs a message with <code>org.apache.avalon.framework.logger.Logger.error</code>.
* *
* @param message to log * @param message to log
* @param t log this cause * @param t log this cause
* @see org.apache.commons.logging.Log#error(Object, Throwable) * @see org.apache.commons.logging.Log#error(Object, Throwable)
@@ -139,7 +139,7 @@ public class AvalonLogger implements Log {
/** /**
* Logs a message with <code>org.apache.avalon.framework.logger.Logger.error</code>. * Logs a message with <code>org.apache.avalon.framework.logger.Logger.error</code>.
* *
* @param message to log * @param message to log
* @see org.apache.commons.logging.Log#error(Object) * @see org.apache.commons.logging.Log#error(Object)
*/ */
@@ -151,7 +151,7 @@ public class AvalonLogger implements Log {
/** /**
* Logs a message with <code>org.apache.avalon.framework.logger.Logger.fatalError</code>. * Logs a message with <code>org.apache.avalon.framework.logger.Logger.fatalError</code>.
* *
* @param message to log. * @param message to log.
* @param t log this cause. * @param t log this cause.
* @see org.apache.commons.logging.Log#fatal(Object, Throwable) * @see org.apache.commons.logging.Log#fatal(Object, Throwable)
@@ -164,7 +164,7 @@ public class AvalonLogger implements Log {
/** /**
* Logs a message with <code>org.apache.avalon.framework.logger.Logger.fatalError</code>. * Logs a message with <code>org.apache.avalon.framework.logger.Logger.fatalError</code>.
* *
* @param message to log * @param message to log
* @see org.apache.commons.logging.Log#fatal(Object) * @see org.apache.commons.logging.Log#fatal(Object)
*/ */
@@ -176,7 +176,7 @@ public class AvalonLogger implements Log {
/** /**
* Logs a message with <code>org.apache.avalon.framework.logger.Logger.info</code>. * Logs a message with <code>org.apache.avalon.framework.logger.Logger.info</code>.
* *
* @param message to log * @param message to log
* @param t log this cause * @param t log this cause
* @see org.apache.commons.logging.Log#info(Object, Throwable) * @see org.apache.commons.logging.Log#info(Object, Throwable)
@@ -189,7 +189,7 @@ public class AvalonLogger implements Log {
/** /**
* Logs a message with <code>org.apache.avalon.framework.logger.Logger.info</code>. * Logs a message with <code>org.apache.avalon.framework.logger.Logger.info</code>.
* *
* @param message to log * @param message to log
* @see org.apache.commons.logging.Log#info(Object) * @see org.apache.commons.logging.Log#info(Object)
*/ */
@@ -249,7 +249,7 @@ public class AvalonLogger implements Log {
/** /**
* Logs a message with <code>org.apache.avalon.framework.logger.Logger.debug</code>. * Logs a message with <code>org.apache.avalon.framework.logger.Logger.debug</code>.
* *
* @param message to log. * @param message to log.
* @param t log this cause. * @param t log this cause.
* @see org.apache.commons.logging.Log#trace(Object, Throwable) * @see org.apache.commons.logging.Log#trace(Object, Throwable)
@@ -262,7 +262,7 @@ public class AvalonLogger implements Log {
/** /**
* Logs a message with <code>org.apache.avalon.framework.logger.Logger.debug</code>. * Logs a message with <code>org.apache.avalon.framework.logger.Logger.debug</code>.
* *
* @param message to log * @param message to log
* @see org.apache.commons.logging.Log#trace(Object) * @see org.apache.commons.logging.Log#trace(Object)
*/ */
@@ -274,7 +274,7 @@ public class AvalonLogger implements Log {
/** /**
* Logs a message with <code>org.apache.avalon.framework.logger.Logger.warn</code>. * Logs a message with <code>org.apache.avalon.framework.logger.Logger.warn</code>.
* *
* @param message to log * @param message to log
* @param t log this cause * @param t log this cause
* @see org.apache.commons.logging.Log#warn(Object, Throwable) * @see org.apache.commons.logging.Log#warn(Object, Throwable)
@@ -287,7 +287,7 @@ public class AvalonLogger implements Log {
/** /**
* Logs a message with <code>org.apache.avalon.framework.logger.Logger.warn</code>. * Logs a message with <code>org.apache.avalon.framework.logger.Logger.warn</code>.
* *
* @param message to log * @param message to log
* @see org.apache.commons.logging.Log#warn(Object) * @see org.apache.commons.logging.Log#warn(Object)
*/ */

View File

@@ -5,15 +5,15 @@
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.commons.logging.impl; package org.apache.commons.logging.impl;

View File

@@ -5,15 +5,15 @@
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.commons.logging.impl; package org.apache.commons.logging.impl;

View File

@@ -5,15 +5,15 @@
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.commons.logging.impl; package org.apache.commons.logging.impl;
@@ -54,7 +54,7 @@ public class Log4JLogger implements Log, Serializable {
/** The fully qualified name of the Log4JLogger class. */ /** The fully qualified name of the Log4JLogger class. */
private static final String FQCN = Log4JLogger.class.getName(); private static final String FQCN = Log4JLogger.class.getName();
/** Log to this logger */ /** Log to this logger */
private transient Logger logger = null; private transient Logger logger = null;
@@ -62,7 +62,7 @@ public class Log4JLogger implements Log, Serializable {
private final String name; private final String name;
private static final Priority traceLevel; private static final Priority traceLevel;
// ------------------------------------------------------------ // ------------------------------------------------------------
// Static Initializer. // Static Initializer.
// //
@@ -82,11 +82,11 @@ public class Log4JLogger implements Log, Serializable {
// nope, this is log4j 1.3, so force an ExceptionInInitializerError // nope, this is log4j 1.3, so force an ExceptionInInitializerError
throw new InstantiationError("Log4J 1.2 not available"); throw new InstantiationError("Log4J 1.2 not available");
} }
// Releases of log4j1.2 >= 1.2.12 have Priority.TRACE available, earlier // Releases of log4j1.2 >= 1.2.12 have Priority.TRACE available, earlier
// versions do not. If TRACE is not available, then we have to map // versions do not. If TRACE is not available, then we have to map
// calls to Log.trace(...) onto the DEBUG level. // calls to Log.trace(...) onto the DEBUG level.
Priority _traceLevel; Priority _traceLevel;
try { try {
_traceLevel = (Priority) Level.class.getDeclaredField("TRACE").get(null); _traceLevel = (Priority) Level.class.getDeclaredField("TRACE").get(null);
@@ -111,7 +111,7 @@ public class Log4JLogger implements Log, Serializable {
this.logger = getLogger(); this.logger = getLogger();
} }
/** /**
* For use with a log4j factory. * For use with a log4j factory.
*/ */
public Log4JLogger(Logger logger ) { public Log4JLogger(Logger logger ) {

File diff suppressed because it is too large Load Diff

View File

@@ -5,15 +5,15 @@
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.commons.logging.impl; package org.apache.commons.logging.impl;
@@ -79,7 +79,7 @@ public class LogKitLogger implements Log, Serializable {
/** /**
* Logs a message with <code>org.apache.log.Priority.DEBUG</code>. * Logs a message with <code>org.apache.log.Priority.DEBUG</code>.
* *
* @param message to log * @param message to log
* @see org.apache.commons.logging.Log#trace(Object) * @see org.apache.commons.logging.Log#trace(Object)
*/ */
@@ -89,7 +89,7 @@ public class LogKitLogger implements Log, Serializable {
/** /**
* Logs a message with <code>org.apache.log.Priority.DEBUG</code>. * Logs a message with <code>org.apache.log.Priority.DEBUG</code>.
* *
* @param message to log * @param message to log
* @param t log this cause * @param t log this cause
* @see org.apache.commons.logging.Log#trace(Object, Throwable) * @see org.apache.commons.logging.Log#trace(Object, Throwable)
@@ -100,7 +100,7 @@ public class LogKitLogger implements Log, Serializable {
/** /**
* Logs a message with <code>org.apache.log.Priority.DEBUG</code>. * Logs a message with <code>org.apache.log.Priority.DEBUG</code>.
* *
* @param message to log * @param message to log
* @see org.apache.commons.logging.Log#debug(Object) * @see org.apache.commons.logging.Log#debug(Object)
*/ */
@@ -112,7 +112,7 @@ public class LogKitLogger implements Log, Serializable {
/** /**
* Logs a message with <code>org.apache.log.Priority.DEBUG</code>. * Logs a message with <code>org.apache.log.Priority.DEBUG</code>.
* *
* @param message to log * @param message to log
* @param t log this cause * @param t log this cause
* @see org.apache.commons.logging.Log#debug(Object, Throwable) * @see org.apache.commons.logging.Log#debug(Object, Throwable)
@@ -125,7 +125,7 @@ public class LogKitLogger implements Log, Serializable {
/** /**
* Logs a message with <code>org.apache.log.Priority.INFO</code>. * Logs a message with <code>org.apache.log.Priority.INFO</code>.
* *
* @param message to log * @param message to log
* @see org.apache.commons.logging.Log#info(Object) * @see org.apache.commons.logging.Log#info(Object)
*/ */
@@ -137,7 +137,7 @@ public class LogKitLogger implements Log, Serializable {
/** /**
* Logs a message with <code>org.apache.log.Priority.INFO</code>. * Logs a message with <code>org.apache.log.Priority.INFO</code>.
* *
* @param message to log * @param message to log
* @param t log this cause * @param t log this cause
* @see org.apache.commons.logging.Log#info(Object, Throwable) * @see org.apache.commons.logging.Log#info(Object, Throwable)
@@ -150,7 +150,7 @@ public class LogKitLogger implements Log, Serializable {
/** /**
* Logs a message with <code>org.apache.log.Priority.WARN</code>. * Logs a message with <code>org.apache.log.Priority.WARN</code>.
* *
* @param message to log * @param message to log
* @see org.apache.commons.logging.Log#warn(Object) * @see org.apache.commons.logging.Log#warn(Object)
*/ */
@@ -162,7 +162,7 @@ public class LogKitLogger implements Log, Serializable {
/** /**
* Logs a message with <code>org.apache.log.Priority.WARN</code>. * Logs a message with <code>org.apache.log.Priority.WARN</code>.
* *
* @param message to log * @param message to log
* @param t log this cause * @param t log this cause
* @see org.apache.commons.logging.Log#warn(Object, Throwable) * @see org.apache.commons.logging.Log#warn(Object, Throwable)
@@ -175,7 +175,7 @@ public class LogKitLogger implements Log, Serializable {
/** /**
* Logs a message with <code>org.apache.log.Priority.ERROR</code>. * Logs a message with <code>org.apache.log.Priority.ERROR</code>.
* *
* @param message to log * @param message to log
* @see org.apache.commons.logging.Log#error(Object) * @see org.apache.commons.logging.Log#error(Object)
*/ */
@@ -187,7 +187,7 @@ public class LogKitLogger implements Log, Serializable {
/** /**
* Logs a message with <code>org.apache.log.Priority.ERROR</code>. * Logs a message with <code>org.apache.log.Priority.ERROR</code>.
* *
* @param message to log * @param message to log
* @param t log this cause * @param t log this cause
* @see org.apache.commons.logging.Log#error(Object, Throwable) * @see org.apache.commons.logging.Log#error(Object, Throwable)
@@ -200,7 +200,7 @@ public class LogKitLogger implements Log, Serializable {
/** /**
* Logs a message with <code>org.apache.log.Priority.FATAL_ERROR</code>. * Logs a message with <code>org.apache.log.Priority.FATAL_ERROR</code>.
* *
* @param message to log * @param message to log
* @see org.apache.commons.logging.Log#fatal(Object) * @see org.apache.commons.logging.Log#fatal(Object)
*/ */
@@ -212,7 +212,7 @@ public class LogKitLogger implements Log, Serializable {
/** /**
* Logs a message with <code>org.apache.log.Priority.FATAL_ERROR</code>. * Logs a message with <code>org.apache.log.Priority.FATAL_ERROR</code>.
* *
* @param message to log * @param message to log
* @param t log this cause * @param t log this cause
* @see org.apache.commons.logging.Log#fatal(Object, Throwable) * @see org.apache.commons.logging.Log#fatal(Object, Throwable)

View File

@@ -5,15 +5,15 @@
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.commons.logging.impl; package org.apache.commons.logging.impl;

View File

@@ -5,15 +5,15 @@
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.commons.logging.impl; package org.apache.commons.logging.impl;
@@ -43,14 +43,14 @@ import org.apache.commons.logging.LogFactory;
* this class on webapp undeploy; the contextDestroyed method will tell * this class on webapp undeploy; the contextDestroyed method will tell
* every accessible LogFactory class that the entry in its map for the * every accessible LogFactory class that the entry in its map for the
* current webapp's context classloader should be cleared. * current webapp's context classloader should be cleared.
* *
* @version $Id$ * @version $Id$
* @since 1.1 * @since 1.1
*/ */
public class ServletContextCleaner implements ServletContextListener { public class ServletContextCleaner implements ServletContextListener {
private static final Class[] RELEASE_SIGNATURE = {ClassLoader.class}; private static final Class[] RELEASE_SIGNATURE = {ClassLoader.class};
/** /**
* Invoked when a webapp is undeployed, this tells the LogFactory * Invoked when a webapp is undeployed, this tells the LogFactory
* class to release any logging information related to the current * class to release any logging information related to the current
@@ -84,7 +84,7 @@ public class ServletContextCleaner implements ServletContextListener {
// and that class calls LogFactory the tccl gets registered in // and that class calls LogFactory the tccl gets registered in
// the LogFactory instance that is visible from the ancestor // the LogFactory instance that is visible from the ancestor
// classloader. However the concrete logging library it points // classloader. However the concrete logging library it points
// to is expected to have been loaded via the TCCL, so the // to is expected to have been loaded via the TCCL, so the
// underlying logging lib is only initialised/configured once. // underlying logging lib is only initialised/configured once.
// These references from ancestor LogFactory classes down to // These references from ancestor LogFactory classes down to
// TCCL classloaders are held via weak references and so should // TCCL classloaders are held via weak references and so should
@@ -120,13 +120,13 @@ public class ServletContextCleaner implements ServletContextListener {
loader = null; loader = null;
} }
} }
// Just to be sure, invoke release on the LogFactory that is visible from // Just to be sure, invoke release on the LogFactory that is visible from
// this ServletContextCleaner class too. This should already have been caught // this ServletContextCleaner class too. This should already have been caught
// by the above loop but just in case... // by the above loop but just in case...
LogFactory.release(tccl); LogFactory.release(tccl);
} }
/** /**
* Invoked when a webapp is deployed. Nothing needs to be done here. * Invoked when a webapp is deployed. Nothing needs to be done here.
*/ */

View File

@@ -5,15 +5,15 @@
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.commons.logging.impl; package org.apache.commons.logging.impl;
@@ -361,7 +361,7 @@ public class SimpleLog implements Log, Serializable {
// -------------------------------------------------------- Log Implementation // -------------------------------------------------------- Log Implementation
/** /**
* Logs a message with * Logs a message with
* <code>org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_DEBUG</code>. * <code>org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_DEBUG</code>.
* *
* @param message to log * @param message to log
@@ -374,7 +374,7 @@ public class SimpleLog implements Log, Serializable {
} }
/** /**
* Logs a message with * Logs a message with
* <code>org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_DEBUG</code>. * <code>org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_DEBUG</code>.
* *
* @param message to log * @param message to log
@@ -598,8 +598,7 @@ public class SimpleLog implements Log, Serializable {
// Get the thread context class loader (if there is one) // Get the thread context class loader (if there is one)
try { try {
classLoader = (ClassLoader)method.invoke(Thread.currentThread(), classLoader = (ClassLoader)method.invoke(Thread.currentThread(), (Class[]) null);
(Class[]) null);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
// ignore // ignore
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {

View File

@@ -5,16 +5,15 @@
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.commons.logging.impl; package org.apache.commons.logging.impl;
@@ -44,17 +43,17 @@ import java.util.Set;
* have been made with this in mind. * have been made with this in mind.
* </p> * </p>
* <p> * <p>
* <strong>Usage:</strong> typical use case is as a drop-in replacement * <strong>Usage:</strong> typical use case is as a drop-in replacement
* for the <code>Hashtable</code> used in <code>LogFactory</code> for J2EE environments * for the <code>Hashtable</code> used in <code>LogFactory</code> for J2EE environments
* running 1.3+ JVMs. Use of this class <i>in most cases</i> (see below) will * running 1.3+ JVMs. Use of this class <i>in most cases</i> (see below) will
* allow classloaders to be collected by the garbage collector without the need * allow classloaders to be collected by the garbage collector without the need
* to call {@link org.apache.commons.logging.LogFactory#release(ClassLoader) LogFactory.release(ClassLoader)}. * to call {@link org.apache.commons.logging.LogFactory#release(ClassLoader) LogFactory.release(ClassLoader)}.
* </p> * </p>
* *
* <p><code>org.apache.commons.logging.LogFactory</code> checks whether this class * <p><code>org.apache.commons.logging.LogFactory</code> checks whether this class
* can be supported by the current JVM, and if so then uses it to store * can be supported by the current JVM, and if so then uses it to store
* references to the <code>LogFactory</code> implementation it loads * references to the <code>LogFactory</code> implementation it loads
* (rather than using a standard Hashtable instance). * (rather than using a standard Hashtable instance).
* Having this class used instead of <code>Hashtable</code> solves * Having this class used instead of <code>Hashtable</code> solves
* certain issues related to dynamic reloading of applications in J2EE-style * certain issues related to dynamic reloading of applications in J2EE-style
* environments. However this class requires java 1.3 or later (due to its use * environments. However this class requires java 1.3 or later (due to its use
@@ -64,37 +63,37 @@ import java.util.Set;
* for method <code>LogFactory.createFactoryStore</code> for more details.</p> * for method <code>LogFactory.createFactoryStore</code> for more details.</p>
* *
* <p>The reason all this is necessary is due to a issue which * <p>The reason all this is necessary is due to a issue which
* arises during hot deploy in a J2EE-like containers. * arises during hot deploy in a J2EE-like containers.
* Each component running in the container owns one or more classloaders; when * Each component running in the container owns one or more classloaders; when
* the component loads a LogFactory instance via the component classloader * the component loads a LogFactory instance via the component classloader
* a reference to it gets stored in the static LogFactory.factories member, * a reference to it gets stored in the static LogFactory.factories member,
* keyed by the component's classloader so different components don't * keyed by the component's classloader so different components don't
* stomp on each other. When the component is later unloaded, the container * stomp on each other. When the component is later unloaded, the container
* sets the component's classloader to null with the intent that all the * sets the component's classloader to null with the intent that all the
* component's classes get garbage-collected. However there's still a * component's classes get garbage-collected. However there's still a
* reference to the component's classloader from a key in the "global" * reference to the component's classloader from a key in the "global"
* <code>LogFactory</code>'s factories member! If <code>LogFactory.release()</code> * <code>LogFactory</code>'s factories member! If <code>LogFactory.release()</code>
* is called whenever component is unloaded, the classloaders will be correctly * is called whenever component is unloaded, the classloaders will be correctly
* garbage collected; this <i>should</i> be done by any container that * garbage collected; this <i>should</i> be done by any container that
* bundles commons-logging by default. However, holding the classloader * bundles commons-logging by default. However, holding the classloader
* references weakly ensures that the classloader will be garbage collected * references weakly ensures that the classloader will be garbage collected
* without the container performing this step. </p> * without the container performing this step. </p>
* *
* <p> * <p>
* <strong>Limitations:</strong> * <strong>Limitations:</strong>
* There is still one (unusual) scenario in which a component will not * There is still one (unusual) scenario in which a component will not
* be correctly unloaded without an explicit release. Though weak references * be correctly unloaded without an explicit release. Though weak references
* are used for its keys, it is necessary to use strong references for its values. * are used for its keys, it is necessary to use strong references for its values.
* </p> * </p>
* *
* <p> If the abstract class <code>LogFactory</code> is * <p> If the abstract class <code>LogFactory</code> is
* loaded by the container classloader but a subclass of * loaded by the container classloader but a subclass of
* <code>LogFactory</code> [LogFactory1] is loaded by the component's * <code>LogFactory</code> [LogFactory1] is loaded by the component's
* classloader and an instance stored in the static map associated with the * classloader and an instance stored in the static map associated with the
* base LogFactory class, then there is a strong reference from the LogFactory * base LogFactory class, then there is a strong reference from the LogFactory
* class to the LogFactory1 instance (as normal) and a strong reference from * class to the LogFactory1 instance (as normal) and a strong reference from
* the LogFactory1 instance to the component classloader via * the LogFactory1 instance to the component classloader via
* <code>getClass().getClassLoader()</code>. This chain of references will prevent * <code>getClass().getClassLoader()</code>. This chain of references will prevent
* collection of the child classloader.</p> * collection of the child classloader.</p>
* *
* <p> * <p>
@@ -102,16 +101,16 @@ import java.util.Set;
* loaded by a parent classloader (e.g. a server level classloader in a * loaded by a parent classloader (e.g. a server level classloader in a
* servlet container) and a custom <code>LogFactory</code> implementation is * servlet container) and a custom <code>LogFactory</code> implementation is
* loaded by a child classloader (e.g. a web app classloader).</p> * loaded by a child classloader (e.g. a web app classloader).</p>
* *
* <p>To avoid this scenario, ensure * <p>To avoid this scenario, ensure
* that any custom LogFactory subclass is loaded by the same classloader as * that any custom LogFactory subclass is loaded by the same classloader as
* the base <code>LogFactory</code>. Creating custom LogFactory subclasses is, * the base <code>LogFactory</code>. Creating custom LogFactory subclasses is,
* however, rare. The standard LogFactoryImpl class should be sufficient * however, rare. The standard LogFactoryImpl class should be sufficient
* for most or all users.</p> * for most or all users.</p>
* *
* *
* @author Brian Stansberry * @author Brian Stansberry
* *
* @version $Id$ * @version $Id$
* @since 1.1 * @since 1.1
*/ */
@@ -120,30 +119,29 @@ public final class WeakHashtable extends Hashtable {
/** Serializable version identifier. */ /** Serializable version identifier. */
private static final long serialVersionUID = -1546036869799732453L; private static final long serialVersionUID = -1546036869799732453L;
/** /**
* The maximum number of times put() or remove() can be called before * The maximum number of times put() or remove() can be called before
* the map will be purged of all cleared entries. * the map will be purged of all cleared entries.
*/ */
private static final int MAX_CHANGES_BEFORE_PURGE = 100; private static final int MAX_CHANGES_BEFORE_PURGE = 100;
/** /**
* The maximum number of times put() or remove() can be called before * The maximum number of times put() or remove() can be called before
* the map will be purged of one cleared entry. * the map will be purged of one cleared entry.
*/ */
private static final int PARTIAL_PURGE_COUNT = 10; private static final int PARTIAL_PURGE_COUNT = 10;
/* ReferenceQueue we check for gc'd keys */ /* ReferenceQueue we check for gc'd keys */
private final ReferenceQueue queue = new ReferenceQueue(); private final ReferenceQueue queue = new ReferenceQueue();
/* Counter used to control how often we purge gc'd entries */ /* Counter used to control how often we purge gc'd entries */
private int changeCount = 0; private int changeCount = 0;
/** /**
* Constructs a WeakHashtable with the Hashtable default * Constructs a WeakHashtable with the Hashtable default
* capacity and load factor. * capacity and load factor.
*/ */
public WeakHashtable() {} public WeakHashtable() {}
/** /**
*@see Hashtable *@see Hashtable
*/ */
@@ -152,7 +150,7 @@ public final class WeakHashtable extends Hashtable {
Referenced referenced = new Referenced(key); Referenced referenced = new Referenced(key);
return super.containsKey(referenced); return super.containsKey(referenced);
} }
/** /**
*@see Hashtable *@see Hashtable
*/ */
@@ -160,7 +158,7 @@ public final class WeakHashtable extends Hashtable {
purge(); purge();
return super.elements(); return super.elements();
} }
/** /**
*@see Hashtable *@see Hashtable
*/ */
@@ -180,7 +178,7 @@ public final class WeakHashtable extends Hashtable {
} }
return unreferencedEntries; return unreferencedEntries;
} }
/** /**
*@see Hashtable *@see Hashtable
*/ */
@@ -189,7 +187,7 @@ public final class WeakHashtable extends Hashtable {
Referenced referenceKey = new Referenced(key); Referenced referenceKey = new Referenced(key);
return super.get(referenceKey); return super.get(referenceKey);
} }
/** /**
*@see Hashtable *@see Hashtable
*/ */
@@ -206,8 +204,7 @@ public final class WeakHashtable extends Hashtable {
} }
}; };
} }
/** /**
*@see Hashtable *@see Hashtable
*/ */
@@ -224,10 +221,10 @@ public final class WeakHashtable extends Hashtable {
} }
return unreferencedKeys; return unreferencedKeys;
} }
/** /**
*@see Hashtable *@see Hashtable
*/ */
public Object put(Object key, Object value) { public Object put(Object key, Object value) {
// check for nulls, ensuring semantics match superclass // check for nulls, ensuring semantics match superclass
if (key == null) { if (key == null) {
@@ -237,7 +234,7 @@ public final class WeakHashtable extends Hashtable {
throw new NullPointerException("Null values are not allowed"); throw new NullPointerException("Null values are not allowed");
} }
// for performance reasons, only purge every // for performance reasons, only purge every
// MAX_CHANGES_BEFORE_PURGE times // MAX_CHANGES_BEFORE_PURGE times
if (changeCount++ > MAX_CHANGES_BEFORE_PURGE) { if (changeCount++ > MAX_CHANGES_BEFORE_PURGE) {
purge(); purge();
@@ -247,14 +244,14 @@ public final class WeakHashtable extends Hashtable {
else if (changeCount % PARTIAL_PURGE_COUNT == 0) { else if (changeCount % PARTIAL_PURGE_COUNT == 0) {
purgeOne(); purgeOne();
} }
Referenced keyRef = new Referenced(key, queue); Referenced keyRef = new Referenced(key, queue);
return super.put(keyRef, value); return super.put(keyRef, value);
} }
/** /**
*@see Hashtable *@see Hashtable
*/ */
public void putAll(Map t) { public void putAll(Map t) {
if (t != null) { if (t != null) {
Set entrySet = t.entrySet(); Set entrySet = t.entrySet();
@@ -264,20 +261,20 @@ public final class WeakHashtable extends Hashtable {
} }
} }
} }
/** /**
*@see Hashtable *@see Hashtable
*/ */
public Collection values() { public Collection values() {
purge(); purge();
return super.values(); return super.values();
} }
/** /**
*@see Hashtable *@see Hashtable
*/ */
public Object remove(Object key) { public Object remove(Object key) {
// for performance reasons, only purge every // for performance reasons, only purge every
// MAX_CHANGES_BEFORE_PURGE times // MAX_CHANGES_BEFORE_PURGE times
if (changeCount++ > MAX_CHANGES_BEFORE_PURGE) { if (changeCount++ > MAX_CHANGES_BEFORE_PURGE) {
purge(); purge();
@@ -289,31 +286,31 @@ public final class WeakHashtable extends Hashtable {
} }
return super.remove(new Referenced(key)); return super.remove(new Referenced(key));
} }
/** /**
*@see Hashtable *@see Hashtable
*/ */
public boolean isEmpty() { public boolean isEmpty() {
purge(); purge();
return super.isEmpty(); return super.isEmpty();
} }
/** /**
*@see Hashtable *@see Hashtable
*/ */
public int size() { public int size() {
purge(); purge();
return super.size(); return super.size();
} }
/** /**
*@see Hashtable *@see Hashtable
*/ */
public String toString() { public String toString() {
purge(); purge();
return super.toString(); return super.toString();
} }
/** /**
* @see Hashtable * @see Hashtable
*/ */
@@ -322,7 +319,7 @@ public final class WeakHashtable extends Hashtable {
purge(); purge();
super.rehash(); super.rehash();
} }
/** /**
* Purges all entries whose wrapped keys * Purges all entries whose wrapped keys
* have been garbage collected. * have been garbage collected.
@@ -335,13 +332,12 @@ public final class WeakHashtable extends Hashtable {
} }
} }
} }
/** /**
* Purges one entry whose wrapped key * Purges one entry whose wrapped key
* has been garbage collected. * has been garbage collected.
*/ */
private void purgeOne() { private void purgeOne() {
synchronized (queue) { synchronized (queue) {
WeakKey key = (WeakKey) queue.poll(); WeakKey key = (WeakKey) queue.poll();
if (key != null) { if (key != null) {
@@ -349,33 +345,33 @@ public final class WeakHashtable extends Hashtable {
} }
} }
} }
/** Entry implementation */ /** Entry implementation */
private final static class Entry implements Map.Entry { private final static class Entry implements Map.Entry {
private final Object key; private final Object key;
private final Object value; private final Object value;
private Entry(Object key, Object value) { private Entry(Object key, Object value) {
this.key = key; this.key = key;
this.value = value; this.value = value;
} }
public boolean equals(Object o) { public boolean equals(Object o) {
boolean result = false; boolean result = false;
if (o != null && o instanceof Map.Entry) { if (o != null && o instanceof Map.Entry) {
Map.Entry entry = (Map.Entry) o; Map.Entry entry = (Map.Entry) o;
result = (getKey()==null ? result = (getKey()==null ?
entry.getKey() == null : entry.getKey() == null :
getKey().equals(entry.getKey())) getKey().equals(entry.getKey()))
&& &&
(getValue()==null ? (getValue()==null ?
entry.getValue() == null : entry.getValue() == null :
getValue().equals(entry.getValue())); getValue().equals(entry.getValue()));
} }
return result; return result;
} }
public int hashCode() { public int hashCode() {
return (getKey()==null ? 0 : getKey().hashCode()) ^ return (getKey()==null ? 0 : getKey().hashCode()) ^
@@ -385,36 +381,35 @@ public final class WeakHashtable extends Hashtable {
public Object setValue(Object value) { public Object setValue(Object value) {
throw new UnsupportedOperationException("Entry.setValue is not supported."); throw new UnsupportedOperationException("Entry.setValue is not supported.");
} }
public Object getValue() { public Object getValue() {
return value; return value;
} }
public Object getKey() { public Object getKey() {
return key; return key;
} }
} }
/** Wrapper giving correct symantics for equals and hashcode */ /** Wrapper giving correct symantics for equals and hashcode */
private final static class Referenced { private final static class Referenced {
private final WeakReference reference; private final WeakReference reference;
private final int hashCode; private final int hashCode;
/** /**
* *
* @throws NullPointerException if referant is <code>null</code> * @throws NullPointerException if referant is <code>null</code>
*/ */
private Referenced(Object referant) { private Referenced(Object referant) {
reference = new WeakReference(referant); reference = new WeakReference(referant);
// Calc a permanent hashCode so calls to Hashtable.remove() // Calc a permanent hashCode so calls to Hashtable.remove()
// work if the WeakReference has been cleared // work if the WeakReference has been cleared
hashCode = referant.hashCode(); hashCode = referant.hashCode();
} }
/** /**
* *
* @throws NullPointerException if key is <code>null</code> * @throws NullPointerException if key is <code>null</code>
*/ */
private Referenced(Object key, ReferenceQueue queue) { private Referenced(Object key, ReferenceQueue queue) {
@@ -424,34 +419,34 @@ public final class WeakHashtable extends Hashtable {
hashCode = key.hashCode(); hashCode = key.hashCode();
} }
public int hashCode() { public int hashCode() {
return hashCode; return hashCode;
} }
private Object getValue() { private Object getValue() {
return reference.get(); return reference.get();
} }
public boolean equals(Object o) { public boolean equals(Object o) {
boolean result = false; boolean result = false;
if (o instanceof Referenced) { if (o instanceof Referenced) {
Referenced otherKey = (Referenced) o; Referenced otherKey = (Referenced) o;
Object thisKeyValue = getValue(); Object thisKeyValue = getValue();
Object otherKeyValue = otherKey.getValue(); Object otherKeyValue = otherKey.getValue();
if (thisKeyValue == null) { if (thisKeyValue == null) {
result = otherKeyValue == null; result = otherKeyValue == null;
// Since our hashcode was calculated from the original // Since our hashcode was calculated from the original
// non-null referant, the above check breaks the // non-null referant, the above check breaks the
// hashcode/equals contract, as two cleared Referenced // hashcode/equals contract, as two cleared Referenced
// objects could test equal but have different hashcodes. // objects could test equal but have different hashcodes.
// We can reduce (not eliminate) the chance of this // We can reduce (not eliminate) the chance of this
// happening by comparing hashcodes. // happening by comparing hashcodes.
result = result && this.hashCode() == otherKey.hashCode(); result = result && this.hashCode() == otherKey.hashCode();
// In any case, as our c'tor does not allow null referants // In any case, as our c'tor does not allow null referants
// and Hashtable does not do equality checks between // and Hashtable does not do equality checks between
// existing keys, normal hashtable operations should never // existing keys, normal hashtable operations should never
// result in an equals comparison between null referants // result in an equals comparison between null referants
} }
else else
@@ -462,7 +457,7 @@ public final class WeakHashtable extends Hashtable {
return result; return result;
} }
} }
/** /**
* WeakReference subclass that holds a hard reference to an * WeakReference subclass that holds a hard reference to an
* associated <code>value</code> and also makes accessible * associated <code>value</code> and also makes accessible
@@ -471,14 +466,14 @@ public final class WeakHashtable extends Hashtable {
private final static class WeakKey extends WeakReference { private final static class WeakKey extends WeakReference {
private final Referenced referenced; private final Referenced referenced;
private WeakKey(Object key, private WeakKey(Object key,
ReferenceQueue queue, ReferenceQueue queue,
Referenced referenced) { Referenced referenced) {
super(key, queue); super(key, queue);
this.referenced = referenced; this.referenced = referenced;
} }
private Referenced getReferenced() { private Referenced getReferenced() {
return referenced; return referenced;
} }