>> On Thu, Aug 5, 2010 at 10:44 AM, Federico Paparoni
>> <[email protected]> wrote:
>> > 2010/8/5 Vidar Ramdal <[email protected]>
>> >>
>> >>
>> >> What are the properties for? Configuration of your components?
>> >> If so, I'd use the OSGi configuration support, which will make the
>> >> configuration available in the Felix Web Console.
>> >>
>> >>
>> > Yes configuration for the components and anyway I would like to show in
>> > David the best way to handle properties (hard coded String are useful
>> only
>> > to show examples :P)

> 2010/8/5 Vidar Ramdal <[email protected]>
>> Then OSGi configurations are definately the way to go.

On Fri, Aug 6, 2010 at 12:21 PM, Federico Paparoni
<[email protected]> wrote:
> These properties are available through the BundleContext object I can
> retrieve from the ComponentContext.
> I tried to understand where I have to put the conf/config.properties file
> but I didn't find an example.
> Can you help me?

The easiest way is probably to specify configuration properties as
Java annotations.
Take a look at org.apache.sling.servlets.get.impl.DefaultGetServlet
for (one of many) examples.

In principle, all you need to do is have a string constant annotated
as @scr.property (or @Property if you're using the 'real'
annotations). Then create local variables to store the property
values. These values are fetchted from the Felix ConfigAdmin on
component activation.

Let's look at the 'aliases' config property in DefaultGetServlet:
/** @scr.property */
private static final String ALIAS_PROPERTY = "aliases"; // Name of the property
...
private String[] aliases; // Local variable to hold the value
...
protected void activate(ComponentContext ctx) {
  Dictionary props = ctx.getProperties();
  // Set the local 'aliases' variable to the value from ConfigAdmin
  this.aliases = OsgiUtil.toStringArray(props.get(ALIAS_PROPERTY));
  ...
}

protected void deactivate(ComponentContext ctx) {
  this.aliases = null;
 ...
}

In short, you don't need *.properties files. You can supply default
values in the Java code itself, or you can supply configuration as JCR
nodes. See 
http://sling.apache.org/site/jcr-installer-jcrjcrinstall-and-osgiinstaller.html#JCRInstaller%28jcr.jcrinstallandosgi.installer%29-Install%2Cmodifyandremoveaconfiguration
for the docs.

You might also find this mail thread useful:
http://web.archiveorange.com/archive/v/8X7ppYhYoN7CEPybNem7

-- 
Vidar S. Ramdal <[email protected]> - http://www.idium.no
Sommerrogata 13-15, N-0255 Oslo, Norway
+ 47 22 00 84 00 / +47 22 00 84 76
Quando omni flunkus moritatus!

Reply via email to