You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@aries.apache.org by CLEMENT Jean-Philippe <je...@fr.thalesgroup.com> on 2013/09/03 17:07:04 UTC

Blueprint string substitution / placeholder

Hi,

I would like to replace Blueprint string values, for instance in:
            <bean id=”sample” class=”test.TestClass”>
                        <argument value=”$(to.replace)” />
            </bean>

Where $(to.replace) would be substituted by the correct value taken from a java service and not directly from a file.

What would be the simplest way to do so? Is there a way to map a placeholder to a bean?

Best regards,
Jean-Philippe

[@@ OPEN @@]

RE: Blueprint string substitution / placeholder

Posted by CLEMENT Jean-Philippe <je...@fr.thalesgroup.com>.
Stephan,

It is just a string replacement inside Blueprint file. The “property-placeholder” does basically what I want but retrieves values from flat files. I would like to retrieve the values from a database for instance.

It seems to be possible providing a PersitanceManager implementation.

Best regards,
Jean-Philippe

[@@ OPEN @@]

De : Siano, Stephan [mailto:stephan.siano@sap.com]
Envoyé : mercredi 4 septembre 2013 10:07
À : user@aries.apache.org
Objet : RE: Blueprint string substitution / placeholder

Hi Jean-Philippe,

If I get you right you have too classes class Foo with a method public Bar getBar() and your test class with a constructor that expects a Bar parameter. You could do something like:

<bean id=”foo” class=”test.Foo” />

<bean id=”bar”  factory-ref=”foo” factory-method=”getBar” />

<bean id=”sample” class=”test.TestClass”>
      <argument ref=”bar” />
</bean>

Best regards
Stephan

From: CLEMENT Jean-Philippe [mailto:jean-philippe.clement@fr.thalesgroup.com]<mailto:[mailto:jean-philippe.clement@fr.thalesgroup.com]>
Sent: Mittwoch, 4. September 2013 09:35
To: user@aries.apache.org<ma...@aries.apache.org>
Subject: RE: Blueprint string substitution / placeholder

Stephan,

I just want to replace $(to.replace) by another value which comes from one of my services/beans rather than directly from a file just as property-placeholder does.

Digging into subject, it seems that Felix implementation of property-placeholder delegates to all registered services which exposes the PersistanceManager interface. I will give it a try.

Best regards,
Jean-Philippe

[@@ OPEN @@]

De : Siano, Stephan [mailto:stephan.siano@sap.com]
Envoyé : mercredi 4 septembre 2013 07:23
À : user@aries.apache.org<ma...@aries.apache.org>
Objet : RE: Blueprint string substitution / placeholder

Hi Jean-Philippe,

I actually don’t understand what you really mean by “correct value taken from a java service and not directly from a file”.
Do you mean an OSGi service that can provide the required information? Or do you mean a standard OSGi service like the config admin service? Or do you want to get the information from a properties file without reading it in code?

If the value is provided by a method of an OSGi service you have actually two options:
Reference the service, instantiate another bean for your parameter (e.g. one of type String) using the method as factory method and the referenced service as a factory. This has the disadvantage that the substitution is static (so even if the value changes in the service it will not in your TestClass instance). Alternatively you could change the test class to use the referenced service directly. In that case the implementation could query the value at each usage und would get the changes from the service.

If you read properties files or the config admin service there are properties placeholders for that. With the config admin properties there is also some dynamics possible but I haven’t really tried that out.

Best regards
Stephan


From: CLEMENT Jean-Philippe [mailto:jean-philippe.clement@fr.thalesgroup.com]<mailto:[mailto:jean-philippe.clement@fr.thalesgroup.com]>
Sent: Dienstag, 3. September 2013 17:07
To: user@aries.apache.org<ma...@aries.apache.org>
Subject: Blueprint string substitution / placeholder

Hi,

I would like to replace Blueprint string values, for instance in:
            <bean id=”sample” class=”test.TestClass”>
                        <argument value=”$(to.replace)” />
            </bean>

Where $(to.replace) would be substituted by the correct value taken from a java service and not directly from a file.

What would be the simplest way to do so? Is there a way to map a placeholder to a bean?

Best regards,
Jean-Philippe

[@@ OPEN @@]

RE: Blueprint string substitution / placeholder

Posted by "Siano, Stephan" <st...@sap.com>.
Hi Jean-Philippe,

If I get you right you have too classes class Foo with a method public Bar getBar() and your test class with a constructor that expects a Bar parameter. You could do something like:

