commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <oliver.he...@oliver-heger.de>
Subject Re: [Configuration] Delete property
Date Tue, 03 Apr 2007 09:59:31 GMT
DECAFFMEYER MATHIEU wrote:
> Hi,
> 
> I am trying to delete a property with this structure :
> <conf>
> ....
> <indexList>
> 
> <index default="false" name="test1_en">
> <dir>C:/UserTemp/test1_en/search_index</dir>
> </index>
> 
> <index default="false" name="test2_en">
> <dir>C:/UserTemp/test2_en/search_index</dir>
> </index>
> 
> <index default="false" name="test3_en">
> <dir>C:/UserTemp/test3_en/search_index</dir>
> </index>
> 
> </indexList>
> ....
> </conf>
> 
> Now let's say I want to delete the idnex named test3_en
> I tried this :
> 
> *for*(*int* i=0;* true*; ++i) {
>        * if*(writerSearchmask.getString("indexList.index("+i+")[@name]") 
> ==* null*)* break*;
>        * 
> if*(writerSearchmask.getString("indexList.index("+i+")[@name]").equals("test3_en")) 
> {
>                 
> ((HierarchicalConfiguration)writerSearchmask).clearTree("indexList.index("+i+")"); 
> 
>                 
> //writerSearchmask.clearProperty("indexList.index("+i+")");  <- I tried 
> this too
>                * break*;
>         }
> }
> 
> But it just won't delete,
> what am I doing wrong ? any help here :) ?
> 
> Thank u.
> 
> *__________________________________*
> 
> *   Matt*////
> 
I can see nothing wrong in this code fragment; deleting should work this 
way. To verify I have written the following unit test based on your 
structures:

     /**
      * Tests removing more complex node structures.
      */
     public void testClearTreeComplex()
     {
         final int count = 5;
         // create the structure
         for (int idx = 0; idx < count; idx++)
         {
             config.addProperty("indexList.index(-1)[@default]", 
Boolean.FALSE);
             config.addProperty("indexList.index[@name]", "test" + idx);
             config.addProperty("indexList.index.dir", "testDir" + idx);
         }
         assertEquals("Wrong number of nodes", count - 1, config
                 .getMaxIndex("indexList.index[@name]"));

         // Remove a sub tree
         boolean found = false;
         for (int idx = 0; true; idx++)
         {
             String name = config.getString("indexList.index(" + idx
                     + ")[@name]");
             if (name == null)
             {
                 break;
             }
             if ("test3".equals(name))
             {
                 config.clearTree("indexList.index(" + idx + ")");
                 found = true;
             }
         }
         assertTrue("Key to remove not found", found);
         assertEquals("Wrong number of nodes after remove", count - 2, 
config
                 .getMaxIndex("indexList.index[@name]"));
         assertEquals("Wrong number of dir nodes after remove", count - 2,
                 config.getMaxIndex("indexList.index.dir"));

         // Verify
         for (int idx = 0; true; idx++)
         {
             String name = config.getString("indexList.index(" + idx
                     + ")[@name]");
             if (name == null)
             {
                 break;
             }
             if ("test3".equals(name))
             {
                 fail("Key was not removed!");
             }
         }
     }

This test passes. Maybe you can use this code to experiment a bit and 
find out what is going wrong.

Oliver

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message