Hi list,
under AMDATU-479 (see [0]) I am running into the common issue off
needing to pass on service properties, not wanting to hardcode them
either by hand or compiler, not wanting to introduce package
dependencies, etc..
Use case:
JspSupport get a callback for a tenant specific ResourceProvider
regsitration with a jspAlias and a tenant_id.
Thus JspSupport must register a JspServlet at path jspAlias and
propagate (at least) the tenant_id
Question:
How do we tell the provider JspSupport which properties to propagate
without hard-coding it, without hard-compiling it (in-lining
constants) and without introducing run-time package dependencies on
modules just to solve this problem?
Solutions:
The DependencyManager adaptor propagates all properties except for a
hard-coded list of exceptions. This is rather crude and has the
drawbacks that this is hardcoded, inlined and has the potential of
doing too much.
Properties props = new Properties();
String[] keys = ref.getPropertyKeys();
for (int i = 0; i < keys.length; i++) {
String key = keys[i];
if (key.equals(Constants.SERVICE_ID) ||
key.equals(Constants.SERVICE_RANKING) ||
key.equals(DependencyManager.ASPECT) ||
key.equals(Constants.OBJECTCLASS)) {
// do not copy these
}
else {
props.put(key, ref.getProperty(key));
}
}
My temporary solution in the support modules uses a prefix heuristic.
Less crude, but still not very flexible. I do like the idea of using a
common prefix for amdatu properties btw. Obvisouly the prefix would
still be hardcoded / inlined. So something like..
for (String key : serviceReference.getPropertyKeys()) {
if(key.startsWith("amdatu."))
properties.put(key, serviceReference.getProperty(key));
}
Finally I was thinking about more flexible solution using a dedicated
property that allows a provider to specify what should be propagated.
This would allow very specific/flexible propagation. Only the reserved
property key would be hardcoded.
String[] propagateKeys = (String[])
serviceReference.getProperty("amdatu.propagate");
for (String key : propagateKeys ) {
properties.put(key, serviceReference.getProperty(key));
}
At this point I am unable to choose... what do you guys think?
grz
Bram
_______________________________________________
Amdatu-developers mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-developers