Package: SaveTask
SaveTask
| name | instruction | branch | complexity | line | method | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| SaveTask() | 
  | 
  | 
  | 
  | 
  | 
||||||||||||||||||||
| generateItemListToXML(List) | 
  | 
  | 
  | 
  | 
  | 
||||||||||||||||||||
| saveGraphConfiguration(String, List) | 
  | 
  | 
  | 
  | 
  | 
||||||||||||||||||||
| saveXML(String, String) | 
  | 
  | 
  | 
  | 
  | 
||||||||||||||||||||
Coverage
1: package networkconfigurator.actions;
2: 
3: import java.io.FileWriter;
4: import java.io.IOException;
5: import java.util.List;
6: 
7: import networkconfigurator.item.Item;
8: import networkconfigurator.xstream.XStreamCreator;
9: 
10: /**
11:  * Save the additional informations of the items.
12:  * 
13:  * @author Jannik Garlisch
14:  *
15:  */
16: public class SaveTask {
17: 
18:         /**
19:          * method for saving the additional information of the nodes.
20:          * 
21:          * @param configPath
22:          *            the path in which the configuration should be located. For example, is as follows:
23:          *            "C:\Users\admin\Documents\example-3.10.15\config"
24:          * @param itemList
25:          *            List of items to save.
26:          * @throws IOException
27:          *             if the xml can't save
28:          * 
29:          */
30:         public void saveGraphConfiguration(final String configPath, final List<Item> itemList)
31:                         throws IOException {
32:                 final String xmlContent = generateItemListToXML(itemList);
33:                 final String configFile = configPath + System.getProperty("file.separator") + "graph.xml";
34:                 saveXML(configFile, xmlContent);
35:         }
36: 
37:         /**
38:          * serialize all objects to a xml file.
39:          * 
40:          * @param itemList
41:          *            the item list where should be transferred to the xml file.
42:          * @return the xml file.
43:          */
44:         private String generateItemListToXML(final List<Item> itemList) {
45:                 final XStreamCreator xs = new XStreamCreator();
46:                 return xs.serializeXml(itemList);
47:         }
48: 
49:         /**
50:          * method for save the xml file.
51:          * 
52:          * @param xmlPath
53:          *            location of the xml file
54:          * @param xmlContent
55:          *            the xml content
56:          * @throws IOException
57:          *             if the xml can't save
58:          */
59:         public void saveXML(final String xmlPath, final String xmlContent) throws IOException {
60:                 final FileWriter fw = new FileWriter(xmlPath);
61:                 fw.write(xmlContent);
62:                 fw.close();
63:         }
64: 
65: }