You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by derekzhangv <ni...@tom.com> on 2006/03/30 04:40:40 UTC

[configuration]how i get the index

i have a xml configuration file like this:
how i get the config of the table user?It seems that i can only access the
user table config by index (here is 0),but how can i know that index?
<database>
  <tables>
    <table name="user">
      <fields>
        <field>
          <name>uid</name>
          <type>long</type>
        </field>
        <field>
          <name>uname</name>
          <type>java.lang.String</type>
        </field>
      </fields>
    </table>
    <table name="address">
      <fields>
        <field>
          <name>docid</name>
          <type>long</type>
        </field>
        <field>
          <name>name</name>
          <type>java.lang.String</type>
        </field>
        <field>
          <name>version</name>
          <type>int</type>
        </field>
      </fields>
    </table>
  </tables>
</database>

--
View this message in context: http://www.nabble.com/-configuration-how-i-get-the-index-t1366159.html#a3663113
Sent from the Commons - User forum at Nabble.com.


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


Re: [configuration]how i get the index

Posted by Oliver Heger <ol...@t-online.de>.
Borut Bolčina wrote:

> Hi,
>
> I did not find the time yet to test 1.3-dev, but I have a question. If
> have a configuration.xml such as
>
>    <?xml version="1.0" encoding="ISO-8859-1" ?>
>    <configuration>
>      <properties fileName="foo.properties"/>
>      <properties fileName="bar.properties"/>
>      <properties fileName="acme.properties"/>
>      <xml fileName="cow.xml"/>
>      <xml fileName="chicken.xml"/>
>    </configuration>
>
>
> then I find these lines in my code:
>
>    public static CompositeConfiguration config;
>    ....
>
>    // WARNING - acme.properties must be 3rd entry in configuration.xml
>    Configuration propertyConfiguration = config.getConfiguration(2);
>
> Will there be a way to get propertyConfiguration (or xmlConfiguration
> or even (!) databaseConfiguration) out of configuartion.xml _by some
> id_ and _not by index_? I don't want my application stop working just
> becouse someone changed the order of elements in configuration.xml.
>
> Regards,
> Borut

Yes, I plan to support names for configurations. But this is one of the
things that are not implemented yet.

Oliver

<snip/>

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


Re: [configuration]how i get the index

Posted by Borut Bolčina <bo...@najdi.si>.
Hi,

I did not find the time yet to test 1.3-dev, but I have a question. If 
have a configuration.xml such as

    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <configuration>
      <properties fileName="foo.properties"/>
      <properties fileName="bar.properties"/>
      <properties fileName="acme.properties"/>
      <xml fileName="cow.xml"/>
      <xml fileName="chicken.xml"/>
    </configuration>


then I find these lines in my code:

    public static CompositeConfiguration config;
    ....

    // WARNING - acme.properties must be 3rd entry in configuration.xml
    Configuration propertyConfiguration = config.getConfiguration(2);

Will there be a way to get propertyConfiguration (or xmlConfiguration or 
even (!) databaseConfiguration) out of configuartion.xml _by some id_ 
and _not by index_? I don't want my application stop working just 
becouse someone changed the order of elements in configuration.xml.

Regards,
Borut

On 11.4.2006 16:14, Oliver Heger wrote:
> Borut Bolčina wrote:
>
>   
>> Oliver, that is great news! I'll check out the latest version to play
>> with. What is the release plan?
>>     
>
> It would be great if somebody could test these new features. So far we
> have not got any feedback.
>
> A new release has not been discussed yet. Don't know about the other
> committers, but I have some things on my list I would like to finish
> before a new version. This is especially the re-design of the
> ConfigurationFactory class. I started with an alternative implementation
> (called DefaultConfigurationBuilder), which is quite functional ATM, but
> some things are missing.
>
> Oliver
>
>   
>> -Borut
>>
>> On 30.3.2006 15:52, Oliver Heger wrote:
>>
>>     
>>> Since the 1.2 release development has continued. The current version
>>> in SVN now supports so called "expression engines", which allow to
>>> plug in different query languages. There is also an XPATH expression
>>> engine, which can be used for querying properties in XPATH syntax.
>>> With this you can write something like that:
>>>
>>> String firstUsrField = config.getString(
>>>   "/database/tables[@name='users']/fields/field[1]/name");
>>>
>>> or use other features provided by XPATH to navigate through your
>>> configuration. The user guide (in the SVN version) was updated to
>>> cover these new facilities.
>>>
>>> Oliver
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>>
>>>       
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>   

