You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "Steven E. Harris" <se...@panix.com> on 2007/03/04 23:39:20 UTC

iPOJO ConfigurationHandler.configure() method skips String properties

I'm trying to figure out why a field in an iPOJO component is not
getting bound to a property in the Configuration that creates it. That
is, I create a Configuration with
ConfigurationAdmin.createFactoryConfiguration(), specifying some
properties, one of which is bound to field:

<iPOJO>
  <component className="..." factory="...">
    <provides>
      <property name="some.prop" field="someProp/>
    </provides>
    <properties>
      <property name="some.prop" field="someProp"/>
    </properties>
  </component>
</iPOJO>

My intention here is that the Configuration property "some.prop" will
be assigned to the component field "someProp", and the current value
of someProp will be exhibited back out as a service property.

If I'm understanding iPOJO correctly, when the component is getting
created, we wind up in ConfigurationHandler.configure(). Staring on
line 145, we see the following code, reformatted here for clarity:

,----
| // Check if the instance configuration contains value for the
| // current property :
| String name = m_configurableProperties[k].getName();
| String fieldName = m_configurableProperties[k].getField();
| if (name != null &&
|     configuration.get(name) != null &&
|     !(configuration.get(name) instanceof String))
|   { m_configurableProperties[k].setValue(configuration.get(name)); }
| else {
|   if (fieldName != null &&
|       configuration.get(fieldName) != null &&
|       !(configuration.get(fieldName) instanceof String))
|   { m_configurableProperties[k].setValue(configuration.get(fieldName)); } }
`----


Stepping through this code in the debugger, both "name" and
"fieldName" are non-null, "some.prop" and "someProp" respectively, and
configuration.get(name) returns a non-null String. But then we run
into the third condition, making sure that the configuration property
is /not a String/. Why does this matter? Why should String-valued
properties not be set here?

-- 
Steven E. Harris

Re: iPOJO ConfigurationHandler.configure() method skips String properties

Posted by Clement Escoffier <cl...@gmail.com>.
Steven E. Harris a écrit :
> "Steven E. Harris" <se...@panix.com> writes:
>
>   
>> However, the field in my component never gets set to the
>> configuration property value. Should the field be set eventually?
>>     
>
> Well, it turns out the field does get set, but in a sneaky way not
> evident in the debugger. Only when the field gets read does it
> manifest the value initially known only to iPOJO.
>
> Forget about my inquiry regarding the String-typed property
> values. Things seem to be working with the current code.
>
>   
Hello,

The creation of String-typed property is a little strange. It cannot be 
at the same place than other properties, because String properties 
(properties with a String set-value) can be set both by the component 
type (<property field="foo" value="bar"/>), and by the instance 
configuration. Component-type are always String, but can be "mapped" on 
non-String property (iPOJO invokes a constructor with a String to create 
the object). iPOJO chooses that instance configuration override 
component-type properties. The actual code is not very clear on this 
aspect. I will think to a better way...

Clement

-- 
Clement Escoffier
Grenoble University
LSR - Bat. C
220, Rue de la Chimie
BP 53
38041 GRENOBLE CEDEX 9
04.76.51.40.24
http://clement.plop-plop.net


Re: iPOJO ConfigurationHandler.configure() method skips String properties

Posted by "Steven E. Harris" <se...@panix.com>.
"Steven E. Harris" <se...@panix.com> writes:

> However, the field in my component never gets set to the
> configuration property value. Should the field be set eventually?

Well, it turns out the field does get set, but in a sneaky way not
evident in the debugger. Only when the field gets read does it
manifest the value initially known only to iPOJO.

Forget about my inquiry regarding the String-typed property
values. Things seem to be working with the current code.

-- 
Steven E. Harris

Re: iPOJO ConfigurationHandler.configure() method skips String properties

Posted by "Steven E. Harris" <se...@panix.com>.
"Steven E. Harris" <se...@panix.com> writes:

> My intention here is that the Configuration property "some.prop" will
> be assigned to the component field "someProp", and the current value
> of someProp will be exhibited back out as a service property.

I did notice that earlier in ConfigurationHandler.configure(), around
line 112, some of the same name/fieldName/configuration inspection
goes on, this time favoring only String-typed configuration property
values.

We make it all the way down to line 127 where

  cd.addProperty(new PropertyDescription(...

gets called. However, the field in my component never gets set to the
configuration property value. Should the field be set eventually?

-- 
Steven E. Harris