<bean id=”foo” class=”test.Foo” />

<bean id=”bar”  factory-ref=”foo” factory-method=”getBar” />

<bean id=”sample” class=”test.TestClass”>
      <argument ref=”bar” />
</bean>

Best regards
Stephan

From: CLEMENT Jean-Philippe [mailto:jean-philippe.clement@fr.thalesgroup.com]
Sent: Mittwoch, 4. September 2013 09:35
To: user@aries.apache.org
Subject: RE: Blueprint string substitution / placeholder

Stephan,

I just want to replace $(to.replace) by another value which comes from one of my services/beans rather than directly from a file just as property-placeholder does.

Digging into subject, it seems that Felix implementation of property-placeholder delegates to all registered services which exposes the PersistanceManager interface. I will give it a try.

Best regards,
Jean-Philippe

[@@ OPEN @@]

De : Siano, Stephan [mailto:stephan.siano@sap.com]
Envoyé : mercredi 4 septembre 2013 07:23
À : user@aries.apache.org<ma...@aries.apache.org>
Objet : RE: Blueprint string substitution / placeholder

Hi Jean-Philippe,

I actually don’t understand what you really mean by “correct value taken from a java service and not directly from a file”.
Do you mean an OSGi service that can provide the required information? Or do you mean a standard OSGi service like the config admin service? Or do you want to get the information from a properties file without reading it in code?

If the value is provided by a method of an OSGi service you have actually two options:
Reference the service, instantiate another bean for your parameter (e.g. one of type String) using the method as factory method and the referenced service as a factory. This has the disadvantage that the substitution is static (so even if the value changes in the service it will not in your TestClass instance). Alternatively you could change the test class to use the referenced service directly. In that case the implementation could query the value at each usage und would get the changes from the service.

If you read properties files or the config admin service there are properties placeholders for that. With the config admin properties there is also some dynamics possible but I haven’t really tried that out.

Best regards
Stephan


From: CLEMENT Jean-Philippe [mailto:jean-philippe.clement@fr.thalesgroup.com]<mailto:[mailto:jean-philippe.clement@fr.thalesgroup.com]>
Sent: Dienstag, 3. September 2013 17:07
To: user@aries.apache.org<ma...@aries.apache.org>
Subject: Blueprint string substitution / placeholder

Hi,

I would like to replace Blueprint string values, for instance in:
            <bean id=”sample” class=”test.TestClass”>
                        <argument value=”$(to.replace)” />
            </bean>

Where $(to.replace) would be substituted by the correct value taken from a java service and not directly from a file.

What would be the simplest way to do so? Is there a way to map a placeholder to a bean?

Best regards,
Jean-Philippe

[@@ OPEN @@]

RE: Blueprint string substitution / placeholder

Posted by CLEMENT Jean-Philippe <je...@fr.thalesgroup.com>.
Stephan,

I just want to replace $(to.replace) by another value which comes from one of my services/beans rather than directly from a file just as property-placeholder does.

Digging into subject, it seems that Felix implementation of property-placeholder delegates to all registered services which exposes the PersistanceManager interface. I will give it a try.

Best regards,
Jean-Philippe

[@@ OPEN @@]

De : Siano, Stephan [mailto:stephan.siano@sap.com]
Envoyé : mercredi 4 septembre 2013 07:23
À : user@aries.apache.org
Objet : RE: Blueprint string substitution / placeholder

Hi Jean-Philippe,

I actually don’t understand what you really mean by “correct value taken from a java service and not directly from a file”.
Do you mean an OSGi service that can provide the required information? Or do you mean a standard OSGi service like the config admin service? Or do you want to get the information from a properties file without reading it in code?

If the value is provided by a method of an OSGi service you have actually two options:
Reference the service, instantiate another bean for your parameter (e.g. one of type String) using the method as factory method and the referenced service as a factory. This has the disadvantage that the substitution is static (so even if the value changes in the service it will not in your TestClass instance). Alternatively you could change the test class to use the referenced service directly. In that case the implementation could query the value at each usage und would get the changes from the service.

If you read properties files or the config admin service there are properties placeholders for that. With the config admin properties there is also some dynamics possible but I haven’t really tried that out.

Best regards
Stephan


From: CLEMENT Jean-Philippe [mailto:jean-philippe.clement@fr.thalesgroup.com]<mailto:[mailto:jean-philippe.clement@fr.thalesgroup.com]>
Sent: Dienstag, 3. September 2013 17:07
To: user@aries.apache.org<ma...@aries.apache.org>
Subject: Blueprint string substitution / placeholder

