You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by CLEMENT Jean-Philippe <je...@fr.thalesgroup.com> on 2013/05/31 11:11:40 UTC
Blueprint scope and reference-list
Dear Karaf Team,
I would like to build a bean each time a reference is matched.
I tried this:
<bean id="KindOfFactory" class="TestClass" scope="prototype"/>
<reference-list interface="SomeInterface"/>
<reference-listener ref="KindOfFactory" bind-method="bind"/>
</reference-list>
But prototype instantiation seems to be linked to the reference-list itself rather than the listener call.
Anyway, is there a way to instantiate a bean each time a kind of service is mapped in Karaf using only blueprint?
Kind regards,
Jean-Philippe
[@@ OPEN @@]
RE: Blueprint scope and reference-list
Posted by rkmoquin <fr...@gmail.com>.
You can use a ref to refer to the factory bean to inject it into the property
of another bean, that won't cause the factory to be invoked. The factory
bean is invoked when specified by by a blueprint bean declaration that uses
the factory-* attributes of the bean. You might want to link the xsd to
your blueprint document so that you can get xml completion and help with
what elements and attributes are available. That would probably help you
immensely.
I believe that you might be able to accomplish what you want if you declare
a prototype bean that references a factory for instantiation. Then if you
also have a prototype bean which is exposed as a service, you could
reference the first bean as a property of the second bean. This way, when
the service gets created, a new instance of the service bean will be
created, then when injecting it's property that refers to the first bean,
the factory should be invoked and a new instance of that bean be created.
This would only work with prototype beans though since once a singleton bean
is created, even if it references a prototype bean in one of it's
properties, the singleton bean won't need to be instantiated again.
I also haven't tried exactly what I described above, but it should work if
you refer to a prototype bean from a prototype bean exposed as a service.
You can find some helpful code snippets on the apache aries blueprint
examples page.
--
View this message in context: http://karaf.922171.n3.nabble.com/Blueprint-scope-and-reference-list-tp4028901p4029042.html
Sent from the Karaf - User mailing list archive at Nabble.com.
RE: Blueprint scope and reference-list
Posted by CLEMENT Jean-Philippe <je...@fr.thalesgroup.com>.
Hi Andreas,
I was more looking for something like this :
<bean id="myFactory" class="SomeClass" scope="prototype"/>
<bean class="TestClass"/>
<argument ?ref?="myFactory"/>
</bean>
With TestClass as:
public final class TestClass {
private final ?class? factory;
public TestClass(final ?class? factory) {
this.factory= factory;
}
public void test() {
final SomeClass instance= factory.?method?();
...
}
}
Where ?ref? would be the way to inject the bean itself (manager) and not the result of the bean creation, ?class? the injected bean manager and ?method? the manager method to create the TestClass bean on demand.
Is there any way to do so?
Cheers,
Jean-Philippe
[@@ OPEN @@]
De : Andreas Pieber [mailto:anpieber@gmail.com]
Envoyé : mercredi 12 juin 2013 07:42
À : Apache Karaf
Objet : Re: Blueprint scope and reference-list
I'm not sure if I understand your question. Yes it is
<!-- Simply call the factory manually on each invocation -->
<bean id="bindHandler" class="TestClass" >
<argument ref="myFactory"/>
</bean>
<reference-list interface="SomeInterface"/>
<reference-listener ref="bindHandler" bind-method="bind"/>
</reference-list>
I hope this helps!
Kind regards,
Andreas
On Mon, Jun 3, 2013 at 11:54 AM, CLEMENT Jean-Philippe <je...@fr.thalesgroup.com>> wrote:
Hi Andreas,
Is there a way to inject the factory (prototype bean) itself?
Cheers,
JP
[@@ OPEN @@]
De : Andreas Pieber [mailto:anpieber@gmail.com<ma...@gmail.com>]
Envoyé : samedi 1 juin 2013 10:57
À : Apache Karaf
Objet : Re: Blueprint scope and reference-list
Hey,
I'm sorry, but there isn't any blueprint only method available for this. You'll need to create your object manually during the bind call if you like such a behavior.
Kind regards,
Andreas
On Fri, May 31, 2013 at 11:11 AM, CLEMENT Jean-Philippe <je...@fr.thalesgroup.com>> wrote:
Dear Karaf Team,
I would like to build a bean each time a reference is matched.
I tried this:
<bean id="KindOfFactory" class="TestClass" scope="prototype"/>
<reference-list interface="SomeInterface"/>
<reference-listener ref="KindOfFactory" bind-method="bind"/>
</reference-list>
But prototype instantiation seems to be linked to the reference-list itself rather than the listener call.
Anyway, is there a way to instantiate a bean each time a kind of service is mapped in Karaf using only blueprint?
Kind regards,
Jean-Philippe
[@@ OPEN @@]
Re: Blueprint scope and reference-list
Posted by Andreas Pieber <an...@gmail.com>.
I'm not sure if I understand your question. Yes it is
<!-- Simply call the factory manually on each invocation -->
<bean id=”bindHandler” class=”TestClass” >****
<argument ref="myFactory"/>
</bean>
<reference-list interface=”SomeInterface”/>****
<reference-listener ref=”bindHandler” bind-method=”bind”/>****
</reference-list>
I hope this helps!
Kind regards,
Andreas
On Mon, Jun 3, 2013 at 11:54 AM, CLEMENT Jean-Philippe <
jean-philippe.clement@fr.thalesgroup.com> wrote:
> Hi Andreas,****
>
> ** **
>
> Is there a way to inject the factory (prototype bean) itself?****
>
> ** **
>
> Cheers,****
>
> JP****
>
> ** **
>
> [@@ OPEN @@]****
>
> ** **
>
> *De :* Andreas Pieber [mailto:anpieber@gmail.com]
> *Envoyé :* samedi 1 juin 2013 10:57
> *À :* Apache Karaf
> *Objet :* Re: Blueprint scope and reference-list****
>
> ** **
>
> Hey,****
>
> ** **
>
> I'm sorry, but there isn't any blueprint only method available for this.
> You'll need to create your object manually during the bind call if you like
> such a behavior.****
>
> ** **
>
> Kind regards,****
>
> Andreas****
>
> ** **
>
> On Fri, May 31, 2013 at 11:11 AM, CLEMENT Jean-Philippe <
> jean-philippe.clement@fr.thalesgroup.com> wrote:****
>
> Dear Karaf Team,****
>
> ****
>
> I would like to build a bean each time a reference is matched.****
>
> ****
>
> I tried this:****
>
> <bean id=”KindOfFactory” class=”TestClass” scope=”prototype”/>****
>
> ****
>
> <reference-list interface=”SomeInterface”/>****
>
> <reference-listener ref=”KindOfFactory” bind-method=”bind”/>****
>
> </reference-list>****
>
> ****
>
> But prototype instantiation seems to be linked to the reference-list
> itself rather than the listener call.****
>
> ****
>
> Anyway, is there a way to instantiate a bean each time a kind of service
> is mapped in Karaf using only blueprint?****
>
> ****
>
> Kind regards,****
>
> Jean-Philippe****
>
> ****
>
> [@@ OPEN @@]****
>
> ** **
>
RE: Blueprint scope and reference-list
Posted by CLEMENT Jean-Philippe <je...@fr.thalesgroup.com>.
Hi Andreas,
Is there a way to inject the factory (prototype bean) itself?
Cheers,
JP
[@@ OPEN @@]
De : Andreas Pieber [mailto:anpieber@gmail.com]
Envoyé : samedi 1 juin 2013 10:57
À : Apache Karaf
Objet : Re: Blueprint scope and reference-list
Hey,
I'm sorry, but there isn't any blueprint only method available for this. You'll need to create your object manually during the bind call if you like such a behavior.
Kind regards,
Andreas
On Fri, May 31, 2013 at 11:11 AM, CLEMENT Jean-Philippe <je...@fr.thalesgroup.com>> wrote:
Dear Karaf Team,
I would like to build a bean each time a reference is matched.
I tried this:
<bean id="KindOfFactory" class="TestClass" scope="prototype"/>
<reference-list interface="SomeInterface"/>
<reference-listener ref="KindOfFactory" bind-method="bind"/>
</reference-list>
But prototype instantiation seems to be linked to the reference-list itself rather than the listener call.
Anyway, is there a way to instantiate a bean each time a kind of service is mapped in Karaf using only blueprint?
Kind regards,
Jean-Philippe
[@@ OPEN @@]
Re: Blueprint scope and reference-list
Posted by Andreas Pieber <an...@gmail.com>.
Hey,
I'm sorry, but there isn't any blueprint only method available for this.
You'll need to create your object manually during the bind call if you like
such a behavior.
Kind regards,
Andreas
On Fri, May 31, 2013 at 11:11 AM, CLEMENT Jean-Philippe <
jean-philippe.clement@fr.thalesgroup.com> wrote:
> Dear Karaf Team,****
>
> ** **
>
> I would like to build a bean each time a reference is matched.****
>
> ** **
>
> I tried this:****
>
> <bean id=”KindOfFactory” class=”TestClass” scope=”prototype”/>****
>
> ** **
>
> <reference-list interface=”SomeInterface”/>****
>
> <reference-listener ref=”KindOfFactory” bind-method=”bind”/>****
>
> </reference-list>****
>
> ** **
>
> But prototype instantiation seems to be linked to the reference-list
> itself rather than the listener call.****
>
> ** **
>
> Anyway, is there a way to instantiate a bean each time a kind of service
> is mapped in Karaf using only blueprint?****
>
> ** **
>
> Kind regards,****
>
> Jean-Philippe****
>
> ** **
>
> [@@ OPEN @@]****
>