Re: [configuration]how i get the index

Posted by Oliver Heger <ol...@t-online.de>.
Borut Bolčina wrote:

> Oliver, that is great news! I'll check out the latest version to play
> with. What is the release plan?

It would be great if somebody could test these new features. So far we
have not got any feedback.

A new release has not been discussed yet. Don't know about the other
committers, but I have some things on my list I would like to finish
before a new version. This is especially the re-design of the
ConfigurationFactory class. I started with an alternative implementation
(called DefaultConfigurationBuilder), which is quite functional ATM, but
some things are missing.

Oliver

>
> -Borut
>
> On 30.3.2006 15:52, Oliver Heger wrote:
>
>>
>> Since the 1.2 release development has continued. The current version
>> in SVN now supports so called "expression engines", which allow to
>> plug in different query languages. There is also an XPATH expression
>> engine, which can be used for querying properties in XPATH syntax.
>> With this you can write something like that:
>>
>> String firstUsrField = config.getString(
>>   "/database/tables[@name='users']/fields/field[1]/name");
>>
>> or use other features provided by XPATH to navigate through your
>> configuration. The user guide (in the SVN version) was updated to
>> cover these new facilities.
>>
>> Oliver
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>


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


Re: [configuration]how i get the index

Posted by Borut Bolčina <bo...@najdi.si>.
Oliver, that is great news! I'll check out the latest version to play 
with. What is the release plan?

-Borut

On 30.3.2006 15:52, Oliver Heger wrote:
>
> Since the 1.2 release development has continued. The current version 
> in SVN now supports so called "expression engines", which allow to 
> plug in different query languages. There is also an XPATH expression 
> engine, which can be used for querying properties in XPATH syntax. 
> With this you can write something like that:
>
> String firstUsrField = config.getString(
>   "/database/tables[@name='users']/fields/field[1]/name");
>
> or use other features provided by XPATH to navigate through your 
> configuration. The user guide (in the SVN version) was updated to 
> cover these new facilities.
>
> Oliver
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>

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


Re: [configuration]how i get the index

Posted by Oliver Heger <he...@med.uni-marburg.de>.
derekzhangv wrote:
> i have a xml configuration file like this:
> how i get the config of the table user?It seems that i can only access the
> user table config by index (here is 0),but how can i know that index?
> <database>
>   <tables>
>     <table name="user">
>       <fields>
>         <field>
>           <name>uid</name>
>           <type>long</type>
>         </field>
>         <field>
>           <name>uname</name>
>           <type>java.lang.String</type>
>         </field>
>       </fields>
>     </table>
>     <table name="address">
>       <fields>
>         <field>
>           <name>docid</name>
>           <type>long</type>
>         </field>
>         <field>
>           <name>name</name>
>           <type>java.lang.String</type>
>         </field>
>         <field>
>           <name>version</name>
>           <type>int</type>
>         </field>
>       </fields>
>     </table>
>   </tables>
> </database>
> 

In the current 1.2 release you are indeed limited to accessing 
properties by an index. If you don't know the index, your only chance is 
to iterate over your data in a loop incrementing the index, e.g. as follows:

int idx = 0;
while(true)
{
     if("users".equals(
       config.getString("tables.table(" + idx + ")@[name]"))
     {
         // do something
         break;
     }
}

Since the 1.2 release development has continued. The current version in 
SVN now supports so called "expression engines", which allow to plug in 
different query languages. There is also an XPATH expression engine, 
which can be used for querying properties in XPATH syntax. With this you 
can write something like that:

String firstUsrField = config.getString(
   "/database/tables[@name='users']/fields/field[1]/name");

or use other features provided by XPATH to navigate through your 
configuration. The user guide (in the SVN version) was updated to cover 
these new facilities.

Oliver

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