Revision: 8473
Author: [email protected]
Date: Tue Aug 3 17:17:07 2010
Log: Rollback of:
Split LogManager class into an set of Impl classes so that any LogManager
calls
in code will compile out cleanly when logging is disabled
Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=8473
Deleted:
/trunk/user/src/com/google/gwt/logging/impl/LogManagerImpl.java
/trunk/user/src/com/google/gwt/logging/impl/LogManagerImplNull.java
/trunk/user/src/com/google/gwt/logging/impl/LogManagerImplRegular.java
Modified:
/trunk/user/src/com/google/gwt/logging/LogImpl.gwt.xml
/trunk/user/super/com/google/gwt/emul/java/util/logging/LogManager.java
=======================================
--- /trunk/user/src/com/google/gwt/logging/impl/LogManagerImpl.java Thu
Aug 5 19:03:31 2010
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright 2010 Google Inc.
- *
- * Licensed 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 com.google.gwt.logging.impl;
-
-import java.util.logging.LogManager;
-import java.util.logging.Logger;
-
-/**
- * Interface for the implementation of LogManager. We use a
LogManagerImplNull
- * to ensure that logging code compiles out when logging is disabled, and a
- * LogManagerImplRegular to provide normal functionality when logging is
enabled
- */
-public interface LogManagerImpl {
- boolean addLogger(Logger logger);
- Logger getLogger(String name);
- LogManager getLogManager();
-}
=======================================
--- /trunk/user/src/com/google/gwt/logging/impl/LogManagerImplNull.java Thu
Aug 5 19:03:31 2010
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2010 Google Inc.
- *
- * Licensed 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 com.google.gwt.logging.impl;
-
-import java.util.logging.LogManager;
-import java.util.logging.Logger;
-
-/**
- * Implementation for the LogManager class when logging is disabled.
- */
-public class LogManagerImplNull {
-
- boolean addLogger(Logger logger) {
- return false;
- }
-
- Logger getLogger(String name) {
- return null;
- }
-
- LogManager getLogManager() {
- return null;
- }
-}
=======================================
--- /trunk/user/src/com/google/gwt/logging/impl/LogManagerImplRegular.java
Thu Aug 5 19:03:31 2010
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright 2010 Google Inc.
- *
- * Licensed 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 com.google.gwt.logging.impl;
-
-import java.util.HashMap;
-import java.util.logging.Level;
-import java.util.logging.LogManager;
-import java.util.logging.Logger;
-
-/**
- * Implementation for the LogManager class when logging is enabled.
- */
-public class LogManagerImplRegular {
-
- /**
- * Since the Impl class is in a different package than the LogManager
class,
- * we need to work around the fact that the Impl class cannot access the
- * protected constructor.
- */
- private static class LogManagerWithExposedConstructor extends LogManager
{
- public LogManagerWithExposedConstructor() {
- super();
- }
- }
-
- /**
- * Since the Logger constructor is protected, the LogManager cannot
create
- * one directly, so we create a RootLogger which has an exposed
constructor.
- */
- private class RootLogger extends Logger {
- public RootLogger() {
- super("", null);
- setLevel(Level.ALL);
- }
- }
-
- private static LogManager singleton;
-
- public static LogManager getLogManager() {
- if (singleton == null) {
- singleton = new LogManagerWithExposedConstructor();
- }
- return singleton;
- }
-
- private HashMap<String, Logger> loggerList;
- private Logger rootLogger;
-
- public LogManagerImplRegular() {
- loggerList = new HashMap<String, Logger>();
- rootLogger = new RootLogger();
- loggerList.put("", rootLogger);
- }
-
- public boolean addLogger(Logger logger) {
- if (getLogger(logger.getName()) != null) {
- return false;
- }
- addLoggerWithoutDuplicationChecking(logger);
- return true;
- }
-
- public Logger getLogger(String name) {
- return loggerList.get(name);
- }
-
- /**
- * Helper function to add a logger when we have already determined that
it
- * does not exist. When we add a logger, we recursively add all of it's
- * ancestors. Since loggers do not get removed, logger creation is
cheap,
- * and there are not usually too many loggers in an ancestry chain,
- * this is a simple way to ensure that the parent/child relationships
are
- * always correctly set up.
- */
- private void addLoggerWithoutDuplicationChecking(Logger logger) {
- String name = logger.getName();
- String parentName = name.substring(0, Math.max(0,
name.lastIndexOf('.')));
- Logger parent = getOrAddLogger(parentName);
- loggerList.put(logger.getName(), logger);
- logger.setParent(parent);
- }
-
- /**
- * Helper function to create a logger if it does not exist since the
public
- * APIs for getLogger and addLogger make it difficult to use those
functions
- * for this.
- */
- private Logger getOrAddLogger(String name) {
- Logger logger = getLogger(name);
- if (logger == null) {
- Logger newLogger = new LoggerWithExposedConstructor(name);
- addLoggerWithoutDuplicationChecking(newLogger);
- return newLogger;
- }
- return logger;
- }
-}
=======================================
--- /trunk/user/src/com/google/gwt/logging/LogImpl.gwt.xml Thu Aug 5
19:03:31 2010
+++ /trunk/user/src/com/google/gwt/logging/LogImpl.gwt.xml Tue Aug 3
17:17:07 2010
@@ -3,15 +3,10 @@
<!-- Set up and handle the gwt.logging property -->
<define-property name="gwt.logging.enabled" values="TRUE, FALSE" />
-
<replace-with class="com.google.gwt.logging.impl.LoggerImplRegular">
<when-type-is class="com.google.gwt.logging.impl.LoggerImplNull"/>
<when-property-is name="gwt.logging.enabled" value="TRUE" />
</replace-with>
- <replace-with class="com.google.gwt.logging.impl.LogManagerImplRegular">
- <when-type-is class="com.google.gwt.logging.impl.LogManagerImplNull"/>
- <when-property-is name="gwt.logging.enabled" value="TRUE" />
- </replace-with>
<replace-with class="com.google.gwt.logging.impl.LevelImplRegular">
<when-type-is class="com.google.gwt.logging.impl.LevelImplNull"/>
<when-property-is name="gwt.logging.enabled" value="TRUE" />
=======================================
--- /trunk/user/super/com/google/gwt/emul/java/util/logging/LogManager.java
Thu Aug 5 19:03:31 2010
+++ /trunk/user/super/com/google/gwt/emul/java/util/logging/LogManager.java
Tue Aug 3 17:17:07 2010
@@ -16,9 +16,7 @@
package java.util.logging;
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.logging.impl.LogManagerImpl;
-import com.google.gwt.logging.impl.LogManagerImplNull;
+import java.util.HashMap;
/**
* An emulation of the java.util.logging.LogManager class. See
@@ -26,25 +24,76 @@
* The Java API doc for details</a>
*/
public class LogManager {
- private static LogManagerImpl staticImpl =
- GWT.create(LogManagerImplNull.class);
-
+ /**
+ * Since the Logger constructor is protected, the LogManager cannot
create
+ * one directly, so we create a RootLogger which has an exposed
constructor.
+ */
+ private class RootLogger extends Logger {
+ public RootLogger() {
+ super("", null);
+ setLevel(Level.ALL);
+ }
+ }
+
+ private static LogManager singleton;
+
public static LogManager getLogManager() {
- return staticImpl.getLogManager();
+ if (singleton == null) {
+ singleton = new LogManager();
+ }
+ return singleton;
}
- private LogManagerImpl impl;
+ private HashMap<String, Logger> loggerList;
+ private Logger rootLogger;
protected LogManager() {
- impl = GWT.create(LogManagerImplNull.class);
+ loggerList = new HashMap<String, Logger>();
+ rootLogger = new RootLogger();
+ loggerList.put("", rootLogger);
}
public boolean addLogger(Logger logger) {
- return impl.addLogger(logger);
+ if (getLogger(logger.getName()) != null) {
+ return false;
+ }
+ addLoggerWithoutDuplicationChecking(logger);
+ return true;
}
public Logger getLogger(String name) {
- return impl.getLogger(name);
+ return loggerList.get(name);
+ }
+
+ /**
+ * Helper function to add a logger when we have already determined that
it
+ * does not exist. When we add a logger, we recursively add all of it's
+ * ancestors. Since loggers do not get removed, logger creation is
cheap,
+ * and there are not usually too many loggers in an ancestry chain,
+ * this is a simple way to ensure that the parent/child relationships
are
+ * always correctly set up.
+ */
+ private void addLoggerWithoutDuplicationChecking(Logger logger) {
+ String name = logger.getName();
+ String parentName = name.substring(0, Math.max(0,
name.lastIndexOf('.')));
+ Logger parent = getOrAddLogger(parentName);
+ loggerList.put(logger.getName(), logger);
+ logger.setParent(parent);
+ }
+
+ /**
+ * Helper function to create a logger if it does not exist since the
public
+ * APIs for getLogger and addLogger make it difficult to use those
functions
+ * for this.
+ */
+ private Logger getOrAddLogger(String name) {
+ Logger logger = getLogger(name);
+ if (logger == null) {
+ Logger newLogger = new Logger(name, null);
+ addLoggerWithoutDuplicationChecking(newLogger);
+ return newLogger;
+ }
+ return logger;
}
/* Not Implemented */
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors