| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| MachineHolder |
|
| 5.2;5.2 |
| 1 | package com.aurea.maven.plugins.sonic.topology.utils; | |
| 2 | ||
| 3 | import java.util.ArrayList; | |
| 4 | ||
| 5 | import org.codehaus.plexus.util.xml.Xpp3Dom; | |
| 6 | ||
| 7 | public class MachineHolder implements java.io.Serializable { | |
| 8 | /** | |
| 9 | * | |
| 10 | */ | |
| 11 | private static final long serialVersionUID = 1L; | |
| 12 | ArrayList<MachineConfig> machineConfigs; | |
| 13 | ||
| 14 | 0 | public MachineHolder() { |
| 15 | 0 | machineConfigs = new ArrayList<MachineConfig>(); |
| 16 | 0 | } |
| 17 | ||
| 18 | public void addMachineConfig(MachineConfig mc) { | |
| 19 | // System.out.println("ADDING MACHINECONFIG"); | |
| 20 | 0 | machineConfigs.add(mc); |
| 21 | 0 | } |
| 22 | ||
| 23 | public void removeMachineConfig(MachineConfig mc) { | |
| 24 | 0 | if (machineConfigs.contains(mc)) { |
| 25 | 0 | machineConfigs.remove(mc); |
| 26 | } | |
| 27 | 0 | } |
| 28 | ||
| 29 | public ArrayList<MachineConfig> getMachineConfigs() { | |
| 30 | 0 | return machineConfigs; |
| 31 | } | |
| 32 | ||
| 33 | public void createMachineXmlContent(Xpp3Dom topology) { | |
| 34 | 0 | final Xpp3Dom machines = new Xpp3Dom("Machines"); |
| 35 | 0 | Xpp3Dom machine = null; |
| 36 | 0 | Xpp3Dom machineId = null; |
| 37 | 0 | Xpp3Dom alternateId = null; |
| 38 | 0 | Xpp3Dom logicalHosts = null; |
| 39 | 0 | Xpp3Dom logicalHost = null; |
| 40 | 0 | Xpp3Dom settings = null; |
| 41 | ||
| 42 | // Iterator <MachineConfig> it = mh.getMachineConfigs().iterator(); | |
| 43 | 0 | for (MachineConfig mc : this.getMachineConfigs()) { |
| 44 | 0 | if (!mc.getMachineId().equals("")) { |
| 45 | 0 | machine = new Xpp3Dom("Machine"); |
| 46 | 0 | machineId = new Xpp3Dom("Id"); |
| 47 | 0 | machineId.setValue(mc.getMachineId()); |
| 48 | 0 | machine.addChild(machineId); |
| 49 | ||
| 50 | // setting alternate ids | |
| 51 | 0 | for (String altid : mc.getAlternateIds()) { |
| 52 | 0 | if (!altid.equals("")) { |
| 53 | 0 | alternateId = new Xpp3Dom("AlternateId"); |
| 54 | 0 | alternateId.setValue(altid); |
| 55 | 0 | machine.addChild(alternateId); |
| 56 | } | |
| 57 | 0 | } |
| 58 | ||
| 59 | // setting Logical hosts | |
| 60 | 0 | for(String loghost : mc.getLogicalhosts()){ |
| 61 | 0 | if(!loghost.equals("")){ |
| 62 | 0 | logicalHost = new Xpp3Dom("LogicalHost"); |
| 63 | 0 | logicalHost.setValue(loghost); |
| 64 | 0 | if(logicalHosts == null){ |
| 65 | 0 | logicalHosts = new Xpp3Dom("LogicalHosts"); |
| 66 | } | |
| 67 | 0 | logicalHosts.addChild(logicalHost); |
| 68 | } | |
| 69 | 0 | } |
| 70 | ||
| 71 | // settings for Environment | |
| 72 | ||
| 73 | 0 | if(mc.getContainerDir() != null && !mc.getContainerDir().equals("")){ |
| 74 | 0 | if(settings == null){ |
| 75 | 0 | settings = new Xpp3Dom("Settings"); |
| 76 | } | |
| 77 | 0 | Xpp3Dom location = new Xpp3Dom("Locations"); |
| 78 | 0 | Xpp3Dom containerDir = new Xpp3Dom("ContainersDir"); |
| 79 | 0 | containerDir.setValue(mc.getContainerDir()); |
| 80 | 0 | location.addChild(containerDir); |
| 81 | 0 | settings.addChild(location); |
| 82 | } | |
| 83 | ||
| 84 | 0 | if(mc.getEncryptPWD() != null && !mc.getEncryptPWD().equals("")){ |
| 85 | 0 | if(settings == null){ |
| 86 | 0 | settings = new Xpp3Dom("Settings"); |
| 87 | } | |
| 88 | 0 | Xpp3Dom encryption = new Xpp3Dom("BootfilesEncryptionPassword"); |
| 89 | 0 | encryption.setValue(mc.getEncryptPWD()); |
| 90 | 0 | settings.addChild(encryption); |
| 91 | } | |
| 92 | ||
| 93 | 0 | if(mc.getRegisterAsService() != null && !mc.getRegisterAsService().equals("")){ |
| 94 | 0 | if(settings == null){ |
| 95 | 0 | settings = new Xpp3Dom("Settings"); |
| 96 | } | |
| 97 | 0 | Xpp3Dom winService = new Xpp3Dom("RegisterBootContainersAsServices"); |
| 98 | 0 | winService.setValue(mc.getRegisterAsService()); |
| 99 | 0 | settings.addChild(winService); |
| 100 | } | |
| 101 | ||
| 102 | 0 | if(mc.getServiceStartupTime() != null && !mc.getServiceStartupTime().equals("")){ |
| 103 | 0 | if(settings == null){ |
| 104 | 0 | settings = new Xpp3Dom("Settings"); |
| 105 | } | |
| 106 | 0 | Xpp3Dom timeout = new Xpp3Dom("WindowsServicesStartupTimeout"); |
| 107 | 0 | timeout.setValue(mc.getServiceStartupTime()); |
| 108 | 0 | settings.addChild(timeout); |
| 109 | } | |
| 110 | ||
| 111 | ||
| 112 | 0 | machine.addChild(logicalHosts); |
| 113 | 0 | if(settings != null){ |
| 114 | 0 | machine.addChild(settings); |
| 115 | } | |
| 116 | 0 | machines.addChild(machine); |
| 117 | } | |
| 118 | 0 | } |
| 119 | ||
| 120 | 0 | topology.addChild(machines); |
| 121 | 0 | } |
| 122 | } |