KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > cli > commands > DomainReporter


1 /*
2  * StartupReporter.java
3  *
4  * Created on March 7, 2006, 8:00 PM
5  *
6  * To change this template, choose Tools | Template Manager
7  * and open the template in the editor.
8  */

9
10 package com.sun.enterprise.cli.commands;
11
12 import com.sun.appserv.server.util.Version;
13 import com.sun.enterprise.admin.servermgmt.DomainConfig;
14 import com.sun.enterprise.admin.servermgmt.pe.PEFileLayout;
15 import com.sun.enterprise.cli.framework.CLILogger;
16 import com.sun.enterprise.config.ConfigContext;
17 import com.sun.enterprise.config.ConfigException;
18 import com.sun.enterprise.config.ConfigFactory;
19 import com.sun.enterprise.config.serverbeans.HttpListener;
20 import com.sun.enterprise.config.serverbeans.IiopListener;
21 import com.sun.enterprise.config.serverbeans.JavaConfig;
22 import com.sun.enterprise.config.serverbeans.JmxConnector;
23 import com.sun.enterprise.config.serverbeans.ServerHelper;
24 import com.sun.enterprise.config.serverbeans.WebModule;
25 import com.sun.enterprise.util.SystemPropertyConstants;
26 import java.util.ArrayList JavaDoc;
27 import java.util.List JavaDoc;
28 import com.sun.enterprise.util.i18n.StringManager;
29 /**
30  *
31  * @author kedarm
32  */

33 public class DomainReporter {
34     
35     private final boolean detailed;
36     private final DomainConfig dc;
37     private static final CLILogger logger = CLILogger.getInstance();
38     private static final StringManager lsm = StringManager.getManager(DomainReporter.class);
39     private final List JavaDoc<String JavaDoc> records = new ArrayList JavaDoc<String JavaDoc>();
40     private ConfigContext cc = null; //the config context
41
private String JavaDoc sn = null; // the server name
42
/* package private constructor */
43     DomainReporter(final DomainConfig dc) {
44         this(dc, false);
45     }
46     DomainReporter(final DomainConfig dc, final boolean terse) {
47         this.dc = dc;
48         this.detailed = !terse;
49     }
50     
51     void report() throws ConfigException {
52         prepare();
53         display();
54     }
55     
56     private void prepare() throws ConfigException {
57         final PEFileLayout layout = new PEFileLayout(dc);
58         final String JavaDoc xmlPath = layout.getDomainConfigFile().getAbsolutePath();
59         this.cc = ConfigFactory.createConfigContext(xmlPath, true, false, false, true);
60         this.sn = SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME;
61         
62         final String JavaDoc ver = Version.getFullVersion();
63         records.add(getDomainBanner(dc.getDomainName(), ver, dc.getDomainRoot()));
64         if (detailed) {
65             records.add(getAdminConsoleMessage());
66             records.add(getHttpUrlsMessage());
67             records.add(getWebContextsMessage());
68             records.add(getJmxServiceUrlMessage());
69             records.add(getOccupiedPorts());
70             records.add(getDebugMessage());
71         }
72     }
73     
74     private String JavaDoc getDomainBanner(final String JavaDoc dn, final String JavaDoc version, final String JavaDoc dr) {
75         return ( lsm.getString("domain.report.banner", dn, version, dr));
76     }
77     
78     private String JavaDoc getDebugMessage() throws ConfigException {
79         String JavaDoc msg = "";
80         boolean debugMode = false;
81         try{
82             debugMode = (Boolean JavaDoc)dc.get(DomainConfig.K_DEBUG);
83         } catch(final Exception JavaDoc e) {}//squelch
84
if (debugMode) {
85             final JavaConfig jc = ServerHelper.getConfigForServer(cc, sn).getJavaConfig();
86             final String JavaDoc dopt = jc.getDebugOptions();
87             msg = lsm.getString("start.debug.msg", dopt);
88         }
89         return ( msg );
90     }
91     private String JavaDoc getAdminConsoleMessage() throws ConfigException {
92         final HttpListener admin = ServerHelper.getHttpListener(cc, sn, ServerHelper.ADMIN_HTTP_LISTNER_ID);
93         String JavaDoc url = "", port = null;
94         if (admin != null) {
95             url = ServerHelper.getUrlString(admin);
96             port = admin.getPort();
97         }
98         return ( lsm.getString("admin.console.msg", url, port) );
99     }
100     private String JavaDoc getHttpUrlsMessage() throws ConfigException {
101         final HttpListener[] lss = ServerHelper.getHttpListeners(cc, sn);
102         String JavaDoc urls = "";
103         if (lss != null) {
104             for (final HttpListener ls : lss) {
105                 if (ServerHelper.ADMIN_HTTP_LISTNER_ID.equals(ls.getId()))
106                     continue; //skip the admin listener
107
if (ls.isEnabled()) {
108                     urls += ServerHelper.getUrlString(ls);
109                     urls += " ";
110                 }
111             }
112         }
113         return ( lsm.getString("http.listeners.msg", urls) );
114     }
115     private String JavaDoc getWebContextsMessage() throws ConfigException {
116         final WebModule[] wms = ServerHelper.getAssociatedWebModules(cc, sn);
117         String JavaDoc crs = "";
118         for (final WebModule wm : wms) {
119            crs += wm.getContextRoot();
120            crs += " ";
121         }
122         return ( lsm.getString("web.contexts.msg", crs) );
123     }
124     
125     private String JavaDoc getJmxServiceUrlMessage() throws ConfigException {
126         String JavaDoc url = "";
127         final JmxConnector sjc = ServerHelper.getServerSystemConnector(cc, sn);
128         if (sjc != null) {
129             url += ServerHelper.getJmxServiceUrl(sjc);
130         }
131         return ( lsm.getString("jmx.connector.msg", url) );
132     }
133     private String JavaDoc getOccupiedPorts() throws ConfigException {
134         String JavaDoc ports = "";
135         ports = getHttpPorts() + getIiopPorts() + getJmxConnectorPorts();
136         return ( lsm.getString("ports.msg", ports) );
137     }
138     private String JavaDoc getHttpPorts() throws ConfigException {
139         String JavaDoc hp = "";
140         final HttpListener[] hss = ServerHelper.getConfigForServer(cc, sn).getHttpService().getHttpListener();
141         for (final HttpListener hs : hss) {
142             if (hs.isEnabled()) {
143                 hp += hs.getPort();
144                 hp += " ";
145             }
146         }
147         return ( hp );
148     }
149     private String JavaDoc getIiopPorts() throws ConfigException {
150         String JavaDoc ip = "";
151         final IiopListener[] ils = ServerHelper.getConfigForServer(cc, sn).getIiopService().getIiopListener();
152         for (final IiopListener is : ils) {
153             if (is.isEnabled()) {
154                 ip += is.getPort();
155                 ip += " ";
156             }
157         }
158         return ( ip );
159     }
160     private String JavaDoc getJmxConnectorPorts() throws ConfigException {
161         String JavaDoc jp = "";
162         final JmxConnector[] jcs = ServerHelper.getConfigForServer(cc, sn).getAdminService().getJmxConnector();
163         for (final JmxConnector jc : jcs) {
164             if (jc.isEnabled()) {
165                 jp += jc.getPort();
166                 jp += " ";
167             }
168         }
169         return ( jp );
170     }
171     
172     private void display() {
173         for (final String JavaDoc record : records) {
174             logger.printMessage(record);
175         }
176     }
177 }
178
Popular Tags