EMMA Coverage Report (generated Mon Jul 24 20:22:52 CDT 2006)
[all classes][com.mysql.jdbc.log]

COVERAGE SUMMARY FOR SOURCE FILE [LogFactory.java]

nameclass, %method, %block, %line, %
LogFactory.java100% (1/1)50%  (1/2)23%  (36/156)29%  (7/24)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class LogFactory100% (1/1)50%  (1/2)23%  (36/156)29%  (7/24)
LogFactory (): void 0%   (0/1)0%   (0/3)0%   (0/1)
getLogger (String, String): Log 100% (1/1)24%  (36/153)30%  (7/23)

1/*
2 Copyright (C) 2002-2004 MySQL AB
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of version 2 of the GNU General Public License as 
6 published by the Free Software Foundation.
7 
8 There are special exceptions to the terms and conditions of the GPL 
9 as it is applied to this software. View the full text of the 
10 exception in file EXCEPTIONS-CONNECTOR-J in the directory of this 
11 software distribution.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 
22 
23 
24 */
25package com.mysql.jdbc.log;
26 
27import java.lang.reflect.Constructor;
28import java.lang.reflect.InvocationTargetException;
29import java.sql.SQLException;
30 
31import com.mysql.jdbc.SQLError;
32 
33/**
34 * Creates instances of loggers for the driver to use.
35 * 
36 * @author Mark Matthews
37 * 
38 * @version $Id: LogFactory.java 4946 2006-02-17 12:44:36 -0600 (Fri, 17 Feb 2006) mmatthews $
39 */
40public class LogFactory {
41 
42        /**
43         * Returns a logger instance of the given class, with the given instance
44         * name.
45         * 
46         * @param className
47         *            the class to instantiate
48         * @param instanceName
49         *            the instance name
50         * @return a logger instance
51         * @throws SQLException
52         *             if unable to create a logger instance
53         */
54        public static Log getLogger(String className, String instanceName)
55                        throws SQLException {
56 
57                if (className == null) {
58                        throw SQLError.createSQLException("Logger class can not be NULL",
59                                        SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
60                }
61 
62                if (instanceName == null) {
63                        throw SQLError.createSQLException("Logger instance name can not be NULL",
64                                        SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
65                }
66 
67                try {
68                        Class loggerClass = null;
69                        
70                        try {
71                                loggerClass = Class.forName(className);
72                        } catch (ClassNotFoundException nfe) {
73                                loggerClass = Class.forName(Log.class.getPackage().getName() + "." + className);
74                        }
75                
76                        Constructor constructor = loggerClass
77                                        .getConstructor(new Class[] { String.class });
78 
79                        return (Log) constructor.newInstance(new Object[] { instanceName });
80                } catch (ClassNotFoundException cnfe) {
81                        throw SQLError.createSQLException("Unable to load class for logger '"
82                                        + className + "'", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
83                } catch (NoSuchMethodException nsme) {
84                        throw SQLError.createSQLException(
85                                        "Logger class does not have a single-arg constructor that takes an instance name",
86                                        SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
87                } catch (InstantiationException inse) {
88                        throw SQLError.createSQLException("Unable to instantiate logger class '"
89                                        + className + "', exception in constructor?",
90                                        SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
91                } catch (InvocationTargetException ite) {
92                        throw SQLError.createSQLException("Unable to instantiate logger class '"
93                                        + className + "', exception in constructor?",
94                                        SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
95                } catch (IllegalAccessException iae) {
96                        throw SQLError.createSQLException("Unable to instantiate logger class '"
97                                        + className + "', constructor not public",
98                                        SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
99                } catch (ClassCastException cce) {
100                        throw SQLError.createSQLException("Logger class '" + className
101                                        + "' does not implement the '" + Log.class.getName()
102                                        + "' interface", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
103                }
104        }
105}

[all classes][com.mysql.jdbc.log]
EMMA 2.0.4217 (C) Vladimir Roubtsov