Hi,

I would like to replace Blueprint string values, for instance in:
            <bean id=”sample” class=”test.TestClass”>
                        <argument value=”$(to.replace)” />
            </bean>

Where $(to.replace) would be substituted by the correct value taken from a java service and not directly from a file.

What would be the simplest way to do so? Is there a way to map a placeholder to a bean?

Best regards,
Jean-Philippe

[@@ OPEN @@]

RE: Blueprint string substitution / placeholder

Posted by "Siano, Stephan" <st...@sap.com>.
Hi Jean-Philippe,

I actually don’t understand what you really mean by “correct value taken from a java service and not directly from a file”.
Do you mean an OSGi service that can provide the required information? Or do you mean a standard OSGi service like the config admin service? Or do you want to get the information from a properties file without reading it in code?

If the value is provided by a method of an OSGi service you have actually two options:
Reference the service, instantiate another bean for your parameter (e.g. one of type String) using the method as factory method and the referenced service as a factory. This has the disadvantage that the substitution is static (so even if the value changes in the service it will not in your TestClass instance). Alternatively you could change the test class to use the referenced service directly. In that case the implementation could query the value at each usage und would get the changes from the service.

If you read properties files or the config admin service there are properties placeholders for that. With the config admin properties there is also some dynamics possible but I haven’t really tried that out.

Best regards
Stephan


From: CLEMENT Jean-Philippe [mailto:jean-philippe.clement@fr.thalesgroup.com]
Sent: Dienstag, 3. September 2013 17:07
To: user@aries.apache.org
Subject: Blueprint string substitution / placeholder

Hi,

I would like to replace Blueprint string values, for instance in:
            <bean id=”sample” class=”test.TestClass”>
                        <argument value=”$(to.replace)” />
            </bean>

Where $(to.replace) would be substituted by the correct value taken from a java service and not directly from a file.

What would be the simplest way to do so? Is there a way to map a placeholder to a bean?

Best regards,
Jean-Philippe

[@@ OPEN @@]

RE: Blueprint string substitution / placeholder

Posted by CLEMENT Jean-Philippe <je...@fr.thalesgroup.com>.
Łukasz,

I’m not too sure how to do this with Blueprint. Do you have a sample config file I could look at?

Best regards,
Jean-Philippe

[@@ OPEN @@]

De : Łukasz Dywicki [mailto:luke@code-house.org]
Envoyé : mardi 3 septembre 2013 23:54
À : user@aries.apache.org
Objet : Re: Blueprint string substitution / placeholder

Jean,
You may use ext:property-placeholder with default properties reference. This default-properties-ref instance could be created by factory method executed on some service.

Cheers!
Łukasz Dywicki
--
luke@code-house.org<ma...@code-house.org>
Twitter: ldywicki
Blog: http://dywicki.pl
Code-House - http://code-house.org

Wiadomość napisana przez CLEMENT Jean-Philippe <je...@fr.thalesgroup.com>> w dniu 3 wrz 2013, o godz. 17:07:


Hi,

I would like to replace Blueprint string values, for instance in:
            <bean id=”sample” class=”test.TestClass”>
                        <argument value=”$(to.replace)” />
            </bean>

Where $(to.replace) would be substituted by the correct value taken from a java service and not directly from a file.

What would be the simplest way to do so? Is there a way to map a placeholder to a bean?

Best regards,
Jean-Philippe

[@@ OPEN @@]


Re: Blueprint string substitution / placeholder

Posted by Łukasz Dywicki <lu...@code-house.org>.
Jean,
You may use ext:property-placeholder with default properties reference. This default-properties-ref instance could be created by factory method executed on some service.

Cheers!
Łukasz Dywicki
--
luke@code-house.org
Twitter: ldywicki
Blog: http://dywicki.pl
Code-House - http://code-house.org

Wiadomość napisana przez CLEMENT Jean-Philippe <je...@fr.thalesgroup.com> w dniu 3 wrz 2013, o godz. 17:07:

> Hi,
>  
> I would like to replace Blueprint string values, for instance in:
>             <bean id=”sample” class=”test.TestClass”>
>                         <argument value=”$(to.replace)” />
>             </bean>
>  
> Where $(to.replace) would be substituted by the correct value taken from a java service and not directly from a file.
>  
> What would be the simplest way to do so? Is there a way to map a placeholder to a bean?
>  
> Best regards,
> Jean-Philippe
>  
> [@@ OPEN @@]