1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package com.gridsystems.config.app;
25
26 import java.text.MessageFormat;
27
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30
31 import com.gridsystems.config.Configurator;
32 import com.gridsystems.config.ConfiguratorModel;
33 import com.gridsystems.config.modules.jvm.JVMConfigurator;
34
35
36
37
38
39
40
41
42 class NullUI extends UI {
43
44
45
46 private static Log log = LogFactory.getLog(NullUI.class);
47
48
49
50
51 private boolean errors = false;
52
53
54
55
56 public boolean execute() {
57 Configurator[] configs = UI.getConfigurators();
58
59 JVMConfigurator jvmc = JVMConfigurator.getInstance();
60
61
62 load(jvmc);
63 for (int i = 0; i < configs.length; i++) {
64 if (configs[i] != jvmc) {
65 load(configs[i]);
66 }
67 }
68
69
70 for (int i = 0; i < configs.length; i++) {
71 if (configs[i] != jvmc) {
72 apply(configs[i]);
73 }
74 }
75 apply(jvmc);
76
77
78 if (errors) {
79 System.exit(1);
80 }
81 return true;
82 }
83
84
85
86
87
88
89 private void load(Configurator config) {
90 if (config != null) {
91 try {
92 ConfiguratorModel model = config.getModel();
93 if (model != null) {
94 model.load();
95 }
96 } catch (Exception e) {
97 String pattern = UI.getString("errors.load_error");
98 String msg = MessageFormat.format(pattern, new Object[] { config.getName() });
99 log.error(msg + ":" + e.getMessage());
100 }
101 }
102 }
103
104
105
106
107
108
109 private void apply(Configurator config) {
110 if (config != null) {
111 try {
112 config.apply();
113 } catch (Exception e) {
114 String pattern = UI.getString("errors.apply_error");
115 String msg = MessageFormat.format(pattern, new Object[] { config.getName() });
116 log.error(msg + ":" + e.getMessage());
117 errors = true;
118 }
119 }
120 }
121 }