KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > console > formatter > GlobalWriter


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.console.formatter;
19
20 import javax.management.ObjectInstance JavaDoc;
21 import javax.management.ObjectName JavaDoc;
22 import javax.management.AttributeList JavaDoc;
23 import javax.jms.Message JavaDoc;
24 import java.util.Map JavaDoc;
25 import java.util.Collection JavaDoc;
26 import java.io.OutputStream JavaDoc;
27
28 public class GlobalWriter {
29     private static OutputFormatter formatter;
30
31     /**
32      * Creates a singleton global writer
33      */

34     private GlobalWriter() {
35     }
36
37     /**
38      * Maintains a global output formatter
39      * @param formatter - the output formatter to use
40      */

41     public static void instantiate(OutputFormatter formatter) {
42             GlobalWriter.formatter = formatter;
43     }
44
45     /**
46      * Retrieve the output stream being used by the global formatter
47      * @return
48      */

49     public static OutputStream JavaDoc getOutputStream() {
50         if (formatter == null) {
51             throw new IllegalStateException JavaDoc("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
52         }
53         return formatter.getOutputStream();
54     }
55
56     /**
57      * Print an ObjectInstance format of an mbean
58      * @param mbean - mbean to print
59      */

60     public static void printMBean(ObjectInstance JavaDoc mbean) {
61         if (formatter == null) {
62             throw new IllegalStateException JavaDoc("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
63         }
64         formatter.printMBean(mbean);
65     }
66
67     /**
68      * Print an ObjectName format of an mbean
69      * @param mbean - mbean to print
70      */

71     public static void printMBean(ObjectName JavaDoc mbean) {
72         if (formatter == null) {
73             throw new IllegalStateException JavaDoc("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
74         }
75         formatter.printMBean(mbean);
76     }
77
78     /**
79      * Print an AttributeList format of an mbean
80      * @param mbean - mbean to print
81      */

82     public static void printMBean(AttributeList JavaDoc mbean) {
83         if (formatter == null) {
84             throw new IllegalStateException JavaDoc("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
85         }
86         formatter.printMBean(mbean);
87     }
88
89     /**
90      * Print a Map format of an mbean
91      * @param mbean
92      */

93     public static void printMBean(Map JavaDoc mbean) {
94         if (formatter == null) {
95             throw new IllegalStateException JavaDoc("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
96         }
97         formatter.printMBean(mbean);
98     }
99
100     /**
101      * Print a Collection format of mbeans
102      * @param mbean - collection of mbeans
103      */

104     public static void printMBean(Collection JavaDoc mbean) {
105         if (formatter == null) {
106             throw new IllegalStateException JavaDoc("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
107         }
108         formatter.printMBean(mbean);
109     }
110
111     /**
112      * Print a Map format of a JMS message
113      * @param msg
114      */

115     public static void printMessage(Map JavaDoc msg) {
116         if (formatter == null) {
117             throw new IllegalStateException JavaDoc("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
118         }
119         formatter.printMessage(msg);
120     }
121
122     /**
123      * Print a Message format of a JMS message
124      * @param msg - JMS message to print
125      */

126     public static void printMessage(Message JavaDoc msg) {
127         if (formatter == null) {
128             throw new IllegalStateException JavaDoc("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
129         }
130         formatter.printMessage(msg);
131     }
132
133     /**
134      * Print a collection of JMS messages
135      * @param msg - collection of JMS messages
136      */

137     public static void printMessage(Collection JavaDoc msg) {
138         if (formatter == null) {
139             throw new IllegalStateException JavaDoc("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
140         }
141         formatter.printMessage(msg);
142     }
143
144     /**
145      * Print help messages
146      * @param helpMsgs - help messages to print
147      */

148     public static void printHelp(String JavaDoc[] helpMsgs) {
149         if (formatter == null) {
150             throw new IllegalStateException JavaDoc("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
151         }
152         formatter.printHelp(helpMsgs);
153     }
154
155     /**
156      * Print an information message
157      * @param info - information message to print
158      */

159     public static void printInfo(String JavaDoc info) {
160         if (formatter == null) {
161             throw new IllegalStateException JavaDoc("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
162         }
163         formatter.printInfo(info);
164     }
165
166     /**
167      * Print an exception message
168      * @param e - exception to print
169      */

170     public static void printException(Exception JavaDoc e) {
171         if (formatter == null) {
172             throw new IllegalStateException JavaDoc("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
173         }
174         formatter.printException(e);
175     }
176
177     /**
178      * Print a version information
179      * @param version - version info to print
180      */

181     public static void printVersion(String JavaDoc version) {
182         if (formatter == null) {
183             throw new IllegalStateException JavaDoc("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
184         }
185         formatter.printVersion(version);
186     }
187
188     /**
189      * Print a generic key value mapping
190      * @param map to print
191      */

192     public static void print(Map JavaDoc map) {
193         if (formatter == null) {
194             throw new IllegalStateException JavaDoc("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
195         }
196         formatter.print(map);
197     }
198
199     /**
200      * Print a generic array of strings
201      * @param strings - string array to print
202      */

203     public static void print(String JavaDoc[] strings) {
204         if (formatter == null) {
205             throw new IllegalStateException JavaDoc("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
206         }
207         formatter.print(strings);
208     }
209
210     /**
211      * Print a collection of objects
212      * @param collection - collection to print
213      */

214     public static void print(Collection JavaDoc collection) {
215         if (formatter == null) {
216             throw new IllegalStateException JavaDoc("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
217         }
218         formatter.print(collection);
219     }
220
221     /**
222      * Print a java string
223      * @param string - string to print
224      */

225     public static void print(String JavaDoc string) {
226         if (formatter == null) {
227             throw new IllegalStateException JavaDoc("No OutputFormatter specified. Use GlobalWriter.instantiate(OutputFormatter).");
228         }
229         formatter.print(string);
230     }
231 }
232
Popular Tags