1 /*
2 * Created on 21.mar.2003
3 *
4 * To change this generated comment go to
5 * Window>Preferences>Java>Code Generation>Code and Comments
6 */
7 package net.sf.panoptes.controller.digester;
8
9 import net.sf.panoptes.controller.MainController;
10 import net.sf.panoptes.model.component.ComponentUtil;
11 import net.sf.panoptes.module.log4j.LogFilter;
12 import net.sf.panoptes.module.log4j.LoggerComponent;
13 import net.sf.panoptes.module.log4j.LoggerRepository;
14 import net.sf.panoptes.model.component.registry.ComponentName;
15 import net.sf.panoptes.model.component.registry.ComponentRegistry;
16 import net.sf.panoptes.model.node.NodeDescriptor;
17
18 import org.apache.commons.digester.Digester;
19 import org.apache.commons.digester.ObjectCreationFactory;
20 import org.apache.log4j.Level;
21 import org.xml.sax.Attributes;
22
23 /***
24 * @author Dag Liodden
25 *
26 */
27 public class LoggerFactory implements ObjectCreationFactory {
28
29 private Digester digester;
30 private ComponentRegistry componentRegistry;
31 private LoggerRepository loggerRepository;
32 private MainController mainController;
33
34 public LoggerFactory(MainController mainController, LoggerRepository loggerRepository, ComponentRegistry componentRegistry) {
35 this.loggerRepository = loggerRepository;
36 this.componentRegistry = componentRegistry;
37 this.mainController = mainController;
38 }
39
40 public Object createObject(Attributes attributes) throws Exception {
41 String host = attributes.getValue("host");
42 String prefix = attributes.getValue("prefix");
43 Level level = Level.toLevel(attributes.getValue("threshold"));
44 String name = attributes.getValue("name");
45 String desc = attributes.getValue("description");
46
47 LoggerComponent logger = new LoggerComponent();
48 logger.setConfigDescriptor(new NodeDescriptor(name, desc));
49 logger.setLoggerRepository(loggerRepository);
50 logger.setFilter(new LogFilter(host, prefix, level));
51 ComponentName componentName = ComponentUtil.createName(logger);
52 componentRegistry.registerComponent(logger, componentName);
53 return logger;
54 }
55
56 /* (non-Javadoc)
57 * @see org.apache.commons.digester.ObjectCreationFactory#getDigester()
58 */
59 public Digester getDigester() {
60 return digester;
61 }
62
63 /* (non-Javadoc)
64 * @see org.apache.commons.digester.ObjectCreationFactory#setDigester(org.apache.commons.digester.Digester)
65 */
66 public void setDigester(Digester digester) {
67 this.digester = digester;
68 }
69 }
This page was automatically generated by Maven