AnsweredAssumed Answered

Reading in a config file results in a change to the order of sections and keys?

Question asked by schmum on Sep 25, 2013
Latest reply on Oct 4, 2013 by comfortably_nim

I'm writing a java program that reads in the NAS configuration file, displays select key values on a GUI, accepts changes from the user, and rewrites the configuration file back out with the modified key values. All is good except for one thing - when I get an instance of the config file, the order of the sections and even keys within sections are changed.

 

For simplicity, here is a small quick and dirty program to read in the config and print it out:

 

public class ConfigTest {
    public static void main(String[] args) throws NimException {
        String copyFileName = "C:\\nascfg_copy.txt";     //location of config file

        NimConfig config;
        config = NimConfig.getInstance();
        config.setFilename(copyFileName);

        System.out.println(config);
   }

}

 

 

Here is a snippet from the original, much larger, config file:

<subsystems>
   1. = NimBUS
   1.1. = Alarm
   1.1.1. = Host
   1.1.1.1. = Disk
   1.1.1.1.1. = AIX Disk
   1.1.1.1.2. = Windows Disk
   1.1.1.1.3. = Linux Disk
   1.1.1.2. = Memory
   1.1.1.2.1. = AIX Memory
   1.1.1.2.2. = Windows Memory
   1.1.1.2.3. = Linux Memory
   1.1.1.3. = CPU
   1.1.1.3.1. = AIX CPU
   1.1.1.3.2. = Windows CPU
   1.1.1.3.3. = Linux CPU
   1.1.1.4. = Hardware
   1.1.1.4.1. = AIX Hardware
   1.1.1.4.2. = Windows Hardware
   1.1.1.4.3. = Linux Hardware

 

Now, here is a snippet from the same section after getting an instance of it in my program:

<subsystems>
    1.1.10. = Users
    1.1.1.7. = Linux Host
    2.5. = Cisco
    1.2.3.12. = NUMA
    1.1.13.5. = DB2
    1.2.3.3. = AlarmServer
    3.2.5.3. = JES2
    1.2.1. = Hub
    2.11.1. = WebLogic
    1.2. = System
    2.7.5. = VM_Monitor_Power
    1.1.17.3. = URL_DI
    3.7. = ISNIM Team
    2.1.1. = SQL-Server
    1.1.1.6. = Windows Host
    2.4. = Remedy
    1.2.3.11. = Dap
    1.1.13.4. = SQL-Server
    1.2.3.2. = RemoteService

 

As you can see, there is a significant change in the order. You can imagine the results on a file that contains over 11,000 lines.

 

As far as I can tell, everything stays within its original boundary, that is, keys in one section stay within that section and don't appear within another section. However, a child/sub section can get moved around in its entirety within a parent section.

 

For example:

 

<parent Section>

   key1 = value 1

   key2 = value 2

   key3 = value 3

   key4 = value 4

   key5 = value 5

      <child Section>

         key1 = value 1

         key2 = value 2

         key3 = value 3

      </child Section>

</parent Section>

 

can become

 

 <parent Section>

   key5 = value 5

   key3 = value 3

      <child Section>

         key1 = value 1

         key3 = value 3

         key2 = value 2

      </child Section>

   key4 = value 4

   key2 = value 2

   key1 = value 1

</parent Section>

 

So, the questions are:

1 - Why is this happening?

2 - How do I preserve the file's original order?

Outcomes