Daniel Bimschas wrote:
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've solved the same problem in the past, although I don't know if what I've done is a best practice.

I configure my apps as follows:

 connection.name1 = somehost.com:1234
 connection.name2 = someotherhost.com:4321

All the connections are prefixed by "connection." (or something similar) so it is easy to find them and do string manipulation. Each connection also has a name that you may find useful in your application (use as a key into maps, put in error messages, etc.). The "somehost.com:1234" is similar in syntax to what is used in HTTP and scp so you don't have to learn a new syntax. It also keeps your hostname and port together to reduce editing mistakes as you pointed out above. If your connection can be made with different protocols, then you can use a URL for the value (e.g., "http://somehost.com:1234/";, ftp://someotherhost.com:4321/";, etc.).

Tim


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

Reply via email to