1 4 package org.oddjob.monitor.model; 5 6 import org.oddjob.Oddjob; 7 import org.oddjob.arooa.ArooaContext; 8 import org.oddjob.logging.ConsoleArchiver; 9 import org.oddjob.logging.LogArchiver; 10 import org.oddjob.scheduling.OddjobScheduler; 11 import org.oddjob.util.ThreadManager; 12 13 23 public class ExplorerContext { 24 25 26 private final Object component; 27 28 29 private final ExplorerContext parent; 30 31 32 private final SchedulerTraker schedulerTraker; 33 34 35 private final ExplorerModel explorerModel; 36 37 38 private final Oddjob oddjob; 39 40 41 private LogArchiver logArchiver; 42 43 44 private ConsoleArchiver consoleArchiver; 45 46 49 public ExplorerContext(ExplorerModel explorerModel) { 50 this.component = explorerModel.getRoot(); 51 if (component == null) { 52 throw new NullPointerException ("Component can't be null"); 53 } 54 this.parent = null; 55 56 this.schedulerTraker = new SchedulerTraker(); 58 this.explorerModel = explorerModel; 59 60 this.logArchiver = explorerModel.getLogArchiver(); 62 this.consoleArchiver = explorerModel.getConsoleArchiver(); 63 64 if (component instanceof Oddjob) { 65 oddjob = ((Oddjob) component); 66 } 67 else { 68 oddjob = null; 69 } 70 71 if (component instanceof OddjobScheduler) { 72 schedulerTraker.addScheduler( 73 (OddjobScheduler) component); 74 } 75 } 76 77 82 public ExplorerContext(Object component, ExplorerContext parent) { 83 if (component == null) { 84 throw new NullPointerException ("Component can't be null"); 85 } 86 if (parent == null) { 87 throw new NullPointerException ("Parent can't be null"); 88 } 89 this.component = component; 90 this.parent = parent; 91 92 this.schedulerTraker = parent.schedulerTraker; 94 this.explorerModel = parent.explorerModel; 95 96 if (parent.component instanceof LogArchiver) { 101 logArchiver = ((LogArchiver) parent.component); 102 } 103 104 if (parent.component instanceof ConsoleArchiver) { 106 consoleArchiver = ((ConsoleArchiver) parent.component); 107 } 108 109 if (component instanceof Oddjob) { 110 oddjob = ((Oddjob) component); 111 } 112 else { 113 oddjob = null; 114 } 115 116 if (component instanceof OddjobScheduler) { 117 schedulerTraker.addScheduler( 118 (OddjobScheduler) component); 119 } 120 } 121 122 130 public Oddjob getOddjob() { 131 if (oddjob != null) { 132 return oddjob; 133 } 134 if (parent == null) { 135 return null; 136 } 137 return parent.getOddjob(); 138 } 139 140 public SchedulerTraker getSchedulerTraker() { 141 return schedulerTraker; 142 } 143 144 151 public ArooaContext getArooaContext() { 152 if (oddjob != null) { 153 return oddjob.loadContext(); 154 } 155 return explorerModel.getArooaContext(); 156 } 157 158 164 public LogArchiver getLogArchiver() { 165 if (logArchiver != null) { 166 return logArchiver; 167 } 168 if (parent == null) { 169 throw new IllegalStateException ("A LogArchiver must be set in the parent node."); 170 } 171 return parent.getLogArchiver(); 172 } 173 174 179 public void setLogArchiver(LogArchiver logArchiver) { 180 this.logArchiver = logArchiver; 181 } 182 183 189 public ConsoleArchiver getConsoleArchiver() { 190 if (consoleArchiver != null) { 191 return consoleArchiver; 192 } 193 if (parent == null) { 194 throw new IllegalStateException ("A ConsoleArchiver must be set in the parent node."); 195 } 196 return parent.getConsoleArchiver(); 197 } 198 199 204 public void setConsoleArchiver(ConsoleArchiver consoleArchiver) { 205 this.consoleArchiver = consoleArchiver; 206 } 207 208 public ThreadManager getThreadManager() { 209 return explorerModel.getThreadManager(); 210 } 211 212 } 213 | Popular Tags |