-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prodive the API for TC XML definition
- Loading branch information
1 parent
d655230
commit 91a0ca4
Showing
11 changed files
with
583 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package model; | ||
|
||
import org.w3c.dom.Element; | ||
|
||
import common.LogUtil; | ||
|
||
public class Action { | ||
private String id; | ||
private int order; | ||
|
||
public Action(Element element) { | ||
setAttributes(element); | ||
} | ||
|
||
private void setAttributes(Element element) { | ||
id = element.getAttribute("id"); | ||
try { | ||
order = Integer.parseInt(element.getAttribute("order")); | ||
} catch (Exception e) { | ||
LogUtil.logException(e); | ||
order = 0; | ||
} | ||
} | ||
|
||
public String getActionId() { | ||
return id; | ||
} | ||
|
||
public int getActionOrder() { | ||
return order; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package model; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
|
||
import org.w3c.dom.Element; | ||
import org.w3c.dom.Node; | ||
import org.w3c.dom.NodeList; | ||
|
||
public class GroupSetting { | ||
private String id; | ||
private Language language; | ||
private Collection<Toolchain> toolchains = new ArrayList<>(); | ||
private String rtosType; | ||
private String rtosVersion; | ||
private Collection<Board> boards = new ArrayList<>(); | ||
private Collection<Config> configs = new ArrayList<>(); | ||
|
||
public GroupSetting(Element element) { | ||
parseAttribute(element); | ||
NodeList children = element.getChildNodes(); | ||
for (int i = 0; i < children.getLength(); i++) { | ||
Node childNode = children.item(i); | ||
if (childNode.getNodeType() == Node.ELEMENT_NODE) { | ||
Element childElement = (Element) childNode; | ||
String name = childElement.getTagName(); | ||
switch (name) { | ||
case "language": | ||
setLanguage(new Language(childElement)); | ||
break; | ||
case "toolchain": | ||
addToolchain(new Toolchain(childElement)); | ||
break; | ||
case "RTOSType": | ||
setRTOSType(childElement.getTextContent()); | ||
break; | ||
case "RTOSVersion": | ||
setRTOSVersion(childElement.getTextContent()); | ||
break; | ||
case "board": | ||
addBoard(new Board(childElement)); | ||
break; | ||
case "config": | ||
addConfig(new Config(childElement)); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
private void parseAttribute(Element element) { | ||
id = element.getAttribute("id"); | ||
} | ||
|
||
public String getSettingId() { | ||
return id; | ||
} | ||
|
||
private void setLanguage(Language language) { | ||
this.language = language; | ||
} | ||
|
||
public Language getLanguage() { | ||
return language; | ||
} | ||
|
||
private void addToolchain(Toolchain toolchain) { | ||
toolchains.add(toolchain); | ||
} | ||
|
||
public Collection<Toolchain> getToolchains() { | ||
return toolchains; | ||
} | ||
|
||
private void setRTOSType(String rtosType) { | ||
this.rtosType = rtosType; | ||
} | ||
|
||
public String getRTOSType() { | ||
return rtosType; | ||
} | ||
|
||
private void setRTOSVersion(String version) { | ||
rtosVersion = version; | ||
} | ||
|
||
public String getRTOSVersion() { | ||
return rtosVersion; | ||
} | ||
|
||
private void addBoard(Board board) { | ||
boards.add(board); | ||
} | ||
|
||
public Collection<Board> getBoards() { | ||
return boards; | ||
} | ||
|
||
private void addConfig(Config config) { | ||
configs.add(config); | ||
} | ||
|
||
public Collection<Config> getConfigs() { | ||
return configs; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package model; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
|
||
import org.w3c.dom.Element; | ||
import org.w3c.dom.Node; | ||
import org.w3c.dom.NodeList; | ||
|
||
public class Project { | ||
private String id; | ||
private String projectName; | ||
private Collection<GroupSetting> groupSettings = new ArrayList<>(); | ||
private Application app; | ||
|
||
public Project(Element element) { | ||
parseAttribute(element); | ||
NodeList children = element.getChildNodes(); | ||
for (int i = 0; i < children.getLength(); i++) { | ||
Node childNode = children.item(i); | ||
if (childNode.getNodeType() == Node.ELEMENT_NODE) { | ||
Element childElement = (Element) childNode; | ||
String name = childElement.getTagName(); | ||
if ("projectname".equalsIgnoreCase(name)) { | ||
setProjectName(childElement.getTextContent()); | ||
} else if ("group".equalsIgnoreCase(name)) { | ||
addGroupSetting(new GroupSetting(childElement)); | ||
} else if ("application".equalsIgnoreCase(name)) { | ||
setApplication(new Application(childElement)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private void parseAttribute(Element element) { | ||
id = element.getAttribute("id"); | ||
} | ||
|
||
public String getProjectId() { | ||
return id; | ||
} | ||
|
||
private void setProjectName(String name) { | ||
projectName = name; | ||
} | ||
|
||
public String getProjectName() { | ||
return projectName; | ||
} | ||
|
||
private void addGroupSetting(GroupSetting setting) { | ||
groupSettings.add(setting); | ||
} | ||
|
||
public GroupSetting getGroupSettingById(String id) { | ||
for (GroupSetting setting : groupSettings) { | ||
if (setting.getSettingId().equalsIgnoreCase(id)) { | ||
return setting; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
private void setApplication(Application app) { | ||
this.app = app; | ||
} | ||
|
||
public Application getApp() { | ||
return app; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package model; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
|
||
import org.w3c.dom.Element; | ||
import org.w3c.dom.Node; | ||
import org.w3c.dom.NodeList; | ||
|
||
public class TC { | ||
private String id; | ||
private Collection<Project> projects = new ArrayList<>(); | ||
private Collection<Action> actions = new ArrayList<>(); | ||
|
||
public TC(Element element) { | ||
parseAttribute(element); | ||
NodeList children = element.getChildNodes(); | ||
for (int i = 0; i < children.getLength(); i++) { | ||
Node childNode = children.item(i); | ||
if (childNode.getNodeType() == Node.ELEMENT_NODE) { | ||
Element childElement = (Element) childNode; | ||
String name = childElement.getTagName(); | ||
if ("project".equalsIgnoreCase(name)) { | ||
addProject(new Project(childElement)); | ||
} else if ("action".equalsIgnoreCase(name)) { | ||
addAction(new Action(childElement)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private void parseAttribute(Element element) { | ||
id = element.getAttribute("id"); | ||
} | ||
|
||
public String getTCId() { | ||
return id; | ||
} | ||
|
||
private void addProject(Project project) { | ||
projects.add(project); | ||
} | ||
|
||
public Collection<Project> getProjects() { | ||
return projects; | ||
} | ||
|
||
private void addAction(Action action) { | ||
actions.add(action); | ||
} | ||
|
||
public Collection<Action> getActions() { | ||
return actions; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package model; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.Reader; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
|
||
import javax.xml.XMLConstants; | ||
import javax.xml.parsers.DocumentBuilder; | ||
import javax.xml.parsers.DocumentBuilderFactory; | ||
|
||
import org.w3c.dom.Document; | ||
import org.w3c.dom.Element; | ||
import org.w3c.dom.Node; | ||
import org.w3c.dom.NodeList; | ||
import org.xml.sax.InputSource; | ||
|
||
import common.LogUtil; | ||
|
||
public class TCManager { | ||
private static Collection<TC> tces = new ArrayList<>(); | ||
|
||
private TCManager() { | ||
// do nothing | ||
} | ||
|
||
public static void loadRTOSModel(File xmlFile) { | ||
if (xmlFile == null || !xmlFile.exists()) { | ||
return; | ||
} | ||
try (Reader reader = new InputStreamReader(new FileInputStream(xmlFile), StandardCharsets.UTF_8)) { | ||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); | ||
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""); | ||
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); | ||
DocumentBuilder builder = factory.newDocumentBuilder(); | ||
InputSource inputSource = new InputSource(reader); | ||
Document doc = builder.parse(inputSource); | ||
Element rootElement = doc.getDocumentElement(); | ||
parseXML(rootElement); | ||
} catch (Exception e) { | ||
LogUtil.logException(e); | ||
} | ||
} | ||
|
||
private static void parseXML(Element rootElement) { | ||
if (!"testdata".equals(rootElement.getTagName())) { | ||
return; | ||
} | ||
tces.clear(); | ||
NodeList children = rootElement.getChildNodes(); | ||
for (int i = 0; i < children.getLength(); i++) { | ||
Node childNode = children.item(i); | ||
if (childNode.getNodeType() == Node.ELEMENT_NODE) { | ||
Element childElement = (Element) childNode; | ||
String name = childElement.getTagName(); | ||
if ("TC".equalsIgnoreCase(name)) { | ||
tces.add(new TC(childElement)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public static Collection<TC> getAllTCes() { | ||
return tces; | ||
} | ||
|
||
public static TC getTCById(String id) { | ||
for (TC tc : tces) { | ||
if (id.equalsIgnoreCase(tc.getTCId())) { | ||
return tc; | ||
} | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.