views:

429

answers:

2

I am using several packages which are configured by using configuration properties for example org.apache.ws.security.crypto. Normally a single configuration file suffices but I now have a need to override one or more of the properties whenever they are used by code which is called from a particular object instance. I am far from a java expert (but have way too many years of programming experience to mention) so any specific guidence for a solution will be greatly appreciated.

+1  A: 

The Java properties store is a single, global, name-value map. There is no general support for overriding properties based on "who" (object, package, etc.) is referencing the property.

JesperE
A: 

The answer is going to depend on the specific package you are using and which property you are interested in changing. A properties file may be read once at startup and never accessed again. If that is what the code does, then there is nothing you can do about it without changing the code. Other packages give you the ability to change the properties, or give you other configuration options that let you set values without using a properties file. The individual callers would have to make sure to change the properties as needed.

You also need to be concerned about threading issues (even if you are running in an application server that abstracts them away). If the properties are stored as a static variable, then changing it for one caller could change it for all callers.

Either way, I would suggest asking about the specific class and property you care about here, and see if anyone knows how to deal with changing the property on a per-caller basis.

Yishai