|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 package com.nokia.s60tools.appdep.export; |
|
20 |
|
21 import java.io.BufferedWriter; |
|
22 import java.io.FileNotFoundException; |
|
23 import java.io.FileWriter; |
|
24 import java.io.IOException; |
|
25 import java.util.Collection; |
|
26 import java.util.HashMap; |
|
27 import java.util.Iterator; |
|
28 import java.util.NoSuchElementException; |
|
29 |
|
30 import com.nokia.s60tools.appdep.core.data.ComponentLinkLeafNode; |
|
31 import com.nokia.s60tools.appdep.core.data.ComponentNode; |
|
32 import com.nokia.s60tools.appdep.core.data.ComponentParentNode; |
|
33 import com.nokia.s60tools.appdep.core.job.IJobProgressStatus; |
|
34 import com.nokia.s60tools.appdep.core.model.ComponentPropertiesData; |
|
35 import com.nokia.s60tools.appdep.core.model.ExportFunctionData; |
|
36 import com.nokia.s60tools.appdep.core.model.ImportFunctionData; |
|
37 import com.nokia.s60tools.appdep.exceptions.CacheFileDoesNotExistException; |
|
38 import com.nokia.s60tools.appdep.exceptions.CacheIndexNotReadyException; |
|
39 import com.nokia.s60tools.appdep.resources.Messages; |
|
40 import com.nokia.s60tools.appdep.ui.views.data.IVisitor; |
|
41 import com.nokia.s60tools.appdep.ui.views.main.MainViewDataPopulator; |
|
42 import com.nokia.s60tools.appdep.util.AppDepConsole; |
|
43 import com.nokia.s60tools.util.console.IConsolePrintUtility; |
|
44 import com.nokia.s60tools.util.debug.DbgUtility; |
|
45 import com.nokia.s60tools.util.exceptions.JobCancelledByUserException; |
|
46 |
|
47 /** |
|
48 * Visitor class from Export report -functionality. |
|
49 */ |
|
50 public class ExportVisitor implements IVisitor { |
|
51 |
|
52 // |
|
53 // Private members and constants. |
|
54 // |
|
55 private String sdkName; |
|
56 private String targets; |
|
57 private String build; |
|
58 private String rootComponentName; |
|
59 private String rootComponentFullName; |
|
60 private StringBuffer components; |
|
61 private StringBuffer properties; |
|
62 private StringBuffer exportedFunctions; |
|
63 private HashMap<String, String> componentNames; |
|
64 private static final String LEAF_NODE = "leafNode"; //$NON-NLS-1$ |
|
65 private static final String PARENT_NODE = "parentNode"; //$NON-NLS-1$ |
|
66 |
|
67 private IJobProgressStatus observer; |
|
68 //Other progress percentage @see ExportJob.java |
|
69 private int COMPONENTS_EXPORT_PERCENTAGE = 85; |
|
70 private int progressBarProgressedCount = 1; |
|
71 private int progressBarComponentsCount = 1; |
|
72 private boolean isExportFromRoot = true; |
|
73 |
|
74 /** |
|
75 * Constructor. |
|
76 * @param sdkName SDK the data is got for the export. |
|
77 * @param targets Targets the data is got for the export. |
|
78 * @param build Build type the data is got for the export. |
|
79 * @param rootComponentName Root component short name. |
|
80 * @param rootComponentFullName Root component fully qualified name. |
|
81 * @param observer Job progress observer |
|
82 */ |
|
83 public ExportVisitor(String sdkName, |
|
84 String targets, String build, String rootComponentName, |
|
85 String rootComponentFullName, |
|
86 IJobProgressStatus observer){ |
|
87 |
|
88 this.sdkName = sdkName; |
|
89 this.targets = targets; |
|
90 this.build = build; |
|
91 this.rootComponentName = rootComponentName; |
|
92 this.rootComponentFullName = rootComponentFullName; |
|
93 |
|
94 this.observer = observer;; |
|
95 |
|
96 DbgUtility.println(DbgUtility.PRIORITY_OPERATION, |
|
97 "Visitor; this.rootComponentName = " +rootComponentName); //$NON-NLS-1$ |
|
98 |
|
99 components = new StringBuffer(); |
|
100 properties = new StringBuffer(); |
|
101 exportedFunctions = new StringBuffer(); |
|
102 componentNames = new HashMap<String, String>(); |
|
103 } |
|
104 |
|
105 /** |
|
106 * Adds a single import function node. |
|
107 * @param node Component node. |
|
108 */ |
|
109 private void addImportedFunctions(ComponentNode node){ |
|
110 try { |
|
111 addImportedFunctionsToComponent(node.getParent().getName(), node.getName()); |
|
112 } catch (NoSuchElementException e) { |
|
113 addErrorCommentToComponents(node, e); |
|
114 |
|
115 DbgUtility.println(DbgUtility.PRIORITY_OPERATION, |
|
116 "Not found imported functions for: " +node.getFullName() //$NON-NLS-1$ |
|
117 +". Error was: " +e); //$NON-NLS-1$ |
|
118 } |
|
119 catch (Exception e) { |
|
120 addErrorCommentToComponents(node, e); |
|
121 e.printStackTrace(); |
|
122 } |
|
123 |
|
124 } |
|
125 |
|
126 /** |
|
127 * Adding error message info related to the component in question. |
|
128 * @param node Component node in question. |
|
129 * @param e Exception encountered. |
|
130 */ |
|
131 private void addErrorCommentToComponents(ComponentNode node, Exception e) { |
|
132 components.append("<!-- ERROR while getting Imported functions for: "); //$NON-NLS-1$ |
|
133 components.append(node.getName()); |
|
134 components.append(", parent: "); //$NON-NLS-1$ |
|
135 components.append(node.getParent().getName()); |
|
136 components.append("\nError was:\n"); //$NON-NLS-1$ |
|
137 components.append(e); |
|
138 components.append("\n-->"); //$NON-NLS-1$ |
|
139 } |
|
140 |
|
141 /** |
|
142 * Adding node name as key |
|
143 * and this.PARENT_NODE as value if node is ComponentParentNode |
|
144 * or this.LEAF_NODE as value if node is ComponentLinkLeafNode |
|
145 * if not exist in this.PARENT_NODE already |
|
146 * to this.componentNames |
|
147 * |
|
148 * If adding this.PARENT_NODE and this.LEAF_NODE already exist, replacing |
|
149 * |
|
150 * This is doing to know if a node exist as a parent in report or not, |
|
151 * this has a affect to generate anchors and links in html |
|
152 * (from properties and external functions "<component name>" link points to |
|
153 * that component only if it exist as parent node |
|
154 * |
|
155 * @param node Node to to be added as key, if it does not exist already. |
|
156 */ |
|
157 private void addNodeName(ComponentNode node){ |
|
158 |
|
159 boolean isParent = false; |
|
160 if(node instanceof ComponentParentNode){ |
|
161 isParent = true; |
|
162 } |
|
163 |
|
164 //Collection all names of components for getting properties and exported functions |
|
165 if(!componentNames.containsKey(node.getName())){ |
|
166 if(isParent){ |
|
167 componentNames.put(node.getName(),PARENT_NODE); |
|
168 } |
|
169 else { |
|
170 componentNames.put(node.getName(),LEAF_NODE); |
|
171 } |
|
172 |
|
173 }else{ |
|
174 String tmp = (String) componentNames.get(node.getName()); |
|
175 if(isParent && tmp.equals(LEAF_NODE)){ |
|
176 componentNames.put(node.getName(),PARENT_NODE); |
|
177 } |
|
178 |
|
179 } |
|
180 } |
|
181 |
|
182 /* (non-Javadoc) |
|
183 * @see com.nokia.s60tools.appdep.ui.views.data.IVisitor#visit(com.nokia.s60tools.appdep.core.data.ComponentLinkLeafNode) |
|
184 */ |
|
185 public void visit(ComponentLinkLeafNode node) { |
|
186 // Exporting XML for this node only because it is leaf |
|
187 if(observer.isCanceled()){ |
|
188 DbgUtility.println(DbgUtility.PRIORITY_OPERATION, |
|
189 "Cancelled by User when prosessing node: " +node.getName()); //$NON-NLS-1$ |
|
190 return; |
|
191 } |
|
192 addNodeName(node); |
|
193 addComponent(node, true); |
|
194 addImportedFunctions(node); |
|
195 updateProgress(node); |
|
196 components.append("</component>"); //$NON-NLS-1$ |
|
197 |
|
198 } |
|
199 |
|
200 /* (non-Javadoc) |
|
201 * @see com.nokia.s60tools.appdep.ui.views.data.IVisitor#visit(com.nokia.s60tools.appdep.core.data.ComponentParentNode) |
|
202 */ |
|
203 public void visit(ComponentParentNode node) { |
|
204 |
|
205 if(observer.isCanceled()){ |
|
206 return; |
|
207 } |
|
208 |
|
209 DbgUtility.println(DbgUtility.PRIORITY_LOOP,"Visiting in node: " +node.getFullName()); //$NON-NLS-1$ |
|
210 if(node.getFullName().equals(rootComponentFullName)){ |
|
211 DbgUtility.println(DbgUtility.PRIORITY_LOOP, "Found ROOT!"); //$NON-NLS-1$ |
|
212 } |
|
213 |
|
214 addNodeName(node); |
|
215 |
|
216 //when found root, counting 2nd and 3rd level components for progress bar |
|
217 if ( node.isRootComponent() || node.getFullName().equals(rootComponentFullName)) { |
|
218 countComponents(node); |
|
219 } |
|
220 |
|
221 addComponent(node, false); |
|
222 |
|
223 addImportedFunctions(node); |
|
224 |
|
225 // For progress bar assuming that components under root is equal sized |
|
226 updateProgress(node); |
|
227 |
|
228 // Exporting XML for this node and for all its children |
|
229 ComponentNode[] childArray = node.getChildren(); |
|
230 for (int i = 0; i < childArray.length; i++) { |
|
231 ComponentNode childNode = childArray[i]; |
|
232 childNode.accept(this); |
|
233 } |
|
234 |
|
235 components.append("</component>"); //$NON-NLS-1$ |
|
236 |
|
237 |
|
238 } |
|
239 |
|
240 /** |
|
241 * Sets this.isExportFromRoot false if Export is not selected to start from root |
|
242 * Sets progressBarComponentsCount |
|
243 * @param node Parent where to start counting, counts nodes under that node |
|
244 * and nodes under those nodes |
|
245 */ |
|
246 private void countComponents(ComponentParentNode node) { |
|
247 // update progress |
|
248 int secondLevelComponentsCount = 0; |
|
249 int rootLevelComponentsCount = 0; |
|
250 |
|
251 try { |
|
252 |
|
253 if(!node.isRootComponent()){ |
|
254 isExportFromRoot = false; |
|
255 DbgUtility.println(DbgUtility.PRIORITY_OPERATION, |
|
256 "Selected Export node was not Root node"); //$NON-NLS-1$ |
|
257 } |
|
258 |
|
259 rootLevelComponentsCount = node.getChildren().length; |
|
260 DbgUtility.println(DbgUtility.PRIORITY_OPERATION, |
|
261 "Export found "+ rootLevelComponentsCount //$NON-NLS-1$ |
|
262 + " 2nd level components under root: " //$NON-NLS-1$ |
|
263 + node.getFullName()); |
|
264 |
|
265 if(node.hasChildren()){ |
|
266 ComponentNode [] nodes = node.getChildren(); |
|
267 ComponentNode tmp; |
|
268 ComponentParentNode parentTmp; |
|
269 for(int i=0; i<nodes.length; i++){ |
|
270 tmp = nodes[i]; |
|
271 if(tmp instanceof ComponentParentNode){ |
|
272 parentTmp = (ComponentParentNode)tmp; |
|
273 secondLevelComponentsCount += parentTmp.getChildren().length; |
|
274 DbgUtility.println(DbgUtility.PRIORITY_OPERATION, |
|
275 "Adding: "+parentTmp.getChildren().length //$NON-NLS-1$ |
|
276 + " when name: " +parentTmp.getFullName()); //$NON-NLS-1$ |
|
277 } |
|
278 //else it is a LeafNode, so under that there aren't any nodes |
|
279 } |
|
280 } |
|
281 } catch (Exception e) { |
|
282 String msg = Messages.getString("ExportVisitor.Could_Not_Count_Components_Msg"); //$NON-NLS-1$ |
|
283 DbgUtility.println(DbgUtility.PRIORITY_OPERATION, msg); |
|
284 AppDepConsole.getInstance().println(msg, IConsolePrintUtility.MSG_WARNING); |
|
285 e.printStackTrace(); |
|
286 } |
|
287 |
|
288 progressBarComponentsCount = rootLevelComponentsCount + secondLevelComponentsCount; |
|
289 |
|
290 } |
|
291 |
|
292 /** |
|
293 * Adds one component to this.components. |
|
294 * @param node node to be added. |
|
295 * @param isReference if component is reference it will be typed on "reference" else for "base" |
|
296 */ |
|
297 private void addComponent(ComponentNode node, boolean isReference ) { |
|
298 //<component> must close after calling, because under components will be imported functions |
|
299 components.append("<component name=\""); //$NON-NLS-1$ |
|
300 components.append(node.getName()); |
|
301 components.append("\" "); //$NON-NLS-1$ |
|
302 components.append(" fullName=\""); //$NON-NLS-1$ |
|
303 components.append(node.getFullName()); |
|
304 components.append("\" "); //$NON-NLS-1$ |
|
305 components.append(" type=\""); //$NON-NLS-1$ |
|
306 if(isReference){ |
|
307 components.append("reference"); //$NON-NLS-1$ |
|
308 }else{ |
|
309 components.append("base"); //$NON-NLS-1$ |
|
310 } |
|
311 |
|
312 components.append("\" "); //$NON-NLS-1$ |
|
313 components.append(">"); //$NON-NLS-1$ |
|
314 components.append("\n"); //$NON-NLS-1$ |
|
315 } |
|
316 |
|
317 /** |
|
318 * Updates progress status. |
|
319 * @param node Node currently under exporting. |
|
320 */ |
|
321 private void updateProgress(ComponentNode node){ |
|
322 |
|
323 try { |
|
324 |
|
325 if(node instanceof ComponentParentNode){ |
|
326 |
|
327 ComponentParentNode tmp = (ComponentParentNode)node; |
|
328 |
|
329 if (isExportFromRoot && !tmp.isRootComponent() && |
|
330 (tmp.getParent().isRootComponent() || tmp.getParent().getParent().isRootComponent() )) { |
|
331 //updateProgress(node.getName()); |
|
332 updateProgress(tmp.getName()); |
|
333 } |
|
334 else if(!isExportFromRoot){ |
|
335 //if parent or parents parent is selected export root |
|
336 if( tmp.getParent().getFullName().equals(rootComponentFullName ) |
|
337 || ( !tmp.getParent().isRootComponent() && tmp.getParent().getParent().getFullName().equals(rootComponentFullName) ) ){ |
|
338 updateProgress(tmp.getName()); |
|
339 } |
|
340 } |
|
341 } |
|
342 else { |
|
343 ComponentLinkLeafNode tmp = (ComponentLinkLeafNode)node; |
|
344 if (isExportFromRoot && (tmp.getParent().isRootComponent() || tmp.getParent().getParent().isRootComponent() )) { |
|
345 updateProgress(tmp.getName()); |
|
346 } |
|
347 else if(!isExportFromRoot){ |
|
348 //if parent or parents parent is selected export root |
|
349 if( tmp.getParent().getFullName().equals(rootComponentFullName ) |
|
350 || ( !tmp.getParent().isRootComponent() && tmp.getParent().getParent().getFullName().equals(rootComponentFullName) ) ){ |
|
351 updateProgress(tmp.getName()); |
|
352 } |
|
353 } |
|
354 |
|
355 } |
|
356 } catch (JobCancelledByUserException e) { |
|
357 AppDepConsole.getInstance().println(Messages.getString("ExportVisitor.Process_Cancelled_ByUser_ConsoleMsg") //$NON-NLS-1$ |
|
358 + node.getName(), IConsolePrintUtility.MSG_NORMAL); |
|
359 } catch (Exception e) { |
|
360 // No exceptions forwarded if error occurs when updating progress |
|
361 AppDepConsole.getInstance().println(Messages.getString("ExportVisitor.Progress_Update_Failed_ConsoleMsg") + e, //$NON-NLS-1$ |
|
362 IConsolePrintUtility.MSG_ERROR); |
|
363 } |
|
364 |
|
365 } |
|
366 |
|
367 /** |
|
368 * Notifies observers about the progress. |
|
369 * @param componentName Component name currently at hand. |
|
370 * @throws Exception |
|
371 */ |
|
372 private void updateProgress(String componentName) throws Exception { |
|
373 int percentage = |
|
374 COMPONENTS_EXPORT_PERCENTAGE * |
|
375 progressBarProgressedCount / progressBarComponentsCount; |
|
376 |
|
377 DbgUtility.println(DbgUtility.PRIORITY_LOOP, |
|
378 "Updating progress to: " + percentage //$NON-NLS-1$ |
|
379 + " progressed so far: " +progressBarProgressedCount //$NON-NLS-1$ |
|
380 + ", all cout: " +progressBarComponentsCount); //$NON-NLS-1$ |
|
381 |
|
382 observer.progress(percentage, componentName); |
|
383 //Avoid > 100% progressed just in case |
|
384 if(progressBarProgressedCount < progressBarComponentsCount){ |
|
385 progressBarProgressedCount++; |
|
386 } |
|
387 } |
|
388 |
|
389 /** |
|
390 * Adds new imported function data for the selected component. |
|
391 * @param parentComponentName parent component for the selected component |
|
392 * @param selectedComponentName selected component. |
|
393 * @throws FileNotFoundException |
|
394 * @throws IOException |
|
395 * @throws CacheIndexNotReadyException |
|
396 * @throws CacheFileDoesNotExistException |
|
397 */ |
|
398 private void addImportedFunctionsToComponent( |
|
399 String parentComponentName, String selectedComponentName ) |
|
400 throws FileNotFoundException, |
|
401 IOException, |
|
402 CacheIndexNotReadyException, |
|
403 CacheFileDoesNotExistException |
|
404 { |
|
405 Collection<ImportFunctionData> importedFunctionsColl |
|
406 = MainViewDataPopulator. |
|
407 getParentImportedFunctionsForComponent( |
|
408 parentComponentName, |
|
409 selectedComponentName); |
|
410 |
|
411 |
|
412 String fOrdinal = null; |
|
413 String fName = null; |
|
414 boolean fVirtualFlag = false; |
|
415 String fOffset = null; |
|
416 |
|
417 //Using own buffer, so the XML will be well formed even if fails |
|
418 StringBuffer importedFunctions = new StringBuffer(); |
|
419 |
|
420 importedFunctions.append("<importedFunctions>"); //$NON-NLS-1$ |
|
421 |
|
422 for (ImportFunctionData importFunctionData : importedFunctionsColl) { |
|
423 fOrdinal = importFunctionData.getFunctionOrdinal(); |
|
424 fName = importFunctionData.getFunctionName(); |
|
425 fVirtualFlag = importFunctionData.isVirtual(); |
|
426 |
|
427 importedFunctions.append("\n"); //$NON-NLS-1$ |
|
428 importedFunctions.append("<function ordinal=\""); //$NON-NLS-1$ |
|
429 importedFunctions.append(fOrdinal); |
|
430 importedFunctions.append("\" name=\""); //$NON-NLS-1$ |
|
431 importedFunctions.append( StringUtils.replaceForbiddenCharacters( fName )); |
|
432 importedFunctions.append("\" "); //$NON-NLS-1$ |
|
433 |
|
434 if(fVirtualFlag){ |
|
435 fOffset = importFunctionData.getFunctionOffsetAsString(); |
|
436 importedFunctions.append(" offset=\""); //$NON-NLS-1$ |
|
437 importedFunctions.append(fOffset); |
|
438 importedFunctions.append("\" "); //$NON-NLS-1$ |
|
439 importedFunctions.append(" virtual=\"1\" "); //$NON-NLS-1$ |
|
440 } |
|
441 else{ |
|
442 // Non-virtual methods do not have offset |
|
443 fOffset = ""; //$NON-NLS-1$ |
|
444 importedFunctions.append(" virtual=\"0\" "); //$NON-NLS-1$ |
|
445 } |
|
446 importedFunctions.append("/>\n"); //$NON-NLS-1$ |
|
447 } |
|
448 importedFunctions.append("</importedFunctions>\n"); //$NON-NLS-1$ |
|
449 components.append(importedFunctions); |
|
450 |
|
451 } |
|
452 |
|
453 /** |
|
454 * Created XML data blocks for component properties. |
|
455 */ |
|
456 public void createProperties(){ |
|
457 |
|
458 if(observer.isCanceled()){ |
|
459 DbgUtility.println(DbgUtility.PRIORITY_OPERATION, |
|
460 Messages.getString("ExportVisitor.Process_Cancelled_ByUser_When_Processing_ConsoleMsg")); //$NON-NLS-1$ |
|
461 return; |
|
462 } |
|
463 |
|
464 Collection<String> col = componentNames.keySet(); |
|
465 Iterator<String> it = col.iterator(); |
|
466 String name; |
|
467 ComponentPropertiesData comPropData = null; |
|
468 String [] cababilities; |
|
469 |
|
470 while(it.hasNext()){ |
|
471 name = (String)it.next(); |
|
472 properties.append("<component name=\""); //$NON-NLS-1$ |
|
473 properties.append(name); |
|
474 |
|
475 properties.append("\" foundAsParent=\""); //$NON-NLS-1$ |
|
476 properties.append(isComponentFoundAsParent(name)); |
|
477 |
|
478 |
|
479 properties.append("\" type=\"properties\">"); //$NON-NLS-1$ |
|
480 properties.append("\n"); //$NON-NLS-1$ |
|
481 |
|
482 |
|
483 try { |
|
484 comPropData = MainViewDataPopulator.getComponentPropertyArrayForComponent(name, null); |
|
485 |
|
486 properties.append("<directory>"); //$NON-NLS-1$ |
|
487 properties.append(comPropData.getDirectory()); |
|
488 properties.append("</directory>"); //$NON-NLS-1$ |
|
489 properties.append("\n"); //$NON-NLS-1$ |
|
490 properties.append("<filename>"); //$NON-NLS-1$ |
|
491 properties.append(comPropData.getFilename()); |
|
492 properties.append("</filename>"); //$NON-NLS-1$ |
|
493 properties.append("\n"); //$NON-NLS-1$ |
|
494 properties.append("<binaryFormat>"); //$NON-NLS-1$ |
|
495 properties.append(comPropData.getBinaryFormat()); |
|
496 properties.append("</binaryFormat>"); //$NON-NLS-1$ |
|
497 properties.append("\n"); //$NON-NLS-1$ |
|
498 properties.append("<UID1>"); //$NON-NLS-1$ |
|
499 properties.append(comPropData.getUid1()); |
|
500 properties.append("</UID1>"); //$NON-NLS-1$ |
|
501 properties.append("\n"); //$NON-NLS-1$ |
|
502 properties.append("<UID2>"); //$NON-NLS-1$ |
|
503 properties.append(comPropData.getUid2()); |
|
504 properties.append("</UID2>"); //$NON-NLS-1$ |
|
505 properties.append("\n"); //$NON-NLS-1$ |
|
506 properties.append("<UID3>"); //$NON-NLS-1$ |
|
507 properties.append(comPropData.getUid3()); |
|
508 properties.append("</UID3>"); //$NON-NLS-1$ |
|
509 properties.append("\n"); //$NON-NLS-1$ |
|
510 properties.append("<secureID>"); //$NON-NLS-1$ |
|
511 properties.append(comPropData.getSecureId()); |
|
512 properties.append("</secureID>"); //$NON-NLS-1$ |
|
513 properties.append("\n"); //$NON-NLS-1$ |
|
514 properties.append("<vendorID>"); //$NON-NLS-1$ |
|
515 properties.append(comPropData.getVendorId()); |
|
516 properties.append("</vendorID>"); //$NON-NLS-1$ |
|
517 properties.append("\n"); //$NON-NLS-1$ |
|
518 properties.append("<capabilities>"); //$NON-NLS-1$ |
|
519 cababilities = comPropData.getCapabilities(); |
|
520 for(int j=0; j<cababilities.length; j++){ |
|
521 properties.append(cababilities[j]); |
|
522 properties.append("\n"); //$NON-NLS-1$ |
|
523 } |
|
524 properties.append("</capabilities>"); //$NON-NLS-1$ |
|
525 properties.append("\n"); //$NON-NLS-1$ |
|
526 properties.append("<minHeapSize>"); //$NON-NLS-1$ |
|
527 properties.append(comPropData.getMinHeapSize()); |
|
528 properties.append("</minHeapSize>"); //$NON-NLS-1$ |
|
529 properties.append("\n"); //$NON-NLS-1$ |
|
530 properties.append("<maxHeapSize>"); //$NON-NLS-1$ |
|
531 properties.append(comPropData.getMaxHeapSize()); |
|
532 properties.append("</maxHeapSize>"); //$NON-NLS-1$ |
|
533 properties.append("\n"); //$NON-NLS-1$ |
|
534 properties.append("<stackSize>"); //$NON-NLS-1$ |
|
535 properties.append(comPropData.getStackSize()); |
|
536 properties.append("</stackSize>"); //$NON-NLS-1$ |
|
537 properties.append("\n"); //$NON-NLS-1$ |
|
538 properties.append("<dllRefTableCount>"); //$NON-NLS-1$ |
|
539 properties.append(comPropData.getDllRefTableCount()); |
|
540 properties.append("</dllRefTableCount>"); //$NON-NLS-1$ |
|
541 properties.append("\n"); //$NON-NLS-1$ |
|
542 |
|
543 } catch (NoSuchElementException e) { |
|
544 // The selected component does necessary |
|
545 // have any data about exported functions. |
|
546 // Therefore we can ignore this exception |
|
547 //e.printStackTrace(); |
|
548 properties.append("<!-- Not found properties for: "); //$NON-NLS-1$ |
|
549 properties.append(name); |
|
550 properties.append(" -->"); //$NON-NLS-1$ |
|
551 } catch (Exception e) { |
|
552 e.printStackTrace(); |
|
553 |
|
554 properties.append("<!-- Error: "); //$NON-NLS-1$ |
|
555 properties.append(e); |
|
556 properties.append(" occurs when founding properties for: "); //$NON-NLS-1$ |
|
557 properties.append(name); |
|
558 properties.append(" -->"); //$NON-NLS-1$ |
|
559 } |
|
560 |
|
561 properties.append("\n"); //$NON-NLS-1$ |
|
562 properties.append("</component>"); //$NON-NLS-1$ |
|
563 properties.append("\n"); //$NON-NLS-1$ |
|
564 } |
|
565 |
|
566 } |
|
567 |
|
568 /** |
|
569 * Checks if there is component parent node available for given component name. |
|
570 * @param name component name. |
|
571 * @return <code>true</code> if found, otherwise <code>false</code>. |
|
572 */ |
|
573 private String isComponentFoundAsParent(String name){ |
|
574 |
|
575 String tmp = (String) componentNames.get(name); |
|
576 |
|
577 return (tmp.equals(PARENT_NODE)) ? "true" : "false" ; //$NON-NLS-1$ //$NON-NLS-2$ |
|
578 } |
|
579 |
|
580 /** |
|
581 * Creates XML data blocks for exported functions. |
|
582 */ |
|
583 public void createExportedFunctions(){ |
|
584 |
|
585 if(observer.isCanceled()){ |
|
586 DbgUtility.println(DbgUtility.PRIORITY_LOOP,Messages.getString("ExportVisitor.Process_Cancelled_ByUser_When_Processing_ExpFuncs_ConsoleMsg")); //$NON-NLS-1$ |
|
587 return; |
|
588 } |
|
589 |
|
590 Collection<String> col = componentNames.keySet(); |
|
591 Iterator<String> it = col.iterator(); |
|
592 String name; |
|
593 |
|
594 while(it.hasNext()){ |
|
595 name = (String)it.next(); |
|
596 exportedFunctions.append("<component name=\""); //$NON-NLS-1$ |
|
597 exportedFunctions.append(name); |
|
598 |
|
599 exportedFunctions.append("\" foundAsParent=\""); //$NON-NLS-1$ |
|
600 exportedFunctions.append(isComponentFoundAsParent(name)); |
|
601 |
|
602 exportedFunctions.append("\" type=\"exportedFunctions\">"); //$NON-NLS-1$ |
|
603 exportedFunctions.append("\n"); //$NON-NLS-1$ |
|
604 |
|
605 |
|
606 try { |
|
607 Collection<ExportFunctionData> exp = MainViewDataPopulator.getExportedFunctionsForComponent(name); |
|
608 |
|
609 for (ExportFunctionData exportFunctionData : exp) { |
|
610 exportedFunctions.append("<function ordinal=\""); //$NON-NLS-1$ |
|
611 exportedFunctions.append(exportFunctionData.getFunctionOrdinal()); |
|
612 exportedFunctions.append("\" name=\""); //$NON-NLS-1$ |
|
613 exportedFunctions.append( |
|
614 StringUtils.replaceForbiddenCharacters( |
|
615 exportFunctionData.getFunctionName() )); |
|
616 exportedFunctions.append("\"/>"); //$NON-NLS-1$ |
|
617 exportedFunctions.append("\n"); //$NON-NLS-1$ |
|
618 } |
|
619 |
|
620 } catch (NoSuchElementException e) { |
|
621 // The selected component does necessary |
|
622 // have any data about exported functions. |
|
623 // Therefore we can ignore this exception |
|
624 //e.printStackTrace(); |
|
625 exportedFunctions.append("<!-- Not found exported functions for: "); //$NON-NLS-1$ |
|
626 exportedFunctions.append(name); |
|
627 exportedFunctions.append(" -->"); //$NON-NLS-1$ |
|
628 } catch (Exception e) { |
|
629 e.printStackTrace(); |
|
630 |
|
631 exportedFunctions.append("<!-- Error: "); //$NON-NLS-1$ |
|
632 exportedFunctions.append(e); |
|
633 exportedFunctions.append(" occurs when founding exported functions for: "); //$NON-NLS-1$ |
|
634 exportedFunctions.append(name); |
|
635 exportedFunctions.append(" -->"); //$NON-NLS-1$ |
|
636 } |
|
637 |
|
638 exportedFunctions.append("\n"); //$NON-NLS-1$ |
|
639 exportedFunctions.append("</component>"); //$NON-NLS-1$ |
|
640 exportedFunctions.append("\n"); //$NON-NLS-1$ |
|
641 } |
|
642 |
|
643 } |
|
644 |
|
645 public String toString(){ |
|
646 |
|
647 if(observer.isCanceled()){ |
|
648 DbgUtility.println(DbgUtility.PRIORITY_LOOP, "Cancelled by User when prosessing String "); //$NON-NLS-1$ |
|
649 return ""; //$NON-NLS-1$ |
|
650 } |
|
651 |
|
652 StringBuffer b = new StringBuffer(); |
|
653 |
|
654 //********************************************************************* |
|
655 //Header |
|
656 //********************************************************************* |
|
657 |
|
658 // href=\"printReport.xsl\" |
|
659 b.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><?xml-stylesheet type=\"text/xsl\" ?><report>"); //$NON-NLS-1$ |
|
660 b.append("\n"); //$NON-NLS-1$ |
|
661 b.append("<info><sdk name=\""); //$NON-NLS-1$ |
|
662 b.append(this.sdkName); |
|
663 b.append("\" target=\""); //$NON-NLS-1$ |
|
664 b.append(this.targets); |
|
665 b.append("\" build=\""); //$NON-NLS-1$ |
|
666 b.append(this.build); |
|
667 b.append("\"/></info>"); //$NON-NLS-1$ |
|
668 b.append("\n"); //$NON-NLS-1$ |
|
669 |
|
670 //********************************************************************* |
|
671 //components |
|
672 //********************************************************************* |
|
673 b.append("<components>"); //$NON-NLS-1$ |
|
674 b.append("\n"); //$NON-NLS-1$ |
|
675 b.append("<rootComponent name=\""); //$NON-NLS-1$ |
|
676 b.append(this.rootComponentName); |
|
677 b.append("\">"); //$NON-NLS-1$ |
|
678 b.append("\n"); //$NON-NLS-1$ |
|
679 |
|
680 //add all components |
|
681 b.append(components); |
|
682 |
|
683 b.append("\n"); //$NON-NLS-1$ |
|
684 b.append("</rootComponent></components>"); //$NON-NLS-1$ |
|
685 b.append("\n"); //$NON-NLS-1$ |
|
686 |
|
687 //********************************************************************* |
|
688 //properties |
|
689 //********************************************************************* |
|
690 b.append("<properties>"); //$NON-NLS-1$ |
|
691 b.append("\n"); //$NON-NLS-1$ |
|
692 b.append(properties); |
|
693 b.append("\n"); //$NON-NLS-1$ |
|
694 b.append("</properties>"); //$NON-NLS-1$ |
|
695 b.append("\n"); //$NON-NLS-1$ |
|
696 |
|
697 //********************************************************************* |
|
698 //exported functions |
|
699 //********************************************************************* |
|
700 b.append("<exportedFunctions>"); //$NON-NLS-1$ |
|
701 b.append("\n"); //$NON-NLS-1$ |
|
702 b.append( exportedFunctions ); |
|
703 b.append("\n"); //$NON-NLS-1$ |
|
704 b.append("</exportedFunctions>"); //$NON-NLS-1$ |
|
705 b.append("\n"); //$NON-NLS-1$ |
|
706 |
|
707 //********************************************************************* |
|
708 //footer |
|
709 //********************************************************************* |
|
710 b.append("</report>"); //$NON-NLS-1$ |
|
711 b.append("\n"); //$NON-NLS-1$ |
|
712 |
|
713 return b.toString(); |
|
714 } |
|
715 |
|
716 /** |
|
717 * Writes XML data to given destination file. |
|
718 * @param fileName destination file. |
|
719 */ |
|
720 public void toFile( String fileName ) { |
|
721 |
|
722 if(observer.isCanceled()){ |
|
723 DbgUtility.println(DbgUtility.PRIORITY_LOOP, Messages.getString("ExportVisitor.Process_Cancelled_ByUser_When_Processing_File_ConsoleMsg")); //$NON-NLS-1$ |
|
724 return; |
|
725 } |
|
726 |
|
727 try { |
|
728 BufferedWriter out = new BufferedWriter(new FileWriter( |
|
729 fileName)); |
|
730 out.write(toString()); |
|
731 out.close(); |
|
732 } catch (IOException e) { |
|
733 e.printStackTrace(); |
|
734 } |
|
735 } |
|
736 |
|
737 } |