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.tree.tool; |
33 |
| |
34 |
| import java.io.File; |
35 |
| import java.util.ArrayList; |
36 |
| import java.util.List; |
37 |
| |
38 |
| import com.unitesk.atp.tree.Node; |
39 |
| import com.unitesk.atp.messages.*; |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
| |
45 |
| |
46 |
| |
47 |
| |
48 |
| |
49 |
| |
50 |
| |
51 |
| |
52 |
| |
53 |
| |
54 |
| |
55 |
| public abstract class Tool extends com.unitesk.atp.tool.Tool |
56 |
| implements PluginManager |
57 |
| { |
58 |
| |
59 |
| |
60 |
| |
61 |
| |
62 |
| |
63 |
| |
64 |
| protected abstract void parse( File inputFile ); |
65 |
| |
66 |
| |
67 |
| |
68 |
| |
69 |
| |
70 |
| |
71 |
0
| protected int run( String[] args )
|
72 |
| { |
73 |
0
| try
|
74 |
| { |
75 |
0
| onToolStart();
|
76 |
0
| if( args.length < 1 )
|
77 |
| { |
78 |
0
| usage();
|
79 |
0
| return 1;
|
80 |
| } |
81 |
| |
82 |
0
| String inputFileName = args[0];
|
83 |
| |
84 |
0
| if( inputFileName.equals( "-" ) )
|
85 |
| { |
86 |
0
| if( args.length == 1 )
|
87 |
| { |
88 |
0
| help( null );
|
89 |
| } else { |
90 |
0
| List l = new ArrayList();
|
91 |
| |
92 |
0
| for( int i = 1; i < args.length; i++ )
|
93 |
| { |
94 |
0
| l.add( args[i] );
|
95 |
| } |
96 |
0
| help( l );
|
97 |
| } |
98 |
0
| return 1;
|
99 |
| } else { |
100 |
0
| mbox.info( "" );
|
101 |
0
| onParserStart( inputFileName );
|
102 |
0
| parse( new File( inputFileName ) );
|
103 |
0
| mbox.status();
|
104 |
0
| onParserFinish( inputFileName );
|
105 |
0
| for ( int i = 1; i < args.length; i++ )
|
106 |
| { |
107 |
0
| process( args[i], null );
|
108 |
| } |
109 |
0
| onToolFinish();
|
110 |
0
| return 0;
|
111 |
| } |
112 |
| } |
113 |
| catch( FatalErrorException e ) |
114 |
| { |
115 |
0
| return e.getCode();
|
116 |
| } |
117 |
| } |
118 |
| |
119 |
| |
120 |
| |
121 |
| protected Tree tree; |
122 |
| |
123 |
| |
124 |
| |
125 |
| |
126 |
0
| public Tree getTree() { return tree; }
|
127 |
| |
128 |
| |
129 |
| |
130 |
| |
131 |
0
| public void setTree( Tree tree ) { this.tree = tree; }
|
132 |
| |
133 |
| |
134 |
| |
135 |
| |
136 |
0
| public void process( String name, Tree tree )
|
137 |
| { |
138 |
0
| Object plugin = getPlugin( name );
|
139 |
| |
140 |
0
| if( plugin != null && plugin instanceof Action )
|
141 |
| { |
142 |
0
| Action action = (Action)plugin;
|
143 |
0
| onActionStart( name, action );
|
144 |
0
| action.process( tree != null ? tree : this.tree );
|
145 |
0
| mbox.status();
|
146 |
0
| onActionFinish( name, action );
|
147 |
| } else { |
148 |
0
| mbox.fatal( new NameNotFoundMessage( null
|
149 |
| , null |
150 |
| , mbox |
151 |
| .getStringManager() |
152 |
| .getString( Action.class |
153 |
| , "message.action" |
154 |
| ) |
155 |
| , name |
156 |
| ) |
157 |
| ); |
158 |
| } |
159 |
| } |
160 |
| |
161 |
| |
162 |
| |
163 |
| |
164 |
0
| public Object get( String name, Tree tree, Node node )
|
165 |
| { |
166 |
0
| Object plugin = getPlugin( name );
|
167 |
| |
168 |
0
| if( plugin != null && plugin instanceof Attribute )
|
169 |
| { |
170 |
0
| return ((Attribute)plugin).get( tree != null ? tree : this.tree
|
171 |
| , node |
172 |
| ); |
173 |
| } else { |
174 |
0
| mbox.fatal( new NameNotFoundMessage( null
|
175 |
| , null |
176 |
| , mbox |
177 |
| .getStringManager() |
178 |
| .getString( Attribute.class |
179 |
| , "message.attribute" |
180 |
| ) |
181 |
| , name |
182 |
| ) |
183 |
| ); |
184 |
0
| return null;
|
185 |
| } |
186 |
| } |
187 |
| |
188 |
| |
189 |
| |
190 |
| |
191 |
| |
192 |
0
| protected void onToolStart()
|
193 |
| { |
194 |
0
| mbox.info( new ToolInfoMessage( this ) );
|
195 |
0
| mbox.info( new FileStatusMessage( properties_file_status
|
196 |
| , properties_file_name |
197 |
| ) |
198 |
| ); |
199 |
0
| mbox.info( new FileStatusMessage( plugins_file_status
|
200 |
| , plugins_file_name |
201 |
| ) |
202 |
| ); |
203 |
| } |
204 |
| |
205 |
| |
206 |
| |
207 |
| |
208 |
| |
209 |
0
| protected void onToolFinish()
|
210 |
| { |
211 |
0
| mbox.statistics();
|
212 |
| } |
213 |
| |
214 |
| |
215 |
| |
216 |
| |
217 |
| |
218 |
| |
219 |
| |
220 |
0
| protected void onParserStart( String inputFileName )
|
221 |
| { |
222 |
0
| mbox.info( new FileStatusMessage( InputFileStatus.status
|
223 |
| , inputFileName |
224 |
| ) |
225 |
| ); |
226 |
| } |
227 |
| |
228 |
| |
229 |
| |
230 |
| |
231 |
| |
232 |
| |
233 |
| |
234 |
0
| protected void onParserFinish( String inputFileName )
|
235 |
| { |
236 |
| } |
237 |
| |
238 |
| |
239 |
| |
240 |
| |
241 |
| |
242 |
| |
243 |
| |
244 |
| |
245 |
0
| protected void onActionStart( String name, Action action )
|
246 |
| { |
247 |
0
| mbox.info( new PluginInfoMessage( name, action) );
|
248 |
| } |
249 |
| |
250 |
| |
251 |
| |
252 |
| |
253 |
| |
254 |
| |
255 |
| |
256 |
| |
257 |
0
| protected void onActionFinish( String name, Action action )
|
258 |
| { |
259 |
| } |
260 |
| } |