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:
@@ -5,12 +5,12 @@
|
||||
* 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 obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
*/
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
* 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 obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
*/
|
||||
|
||||
package org.apache.commons.logging;
|
||||
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
* 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 obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
*/
|
||||
|
||||
package org.apache.commons.logging;
|
||||
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
* 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 obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
*/
|
||||
|
||||
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
|
||||
// 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
|
||||
// with an AccessController anywhere in the call stack, otherwise an
|
||||
// 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.
|
||||
//
|
||||
// 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
|
||||
// trust domain, and therefore must have permissions to do whatever it
|
||||
// is trying to do regardless of the permissions granted to JCL. There is
|
||||
@@ -76,21 +76,21 @@ public abstract class LogFactory {
|
||||
// ----------------------------------------------------- Manifest Constants
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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
|
||||
* is a floating-point number; higher values take priority over lower values.
|
||||
*/
|
||||
public static final String PRIORITY_KEY = "priority";
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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
|
||||
* context class loader (TCCL), or not. By default, the TCCL is used.
|
||||
*/
|
||||
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
|
||||
* class name. This can be used as a system property, or as an entry in a
|
||||
* configuration properties file.
|
||||
@@ -116,10 +116,10 @@ public abstract class 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
|
||||
* 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.
|
||||
* <p>
|
||||
* 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.
|
||||
*/
|
||||
private static PrintStream diagnosticsStream = null;
|
||||
|
||||
|
||||
/**
|
||||
* A string that gets prefixed to every message output by the
|
||||
* logDiagnostic method, so that users can clearly see which
|
||||
* LogFactory class is generating the output.
|
||||
*/
|
||||
private static final String diagnosticPrefix;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Setting this system property
|
||||
* (<code>org.apache.commons.logging.LogFactory.HashtableImpl</code>)
|
||||
* <p>Setting this system property
|
||||
* (<code>org.apache.commons.logging.LogFactory.HashtableImpl</code>)
|
||||
* value allows the <code>Hashtable</code> used to store
|
||||
* classloaders to be substituted by an alternative implementation.
|
||||
* </p>
|
||||
@@ -162,13 +162,13 @@ public abstract class LogFactory {
|
||||
* </p>
|
||||
* <p>
|
||||
* <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.
|
||||
* For example, running the following ant scriplet:
|
||||
* <code><pre>
|
||||
* <java classname="${test.runner}" fork="yes" failonerror="${test.failonerror}">
|
||||
* ...
|
||||
* <sysproperty
|
||||
* <sysproperty
|
||||
* key="org.apache.commons.logging.LogFactory.HashtableImpl"
|
||||
* value="org.apache.commons.logging.AltHashtable"/>
|
||||
* </java>
|
||||
@@ -187,7 +187,7 @@ public abstract class LogFactory {
|
||||
"org.apache.commons.logging.LogFactory.HashtableImpl";
|
||||
|
||||
/** 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";
|
||||
|
||||
/**
|
||||
@@ -198,7 +198,7 @@ public abstract class LogFactory {
|
||||
* cache it here.
|
||||
*/
|
||||
private static final ClassLoader thisClassLoader;
|
||||
|
||||
|
||||
// ----------------------------------------------------------- Constructors
|
||||
|
||||
/**
|
||||
@@ -206,7 +206,7 @@ public abstract class LogFactory {
|
||||
*/
|
||||
protected LogFactory() {
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
/**
|
||||
@@ -291,7 +291,7 @@ public abstract class LogFactory {
|
||||
* the <code>ClassLoader</code> with which it was created.
|
||||
*/
|
||||
protected static Hashtable factories = null;
|
||||
|
||||
|
||||
/**
|
||||
* Previously constructed <code>LogFactory</code> instance as in the
|
||||
* <code>factories</code> map, but for the case where
|
||||
@@ -320,7 +320,7 @@ public abstract class LogFactory {
|
||||
* arbitrary Hashtable implementation name.
|
||||
* <p>
|
||||
* 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.
|
||||
*/
|
||||
private static final Hashtable createFactoryStore() {
|
||||
@@ -340,7 +340,6 @@ public abstract class LogFactory {
|
||||
try {
|
||||
Class implementationClass = Class.forName(storeImplementationClass);
|
||||
result = (Hashtable) implementationClass.newInstance();
|
||||
|
||||
} catch (Throwable t) {
|
||||
// ignore
|
||||
if (!WEAK_HASHTABLE_CLASSNAME.equals(storeImplementationClass)) {
|
||||
@@ -365,10 +364,10 @@ public abstract class LogFactory {
|
||||
|
||||
/** Utility method to safely trim a string. */
|
||||
private static String trim(String src) {
|
||||
if (src == null) {
|
||||
return null;
|
||||
}
|
||||
return src.trim();
|
||||
if (src == null) {
|
||||
return null;
|
||||
}
|
||||
return src.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -394,9 +393,9 @@ public abstract class LogFactory {
|
||||
* properties defined in this file will be set as configuration attributes
|
||||
* on the corresponding <code>LogFactory</code> instance.
|
||||
* <p>
|
||||
* <em>NOTE</em> - In a multi-threaded environment it is possible
|
||||
* that two different instances will be returned for the same
|
||||
* classloader environment.
|
||||
* <em>NOTE</em> - In a multi-threaded environment it is possible
|
||||
* that two different instances will be returned for the same
|
||||
* classloader environment.
|
||||
*
|
||||
* @throws LogConfigurationException if the implementation class is not
|
||||
* available or cannot be instantiated.
|
||||
@@ -422,8 +421,8 @@ public abstract class LogFactory {
|
||||
|
||||
if (isDiagnosticsEnabled()) {
|
||||
logDiagnostic(
|
||||
"[LOOKUP] LogFactory implementation requested for the first time for context classloader "
|
||||
+ objectId(contextClassLoader));
|
||||
"[LOOKUP] LogFactory implementation requested for the first time for context classloader " +
|
||||
objectId(contextClassLoader));
|
||||
logHierarchy("[LOOKUP] ", contextClassLoader);
|
||||
}
|
||||
|
||||
@@ -434,7 +433,7 @@ public abstract class LogFactory {
|
||||
// property may also control which LogFactory concrete subclass is
|
||||
// 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.
|
||||
|
||||
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
|
||||
// implementation whether to load library-specific config files
|
||||
// from the TCCL or not.
|
||||
baseClassLoader = thisClassLoader;
|
||||
baseClassLoader = thisClassLoader;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -463,35 +462,28 @@ public abstract class LogFactory {
|
||||
// Determine which concrete LogFactory subclass to use.
|
||||
// First, try a global system property
|
||||
if (isDiagnosticsEnabled()) {
|
||||
logDiagnostic(
|
||||
"[LOOKUP] Looking for system property [" + FACTORY_PROPERTY
|
||||
+ "] to define the LogFactory subclass to use...");
|
||||
logDiagnostic("[LOOKUP] Looking for system property [" + FACTORY_PROPERTY +
|
||||
"] to define the LogFactory subclass to use...");
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
String factoryClass = getSystemProperty(FACTORY_PROPERTY, null);
|
||||
if (factoryClass != null) {
|
||||
if (isDiagnosticsEnabled()) {
|
||||
logDiagnostic(
|
||||
"[LOOKUP] Creating an instance of LogFactory class '" + factoryClass
|
||||
+ "' as specified by system property " + FACTORY_PROPERTY);
|
||||
logDiagnostic("[LOOKUP] Creating an instance of LogFactory class '" + factoryClass +
|
||||
"' as specified by system property " + FACTORY_PROPERTY);
|
||||
}
|
||||
|
||||
factory = newFactory(factoryClass, baseClassLoader, contextClassLoader);
|
||||
} else {
|
||||
if (isDiagnosticsEnabled()) {
|
||||
logDiagnostic(
|
||||
"[LOOKUP] No system property [" + FACTORY_PROPERTY
|
||||
+ "] defined.");
|
||||
logDiagnostic("[LOOKUP] No system property [" + FACTORY_PROPERTY + "] defined.");
|
||||
}
|
||||
}
|
||||
} catch (SecurityException e) {
|
||||
if (isDiagnosticsEnabled()) {
|
||||
logDiagnostic(
|
||||
"[LOOKUP] A security exception occurred while trying to create an"
|
||||
+ " instance of the custom factory class"
|
||||
+ ": [" + trim(e.getMessage())
|
||||
+ "]. Trying alternative implementations...");
|
||||
logDiagnostic("[LOOKUP] A security exception occurred while trying to create an" +
|
||||
" instance of the custom factory class" + ": [" + trim(e.getMessage()) +
|
||||
"]. Trying alternative implementations...");
|
||||
}
|
||||
// ignore
|
||||
} catch(RuntimeException e) {
|
||||
@@ -501,11 +493,9 @@ public abstract class LogFactory {
|
||||
// One possible exception that can occur here is a ClassCastException when
|
||||
// the specified class wasn't castable to this LogFactory type.
|
||||
if (isDiagnosticsEnabled()) {
|
||||
logDiagnostic(
|
||||
"[LOOKUP] An exception occurred while trying to create an"
|
||||
+ " instance of the custom factory class"
|
||||
+ ": [" + trim(e.getMessage())
|
||||
+ "] as specified by a system property.");
|
||||
logDiagnostic("[LOOKUP] An exception occurred while trying to create an" +
|
||||
" instance of the custom factory class" + ": [" + trim(e.getMessage()) +
|
||||
"] as specified by a system property.");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
@@ -513,14 +503,13 @@ public abstract class LogFactory {
|
||||
// Second, try to find a service by using the JDK1.3 class
|
||||
// discovery mechanism, which involves putting a file with the name
|
||||
// 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.
|
||||
|
||||
if (factory == null) {
|
||||
if (isDiagnosticsEnabled()) {
|
||||
logDiagnostic(
|
||||
"[LOOKUP] Looking for a resource file of name [" + SERVICE_ID
|
||||
+ "] to define the LogFactory subclass to use...");
|
||||
logDiagnostic("[LOOKUP] Looking for a resource file of name [" + SERVICE_ID +
|
||||
"] to define the LogFactory subclass to use...");
|
||||
}
|
||||
try {
|
||||
InputStream is = getResourceAsStream(contextClassLoader,
|
||||
@@ -542,20 +531,16 @@ public abstract class LogFactory {
|
||||
if (factoryClassName != null &&
|
||||
! "".equals(factoryClassName)) {
|
||||
if (isDiagnosticsEnabled()) {
|
||||
logDiagnostic(
|
||||
"[LOOKUP] Creating an instance of LogFactory class " + factoryClassName
|
||||
+ " as specified by file '" + SERVICE_ID
|
||||
+ "' which was present in the path of the context"
|
||||
+ " classloader.");
|
||||
logDiagnostic("[LOOKUP] Creating an instance of LogFactory class " + factoryClassName +
|
||||
" as specified by file '" + SERVICE_ID +
|
||||
"' which was present in the path of the context classloader.");
|
||||
}
|
||||
factory = newFactory(factoryClassName, baseClassLoader, contextClassLoader );
|
||||
}
|
||||
} else {
|
||||
// is == null
|
||||
if (isDiagnosticsEnabled()) {
|
||||
logDiagnostic(
|
||||
"[LOOKUP] No resource file with name '" + SERVICE_ID
|
||||
+ "' found.");
|
||||
logDiagnostic("[LOOKUP] No resource file with name '" + SERVICE_ID + "' found.");
|
||||
}
|
||||
}
|
||||
} catch( Exception ex ) {
|
||||
@@ -760,7 +745,7 @@ public abstract class LogFactory {
|
||||
* Even when using an AccessController, however, this method can still
|
||||
* throw SecurityException. Commons-logging basically relies on the
|
||||
* 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
|
||||
* from starting up. Maybe it would be good to detect this situation and
|
||||
* 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
|
||||
* to a trusted JCL library could use it to fetch the classloader for
|
||||
* a class even when forbidden to do so directly.
|
||||
*
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
protected static ClassLoader getClassLoader(Class clazz) {
|
||||
@@ -797,13 +782,13 @@ public abstract class LogFactory {
|
||||
* an AccessController. User code wishing to obtain the context classloader
|
||||
* must invoke this method via AccessController.doPrivileged if it needs
|
||||
* support for that.
|
||||
*
|
||||
*
|
||||
* @return the context classloader associated with the current thread,
|
||||
* or null if security doesn't allow it.
|
||||
*
|
||||
*
|
||||
* @throws LogConfigurationException if there was some weird error while
|
||||
* attempting to get the context classloader.
|
||||
*
|
||||
*
|
||||
* @throws SecurityException if the current java security policy doesn't
|
||||
* 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
|
||||
* the entire call stack must have the privilege before the call is
|
||||
* allowed.
|
||||
*
|
||||
*
|
||||
* @return the context classloader associated with the current thread,
|
||||
* or null if security doesn't allow it.
|
||||
*
|
||||
*
|
||||
* @throws LogConfigurationException if there was some weird error while
|
||||
* attempting to get the context classloader.
|
||||
*
|
||||
*
|
||||
* @throws SecurityException if the current java security policy doesn't
|
||||
* 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
|
||||
* null.
|
||||
* null.
|
||||
* <p>
|
||||
* Most/all code should call getContextClassLoaderInternal rather than
|
||||
* calling this method directly.
|
||||
@@ -853,13 +838,13 @@ public abstract class LogFactory {
|
||||
* Note that no internal logging is done within this method because
|
||||
* this method is called every time LogFactory.getLogger() is called,
|
||||
* and we don't want too much output generated here.
|
||||
*
|
||||
*
|
||||
* @exception LogConfigurationException if a suitable class loader
|
||||
* cannot be identified.
|
||||
*
|
||||
*
|
||||
* @exception SecurityException if the java security policy forbids
|
||||
* access to the context classloader from one of the classes in the
|
||||
* current call stack.
|
||||
* current call stack.
|
||||
* @since 1.1
|
||||
*/
|
||||
protected static ClassLoader directGetContextClassLoader()
|
||||
@@ -869,13 +854,11 @@ public abstract class LogFactory {
|
||||
|
||||
try {
|
||||
// Are we running on a JDK 1.2 or later system?
|
||||
Method method = Thread.class.getMethod("getContextClassLoader",
|
||||
(Class[]) null);
|
||||
Method method = Thread.class.getMethod("getContextClassLoader", (Class[]) null);
|
||||
|
||||
// Get the thread context class loader (if there is one)
|
||||
try {
|
||||
classLoader = (ClassLoader)method.invoke(Thread.currentThread(),
|
||||
(Object[]) null);
|
||||
classLoader = (ClassLoader)method.invoke(Thread.currentThread(), (Object[]) null);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new LogConfigurationException
|
||||
("Unexpected IllegalAccessException", e);
|
||||
@@ -920,7 +903,6 @@ public abstract class LogFactory {
|
||||
// + " classloader is the same as the class that loaded"
|
||||
// + " the concrete LogFactory class.");
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
// Return the selected class loader
|
||||
@@ -936,7 +918,7 @@ public abstract class LogFactory {
|
||||
* a distinct context classloader set. This parameter may be null
|
||||
* in JDK1.1, and in embedded systems where jcl-using code is
|
||||
* placed in the bootclasspath.
|
||||
*
|
||||
*
|
||||
* @return the factory associated with the specified classloader if
|
||||
* one has previously been created, or null if this is the first time
|
||||
* we have seen this particular classloader.
|
||||
@@ -985,7 +967,7 @@ public abstract class LogFactory {
|
||||
* (abstract) LogFactory.
|
||||
* <p>
|
||||
* <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
|
||||
* concrete LogFactory subclass via a context classloader.
|
||||
* <p>
|
||||
@@ -1040,16 +1022,13 @@ public abstract class LogFactory {
|
||||
if (result instanceof LogConfigurationException) {
|
||||
LogConfigurationException ex = (LogConfigurationException) result;
|
||||
if (isDiagnosticsEnabled()) {
|
||||
logDiagnostic(
|
||||
"An error occurred while loading the factory class:"
|
||||
+ ex.getMessage());
|
||||
logDiagnostic("An error occurred while loading the factory class:" + ex.getMessage());
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
if (isDiagnosticsEnabled()) {
|
||||
logDiagnostic(
|
||||
"Created object " + objectId(result)
|
||||
+ " to manage classloader " + objectId(contextClassLoader));
|
||||
logDiagnostic("Created object " + objectId(result) + " to manage classloader " +
|
||||
objectId(contextClassLoader));
|
||||
}
|
||||
return (LogFactory)result;
|
||||
}
|
||||
@@ -1076,14 +1055,14 @@ public abstract class LogFactory {
|
||||
|
||||
/**
|
||||
* Implements the operations described in the javadoc for newFactory.
|
||||
*
|
||||
*
|
||||
* @param factoryClass
|
||||
*
|
||||
*
|
||||
* @param classLoader used to load the specified factory class. This is
|
||||
* expected to be either the TCCL or the classloader which loaded this
|
||||
* class. Note that the classloader which loaded this class might be
|
||||
* "null" (ie the bootloader) for embedded systems.
|
||||
*
|
||||
*
|
||||
* @return either a LogFactory object or a LogConfigurationException object.
|
||||
* @since 1.1
|
||||
*/
|
||||
@@ -1108,14 +1087,14 @@ public abstract class LogFactory {
|
||||
} else {
|
||||
//
|
||||
// This indicates a problem with the ClassLoader tree.
|
||||
// An incompatible ClassLoader was used to load the
|
||||
// implementation.
|
||||
// An incompatible ClassLoader was used to load the
|
||||
// implementation.
|
||||
// As the same classes
|
||||
// must be available in multiple class loaders,
|
||||
// it is very likely that multiple JCL jars are present.
|
||||
// The most likely fix for this
|
||||
// problem is to remove the extra JCL jars from the
|
||||
// ClassLoader hierarchy.
|
||||
// problem is to remove the extra JCL jars from the
|
||||
// ClassLoader hierarchy.
|
||||
//
|
||||
if (isDiagnosticsEnabled()) {
|
||||
logDiagnostic(
|
||||
@@ -1126,7 +1105,7 @@ public abstract class LogFactory {
|
||||
logHierarchy("[BAD CL TREE] ", classLoader);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return (LogFactory) logFactoryClass.newInstance();
|
||||
|
||||
} catch (ClassNotFoundException ex) {
|
||||
@@ -1161,13 +1140,13 @@ public abstract class LogFactory {
|
||||
// appropriate exception here.
|
||||
|
||||
final boolean implementsLogFactory = implementsLogFactory(logFactoryClass);
|
||||
|
||||
|
||||
//
|
||||
// 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
|
||||
// to their native logging system.
|
||||
//
|
||||
String msg =
|
||||
// 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
|
||||
// to their native logging system.
|
||||
//
|
||||
String msg =
|
||||
"The application has specified that a custom LogFactory implementation should be used but " +
|
||||
"Class '" + factoryClass + "' cannot be converted to '"
|
||||
+ LogFactory.class.getName() + "'. ";
|
||||
@@ -1182,14 +1161,14 @@ public abstract class LogFactory {
|
||||
msg = msg + "Please check the custom implementation. ";
|
||||
}
|
||||
msg = msg + "Help can be found @http://commons.apache.org/logging/troubleshooting.html.";
|
||||
|
||||
|
||||
if (isDiagnosticsEnabled()) {
|
||||
logDiagnostic(msg);
|
||||
}
|
||||
|
||||
|
||||
throw new ClassCastException(msg);
|
||||
}
|
||||
|
||||
|
||||
// Ignore exception, continue. Presumably the classloader was the
|
||||
// TCCL; the code below will try to load the class via thisClassLoader.
|
||||
// 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
|
||||
* the classloader parameter the caller passed, and fall back
|
||||
* 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.
|
||||
*
|
||||
* Notes:
|
||||
@@ -1223,7 +1202,7 @@ public abstract class LogFactory {
|
||||
// to be generated/caught & recast properly.
|
||||
if (isDiagnosticsEnabled()) {
|
||||
logDiagnostic(
|
||||
"Unable to load factory class via classloader "
|
||||
"Unable to load factory class via classloader "
|
||||
+ objectId(classLoader)
|
||||
+ " - trying the classloader associated with this LogFactory.");
|
||||
}
|
||||
@@ -1234,9 +1213,7 @@ public abstract class LogFactory {
|
||||
if (isDiagnosticsEnabled()) {
|
||||
logDiagnostic("Unable to create LogFactory instance.");
|
||||
}
|
||||
if (logFactoryClass != null
|
||||
&& !LogFactory.class.isAssignableFrom(logFactoryClass)) {
|
||||
|
||||
if (logFactoryClass != null && !LogFactory.class.isAssignableFrom(logFactoryClass)) {
|
||||
return new LogConfigurationException(
|
||||
"The chosen LogFactory implementation does not extend LogFactory."
|
||||
+ " 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
|
||||
* 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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
private static Enumeration getResources(final ClassLoader loader, final String name) {
|
||||
PrivilegedAction action =
|
||||
PrivilegedAction action =
|
||||
new PrivilegedAction() {
|
||||
public Object run() {
|
||||
try {
|
||||
@@ -1356,9 +1333,8 @@ public abstract class LogFactory {
|
||||
}
|
||||
} catch(IOException e) {
|
||||
if (isDiagnosticsEnabled()) {
|
||||
logDiagnostic(
|
||||
"Exception while trying to find configuration file "
|
||||
+ name + ":" + e.getMessage());
|
||||
logDiagnostic("Exception while trying to find configuration file " +
|
||||
name + ":" + e.getMessage());
|
||||
}
|
||||
return null;
|
||||
} catch(NoSuchMethodError e) {
|
||||
@@ -1382,7 +1358,7 @@ public abstract class LogFactory {
|
||||
* {@code Null} is returned if the URL cannot be opened.
|
||||
*/
|
||||
private static Properties getProperties(final URL url) {
|
||||
PrivilegedAction action =
|
||||
PrivilegedAction action =
|
||||
new PrivilegedAction() {
|
||||
public Object run() {
|
||||
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
|
||||
* value for its PRIORITY property is returned. If multiple files have the
|
||||
* 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.
|
||||
* However as the priority is a new field, this change is backwards compatible.
|
||||
* <p>
|
||||
@@ -1440,7 +1416,7 @@ public abstract class LogFactory {
|
||||
* file in a shared classpath location with a priority > 0; this overrides any
|
||||
* commons-logging.properties files without priorities which are in the
|
||||
* 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) {
|
||||
Properties props = null;
|
||||
@@ -1452,14 +1428,14 @@ public abstract class LogFactory {
|
||||
if (urls == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
while (urls.hasMoreElements()) {
|
||||
URL url = (URL) urls.nextElement();
|
||||
|
||||
|
||||
Properties newProps = getProperties(url);
|
||||
if (newProps != null) {
|
||||
if (props == null) {
|
||||
propsUrl = url;
|
||||
propsUrl = url;
|
||||
props = newProps;
|
||||
String priorityStr = props.getProperty(PRIORITY_KEY);
|
||||
priority = 0.0;
|
||||
@@ -1470,7 +1446,7 @@ public abstract class LogFactory {
|
||||
if (isDiagnosticsEnabled()) {
|
||||
logDiagnostic(
|
||||
"[LOOKUP] Properties file found at '" + url + "'"
|
||||
+ " with priority " + priority);
|
||||
+ " with priority " + priority);
|
||||
}
|
||||
} else {
|
||||
String newPriorityStr = newProps.getProperty(PRIORITY_KEY);
|
||||
@@ -1483,12 +1459,12 @@ public abstract class LogFactory {
|
||||
if (isDiagnosticsEnabled()) {
|
||||
logDiagnostic(
|
||||
"[LOOKUP] Properties file at '" + url + "'"
|
||||
+ " with priority " + newPriority
|
||||
+ " with priority " + newPriority
|
||||
+ " overrides file at '" + propsUrl + "'"
|
||||
+ " with priority " + priority);
|
||||
}
|
||||
|
||||
propsUrl = url;
|
||||
propsUrl = url;
|
||||
props = newProps;
|
||||
priority = newPriority;
|
||||
} else {
|
||||
@@ -1512,13 +1488,9 @@ public abstract class LogFactory {
|
||||
|
||||
if (isDiagnosticsEnabled()) {
|
||||
if (props == null) {
|
||||
logDiagnostic(
|
||||
"[LOOKUP] No properties file of name '" + fileName
|
||||
+ "' found.");
|
||||
logDiagnostic("[LOOKUP] No properties file of name '" + fileName + "' found.");
|
||||
} else {
|
||||
logDiagnostic(
|
||||
"[LOOKUP] Properties file of name '" + fileName
|
||||
+ "' found at '" + propsUrl + '"');
|
||||
logDiagnostic("[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
|
||||
* security rights even if the calling code has not.
|
||||
* <p>
|
||||
@@ -1548,7 +1520,7 @@ public abstract class LogFactory {
|
||||
* Determines whether the user wants internal diagnostic output. If so,
|
||||
* returns an appropriate writer object. Users can enable diagnostic
|
||||
* 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() {
|
||||
String dest;
|
||||
@@ -1584,7 +1556,7 @@ public abstract class LogFactory {
|
||||
* <p>
|
||||
* By the way, sorry for the incorrect grammar, but calling this method
|
||||
* areDiagnosticsEnabled just isn't java beans style.
|
||||
*
|
||||
*
|
||||
* @return true if calls to logDiagnostic will have any effect.
|
||||
* @since 1.1
|
||||
*/
|
||||
@@ -1607,7 +1579,7 @@ public abstract class LogFactory {
|
||||
* Note that it is safe to call this method before initDiagnostics
|
||||
* is called; any output will just be ignored (as isDiagnosticsEnabled
|
||||
* will return false).
|
||||
*
|
||||
*
|
||||
* @param msg is the diagnostic message to be output.
|
||||
*/
|
||||
private static final void logDiagnostic(String msg) {
|
||||
@@ -1620,7 +1592,7 @@ public abstract class LogFactory {
|
||||
|
||||
/**
|
||||
* Write the specified message to the internal logging destination.
|
||||
*
|
||||
*
|
||||
* @param msg is the diagnostic message to be output.
|
||||
* @since 1.1
|
||||
*/
|
||||
@@ -1639,12 +1611,12 @@ public abstract class LogFactory {
|
||||
* classloader, then you may get the following output:
|
||||
* <pre>
|
||||
* Class com.acme.Foo was loaded via classloader 11111
|
||||
* ClassLoader tree: 11111 -> 22222 (SYSTEM) -> 33333 -> BOOT
|
||||
* ClassLoader tree: 11111 -> 22222 (SYSTEM) -> 33333 -> BOOT
|
||||
* </pre>
|
||||
* <p>
|
||||
* This method returns immediately if isDiagnosticsEnabled()
|
||||
* returns false.
|
||||
*
|
||||
*
|
||||
* @param clazz is the class whose classloader + tree are to be
|
||||
* output.
|
||||
*/
|
||||
@@ -1652,20 +1624,20 @@ public abstract class LogFactory {
|
||||
if (!isDiagnosticsEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
// Deliberately use System.getProperty here instead of getSystemProperty; if
|
||||
// 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] Application classpath (java.class.path): " + System.getProperty("java.class.path"));
|
||||
} catch(SecurityException ex) {
|
||||
logDiagnostic("[ENV] Security setting prevent interrogation of system classpaths.");
|
||||
}
|
||||
|
||||
|
||||
String className = clazz.getName();
|
||||
ClassLoader classLoader;
|
||||
|
||||
|
||||
try {
|
||||
classLoader = getClassLoader(clazz);
|
||||
} catch(SecurityException ex) {
|
||||
@@ -1675,9 +1647,7 @@ public abstract class LogFactory {
|
||||
return;
|
||||
}
|
||||
|
||||
logDiagnostic(
|
||||
"[ENV] Class " + className + " was loaded via classloader "
|
||||
+ objectId(classLoader));
|
||||
logDiagnostic("[ENV] Class " + className + " was loaded via classloader " + objectId(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
|
||||
* and it's hierarchy. The prefix is prepended to the message
|
||||
* and is intended to make it easier to understand the logs.
|
||||
* @param prefix
|
||||
* @param prefix
|
||||
* @param classLoader
|
||||
*/
|
||||
private static void logHierarchy(String prefix, ClassLoader classLoader) {
|
||||
@@ -1697,14 +1667,13 @@ public abstract class LogFactory {
|
||||
final String classLoaderString = classLoader.toString();
|
||||
logDiagnostic(prefix + objectId(classLoader) + " == '" + classLoaderString + "'");
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
systemClassLoader = ClassLoader.getSystemClassLoader();
|
||||
} catch(SecurityException ex) {
|
||||
logDiagnostic(
|
||||
prefix + "Security forbids determining the system classloader.");
|
||||
logDiagnostic(prefix + "Security forbids determining the system classloader.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (classLoader != null) {
|
||||
StringBuffer buf = new StringBuffer(prefix + "ClassLoader tree:");
|
||||
for(;;) {
|
||||
@@ -1737,7 +1706,7 @@ public abstract class LogFactory {
|
||||
* 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 specified object's class has overidden the toString method.
|
||||
*
|
||||
*
|
||||
* @param o may be null.
|
||||
* @return a string of form classname@hashcode, or "null" if param o is null.
|
||||
* @since 1.1
|
||||
@@ -1753,7 +1722,7 @@ public abstract class LogFactory {
|
||||
// ----------------------------------------------------------------------
|
||||
// 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
|
||||
// LogFactory instances are created, and they depend upon this
|
||||
// stuff having been set up.
|
||||
@@ -1778,7 +1747,7 @@ public abstract class LogFactory {
|
||||
// ensure each logged message has a prefix of form
|
||||
// [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
|
||||
// about the actual *instance* of LogFactory, as all methods that
|
||||
// output diagnostics from this class are static.
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
* 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 obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
*/
|
||||
|
||||
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 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.
|
||||
*
|
||||
*
|
||||
* @param name the log name (or category)
|
||||
*/
|
||||
static public Log makeNewLogInstance(String name) {
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
* 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 obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
*/
|
||||
|
||||
package org.apache.commons.logging.impl;
|
||||
|
||||
@@ -26,13 +26,13 @@ import org.apache.commons.logging.Log;
|
||||
* <p>
|
||||
* There are two ways in which this class can be used:
|
||||
* <ul>
|
||||
* <li>the instance can be constructed with an Avalon logger
|
||||
* (by calling {@link #AvalonLogger(Logger)}). In this case, it acts
|
||||
* as a simple thin wrapping implementation over the logger. This is
|
||||
* <li>the instance can be constructed with an Avalon logger
|
||||
* (by calling {@link #AvalonLogger(Logger)}). In this case, it acts
|
||||
* as a simple thin wrapping implementation over the logger. This is
|
||||
* particularly useful when using a property setter.
|
||||
* </li>
|
||||
* <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
|
||||
* to child loggers of this <code>Logger</code>.
|
||||
* </li>
|
||||
@@ -43,7 +43,7 @@ import org.apache.commons.logging.Log;
|
||||
* 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
|
||||
* 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
|
||||
* is not considered to be an incompatible change.
|
||||
*
|
||||
@@ -52,7 +52,7 @@ import org.apache.commons.logging.Log;
|
||||
*/
|
||||
public class AvalonLogger implements Log {
|
||||
|
||||
/** Ancestral Avalon logger. */
|
||||
/** Ancestral Avalon logger. */
|
||||
private static Logger defaultLogger = null;
|
||||
/** Avalon logger used to perform log. */
|
||||
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>.
|
||||
*
|
||||
*
|
||||
* @param message to log
|
||||
* @param t log this cause
|
||||
* @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>.
|
||||
*
|
||||
*
|
||||
* @param message to log.
|
||||
* @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>.
|
||||
*
|
||||
*
|
||||
* @param message to log
|
||||
* @param t log this cause
|
||||
* @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>.
|
||||
*
|
||||
*
|
||||
* @param message to log
|
||||
* @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>.
|
||||
*
|
||||
*
|
||||
* @param message to log.
|
||||
* @param t log this cause.
|
||||
* @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>.
|
||||
*
|
||||
*
|
||||
* @param message to log
|
||||
* @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>.
|
||||
*
|
||||
*
|
||||
* @param message to log
|
||||
* @param t log this cause
|
||||
* @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>.
|
||||
*
|
||||
*
|
||||
* @param message to log
|
||||
* @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>.
|
||||
*
|
||||
*
|
||||
* @param message to log.
|
||||
* @param t log this cause.
|
||||
* @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>.
|
||||
*
|
||||
*
|
||||
* @param message to log
|
||||
* @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>.
|
||||
*
|
||||
*
|
||||
* @param message to log
|
||||
* @param t log this cause
|
||||
* @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>.
|
||||
*
|
||||
*
|
||||
* @param message to log
|
||||
* @see org.apache.commons.logging.Log#warn(Object)
|
||||
*/
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
* 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 obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
*/
|
||||
|
||||
package org.apache.commons.logging.impl;
|
||||
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
* 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 obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
*/
|
||||
|
||||
package org.apache.commons.logging.impl;
|
||||
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
* 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 obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
*/
|
||||
|
||||
package org.apache.commons.logging.impl;
|
||||
|
||||
@@ -54,7 +54,7 @@ public class Log4JLogger implements Log, Serializable {
|
||||
|
||||
/** The fully qualified name of the Log4JLogger class. */
|
||||
private static final String FQCN = Log4JLogger.class.getName();
|
||||
|
||||
|
||||
/** Log to this logger */
|
||||
private transient Logger logger = null;
|
||||
|
||||
@@ -62,7 +62,7 @@ public class Log4JLogger implements Log, Serializable {
|
||||
private final String name;
|
||||
|
||||
private static final Priority traceLevel;
|
||||
|
||||
|
||||
// ------------------------------------------------------------
|
||||
// Static Initializer.
|
||||
//
|
||||
@@ -82,11 +82,11 @@ public class Log4JLogger implements Log, Serializable {
|
||||
// nope, this is log4j 1.3, so force an ExceptionInInitializerError
|
||||
throw new InstantiationError("Log4J 1.2 not available");
|
||||
}
|
||||
|
||||
|
||||
// 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
|
||||
// calls to Log.trace(...) onto the DEBUG level.
|
||||
|
||||
|
||||
Priority _traceLevel;
|
||||
try {
|
||||
_traceLevel = (Priority) Level.class.getDeclaredField("TRACE").get(null);
|
||||
@@ -111,7 +111,7 @@ public class Log4JLogger implements Log, Serializable {
|
||||
this.logger = getLogger();
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* For use with a log4j factory.
|
||||
*/
|
||||
public Log4JLogger(Logger logger ) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -5,15 +5,15 @@
|
||||
* 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 obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
*/
|
||||
|
||||
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>.
|
||||
*
|
||||
*
|
||||
* @param message to log
|
||||
* @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>.
|
||||
*
|
||||
*
|
||||
* @param message to log
|
||||
* @param t log this cause
|
||||
* @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>.
|
||||
*
|
||||
*
|
||||
* @param message to log
|
||||
* @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>.
|
||||
*
|
||||
*
|
||||
* @param message to log
|
||||
* @param t log this cause
|
||||
* @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>.
|
||||
*
|
||||
*
|
||||
* @param message to log
|
||||
* @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>.
|
||||
*
|
||||
*
|
||||
* @param message to log
|
||||
* @param t log this cause
|
||||
* @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>.
|
||||
*
|
||||
*
|
||||
* @param message to log
|
||||
* @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>.
|
||||
*
|
||||
*
|
||||
* @param message to log
|
||||
* @param t log this cause
|
||||
* @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>.
|
||||
*
|
||||
*
|
||||
* @param message to log
|
||||
* @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>.
|
||||
*
|
||||
*
|
||||
* @param message to log
|
||||
* @param t log this cause
|
||||
* @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>.
|
||||
*
|
||||
*
|
||||
* @param message to log
|
||||
* @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>.
|
||||
*
|
||||
*
|
||||
* @param message to log
|
||||
* @param t log this cause
|
||||
* @see org.apache.commons.logging.Log#fatal(Object, Throwable)
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
* 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 obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
*/
|
||||
|
||||
package org.apache.commons.logging.impl;
|
||||
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
* 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 obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
*/
|
||||
|
||||
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
|
||||
* every accessible LogFactory class that the entry in its map for the
|
||||
* current webapp's context classloader should be cleared.
|
||||
*
|
||||
*
|
||||
* @version $Id$
|
||||
* @since 1.1
|
||||
*/
|
||||
public class ServletContextCleaner implements ServletContextListener {
|
||||
|
||||
private static final Class[] RELEASE_SIGNATURE = {ClassLoader.class};
|
||||
|
||||
|
||||
/**
|
||||
* Invoked when a webapp is undeployed, this tells the LogFactory
|
||||
* 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
|
||||
// the LogFactory instance that is visible from the ancestor
|
||||
// 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.
|
||||
// These references from ancestor LogFactory classes down to
|
||||
// TCCL classloaders are held via weak references and so should
|
||||
@@ -120,13 +120,13 @@ public class ServletContextCleaner implements ServletContextListener {
|
||||
loader = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Just to be sure, invoke release on the LogFactory that is visible from
|
||||
// this ServletContextCleaner class too. This should already have been caught
|
||||
// by the above loop but just in case...
|
||||
LogFactory.release(tccl);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Invoked when a webapp is deployed. Nothing needs to be done here.
|
||||
*/
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
* 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 obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
*/
|
||||
|
||||
package org.apache.commons.logging.impl;
|
||||
|
||||
@@ -361,7 +361,7 @@ public class SimpleLog implements Log, Serializable {
|
||||
// -------------------------------------------------------- Log Implementation
|
||||
|
||||
/**
|
||||
* Logs a message with
|
||||
* Logs a message with
|
||||
* <code>org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_DEBUG</code>.
|
||||
*
|
||||
* @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>.
|
||||
*
|
||||
* @param message to log
|
||||
@@ -598,8 +598,7 @@ public class SimpleLog implements Log, Serializable {
|
||||
|
||||
// Get the thread context class loader (if there is one)
|
||||
try {
|
||||
classLoader = (ClassLoader)method.invoke(Thread.currentThread(),
|
||||
(Class[]) null);
|
||||
classLoader = (ClassLoader)method.invoke(Thread.currentThread(), (Class[]) null);
|
||||
} catch (IllegalAccessException e) {
|
||||
// ignore
|
||||
} catch (InvocationTargetException e) {
|
||||
|
||||
@@ -5,16 +5,15 @@
|
||||
* 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 obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
*/
|
||||
|
||||
package org.apache.commons.logging.impl;
|
||||
|
||||
@@ -44,17 +43,17 @@ import java.util.Set;
|
||||
* have been made with this in mind.
|
||||
* </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
|
||||
* 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)}.
|
||||
* </p>
|
||||
*
|
||||
* <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
|
||||
* references to the <code>LogFactory</code> implementation it loads
|
||||
* (rather than using a standard Hashtable instance).
|
||||
* references to the <code>LogFactory</code> implementation it loads
|
||||
* (rather than using a standard Hashtable instance).
|
||||
* Having this class used instead of <code>Hashtable</code> solves
|
||||
* 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
|
||||
@@ -64,37 +63,37 @@ import java.util.Set;
|
||||
* for method <code>LogFactory.createFactoryStore</code> for more details.</p>
|
||||
*
|
||||
* <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
|
||||
* the component loads a LogFactory instance via the component classloader
|
||||
* a reference to it gets stored in the static LogFactory.factories member,
|
||||
* keyed by the component's classloader so different components don't
|
||||
* 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
|
||||
* reference to the component's classloader from a key in the "global"
|
||||
* <code>LogFactory</code>'s factories member! If <code>LogFactory.release()</code>
|
||||
* 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
|
||||
* references weakly ensures that the classloader will be garbage collected
|
||||
* without the container performing this step. </p>
|
||||
*
|
||||
* <p>
|
||||
* <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
|
||||
* are used for its keys, it is necessary to use strong references for its values.
|
||||
* </p>
|
||||
*
|
||||
* <p> If the abstract class <code>LogFactory</code> is
|
||||
* loaded by the container classloader but a subclass of
|
||||
* <code>LogFactory</code> [LogFactory1] is loaded by the component's
|
||||
* <p> If the abstract class <code>LogFactory</code> is
|
||||
* loaded by the container classloader but a subclass of
|
||||
* <code>LogFactory</code> [LogFactory1] is loaded by the component's
|
||||
* classloader and an instance stored in the static map associated with the
|
||||
* base LogFactory class, then there is a strong reference from the LogFactory
|
||||
* class to the LogFactory1 instance (as normal) and a strong reference from
|
||||
* 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>
|
||||
*
|
||||
* <p>
|
||||
@@ -102,16 +101,16 @@ import java.util.Set;
|
||||
* loaded by a parent classloader (e.g. a server level classloader in a
|
||||
* servlet container) and a custom <code>LogFactory</code> implementation is
|
||||
* loaded by a child classloader (e.g. a web app classloader).</p>
|
||||
*
|
||||
*
|
||||
* <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,
|
||||
* however, rare. The standard LogFactoryImpl class should be sufficient
|
||||
* for most or all users.</p>
|
||||
*
|
||||
*
|
||||
* @author Brian Stansberry
|
||||
*
|
||||
*
|
||||
* @version $Id$
|
||||
* @since 1.1
|
||||
*/
|
||||
@@ -120,30 +119,29 @@ public final class WeakHashtable extends Hashtable {
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = -1546036869799732453L;
|
||||
|
||||
/**
|
||||
/**
|
||||
* The maximum number of times put() or remove() can be called before
|
||||
* the map will be purged of all cleared entries.
|
||||
*/
|
||||
private static final int MAX_CHANGES_BEFORE_PURGE = 100;
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* The maximum number of times put() or remove() can be called before
|
||||
* the map will be purged of one cleared entry.
|
||||
*/
|
||||
private static final int PARTIAL_PURGE_COUNT = 10;
|
||||
|
||||
|
||||
/* ReferenceQueue we check for gc'd keys */
|
||||
private final ReferenceQueue queue = new ReferenceQueue();
|
||||
/* Counter used to control how often we purge gc'd entries */
|
||||
private int changeCount = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a WeakHashtable with the Hashtable default
|
||||
* capacity and load factor.
|
||||
*/
|
||||
public WeakHashtable() {}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*@see Hashtable
|
||||
*/
|
||||
@@ -152,7 +150,7 @@ public final class WeakHashtable extends Hashtable {
|
||||
Referenced referenced = new Referenced(key);
|
||||
return super.containsKey(referenced);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*@see Hashtable
|
||||
*/
|
||||
@@ -160,7 +158,7 @@ public final class WeakHashtable extends Hashtable {
|
||||
purge();
|
||||
return super.elements();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*@see Hashtable
|
||||
*/
|
||||
@@ -180,7 +178,7 @@ public final class WeakHashtable extends Hashtable {
|
||||
}
|
||||
return unreferencedEntries;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*@see Hashtable
|
||||
*/
|
||||
@@ -189,7 +187,7 @@ public final class WeakHashtable extends Hashtable {
|
||||
Referenced referenceKey = new Referenced(key);
|
||||
return super.get(referenceKey);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*@see Hashtable
|
||||
*/
|
||||
@@ -206,8 +204,7 @@ public final class WeakHashtable extends Hashtable {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*@see Hashtable
|
||||
*/
|
||||
@@ -224,10 +221,10 @@ public final class WeakHashtable extends Hashtable {
|
||||
}
|
||||
return unreferencedKeys;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*@see Hashtable
|
||||
*/
|
||||
*/
|
||||
public Object put(Object key, Object value) {
|
||||
// check for nulls, ensuring semantics match superclass
|
||||
if (key == null) {
|
||||
@@ -237,7 +234,7 @@ public final class WeakHashtable extends Hashtable {
|
||||
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
|
||||
if (changeCount++ > MAX_CHANGES_BEFORE_PURGE) {
|
||||
purge();
|
||||
@@ -247,14 +244,14 @@ public final class WeakHashtable extends Hashtable {
|
||||
else if (changeCount % PARTIAL_PURGE_COUNT == 0) {
|
||||
purgeOne();
|
||||
}
|
||||
|
||||
|
||||
Referenced keyRef = new Referenced(key, queue);
|
||||
return super.put(keyRef, value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*@see Hashtable
|
||||
*/
|
||||
*/
|
||||
public void putAll(Map t) {
|
||||
if (t != null) {
|
||||
Set entrySet = t.entrySet();
|
||||
@@ -264,20 +261,20 @@ public final class WeakHashtable extends Hashtable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*@see Hashtable
|
||||
*/
|
||||
*/
|
||||
public Collection values() {
|
||||
purge();
|
||||
return super.values();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*@see Hashtable
|
||||
*/
|
||||
*/
|
||||
public Object remove(Object key) {
|
||||
// for performance reasons, only purge every
|
||||
// for performance reasons, only purge every
|
||||
// MAX_CHANGES_BEFORE_PURGE times
|
||||
if (changeCount++ > MAX_CHANGES_BEFORE_PURGE) {
|
||||
purge();
|
||||
@@ -289,31 +286,31 @@ public final class WeakHashtable extends Hashtable {
|
||||
}
|
||||
return super.remove(new Referenced(key));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*@see Hashtable
|
||||
*/
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
purge();
|
||||
return super.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*@see Hashtable
|
||||
*/
|
||||
*/
|
||||
public int size() {
|
||||
purge();
|
||||
return super.size();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*@see Hashtable
|
||||
*/
|
||||
*/
|
||||
public String toString() {
|
||||
purge();
|
||||
return super.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see Hashtable
|
||||
*/
|
||||
@@ -322,7 +319,7 @@ public final class WeakHashtable extends Hashtable {
|
||||
purge();
|
||||
super.rehash();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Purges all entries whose wrapped keys
|
||||
* 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.
|
||||
*/
|
||||
private void purgeOne() {
|
||||
|
||||
synchronized (queue) {
|
||||
WeakKey key = (WeakKey) queue.poll();
|
||||
if (key != null) {
|
||||
@@ -349,33 +345,33 @@ public final class WeakHashtable extends Hashtable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Entry implementation */
|
||||
private final static class Entry implements Map.Entry {
|
||||
|
||||
|
||||
private final Object key;
|
||||
private final Object value;
|
||||
|
||||
|
||||
private Entry(Object key, Object value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
public boolean equals(Object o) {
|
||||
boolean result = false;
|
||||
if (o != null && o instanceof Map.Entry) {
|
||||
Map.Entry entry = (Map.Entry) o;
|
||||
result = (getKey()==null ?
|
||||
entry.getKey() == null :
|
||||
entry.getKey() == null :
|
||||
getKey().equals(entry.getKey()))
|
||||
&&
|
||||
(getValue()==null ?
|
||||
entry.getValue() == null :
|
||||
entry.getValue() == null :
|
||||
getValue().equals(entry.getValue()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
|
||||
return (getKey()==null ? 0 : getKey().hashCode()) ^
|
||||
@@ -385,36 +381,35 @@ public final class WeakHashtable extends Hashtable {
|
||||
public Object setValue(Object value) {
|
||||
throw new UnsupportedOperationException("Entry.setValue is not supported.");
|
||||
}
|
||||
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
public Object getKey() {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Wrapper giving correct symantics for equals and hashcode */
|
||||
private final static class Referenced {
|
||||
|
||||
|
||||
private final WeakReference reference;
|
||||
private final int hashCode;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @throws NullPointerException if referant is <code>null</code>
|
||||
*/
|
||||
*/
|
||||
private Referenced(Object referant) {
|
||||
reference = new WeakReference(referant);
|
||||
// Calc a permanent hashCode so calls to Hashtable.remove()
|
||||
// work if the WeakReference has been cleared
|
||||
hashCode = referant.hashCode();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @throws NullPointerException if key is <code>null</code>
|
||||
*/
|
||||
private Referenced(Object key, ReferenceQueue queue) {
|
||||
@@ -424,34 +419,34 @@ public final class WeakHashtable extends Hashtable {
|
||||
hashCode = key.hashCode();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public int hashCode() {
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
|
||||
private Object getValue() {
|
||||
return reference.get();
|
||||
}
|
||||
|
||||
|
||||
public boolean equals(Object o) {
|
||||
boolean result = false;
|
||||
if (o instanceof Referenced) {
|
||||
Referenced otherKey = (Referenced) o;
|
||||
Object thisKeyValue = getValue();
|
||||
Object otherKeyValue = otherKey.getValue();
|
||||
if (thisKeyValue == null) {
|
||||
if (thisKeyValue == null) {
|
||||
result = otherKeyValue == null;
|
||||
|
||||
|
||||
// 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
|
||||
// objects could test equal but have different hashcodes.
|
||||
// We can reduce (not eliminate) the chance of this
|
||||
// happening by comparing hashcodes.
|
||||
result = result && this.hashCode() == otherKey.hashCode();
|
||||
// In any case, as our c'tor does not allow null referants
|
||||
// and Hashtable does not do equality checks between
|
||||
// existing keys, normal hashtable operations should never
|
||||
// and Hashtable does not do equality checks between
|
||||
// existing keys, normal hashtable operations should never
|
||||
// result in an equals comparison between null referants
|
||||
}
|
||||
else
|
||||
@@ -462,7 +457,7 @@ public final class WeakHashtable extends Hashtable {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* WeakReference subclass that holds a hard reference to an
|
||||
* 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 Referenced referenced;
|
||||
|
||||
private WeakKey(Object key,
|
||||
|
||||
private WeakKey(Object key,
|
||||
ReferenceQueue queue,
|
||||
Referenced referenced) {
|
||||
super(key, queue);
|
||||
this.referenced = referenced;
|
||||
}
|
||||
|
||||
|
||||
private Referenced getReferenced() {
|
||||
return referenced;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user