|
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.io.File; |
|
37 |
| import java.io.FileInputStream; |
|
38 |
| import java.io.FileNotFoundException; |
|
39 |
| |
|
40 |
| import java.util.Properties; |
|
41 |
| |
|
42 |
| import com.unitesk.atp.messages.*; |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| public abstract class Tool extends PluginManagerClass |
|
51 |
| { |
|
52 |
| protected String version; |
|
53 |
| |
|
54 |
| protected String properties_file_property_name; |
|
55 |
| protected String default_properties_file_name; |
|
56 |
| protected String properties_file_name; |
|
57 |
| protected FileStatus properties_file_status; |
|
58 |
| |
|
59 |
| protected String plugins_file_property_name; |
|
60 |
| protected String default_plugins_file_name; |
|
61 |
| protected String plugins_file_name; |
|
62 |
| protected FileStatus plugins_file_status; |
|
63 |
| |
|
64 |
| protected String mbox_class_property_name; |
|
65 |
| protected String default_mbox_class; |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
0
| public final String getVersion()
|
|
71 |
| { |
|
72 |
0
| return version;
|
|
73 |
| } |
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| protected abstract void initName(); |
|
80 |
| |
|
81 |
| |
|
82 |
| |
|
83 |
| |
|
84 |
0
| protected void initConfig()
|
|
85 |
| { |
|
86 |
0
| properties_file_property_name = name + ".properties.file";
|
|
87 |
0
| default_properties_file_name = name + ".properties";
|
|
88 |
| |
|
89 |
0
| properties_file_name
|
|
90 |
| = System.getProperty( properties_file_property_name |
|
91 |
| , default_properties_file_name |
|
92 |
| ); |
|
93 |
0
| properties_file_status = NotFoundFileStatus.status;
|
|
94 |
| |
|
95 |
0
| config = new Properties();
|
|
96 |
| |
|
97 |
0
| try
|
|
98 |
| { |
|
99 |
0
| InputStream in = findFile( properties_file_name );
|
|
100 |
| |
|
101 |
0
| if( in != null )
|
|
102 |
| { |
|
103 |
0
| config.load( in );
|
|
104 |
0
| properties_file_status = FoundFileStatus.status;
|
|
105 |
| } |
|
106 |
| } |
|
107 |
| catch( IOException e ) |
|
108 |
| { |
|
109 |
0
| mbox = new PrintStreamMessageBox();
|
|
110 |
0
| mbox.fatal( new IOErrorMessage( new File( properties_file_name ) ) );
|
|
111 |
| } |
|
112 |
| } |
|
113 |
| |
|
114 |
| |
|
115 |
| |
|
116 |
| |
|
117 |
| |
|
118 |
| |
|
119 |
| |
|
120 |
0
| protected void initMessageBox()
|
|
121 |
| { |
|
122 |
0
| mbox_class_property_name = name + ".mbox.class";
|
|
123 |
0
| default_mbox_class
|
|
124 |
| = "com.unitesk.atp.messages.PrintStreamMessageBox"; |
|
125 |
0
| String mbox_class
|
|
126 |
| = getProperty( mbox_class_property_name, default_mbox_class ); |
|
127 |
0
| try
|
|
128 |
| { |
|
129 |
0
| mbox = (MessageBox)Class.forName( mbox_class ).newInstance();
|
|
130 |
| } |
|
131 |
| catch( Exception e ) |
|
132 |
| { |
|
133 |
0
| mbox = new PrintStreamMessageBox();
|
|
134 |
0
| mbox.fatal( new NameNotFoundMessage
|
|
135 |
| ( null |
|
136 |
| , null |
|
137 |
| , mbox |
|
138 |
| .getStringManager() |
|
139 |
| .getString( Tool.class, "message.class" ) |
|
140 |
| , mbox_class |
|
141 |
| ) |
|
142 |
| ); |
|
143 |
| } |
|
144 |
| } |
|
145 |
| |
|
146 |
| |
|
147 |
| |
|
148 |
| |
|
149 |
| |
|
150 |
| |
|
151 |
0
| protected void initPluginsTable()
|
|
152 |
| { |
|
153 |
0
| plugins_file_property_name = name + ".plugins.file";
|
|
154 |
0
| default_plugins_file_name = name + ".plugins";
|
|
155 |
| |
|
156 |
0
| plugins_file_name = getProperty( plugins_file_property_name
|
|
157 |
| , default_plugins_file_name |
|
158 |
| ); |
|
159 |
0
| plugins_file_status = NotFoundFileStatus.status;
|
|
160 |
| |
|
161 |
0
| try
|
|
162 |
| { |
|
163 |
0
| InputStream in = findFile( plugins_file_name );
|
|
164 |
0
| if( in != null )
|
|
165 |
| { |
|
166 |
0
| loadPlugins( in );
|
|
167 |
0
| plugins_file_status = FoundFileStatus.status;
|
|
168 |
| } else { |
|
169 |
0
| mbox.warning( new FileNotFoundMessage
|
|
170 |
| ( new File( plugins_file_name ) ) |
|
171 |
| ); |
|
172 |
0
| createPluginsTable();
|
|
173 |
0
| return;
|
|
174 |
| } |
|
175 |
| } |
|
176 |
| catch( IOException e ) |
|
177 |
| { |
|
178 |
0
| mbox.fatal( new IOErrorMessage( new File( plugins_file_name ) ) );
|
|
179 |
| } |
|
180 |
| catch( ClassNotFoundException e ) |
|
181 |
| { |
|
182 |
0
| mbox.fatal( new NameNotFoundMessage
|
|
183 |
| ( new File( plugins_file_name ) |
|
184 |
| , null |
|
185 |
| , mbox |
|
186 |
| .getStringManager() |
|
187 |
| .getString( Plugin.class, "message.plugin_class" ) |
|
188 |
| , e.getMessage() |
|
189 |
| ) |
|
190 |
| ); |
|
191 |
| } |
|
192 |
| } |
|
193 |
| |
|
194 |
| |
|
195 |
| |
|
196 |
| |
|
197 |
0
| protected final void usage()
|
|
198 |
| { |
|
199 |
0
| mbox.info( mbox
|
|
200 |
| .getStringManager() |
|
201 |
| .getString( com.unitesk.atp.tool.Tool.class |
|
202 |
| , "usage" |
|
203 |
| , this |
|
204 |
| ) |
|
205 |
| ); |
|
206 |
| } |
|
207 |
| |
|
208 |
| |
|
209 |
| |
|
210 |
| |
|
211 |
| |
|
212 |
| |
|
213 |
| |
|
214 |
| |
|
215 |
| |
|
216 |
| |
|
217 |
| |
|
218 |
| |
|
219 |
| |
|
220 |
| |
|
221 |
| |
|
222 |
| |
|
223 |
0
| public static InputStream findFile( String name )
|
|
224 |
| { |
|
225 |
0
| try
|
|
226 |
| { |
|
227 |
0
| return new FileInputStream( name );
|
|
228 |
| } |
|
229 |
| catch( FileNotFoundException e ) |
|
230 |
| { |
|
231 |
0
| ClassLoader contextCL = Thread
|
|
232 |
| .currentThread() |
|
233 |
| .getContextClassLoader(); |
|
234 |
0
| InputStream res;
|
|
235 |
0
| if( contextCL != null )
|
|
236 |
| { |
|
237 |
0
| res = contextCL.getResourceAsStream( name );
|
|
238 |
0
| if( res != null ) return res;
|
|
239 |
| } |
|
240 |
0
| res = Tool.class.getClassLoader().getResourceAsStream( name );
|
|
241 |
0
| if( res != null ) return res;
|
|
242 |
0
| return ClassLoader.getSystemClassLoader().getResourceAsStream( name );
|
|
243 |
| } |
|
244 |
| } |
|
245 |
| } |
|
246 |
| |