KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > logging > LogHelper


1 /*
2  * (c) Rob Gordon 2005
3  */

4 package org.oddjob.logging;
5
6 import org.oddjob.Reserved;
7 import org.oddjob.arooa.reflect.BeanUtilsHelper;
8 import org.oddjob.arooa.reflect.IntrospectionHelper;
9
10 /**
11  * A helper class which provides a method of getting
12  * a logger for a given component.
13  */

14 public class LogHelper {
15
16     /**
17      * Inspect the given component for a logger property.
18      *
19      * @param component The component.
20      * @return The logger or null if one doesn't exist.
21      */

22     public static String JavaDoc getLogger(Object JavaDoc component) {
23         if (component instanceof LogEnabled) {
24             return ((LogEnabled) component).getLogger();
25         }
26         try {
27             // use valueFor becuase the logger might be a PropertyType
28
// (from VariableJob for instance) which wraps a string.
29
return (String JavaDoc) IntrospectionHelper.valueFor(
30                     BeanUtilsHelper.getProperty(component, Reserved.LOGGER_PROPERTY));
31         } catch (Exception JavaDoc e) {
32             return null;
33         }
34     }
35 }
36
Popular Tags