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 |
| package com.unitesk.atp.tool; |
33 |
| |
34 |
| import java.io.InputStream; |
35 |
| import java.io.IOException; |
36 |
| import java.util.Iterator; |
37 |
| import java.util.List; |
38 |
| import java.util.Properties; |
39 |
| |
40 |
| import com.unitesk.atp.messages.MessageBox; |
41 |
| import com.unitesk.atp.text.localize.StringManager; |
42 |
| |
43 |
| |
44 |
| |
45 |
| |
46 |
| |
47 |
| |
48 |
| |
49 |
| public class PluginManagerClass implements PluginManager |
50 |
| { |
51 |
| |
52 |
| |
53 |
| |
54 |
| protected String name; |
55 |
| |
56 |
| |
57 |
| |
58 |
| |
59 |
| protected MessageBox mbox; |
60 |
| |
61 |
| |
62 |
| |
63 |
| |
64 |
| |
65 |
| protected Properties config = new Properties(); |
66 |
| |
67 |
| |
68 |
| |
69 |
| |
70 |
| |
71 |
| |
72 |
| protected DynamicVariablesTable table; |
73 |
| |
74 |
| |
75 |
| |
76 |
| |
77 |
| |
78 |
| |
79 |
| |
80 |
| |
81 |
| |
82 |
| |
83 |
| |
84 |
0
| public PluginManagerClass( String name
|
85 |
| , MessageBox mbox |
86 |
| , Properties config |
87 |
| , InputStream in |
88 |
| ) throws IOException, ClassNotFoundException |
89 |
| { |
90 |
0
| this.name = name;
|
91 |
0
| this.mbox = mbox;
|
92 |
0
| this.config = config != null ? config : new Properties();
|
93 |
0
| loadPlugins( in );
|
94 |
| } |
95 |
| |
96 |
| |
97 |
| |
98 |
| |
99 |
| |
100 |
| |
101 |
| |
102 |
0
| public PluginManagerClass()
|
103 |
| { |
104 |
0
| initName();
|
105 |
0
| initConfig();
|
106 |
0
| initMessageBox();
|
107 |
0
| initPluginsTable();
|
108 |
| } |
109 |
| |
110 |
| |
111 |
| |
112 |
| |
113 |
| |
114 |
| |
115 |
| |
116 |
| |
117 |
0
| protected void initName()
|
118 |
| { |
119 |
0
| throw new UnsupportedOperationException();
|
120 |
| } |
121 |
| |
122 |
| |
123 |
| |
124 |
| |
125 |
| |
126 |
| |
127 |
| |
128 |
| |
129 |
0
| protected void initConfig()
|
130 |
| { |
131 |
0
| throw new UnsupportedOperationException();
|
132 |
| } |
133 |
| |
134 |
| |
135 |
| |
136 |
| |
137 |
| |
138 |
| |
139 |
| |
140 |
| |
141 |
0
| protected void initMessageBox()
|
142 |
| { |
143 |
0
| throw new UnsupportedOperationException();
|
144 |
| } |
145 |
| |
146 |
| |
147 |
| |
148 |
| |
149 |
| |
150 |
| |
151 |
| |
152 |
| |
153 |
0
| protected void initPluginsTable()
|
154 |
| { |
155 |
0
| throw new UnsupportedOperationException();
|
156 |
| } |
157 |
| |
158 |
| |
159 |
| |
160 |
| |
161 |
0
| public String getName() { return name; }
|
162 |
| |
163 |
| |
164 |
| |
165 |
| |
166 |
0
| public MessageBox getMessageBox() { return mbox; }
|
167 |
| |
168 |
| |
169 |
| |
170 |
| |
171 |
0
| public Object getPlugin( String name )
|
172 |
| { |
173 |
0
| return table.get( name );
|
174 |
| } |
175 |
| |
176 |
| |
177 |
| |
178 |
| |
179 |
| |
180 |
| |
181 |
| |
182 |
| |
183 |
| |
184 |
| |
185 |
0
| public final String getProperty( String name )
|
186 |
| { |
187 |
0
| String v = config.getProperty( name );
|
188 |
| |
189 |
0
| if( v != null ) return v;
|
190 |
| |
191 |
0
| return System.getProperty( name );
|
192 |
| } |
193 |
| |
194 |
| |
195 |
| |
196 |
| |
197 |
| |
198 |
| |
199 |
| |
200 |
| |
201 |
| |
202 |
| |
203 |
| |
204 |
0
| public final String getProperty( String name, String value )
|
205 |
| { |
206 |
0
| String v = config.getProperty( name );
|
207 |
| |
208 |
0
| if( v != null ) return v;
|
209 |
| |
210 |
0
| return System.getProperty( name, value );
|
211 |
| } |
212 |
| |
213 |
| |
214 |
| |
215 |
| |
216 |
0
| public String getPluginPropertyName( Object plugin, String name )
|
217 |
| { |
218 |
0
| return table.getPropertyName( plugin, name );
|
219 |
| } |
220 |
| |
221 |
| |
222 |
| |
223 |
| |
224 |
0
| public String getPluginProperty( Object plugin, String name )
|
225 |
| { |
226 |
0
| return getProperty( table.getPropertyName( plugin, name ) );
|
227 |
| } |
228 |
| |
229 |
| |
230 |
| |
231 |
| |
232 |
0
| public String getPluginProperty( Object plugin, String name, String value )
|
233 |
| { |
234 |
0
| return getProperty( table.getPropertyName( plugin, name ), value );
|
235 |
| } |
236 |
| |
237 |
| |
238 |
| |
239 |
| |
240 |
0
| protected void createPluginsTable()
|
241 |
| { |
242 |
0
| table = new DynamicVariablesTable( name );
|
243 |
| } |
244 |
| |
245 |
| |
246 |
| |
247 |
| |
248 |
| |
249 |
| |
250 |
| |
251 |
| |
252 |
| |
253 |
| |
254 |
| |
255 |
| |
256 |
0
| protected void loadPlugins( InputStream in )
|
257 |
| throws IOException, ClassNotFoundException |
258 |
| { |
259 |
0
| if( in == null ) throw new NullPointerException( "in" );
|
260 |
| |
261 |
0
| if( table == null ) createPluginsTable();
|
262 |
| |
263 |
0
| table.load( in );
|
264 |
| |
265 |
0
| Iterator names = table.names().iterator();
|
266 |
| |
267 |
0
| while( names.hasNext() )
|
268 |
| { |
269 |
0
| String name = (String)names.next();
|
270 |
0
| Object obj = table.get( name );
|
271 |
| |
272 |
0
| if( obj instanceof Plugin )
|
273 |
| { |
274 |
0
| Plugin p = ((Plugin)obj);
|
275 |
0
| if( p.getName() == null ) p.init( this, name );
|
276 |
| } |
277 |
| } |
278 |
| } |
279 |
| |
280 |
| |
281 |
| |
282 |
| |
283 |
| |
284 |
| |
285 |
| |
286 |
| |
287 |
| |
288 |
| |
289 |
0
| protected void help( List pluginNames )
|
290 |
| { |
291 |
0
| StringBuffer sb = new StringBuffer();
|
292 |
0
| StringManager sm = mbox.getStringManager();
|
293 |
| |
294 |
0
| if( pluginNames == null
|
295 |
| || pluginNames.size() == 0 |
296 |
| ) |
297 |
| { |
298 |
0
| sb.append( endl );
|
299 |
0
| sb.append( sm.getString( PluginManagerClass.class
|
300 |
| , "defined_names" |
301 |
| , null |
302 |
| ) |
303 |
| ); |
304 |
| |
305 |
0
| Iterator names = table.names().iterator();
|
306 |
| |
307 |
0
| while( names.hasNext() )
|
308 |
| { |
309 |
0
| String name = (String)names.next();
|
310 |
0
| Object obj = table.get( name );
|
311 |
| |
312 |
0
| sb.append( name );
|
313 |
| |
314 |
0
| if( obj instanceof Plugin )
|
315 |
| { |
316 |
0
| sb.append( ", " );
|
317 |
0
| sb.append( ((Plugin)obj).getVersion() );
|
318 |
0
| sb.append( " - " );
|
319 |
0
| sb.append( ((Plugin)obj).getKind() );
|
320 |
| } |
321 |
0
| sb.append( endl );
|
322 |
| } |
323 |
| } else { |
324 |
0
| for ( int i = 0; i < pluginNames.size(); i++ )
|
325 |
| { |
326 |
0
| String name = (String)pluginNames.get( i );
|
327 |
0
| Object obj = table.get( name );
|
328 |
| |
329 |
0
| sb.append( endl );
|
330 |
0
| if( obj == null )
|
331 |
| { |
332 |
0
| sb.append( sm.getString( PluginManagerClass.class
|
333 |
| , "name_not_defined" |
334 |
| , null |
335 |
| ) |
336 |
| ); |
337 |
0
| sb.append( name );
|
338 |
| } else { |
339 |
0
| sb.append( name );
|
340 |
0
| if( obj instanceof Plugin )
|
341 |
| { |
342 |
0
| sb.append( ", " );
|
343 |
0
| sb.append( ((Plugin)obj).getVersion() );
|
344 |
| } |
345 |
0
| sb.append( ":" );
|
346 |
0
| sb.append( endl );
|
347 |
| |
348 |
0
| String pluginHelp = mbox.getStringManager().getString( "help", obj );
|
349 |
0
| if( pluginHelp != null )
|
350 |
| { |
351 |
0
| sb.append( pluginHelp );
|
352 |
| } else { |
353 |
0
| sb.append( sm.getString( PluginManagerClass.class
|
354 |
| , "help_not_available" |
355 |
| , null |
356 |
| ) |
357 |
| ); |
358 |
| } |
359 |
0
| sb.append( endl );
|
360 |
| } |
361 |
| } |
362 |
| } |
363 |
0
| mbox.info( sb.toString() );
|
364 |
| } |
365 |
| |
366 |
| private static final String endl = System.getProperty( "line.separator" ); |
367 |
| } |