Tim,
thank you for your answer. I did something like that, too. But with that kind
of solution I can't use MetaType Service as it only allows to declare a fixed
set of allowed keys (please somebody correct me on that if I'm wrong here!).
Also the host:port thing is fine for host and port scenario but you don't want
to be editing such a string if you have a list with lets say ten properties per
object (key = prop1:prop2:prop3:prop4:....). It's like manually writing CSV
files which somewhat sucks.
Regarding my XML-related question I would like to use the power of validation
against a schema.
Cheers,
Daniel
Am 06.02.2010 um 16:52 schrieb Tim Moloney:
> 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]
>
--
M.Sc. Daniel Bimschas
Institute of Telematics, University of Lübeck
http://www.itm.uni-luebeck.de/users/bimschas
Ratzeburger Allee 160, 23538 Lübeck, Germany
Phone: +49 451 500 5389
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]