1 /**
2 * Logback: the generic, reliable, fast and flexible logging framework.
3 *
4 * Copyright (C) 2000-2008, QOS.ch
5 *
6 * This library is free software, you can redistribute it and/or modify it under
7 * the terms of the GNU Lesser General Public License as published by the Free
8 * Software Foundation.
9 */
10 package ch.qos.logback.classic.spi;
11
12 import ch.qos.logback.classic.LoggerContext;
13 import ch.qos.logback.core.Context;
14 import ch.qos.logback.core.spi.ContextAwareBase;
15
16
17 public class LoggerContextAwareBase extends ContextAwareBase implements LoggerContextAware {
18
19 /**
20 * Set the owning context. The owning context cannot be set more than
21 * once.
22 */
23 public void setLoggerContext(LoggerContext context) {
24 super.setContext(context);
25 }
26
27 public void setContext(Context context) {
28 // check that the context is of type LoggerContext. Otherwise, throw an exception
29 // Context == null is a degenarate case but nonetheless permitted.
30 if(context instanceof LoggerContext || context == null) {
31 super.setContext(context);
32 } else {
33 throw new IllegalArgumentException("LoggerContextAwareBase only accepts contexts of type c.l.classic.LoggerContext");
34 }
35 }
36
37 /**
38 * Return the {@link LoggerContext} this component is attached to.
39 *
40 * @return The owning LoggerContext
41 */
42 public LoggerContext getLoggerContext() {
43 return (LoggerContext) context;
44 }
45
46 }