KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > spi > persistence > utility > logging > AbstractLoggerFactory


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * AbstractLoggerFactory.java
26  *
27  * Created on May 13, 2002, 10:15 PM
28  */

29
30 package com.sun.jdo.spi.persistence.utility.logging;
31
32 import java.util.Map JavaDoc;
33 import java.util.HashMap JavaDoc;
34
35 /**
36  *
37  * @author Rochelle Raccah
38  * @version %I%
39  */

40 abstract public class AbstractLoggerFactory implements LoggerFactory
41 {
42     private final static String JavaDoc _domainPrefix = "com.sun.jdo."; //NOI18N
43

44     private final static Map JavaDoc _loggerCache = new HashMap JavaDoc();
45
46     private static final String JavaDoc _bundleName =
47         "com.sun.jdo.spi.persistence.utility.logging.Bundle"; // NOI18N
48

49
50     /** Get the error logger which is used to log things during creation of
51      * loggers.
52      */

53     protected static Logger getErrorLogger ()
54     {
55         return LogHelper.getLogger("", _bundleName, // NOI18N
56
AbstractLoggerFactory.class.getClassLoader());
57     }
58
59     /** Get a Logger. The class that implements this interface is responsible
60      * for creating a logger for the named component.
61      * The bundle name and class loader are passed to allow the implementation
62      * to properly find and construct the internationalization bundle.
63      * @param relativeLoggerName the relative name of this logger
64      * @param bundleName the fully qualified name of the resource bundle
65      * @param loader the class loader used to load the resource bundle, or null
66      * @return the logger
67      */

68     public synchronized Logger getLogger (String JavaDoc relativeLoggerName,
69         String JavaDoc bundleName, ClassLoader JavaDoc loader)
70     {
71         String JavaDoc absoluteLoggerName = getAbsoluteLoggerName(relativeLoggerName);
72         Logger value = (Logger)_loggerCache.get(absoluteLoggerName);
73
74         if (value == null)
75         {
76             value = createLogger(absoluteLoggerName, bundleName, loader);
77
78             if (value != null)
79                 _loggerCache.put(absoluteLoggerName, value);
80         }
81
82         return value;
83     }
84
85     /** Create a new Logger. Subclasses are responsible for creating a
86      * logger for the named component. The bundle name and class loader
87      * are passed to allow the implementation to properly find and
88      * construct the internationalization bundle.
89      * @param absoluteLoggerName the absolute name of this logger
90      * @param bundleName the fully qualified name of the resource bundle
91      * @param loader the class loader used to load the resource bundle, or null
92      * @return the logger
93      */

94     abstract protected Logger createLogger (String JavaDoc absoluteLoggerName,
95         String JavaDoc bundleName, ClassLoader JavaDoc loader);
96
97     protected String JavaDoc getDomainRoot () { return _domainPrefix; }
98
99     protected String JavaDoc getAbsoluteLoggerName (String JavaDoc relativeLoggerName)
100     {
101         return (relativeLoggerName.startsWith("java") ? //NOI18N
102
relativeLoggerName : (getDomainRoot() + relativeLoggerName));
103     }
104 }
105
Popular Tags