Source Code Cross Referenced for LoggerFactory.java in  » GIS » GeoTools-2.4.1 » org » geotools » util » logging » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » GeoTools 2.4.1 » org.geotools.util.logging 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2006-2007, Geotools Project Managment Committee (PMC)
005:         *
006:         *    This library is free software; you can redistribute it and/or
007:         *    modify it under the terms of the GNU Lesser General Public
008:         *    License as published by the Free Software Foundation; either
009:         *    version 2.1 of the License, or (at your option) any later version.
010:         *
011:         *    This library is distributed in the hope that it will be useful,
012:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *    Lesser General Public License for more details.
015:         */
016:        package org.geotools.util.logging;
017:
018:        import java.util.logging.Logger;
019:        import org.geotools.util.WeakValueHashMap;
020:
021:        /**
022:         * A factory for Java {@link Logger} wrapping an other logging framework. This factory is used
023:         * only when wanting to log to an other framework than Java logging. The {@link #getLogger}
024:         * method returns some subclass of {@link Logger} (typicallly {@link LoggerAdapter}) that
025:         * forward directly all log methods to an other framework.
026:         *
027:         * @since 2.4
028:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/metadata/src/main/java/org/geotools/util/logging/LoggerFactory.java $
029:         * @version $Id: LoggerFactory.java 27891 2007-11-14 14:10:48Z desruisseaux $
030:         * @author Martin Desruisseaux
031:         *
032:         * @see Logging
033:         * @see LoggerAdapter
034:         */
035:        public abstract class LoggerFactory {
036:            /**
037:             * The logger class. We ask for this information right at construction time in order to
038:             * force a {@link NoClassDefFoundError} early rather than only the first time a message
039:             * is logged.
040:             */
041:            private final Class loggerClass;
042:
043:            /**
044:             * The loggers created up to date.
045:             */
046:            private final WeakValueHashMap loggers;
047:
048:            /**
049:             * Creates a new factory.
050:             *
051:             * @param loggerClass The class of the wrapped logger.
052:             */
053:            protected LoggerFactory(final Class loggerClass) {
054:                this .loggerClass = loggerClass;
055:                loggers = new WeakValueHashMap();
056:            }
057:
058:            /**
059:             * Returns the logger of the specified name, or {@code null}. If this method has already been
060:             * invoked previously with the same {@code name} argument, then it may returns the same logger
061:             * provided that:
062:             * <ul>
063:             *   <li>the logger has not yet been garbage collected;</li>
064:             *   <li>the implementation instance (Log4J, SLF4J, <cite>etc.</cite>) returned by
065:             *       <code>{@linkplain #getImplementation getImplementation}(name)</code> has
066:             *       not changed.</li>
067:             * </ul>
068:             * Otherwise this method returns a new {@code Logger} instance, or {@code null} if the
069:             * standard Java logging framework should be used.
070:             *
071:             * @param  name The name of the logger.
072:             * @return The logger, or {@code null}.
073:             */
074:            public Logger getLogger(final String name) {
075:                final Object target = getImplementation(name);
076:                if (target == null) {
077:                    return null;
078:                }
079:                synchronized (loggers) {
080:                    Logger logger = (Logger) loggers.get(name);
081:                    if (logger == null || !target.equals(unwrap(logger))) {
082:                        logger = wrap(name, target);
083:                        loggers.put(name, logger);
084:                    }
085:                    return logger;
086:                }
087:            }
088:
089:            /**
090:             * Returns the base class of objects to be returned by {@link #getImplementation}. The
091:             * class depends on the underlying logging framework (Log4J, SLF4J, <cite>etc.</cite>).
092:             */
093:            public Class getImplementationClass() {
094:                return loggerClass;
095:            }
096:
097:            /**
098:             * Returns the implementation to use for the logger of the specified name. The object to be
099:             * returned depends on the logging framework (Log4J, SLF4J, <cite>etc.</cite>). If the target
100:             * framework redirects logging events to Java logging, then this method should returns
101:             * {@code null} since we should not use wrapper at all.
102:             *
103:             * @param  name The name of the logger.
104:             * @return The logger as an object of the target logging framework (Log4J, SLF4J,
105:             *         <cite>etc.</cite>), or {@code null} if the target framework would redirect
106:             *         to the Java logging framework.
107:             */
108:            protected abstract Object getImplementation(String name);
109:
110:            /**
111:             * Wraps the specified {@linkplain #getImplementation implementation} in a Java logger.
112:             *
113:             * @param  name The name of the logger.
114:             * @param  implementation An implementation returned by {@link #getImplementation}.
115:             * @return A new logger wrapping the specified implementation.
116:             * @throws ClassCastException if the given implementation is not an instance
117:             *         of the expected class.
118:             */
119:            protected abstract Logger wrap(String name, Object implementation)
120:                    throws ClassCastException;
121:
122:            /**
123:             * Returns the {@linkplain #getImplementation implementation} wrapped by the specified logger,
124:             * or {@code null} if none. If the specified logger is not an instance of the expected class,
125:             * then this method should returns {@code null}.
126:             *
127:             * @param  logger The logger to test.
128:             * @return The implementation wrapped by the specified logger, or {@code null} if none.
129:             */
130:            protected abstract Object unwrap(Logger logger);
131:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.