
package net.atomique.ksar.Parser;

import java.util.HashMap;
import java.util.Map;

import net.atomique.ksar.GlobalOptions;
import net.atomique.ksar.kSar;
import net.atomique.ksar.XML.OSConfig;

/**
 *
 * @author Max
 */
public abstract class OSParser extends BaseParser {

    public OSParser () {
    }

    public OSParser(kSar hissar, String header) {
        init(hissar, header);
    }

    @Override
    public void init (kSar hissar, String header) {
        String[] s = header.split("\\s+");
        this.mysar = hissar;
        this.parserName = s[0];
        this.myosconfig = GlobalOptions.getOSinfo(this.parserName);
        parseHeader(header);
    }
    
    public OSConfig getOSConfig() {
        return myosconfig;
    }

    public void setHostname(String s) {
        Hostname = s;
    }

    public void setOSversion(String s) {
        OSversion = s;
    }

    public void setKernel(String s) {
        Kernel = s;
    }

    public void setCpuType(String s) {
        CpuType = s;
    }

    public void setMacAddress(String s) {
        MacAddress = s;
    }

    public void setMemory(String s) {
        Memory = s;
    }

    public void setNBDisk(String s) {
        NBDisk = s;
    }

    public void setNBCpu(String s) {
        nbCpu = s;
    }

    public void setENT(String s) {
        ENT = s;
    }

    

    @Override
    public String getInfo() {
        StringBuilder tmpstr = new StringBuilder();
        tmpstr.append("OS Type: ").append(ostype);
        if (OSversion != null) {
           tmpstr.append("OS Version: ").append(OSversion).append("\n");
        }
        if (Kernel != null) {
            tmpstr.append("Kernel Release: ").append(Kernel).append("\n");
        }
        if (CpuType != null) {
            tmpstr.append("CPU Type: ").append(CpuType).append("\n");
        }
        if (Hostname != null) {
            tmpstr.append("Hostname: ").append(Hostname).append("\n");
        }
        if (MacAddress != null) {
            tmpstr.append("Mac Address: ").append(MacAddress).append("\n");
        }
        if (Memory != null) {
            tmpstr.append("Memory: ").append(Memory).append("\n");
        }
        if (NBDisk != null) {
            tmpstr.append("Number of disks: ").append(NBDisk).append("\n");
        }
        if (nbCpu != null) {
            tmpstr.append("Number of CPU: ").append(nbCpu).append("\n");
        }
        if (ENT != null) {
            tmpstr.append("Ent: ").append(ENT).append("\n");
        }
        if (sarStartDate != null) {
            tmpstr.append("Start of SAR: ").append(sarStartDate).append("\n");
        }
        if (sarEndDate != null) {
            tmpstr.append("End of SAR: ").append(sarEndDate).append("\n");
        }

        tmpstr.append("\n");

        return tmpstr.toString();
    }

    public String getOriginal_line() {
        return originalLine;
    }

    public void setOriginal_line(String original_line) {
        this.originalLine = original_line;
    }

    public String gethostName() {
        return Hostname;
    }

    public String getOstype() {
        return ostype;
    }

    public void setOstype(String ostype) {
        this.ostype = ostype;
    }

    
    protected Map<String, Object> listofGraph = new HashMap<String, Object>();
    
    protected String lastStat = null;
    protected Object currentStatObj = null;
    
    protected String ostype = null;
    protected String Hostname = null;
    protected String OSversion = null;
    protected String Kernel = null;
    protected String CpuType = null;
    protected String MacAddress = null;
    protected String Memory = null;
    protected String NBDisk = null;
    protected String nbCpu = null;
    protected String ENT = null;
    protected String detect = null;
    protected String originalLine=null;
    
}

@@ -783,17 +783,17 @@
         
-H
+h
 ostname 
@@ -853,19 +853,19 @@
         
-OSv
+osV
 ersion =
@@ -921,17 +921,17 @@
         
-K
+k
 ernel = 
@@ -987,17 +987,17 @@
         
-C
+c
 puType =
@@ -1057,17 +1057,17 @@
         
-M
+m
 acAddres
@@ -1126,17 +1126,17 @@
         
-M
+m
 emory = 
@@ -1191,18 +1191,18 @@
         
-NB
+nb
 Disk = s
@@ -1497,19 +1497,19 @@
     if (
-OSv
+osV
 ersion !
@@ -1566,19 +1566,19 @@
 .append(
-OSv
+osV
 ersion).
@@ -1613,17 +1613,17 @@
     if (
-K
+k
 ernel !=
@@ -1684,17 +1684,17 @@
 .append(
-K
+k
 ernel).a
@@ -1728,17 +1728,17 @@
     if (
-C
+c
 puType !
@@ -1794,17 +1794,17 @@
 .append(
-C
+c
 puType).
@@ -1839,17 +1839,17 @@
     if (
-H
+h
 ostname 
@@ -1906,17 +1906,17 @@
 .append(
-H
+h
 ostname)
@@ -1952,17 +1952,17 @@
     if (
-M
+m
 acAddres
@@ -2024,17 +2024,17 @@
 .append(
-M
+m
 acAddres
@@ -2072,17 +2072,17 @@
     if (
-M
+m
 emory !=
@@ -2135,17 +2135,17 @@
 .append(
-M
+m
 emory).a
@@ -2179,18 +2179,18 @@
     if (
-NB
+nb
 Disk != 
@@ -2251,18 +2251,18 @@
 .append(
-NB
+nb
 Disk).ap
@@ -3040,17 +3040,17 @@
  return 
-H
+h
 ostname;
@@ -3432,17 +3432,17 @@
  String 
-H
+h
 ostname 
@@ -3470,19 +3470,19 @@
  String 
-OSv
+osV
 ersion =
@@ -3509,17 +3509,17 @@
  String 
-K
+k
 ernel = 
@@ -3545,17 +3545,17 @@
  String 
-C
+c
 puType =
@@ -3582,17 +3582,17 @@
  String 
-M
+m
 acAddres
@@ -3622,17 +3622,17 @@
  String 
-M
+m
 emory = 
@@ -3658,18 +3658,18 @@
  String 
-NB
+nb
 Disk = n
@@ -3810,17 +3810,19 @@
 inalLine
-=
+ = 
 null;%0A  

clean up