1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
/*
* VS is (c) 2008 by Paul C. Buetow
* vs@dev.buetow.org
*/
package events;
import java.util.*;
import prefs.*;
import core.*;
import utils.*;
/**
* The Class VSRegisteredEvents.
*/
public final class VSRegisteredEvents {
private static final long serialVersionUID = 1L;
/** The event classnames. */
private static HashMap<String,String> eventClassnames;
/** The event shortnames. */
private static HashMap<String,String> eventShortnames;
/** The event names. */
private static HashMap<String,String> eventNames;
/** The editable protocols classnames. */
private static ArrayList<String> editableProtocolsClassnames;
/** The prefs. */
private static VSPrefs prefs;
/**
* Inits the.
*
* @param prefs_ the prefs_
*/
public static void init(VSPrefs prefs_) {
prefs = prefs_;
eventNames = new HashMap<String, String>();
eventShortnames = new HashMap<String, String>();
eventClassnames = new HashMap<String, String>();
editableProtocolsClassnames = new ArrayList<String>();
registerEvent("events.implementations.ProcessCrashEvent", "Prozessabsturz", null);
registerEvent("events.implementations.ProcessRecoverEvent", "Prozesswiederbelebung", null);
registerEvent("protocols.implementations.BerkelyTimeProtocol", "Berkeley Algorithmus zur internen Sync.", "Berkeley");
registerEvent("protocols.implementations.BroadcastSturmProtocol", "Broadcaststurm", null);
registerEvent("protocols.implementations.DummyProtocol", "Beispiel/Dummy", null);
registerEvent("protocols.implementations.ExternalTimeSyncProtocol", "Christians Methode zur externen Sync.", "Christians");
registerEvent("protocols.implementations.InternalTimeSyncProtocol", "Interne Synchronisation", "Interne Sync.");
registerEvent("protocols.implementations.PingPongProtocol", "Ping Pong", null);
/* Make dummy objects of each protocol, to see if they contain VSPrefs values to edit */
Vector<String> protocolClassnames = getProtocolClassnames();
VSClassLoader classLoader = new VSClassLoader();
for (String protocolClassname : protocolClassnames) {
Object object = classLoader.newInstance(protocolClassname);
if (object instanceof protocols.VSProtocol) {
protocols.VSProtocol protocol = (protocols.VSProtocol) object;
if (!protocol.isEmpty())
editableProtocolsClassnames.add(protocolClassname);
}
}
}
/**
* Gets the editable protocols classnames.
*
* @return the editable protocols classnames
*/
public static ArrayList<String> getEditableProtocolsClassnames() {
return editableProtocolsClassnames;
}
/**
* Gets the protocol names.
*
* @return the protocol names
*/
public static Vector<String> getProtocolNames() {
Set<String> set = eventClassnames.keySet();
Vector<String> vector = new Vector<String>();
for (String eventName : set)
if (getClassname(eventName).startsWith("protocols.implementations"))
vector.add(eventName);
Collections.sort(vector);
return vector;
}
/**
* Gets the protocol classnames.
*
* @return the protocol classnames
*/
public static Vector<String> getProtocolClassnames() {
Set<String> set = eventNames.keySet();
Vector<String> vector = new Vector<String>();
for (String eventClassname : set)
if (eventClassname.startsWith("protocols.implementations"))
vector.add(eventClassname);
Collections.sort(vector);
return vector;
}
/**
* Gets the non protocol names.
*
* @return the non protocol names
*/
public static Vector<String> getNonProtocolNames() {
Set<String> set = eventClassnames.keySet();
Vector<String> vector = new Vector<String>();
for (String eventName : set)
if (getClassname(eventName).startsWith("events.implementations"))
vector.add(eventName);
Collections.sort(vector);
return vector;
}
/**
* Gets the non protocol classnames.
*
* @return the non protocol classnames
*/
public static Vector<String> getNonProtocolClassnames() {
Set<String> set = eventNames.keySet();
Vector<String> vector = new Vector<String>();
for (String eventClassname : set)
if (eventClassname.startsWith("events.implementations"))
vector.add(eventClassname);
Collections.sort(vector);
return vector;
}
/**
* Gets the classname.
*
* @param eventName the event name
*
* @return the classname
*/
public static String getClassname(String eventName) {
return eventClassnames.get(eventName);
}
/**
* Gets the name.
*
* @param eventClassname the event classname
*
* @return the name
*/
public static String getName(String eventClassname) {
return eventNames.get(eventClassname);
}
/**
* Gets the shortname.
*
* @param eventClassname the event classname
*
* @return the shortname
*/
public static String getShortname(String eventClassname) {
return eventShortnames.get(eventClassname);
}
/**
* Creates the event instance by classname.
*
* @param eventClassname the event classname
* @param process the process
*
* @return the lang.process.removeevent
*/
public static VSEvent createEventInstanceByClassname(String eventClassname, VSProcess process) {
final Object protocolObj = new VSClassLoader().newInstance(eventClassname);
if (protocolObj instanceof VSEvent) {
VSEvent event = (VSEvent) protocolObj;
event.init(process);
return event;
}
return null;
}
/**
* Creates the event instance by name.
*
* @param eventName the event name
* @param process the process
*
* @return the lang.process.removeevent
*/
public static VSEvent createEventInstanceByName(String eventName, VSProcess process) {
return createEventInstanceByClassname(eventClassnames.get(eventName), process);
}
/**
* Register event.
*
* @param eventClassname the event classname
* @param eventName the event name
* @param eventShortname the event shortname
*/
private static void registerEvent(String eventClassname, String eventName, String eventShortname) {
if (eventShortname == null)
eventShortname = eventName;
eventNames.put(eventClassname, eventName);
eventShortnames.put(eventClassname, eventShortname);
eventClassnames.put(eventName, eventClassname);
}
}
|