diff --git a/Varianten/FeatureModelConfigurator/bin/Adapter.class b/Varianten/FeatureModelConfigurator/bin/Adapter.class new file mode 100644 index 0000000000000000000000000000000000000000..1d29be803e4ae0515bcdc9b7d7da372cb4caf871 Binary files /dev/null and b/Varianten/FeatureModelConfigurator/bin/Adapter.class differ diff --git a/Varianten/FeatureModelConfigurator/bin/Configurator$$ConfiguratorMain$Module.class b/Varianten/FeatureModelConfigurator/bin/Configurator$$ConfiguratorMain$Module.class new file mode 100644 index 0000000000000000000000000000000000000000..ea2e6fdb4c44df2d4a6fe46d6dac428344aacdbd Binary files /dev/null and b/Varianten/FeatureModelConfigurator/bin/Configurator$$ConfiguratorMain$Module.class differ diff --git a/Varianten/FeatureModelConfigurator/bin/Configurator$$ConfiguratorMain.class b/Varianten/FeatureModelConfigurator/bin/Configurator$$ConfiguratorMain.class new file mode 100644 index 0000000000000000000000000000000000000000..679eacc455d2aa4d5ddd1a30152b9f8f78bc5810 Binary files /dev/null and b/Varianten/FeatureModelConfigurator/bin/Configurator$$ConfiguratorMain.class differ diff --git a/Varianten/FeatureModelConfigurator/bin/Configurator.class b/Varianten/FeatureModelConfigurator/bin/Configurator.class new file mode 100644 index 0000000000000000000000000000000000000000..5be86ad8f7b5500995f01f112f2db4fabddea69d Binary files /dev/null and b/Varianten/FeatureModelConfigurator/bin/Configurator.class differ diff --git a/Varianten/FeatureModelConfigurator/src/Configurator.jak b/Varianten/FeatureModelConfigurator/src/Configurator.jak index 656bc98e11d9ac55d3c0e8dba95a993cedb171f7..d2aac617363e87b0c46138d72c116a090841d6d7 100644 --- a/Varianten/FeatureModelConfigurator/src/Configurator.jak +++ b/Varianten/FeatureModelConfigurator/src/Configurator.jak @@ -1,16 +1,11 @@ import java.util.List; import java.util.ArrayList; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; import java.io.IOException; -import org.jsoup.Jsoup; -import org.jsoup.nodes.*; -import org.jsoup.nodes.Document.OutputSettings; -import org.jsoup.nodes.Document.OutputSettings.Syntax; -import org.jsoup.parser.Parser; +import org.jdom2.Document; +import org.jdom2.Element; +import org.jdom2.JDOMException; SoUrCe RooT ConfiguratorMain "../features/ConfiguratorMain/Configurator.jak"; @@ -35,16 +30,12 @@ abstract class Configurator$$ConfiguratorMain { //module list private List m_aModuleList; //output path - private String m_sOutputPath = "./test.xml"; + private String m_sOutputPath = "resources/output/featuremodel.xml"; //TODO: set this //path for test case selector, which has to be launched from this application private String m_sTestCaseSelectorPath; - //TODO: set this - //path for the Gazebo adapter, which has to be launched from this application - private String m_sGazeboAdapterPath; - //TODO: properly set this //path to the feature model xml - private String m_sFeatureModelPath = "./model.xml"; + private String m_sFeatureModelPath = "model.xml"; //document representation of the feature model private Document m_oFeatureModelDoc; //representation of a single module with all of its types @@ -59,10 +50,9 @@ abstract class Configurator$$ConfiguratorMain { } public void save() { - //transform list to XML document using jsoup - Document oDoc = Jsoup.parse("<?xml version=\"1.0\"?>\n", "", Parser.xmlParser()); + //create empty xml Element oStruct = new Element("specification"); - oDoc.appendChild(oStruct); + Document oDoc = new Document(oStruct); //if the module list was initialized if(m_aModuleList!=null) { @@ -71,7 +61,7 @@ abstract class Configurator$$ConfiguratorMain { Element oModuleElement = new Element("module"); //Add name Module oModule = (Module)m_aModuleList.get(i); - oModuleElement.attr("name", oModule.sModuleName); + oModuleElement.setAttribute("name", oModule.sModuleName); //Create type String ArrayList<String> aTypes = oModule.aModuleTypes; String sTypesString = ""; @@ -82,59 +72,59 @@ abstract class Configurator$$ConfiguratorMain { if(j<aTypes.size()-1) sTypesString += ", "; } - oModuleElement.attr("types", sTypesString); - oStruct.appendChild(oModuleElement); + oModuleElement.setAttribute("types", sTypesString); + oStruct.addContent(oModuleElement); } } - //generate xml String - OutputSettings oOutputSettings = new OutputSettings(); - oOutputSettings.syntax(Syntax.xml); - oDoc.outputSettings(oOutputSettings); - String sDoc = oDoc.toString(); - System.out.println(sDoc); - - //save to file + //generate xml String and save it to a file try { - BufferedWriter writer = new BufferedWriter(new FileWriter(m_sOutputPath)); - writer.write(sDoc); - writer.close(); - } - catch (IOException oEx) { + Adapter.saveAsXml(oDoc, m_sOutputPath); + } + catch (Exception oEx) { System.out.println(oEx); + return; } + + //create and launch Adapter + new Adapter(); } //get all parents of a given module from the Feature Model file - private Module GetModuleParents(String sModuleName) throws IOException { + private Module GetModuleParents(String sModuleName) throws IOException, JDOMException { Module oModule = new Module(); //set name oModule.sModuleName = sModuleName; //init Doc if not done if(m_oFeatureModelDoc==null) { - File oModel = new File(m_sFeatureModelPath); - m_oFeatureModelDoc = Jsoup.parse(oModel, "UTF-8"); + m_oFeatureModelDoc = Adapter.readXml(m_sFeatureModelPath); + System.out.println(m_oFeatureModelDoc.toString()); + } + //get element + String sQuery = "//*[@name= '"+sModuleName+"']"; + List<Element> aModules = Adapter.xQueryElements(m_oFeatureModelDoc, sQuery); + Element oModuleElement; + try { + oModuleElement = aModules.get(0); } - //should have size 1 - org.jsoup.select.Elements aModuleBuffer = m_oFeatureModelDoc.getElementsByAttributeValue("name", sModuleName); - if(aModuleBuffer.size()>1) { - //somethings wrong - //TODO: properly log this - System.out.println("Found more than one module with the name " + sModuleName); + catch (Exception oEx) { + System.out.println(oEx.toString() + "\nList empty for query "+ sQuery); + return null; } - Element oModuleElement = aModuleBuffer.first(); //get all anchestors - aModuleBuffer = oModuleElement.parents(); + Element oParent = oModuleElement.getParentElement(); ArrayList<String> aTypes = new ArrayList(); //itterate through parents of module - for(int i=0; i<aModuleBuffer.size(); i++) { - Element oElement = aModuleBuffer.get(i); - String sElementName = oElement.attr("name"); + while(true) { + String sElementName = oParent.getAttribute("name").getValue(); //break if we reach the Main class, as there are no types further up if(sElementName.equals("ConfiguratorMain")) { break; } aTypes.add(sElementName); + //iterate further trough List + oModuleElement = oParent; + oParent = oModuleElement.getParentElement(); } oModule.aModuleTypes = aTypes; return oModule; @@ -151,7 +141,7 @@ abstract class Configurator$$ConfiguratorMain { try { oModule = GetModuleParents(sModuleName); } - catch (IOException oEx) { + catch (Exception oEx) { System.out.print(oEx); return; }