01: /**
02: *
03: */package clime.messadmin.providers.userdata;
04:
05: import java.lang.reflect.Method;
06: import java.text.NumberFormat;
07: import java.util.ArrayList;
08: import java.util.Iterator;
09: import java.util.List;
10: import java.util.Map;
11:
12: import clime.messadmin.i18n.I18NSupport;
13: import clime.messadmin.model.Server;
14: import clime.messadmin.providers.spi.BaseTabularServerDataProvider;
15: import clime.messadmin.providers.spi.ServerDataProvider;
16:
17: /**
18: * @author Cédrik LIME
19: */
20: public class SystemEnvironmentProvider extends
21: BaseTabularServerDataProvider implements ServerDataProvider {
22: private static final String BUNDLE_NAME = SystemEnvironmentProvider.class
23: .getName();
24: private static transient Method getenv = null;
25:
26: static {
27: // @since 1.5
28: try {
29: getenv = System.class.getMethod("getenv", null);//$NON-NLS-1$
30: } catch (SecurityException e) {
31: } catch (NoSuchMethodException e) {
32: }
33: }
34:
35: /**
36: *
37: */
38: public SystemEnvironmentProvider() {
39: super ();
40: }
41:
42: /**
43: * {@inheritDoc}
44: */
45: public String[] getServerTabularDataLabels() {
46: String name = I18NSupport.getLocalizedMessage(BUNDLE_NAME,
47: null, "label.name");//$NON-NLS-1$
48: String value = I18NSupport.getLocalizedMessage(BUNDLE_NAME,
49: null, "label.value");//$NON-NLS-1$
50: return new String[] { name, value };
51: }
52:
53: /**
54: * {@inheritDoc}
55: */
56: protected String getTableCaption(String[] labels, Object[][] values) {
57: NumberFormat numberFormatter = NumberFormat
58: .getNumberInstance(I18NSupport.getAdminLocale());
59: String caption = I18NSupport
60: .getLocalizedMessage(
61: BUNDLE_NAME,
62: null,
63: "table.caption", new Object[] { numberFormatter.format(values.length) });//$NON-NLS-1$
64: return caption;
65: }
66:
67: /**
68: * {@inheritDoc}
69: */
70: public Object[][] getServerTabularData() {
71: Map sysProps = Server.getInstance().getServerInfo()
72: .getSystemEnv();
73: List resultList = new ArrayList(sysProps.size());
74: Iterator iter = sysProps.entrySet().iterator();
75: while (iter.hasNext()) {
76: Map.Entry prop = (Map.Entry) iter.next();
77: resultList.add(new Object[] { prop.getKey(),
78: prop.getValue() });
79: }
80: Object[][] result = new Object[resultList.size()][];
81: return (Object[][]) resultList.toArray(result);
82: }
83:
84: /**
85: * {@inheritDoc}
86: */
87: public String getServerDataTitle() {
88: return getenv != null ? I18NSupport.getLocalizedMessage(
89: BUNDLE_NAME, null, "title") : null;//$NON-NLS-1$
90: }
91:
92: /**
93: * {@inheritDoc}
94: */
95: public int getPriority() {
96: return 20;
97: }
98:
99: }
|