1 8 package examples.logging; 9 10 import org.codehaus.aspectwerkz.joinpoint.StaticJoinPoint; 11 12 18 public class LoggerIdiom { 19 20 23 public Object log(StaticJoinPoint jp, Loggable loggable) throws Throwable { 24 loggable.getLog().log(Level.ALL, "entering " + jp.getSignature()); 25 Object result = jp.proceed(); 26 loggable.getLog().log(Level.ALL, "exiting " + jp.getSignature()); 27 return result; 28 } 29 30 36 public static class LoggableImpl implements Loggable { 37 38 private final Logger LOG; 39 40 public LoggableImpl(Class targetClass) { 41 LOG = Logger.getLogger(targetClass.getName()); 42 } 43 44 public Logger getLog() { 45 return LOG; 46 } 47 } 48 49 public static interface Loggable { 50 Logger getLog(); 51 } 52 53 static class Level { 56 static final Level ALL = new Level(); 57 } 58 static class Logger { 59 private static Logger SINGLETON = new Logger(); 60 static Logger getLogger(String name) { 61 return SINGLETON; 62 } 63 void log(Level level, String m) { 64 System.out.println("examples.logging.Logger : " + m); 65 } 66 } 67 } 68 69 | Popular Tags |