1 /* |
1 /* |
2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of the License "Eclipse Public License v1.0" |
5 * under the terms of the License "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
8 * |
8 * |
9 * Initial Contributors: |
9 * Initial Contributors: |
10 * Nokia Corporation - initial contribution. |
10 * Nokia Corporation - initial contribution. |
11 * |
11 * |
12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 package com.nokia.helium.sbs; |
18 package com.nokia.helium.sbs; |
19 |
19 |
|
20 import java.io.File; |
|
21 import java.util.ArrayList; |
|
22 import java.util.Iterator; |
|
23 import java.util.List; |
|
24 |
20 import org.apache.tools.ant.BuildException; |
25 import org.apache.tools.ant.BuildException; |
|
26 import org.dom4j.Attribute; |
|
27 import org.dom4j.DocumentException; |
21 import org.dom4j.Element; |
28 import org.dom4j.Element; |
22 import org.dom4j.Attribute; |
29 import org.dom4j.ElementHandler; |
23 import org.dom4j.ElementPath; |
30 import org.dom4j.ElementPath; |
24 import org.dom4j.ElementHandler; |
|
25 import org.dom4j.io.SAXReader; |
31 import org.dom4j.io.SAXReader; |
26 import org.dom4j.DocumentException; |
|
27 |
|
28 import java.io.*; |
|
29 import java.util.*; |
|
30 |
32 |
31 /** |
33 /** |
32 * Parses the sysdef config file and extracts the available configurations |
34 * Parses the sysdef config file and extracts the available configurations |
33 */ |
35 */ |
34 public class SAXSysdefParser { |
36 public class SAXSysdefParser { |
36 private List<String> layers; |
38 private List<String> layers; |
37 private boolean initialized; |
39 private boolean initialized; |
38 |
40 |
39 /** |
41 /** |
40 * Constructor |
42 * Constructor |
|
43 * |
41 * @param fileName - name of the sysdef file to parse |
44 * @param fileName - name of the sysdef file to parse |
42 */ |
45 */ |
43 public SAXSysdefParser(File fileName) { |
46 public SAXSysdefParser(File fileName) { |
44 |
47 |
45 sysdefFile = fileName; |
48 sysdefFile = fileName; |
46 } |
49 } |
47 |
50 |
48 public List<String> getLayers() { |
51 public List<String> getLayers() { |
49 if (!initialized ) { |
52 if (!initialized) { |
50 initialized = true; |
53 initialized = true; |
51 parseConfig("layer"); |
54 parseConfig("layer"); |
52 if (layers == null) { |
55 if (layers == null) { |
53 throw new BuildException("No layers found from sysdef"); |
56 throw new BuildException("No layers found from sysdef"); |
54 } |
57 } |
56 return layers; |
59 return layers; |
57 } |
60 } |
58 |
61 |
59 /** |
62 /** |
60 * Constructor |
63 * Constructor |
|
64 * |
61 * @return list of available configurations that can be built. |
65 * @return list of available configurations that can be built. |
62 */ |
66 */ |
63 public void parseConfig(String nodeToGet) { |
67 public void parseConfig(String nodeToGet) { |
64 layers = new ArrayList<String>(); |
68 layers = new ArrayList<String>(); |
65 SAXReader reader = new SAXReader(); |
69 SAXReader reader = new SAXReader(); |
66 reader.addHandler( "/SystemDefinition/systemModel/" + nodeToGet, |
70 reader.addHandler("/SystemDefinition/systemModel/" + nodeToGet, new ElementHandler() { |
67 new ElementHandler() { |
71 public void onStart(ElementPath path) { |
68 public void onStart(ElementPath path) { |
72 } |
69 } |
73 |
70 public void onEnd(ElementPath path) { |
74 public void onEnd(ElementPath path) { |
71 Element row = path.getCurrent(); |
75 Element row = path.getCurrent(); |
72 Iterator itr = row.attributeIterator(); |
76 Iterator itr = row.attributeIterator(); |
73 while (itr.hasNext()) |
77 while (itr.hasNext()) { |
74 { |
78 Attribute child = (Attribute) itr.next(); |
75 Attribute child = (Attribute) itr.next(); |
79 String attrName = child.getQualifiedName(); |
76 String attrName = child.getQualifiedName(); |
80 if (attrName.equals("name")) { |
77 if (attrName.equals("name")) { |
81 layers.add(child.getValue()); |
78 layers.add(child.getValue()); |
|
79 } |
|
80 } |
|
81 row.detach(); |
|
82 } |
82 } |
83 } |
83 } |
84 ); |
84 row.detach(); |
|
85 } |
|
86 }); |
85 try { |
87 try { |
86 reader.read(sysdefFile); |
88 reader.read(sysdefFile); |
87 } catch (DocumentException e) { |
89 } |
|
90 catch (DocumentException e) { |
88 e.printStackTrace(); |
91 e.printStackTrace(); |
89 } |
92 } |
90 } |
93 } |
91 } |
94 } |