Daniel Bimschas wrote:
> Hi list!
> 
> I've posted this question on [email protected], too, but as this list is 
> more active by far I thought I would also give it a try :-).
> 
> I'm writing an application that uses Configuration Admin to be configured at 
> runtime. Now, for one of my DS components I have a more complex configuration 
> requirement. Assume e.g. I want to configure the component to create a set of 
> TCP connections. Using XML configuration I would use something like this 
> snippet:
> 
>  <connections>
>    <connection>
>      <host>somehost.com</host>
>      <port>1234</port>
>    </connection>
>    <connection>
>      <host>someotherhost.com</host>
>      <port>4321</port>
>    </connection>
>  </connections>
> 
> My question now is if there's an elegant way to map such a set of complex 
> configuration objects to Configuration Admins properties file format? Maybe I 
> don't see the wood for the trees but I can't think of a nice way (so that I 
> could also use the Metatype Service specification), except this suboptimal 
> one:
> 
>  connection.host = {somehost.com,someotherhost.com}
>  connection.port = {1234,4321}
> 
> where each entry of the string array of the property 'connection.host' key 
> must have an according entry 'connection.port' with the same index. However, 
> that solution will make editing the configuration files very error prone and 
> unintuitive.
> 
> I can think of another alternative, which is using a component factory that 
> creates one instance of my service per connection configuration. But I have 
> other use cases for which this approach would not be feasible.
> 
We usually solve such problems by using this mentioned alternative: a
component factory for connections and some kind of manager service that
holds all connections.
I think there are usually two different problems involved: a) a list of
configurations (like in your connections example) and b) a structured
configuration for a single component. While you can solve a) with the
factory approach, b) is more difficult. For b) we sometimes use special
string constructs like if you want to a configuration like:
<server>
  <name/>
  <port/>
</server>
we have a single config property "server" with a value like "name|port".

HTH
Carsten
-- 
Carsten Ziegeler
[email protected]

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to