KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > jmx > server > ServerModel


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

4 package org.oddjob.jmx.server;
5
6 import org.oddjob.OJConstants;
7 import org.oddjob.arooa.Lifecycle;
8 import org.oddjob.arooa.registry.ComponentRegistry;
9 import org.oddjob.logging.ConsoleArchiver;
10 import org.oddjob.logging.LocalConsoleArchiver;
11 import org.oddjob.logging.Log4jArchiver;
12 import org.oddjob.logging.LogArchiver;
13 import org.oddjob.util.ThreadManager;
14
15 /**
16  * Collects properties of the server in one place.
17  *
18  * @author Rob Gordon.
19  */

20 public class ServerModel {
21
22     private final ThreadManager threadManager;
23     private final InterfaceManagerFactory imf;
24     private final String JavaDoc url;
25     
26         
27     private Object JavaDoc root;
28     
29     private ComponentRegistry componentRegistry;
30     private LogArchiver logArchiver;
31     private ConsoleArchiver consoleArchiver;
32
33     private String JavaDoc logFormat;
34     
35     /**
36      * A constructor for the top most server
37      * context.
38      */

39     public ServerModel(String JavaDoc url,
40             ThreadManager threadManager,
41             InterfaceManagerFactory imf) {
42         
43         this.url = url;
44         this.threadManager = threadManager;
45         this.imf = imf;
46     }
47
48     /**
49      * Set the root object. This fixes this model. Other properties must be
50      * set before this is called.
51      *
52      * @param root
53      */

54     public void setRoot(Object JavaDoc root) {
55         this.root = root;
56         
57         logArchiver = new Log4jArchiver(root,
58                 logFormat == null ? OJConstants.DEFAULT_LOG_FORMAT : logFormat);
59         consoleArchiver = new LocalConsoleArchiver(root);
60
61     }
62     
63     /**
64      * Get the root node.
65      *
66      * @return The root.
67      */

68     public Object JavaDoc getRoot() {
69         return root;
70     }
71     
72     /**
73      * @return Returns the uniqueId.
74      */

75     public String JavaDoc getUrl() {
76         return url;
77     }
78             
79     /**
80      * @return Returns the threadManager.
81      */

82     public ThreadManager getThreadManager() {
83         return threadManager;
84     }
85     
86     /**
87      *
88      * @return Returns the interfaceManagerFactory.
89      */

90     public InterfaceManagerFactory getInterfaceManagerFactory() {
91         return imf;
92     }
93     
94     /**
95      * Get the root LogArchiver.
96      *
97      * @return The LogArchiver.
98      */

99     public LogArchiver getLogArchiver() {
100         return logArchiver;
101     }
102         
103     /**
104      * Get the root ConsoleArchiver.
105      *
106      * @return The ConsoleArchiver.
107      */

108     public ConsoleArchiver getConsoleArchiver() {
109         return consoleArchiver;
110     }
111
112     /**
113      * Get the component registry.
114      *
115      * @return The component registry.
116      */

117     public ComponentRegistry getComponentRegistry() {
118         if (componentRegistry == null) {
119             componentRegistry = new ComponentRegistry();
120         }
121         return componentRegistry;
122     }
123     
124     /**
125      * Set the ComponentRegistry.
126      *
127      * @param componentRegistry The ComponentRegistry.
128      */

129     public void setComponentRegistry(ComponentRegistry componentRegistry) {
130         this.componentRegistry = componentRegistry;
131     }
132     
133     /**
134      * Getter for log format.
135      *
136      * @return The log format.
137      */

138     public String JavaDoc getLogFormat() {
139         return logFormat;
140     }
141     
142     /**
143      * The log format.
144      *
145      * @param logFormat The log format.
146      */

147     public void setLogFormat(String JavaDoc logFormat) {
148         this.logFormat = logFormat;
149     }
150     
151     /**
152      * Destroy the model.
153      */

154     public void destroy() {
155         Lifecycle.destroy(consoleArchiver);
156         consoleArchiver = null;
157         Lifecycle.destroy(logArchiver);
158         logArchiver = null;
159         root = null;
160     }
161 }
162
Popular Tags