587
|
1 |
/*
|
628
|
2 |
* Copyright (c) 2007-2008 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 the License "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 |
|
587
|
18 |
package com.nokia.helium.sbs;
|
|
19 |
|
628
|
20 |
import java.io.File;
|
|
21 |
import java.util.ArrayList;
|
|
22 |
import java.util.Iterator;
|
|
23 |
import java.util.List;
|
|
24 |
|
587
|
25 |
import org.apache.tools.ant.BuildException;
|
628
|
26 |
import org.dom4j.Attribute;
|
|
27 |
import org.dom4j.DocumentException;
|
587
|
28 |
import org.dom4j.Element;
|
|
29 |
import org.dom4j.ElementHandler;
|
628
|
30 |
import org.dom4j.ElementPath;
|
587
|
31 |
import org.dom4j.io.SAXReader;
|
|
32 |
|
|
33 |
/**
|
|
34 |
* Parses the sysdef config file and extracts the available configurations
|
|
35 |
*/
|
|
36 |
public class SAXSysdefParser {
|
|
37 |
private File sysdefFile;
|
|
38 |
private List<String> layers;
|
|
39 |
private boolean initialized;
|
|
40 |
|
|
41 |
/**
|
|
42 |
* Constructor
|
628
|
43 |
*
|
587
|
44 |
* @param fileName - name of the sysdef file to parse
|
|
45 |
*/
|
|
46 |
public SAXSysdefParser(File fileName) {
|
628
|
47 |
|
587
|
48 |
sysdefFile = fileName;
|
|
49 |
}
|
628
|
50 |
|
587
|
51 |
public List<String> getLayers() {
|
628
|
52 |
if (!initialized) {
|
587
|
53 |
initialized = true;
|
|
54 |
parseConfig("layer");
|
|
55 |
if (layers == null) {
|
|
56 |
throw new BuildException("No layers found from sysdef");
|
|
57 |
}
|
|
58 |
}
|
|
59 |
return layers;
|
|
60 |
}
|
|
61 |
|
|
62 |
/**
|
|
63 |
* Constructor
|
628
|
64 |
*
|
587
|
65 |
* @return list of available configurations that can be built.
|
628
|
66 |
*/
|
|
67 |
public void parseConfig(String nodeToGet) {
|
587
|
68 |
layers = new ArrayList<String>();
|
|
69 |
SAXReader reader = new SAXReader();
|
628
|
70 |
reader.addHandler("/SystemDefinition/systemModel/" + nodeToGet, new ElementHandler() {
|
|
71 |
public void onStart(ElementPath path) {
|
|
72 |
}
|
|
73 |
|
|
74 |
public void onEnd(ElementPath path) {
|
|
75 |
Element row = path.getCurrent();
|
|
76 |
Iterator itr = row.attributeIterator();
|
|
77 |
while (itr.hasNext()) {
|
|
78 |
Attribute child = (Attribute) itr.next();
|
|
79 |
String attrName = child.getQualifiedName();
|
|
80 |
if (attrName.equals("name")) {
|
|
81 |
layers.add(child.getValue());
|
587
|
82 |
}
|
|
83 |
}
|
628
|
84 |
row.detach();
|
|
85 |
}
|
|
86 |
});
|
587
|
87 |
try {
|
|
88 |
reader.read(sysdefFile);
|
628
|
89 |
}
|
|
90 |
catch (DocumentException e) {
|
587
|
91 |
e.printStackTrace();
|
|
92 |
}
|
|
93 |
}
|
|
94 |
} |