### Eclipse Workspace Patch 1.0
#P ch.qos.logback.classic
Index: source-bundle/ch/qos/logback/classic/selector/servlet/ContextDetachingSCL.java
===================================================================
RCS file: /cvsroot/tools/org.eclipse.orbit/ch.qos.logback.classic/source-bundle/ch/qos/logback/classic/selector/servlet/Attic/ContextDetachingSCL.java,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 ContextDetachingSCL.java
--- source-bundle/ch/qos/logback/classic/selector/servlet/ContextDetachingSCL.java	21 Jan 2010 13:35:08 -0000	1.1.2.1
+++ source-bundle/ch/qos/logback/classic/selector/servlet/ContextDetachingSCL.java	4 Feb 2010 09:51:40 -0000
@@ -21,27 +21,27 @@
 import javax.servlet.ServletContextListener;
 
 import org.slf4j.Logger;
-import org.slf4j.impl.StaticLoggerBinder;
 
 import ch.qos.logback.classic.LoggerContext;
 import ch.qos.logback.classic.selector.ContextSelector;
+import ch.qos.logback.classic.util.ContextSelectorUtil;
 import ch.qos.logback.classic.util.JNDIUtil;
 
 public class ContextDetachingSCL implements ServletContextListener {
 
   public void contextDestroyed(ServletContextEvent servletContextEvent) {
     String loggerContextName = null;
-    
+
     try {
       Context ctx = JNDIUtil.getInitialContext();
       loggerContextName = (String) JNDIUtil.lookup(ctx, JNDI_CONTEXT_NAME);
     } catch (NamingException ne) {
     }
-    
+
     if (loggerContextName != null) {
       System.out.println("About to detach context named " + loggerContextName);
-      
-      ContextSelector selector = StaticLoggerBinder.getSingleton().getContextSelector();
+
+      ContextSelector selector = ContextSelectorUtil.getSingleton();
       LoggerContext context = selector.detachLoggerContext(loggerContextName);
       if (context != null) {
         Logger logger = context.getLogger(Logger.ROOT_LOGGER_NAME);
Index: source-bundle/ch/qos/logback/classic/selector/servlet/LoggerContextFilter.java
===================================================================
RCS file: /cvsroot/tools/org.eclipse.orbit/ch.qos.logback.classic/source-bundle/ch/qos/logback/classic/selector/servlet/Attic/LoggerContextFilter.java,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 LoggerContextFilter.java
--- source-bundle/ch/qos/logback/classic/selector/servlet/LoggerContextFilter.java	21 Jan 2010 13:35:08 -0000	1.1.2.1
+++ source-bundle/ch/qos/logback/classic/selector/servlet/LoggerContextFilter.java	4 Feb 2010 09:51:40 -0000
@@ -23,20 +23,20 @@
 import javax.servlet.ServletResponse;
 
 import org.slf4j.LoggerFactory;
-import org.slf4j.impl.StaticLoggerBinder;
 
 import ch.qos.logback.classic.LoggerContext;
 import ch.qos.logback.classic.selector.ContextJNDISelector;
 import ch.qos.logback.classic.selector.ContextSelector;
+import ch.qos.logback.classic.util.ContextSelectorUtil;
 
 /**
  * A servlet filter that puts the environment-dependend
  * LoggerContext in a Threadlocal variable.
- * 
+ *
  * It removes it after the request is processed.
  *
  * To use it, add the following lines to a web.xml file
- * 
+ *
  * <filter>
  *   <filter-name>LoggerContextFilter</filter-name>
  *   <filter-class>
@@ -47,7 +47,7 @@
  *   <filter-name>LoggerContextFilter</filter-name>
  *   <url-pattern>/*</url-pattern>
  * </filter-mapping>
- * 
+ *
  * @author S&eacute;bastien Pennec
  */
 public class LoggerContextFilter implements Filter {
@@ -60,7 +60,7 @@
       FilterChain chain) throws IOException, ServletException {
 
     LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
-    ContextSelector selector = StaticLoggerBinder.getSingleton().getContextSelector();
+    ContextSelector selector = ContextSelectorUtil.getSingleton();
     ContextJNDISelector sel = null;
 
     if (selector instanceof ContextJNDISelector) {
Index: source-bundle/ch/qos/logback/classic/util/ContextSelectorUtil.java
===================================================================
RCS file: source-bundle/ch/qos/logback/classic/util/ContextSelectorUtil.java
diff -N source-bundle/ch/qos/logback/classic/util/ContextSelectorUtil.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ source-bundle/ch/qos/logback/classic/util/ContextSelectorUtil.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,94 @@
+/**
+ * Copyright (c) 2010 Gunnar Wagenknecht and others.
+ * All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     Gunnar Wagenknecht - initial API and implementation
+ */
+package ch.qos.logback.classic.util;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
+import ch.qos.logback.classic.ClassicConstants;
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.selector.ContextJNDISelector;
+import ch.qos.logback.classic.selector.ContextSelector;
+import ch.qos.logback.classic.selector.DefaultContextSelector;
+import ch.qos.logback.core.util.Loader;
+import ch.qos.logback.core.util.OptionHelper;
+
+/**
+ * Class for selecting and initializing ContextSelector
+ */
+public class ContextSelectorUtil {
+
+	private static ContextSelector contextSelector;
+
+	/**
+	 * Instantiate the context selector class designated by the user. The
+	 * selector must have a constructor taking a LoggerContext instance as an
+	 * argument.
+	 * 
+	 * @param defaultLoggerContext
+	 * @param contextSelectorStr
+	 * @return an instance of the designated context selector class
+	 * @throws ClassNotFoundException
+	 * @throws SecurityException
+	 * @throws NoSuchMethodException
+	 * @throws IllegalArgumentException
+	 * @throws InstantiationException
+	 * @throws IllegalAccessException
+	 * @throws InvocationTargetException
+	 */
+	static ContextSelector dynamicalContextSelector(final LoggerContext defaultLoggerContext, final String contextSelectorStr) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
+		final Class<?> contextSelectorClass = Loader.loadClass(contextSelectorStr);
+		final Constructor cons = contextSelectorClass.getConstructor(new Class[] { LoggerContext.class });
+		return (ContextSelector) cons.newInstance(defaultLoggerContext);
+	}
+
+	/**
+	 * Returns the singleton instance.
+	 * 
+	 * @return the singleton instance
+	 */
+	public static ContextSelector getSingleton() {
+		final ContextSelector selector = contextSelector;
+		if (null == selector) {
+			// TODO should we synchronize here? this depends on parallel initialization ... might never occur
+			throw new IllegalStateException("not initialized");
+		}
+		return selector;
+	}
+
+	/**
+	 * Initializes the singleton instance.
+	 * 
+	 * @param defaultLoggerContext
+	 *            the default logger context
+	 * @throws IllegalStateException
+	 *             if already initialized
+	 * @throws Exception
+	 *             if a context selector could not be initialized
+	 */
+	public static synchronized void initialize(final LoggerContext defaultLoggerContext) throws IllegalStateException, Exception {
+		if (null != contextSelector) {
+			throw new IllegalStateException("already initialized");
+		}
+
+		// See if a special context selector is needed
+		final String contextSelectorStr = OptionHelper.getSystemProperty(ClassicConstants.LOGBACK_CONTEXT_SELECTOR);
+		if (contextSelectorStr == null) {
+			contextSelector = new DefaultContextSelector(defaultLoggerContext);
+		} else if (contextSelectorStr.equals("JNDI")) {
+			// if jndi is specified, let's use the appropriate class
+			contextSelector = new ContextJNDISelector(defaultLoggerContext);
+		} else {
+			contextSelector = dynamicalContextSelector(defaultLoggerContext, contextSelectorStr);
+		}
+	}
+}
#P ch.qos.logback.slf4j
Index: source-bundle/org/slf4j/impl/StaticLoggerBinder.java
===================================================================
RCS file: /cvsroot/tools/org.eclipse.orbit/ch.qos.logback.slf4j/source-bundle/org/slf4j/impl/Attic/StaticLoggerBinder.java,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 StaticLoggerBinder.java
--- source-bundle/org/slf4j/impl/StaticLoggerBinder.java	21 Jan 2010 13:34:42 -0000	1.1.2.1
+++ source-bundle/org/slf4j/impl/StaticLoggerBinder.java	4 Feb 2010 09:51:43 -0000
@@ -13,31 +13,24 @@
  */
 package org.slf4j.impl;
 
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-
 import org.slf4j.ILoggerFactory;
 import org.slf4j.LoggerFactory;
 import org.slf4j.helpers.Util;
 import org.slf4j.spi.LoggerFactoryBinder;
 
-import ch.qos.logback.classic.ClassicConstants;
 import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.selector.ContextJNDISelector;
 import ch.qos.logback.classic.selector.ContextSelector;
-import ch.qos.logback.classic.selector.DefaultContextSelector;
 import ch.qos.logback.classic.util.ContextInitializer;
+import ch.qos.logback.classic.util.ContextSelectorUtil;
 import ch.qos.logback.core.CoreConstants;
 import ch.qos.logback.core.joran.spi.JoranException;
-import ch.qos.logback.core.util.Loader;
-import ch.qos.logback.core.util.OptionHelper;
 import ch.qos.logback.core.util.StatusPrinter;
 
 /**
- * 
+ *
  * The binding of {@link LoggerFactory} class with an actual instance of
  * {@link ILoggerFactory} is performed using information returned by this class.
- * 
+ *
  * @author <a href="http://www.qos.ch/log4j/">Ceki G&uuml;lc&uuml;</a>
  */
 public class StaticLoggerBinder implements LoggerFactoryBinder {
@@ -93,18 +86,9 @@
       }
       StatusPrinter.printInCaseOfErrorsOrWarnings(defaultLoggerContext);
 
-      // See if a special context selector is needed
-      String contextSelectorStr = OptionHelper
-          .getSystemProperty(ClassicConstants.LOGBACK_CONTEXT_SELECTOR);
-      if (contextSelectorStr == null) {
-        contextSelector = new DefaultContextSelector(defaultLoggerContext);
-      } else if (contextSelectorStr.equals("JNDI")) {
-        // if jndi is specified, let's use the appropriate class
-        contextSelector = new ContextJNDISelector(defaultLoggerContext);
-      } else {
-        contextSelector = dynamicalContextSelector(defaultLoggerContext,
-            contextSelectorStr);
-      }
+      // Initialize context selector
+      ContextSelectorUtil.initialize(defaultLoggerContext);
+      contextSelector = ContextSelectorUtil.getSingleton();
       initialized = true;
     } catch (Throwable t) {
       // we should never get here
@@ -113,32 +97,6 @@
     }
   }
 
-  /**
-   * Intantiate the context selector class designated by the user. The selector
-   * must have a constructor taking a LoggerContext instance as an argument.
-   * 
-   * @param defaultLoggerContext
-   * @param contextSelectorStr
-   * @return an instance of the designated context selector class
-   * @throws ClassNotFoundException
-   * @throws SecurityException
-   * @throws NoSuchMethodException
-   * @throws IllegalArgumentException
-   * @throws InstantiationException
-   * @throws IllegalAccessException
-   * @throws InvocationTargetException
-   */
-  static ContextSelector dynamicalContextSelector(
-      LoggerContext defaultLoggerContext, String contextSelectorStr)
-      throws ClassNotFoundException, SecurityException, NoSuchMethodException,
-      IllegalArgumentException, InstantiationException, IllegalAccessException,
-      InvocationTargetException {
-    Class<?> contextSelectorClass = Loader.loadClass(contextSelectorStr);
-    Constructor cons = contextSelectorClass
-        .getConstructor(new Class[] { LoggerContext.class });
-    return (ContextSelector) cons.newInstance(defaultLoggerContext);
-  }
-
   public ILoggerFactory getLoggerFactory() {
     if (!initialized) {
       return defaultLoggerContext;
@@ -157,7 +115,7 @@
 
   /**
    * Return the {@link ContextSelector} instance in use.
-   * 
+   *
    * @return the ContextSelector instance in use
    */
   public ContextSelector getContextSelector() {
