You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@openwebbeans.apache.org by Charles Moulliard <cm...@gmail.com> on 2012/07/12 14:21:38 UTC
Util class to find annotations in a class
Hi,
Is there a DeltaSpike or OpenWebbeans util class that I could use to scan
classes and find annotations (which have been of course designed without
CDI in mind) and next inject them ?
Camel provides @EndpointInject(uri or ref), @Produce(uri) and @Consume
annotations to inject Endpoint definition or Producer/ConsumerTemplate into
CamelContext.
We have to call getInjectionValue(type, uri, endpointRef,
injectionPointName, null, null) method of CamelPostProcessorHelper tevery
time such annotation is discovered o add such injected bean. Camel-guice,
camel-spring and camel-blueprint projects proposes such impl (which is not
CDI compliant). I would like to implement this in camel-cdi (where we
already have defined a CamelInjector) and tries to find the best strategy.
Is there something equivalent to what we have here in camel-guice ?
bindAnnotationInjector(EndpointInject.class,
EndpointInjector.class); where bindAnnotationInjector is a method of this
class GuiceyFruitModule
and EndpointInjectorClass is the class containing the code to find
annotations wiithin a class
public class EndpointInjector extends CamelPostProcessorHelper implements
AnnotationMemberProvider<EndpointInject> {
@Inject
public EndpointInjector(CamelContext camelContext) {
super(camelContext);
}
public Object provide(EndpointInject inject, TypeLiteral<?>
typeLiteral, Field field) {
Class<?> type = field.getType();
String injectionPointName = field.getName();
String uri = inject.uri();
String endpointRef = inject.ref();
return getInjectionValue(type, uri, endpointRef,
injectionPointName, null, null);
}
Regards,
Apache Committer
Blog : http://cmoulliard.blogspot.com
Twitter : http://twitter.com/cmoulliard
Linkedin : http://www.linkedin.com/in/charlesmoulliard
Skype: cmoulliard
Re: Util class to find annotations in a class
Posted by Romain Manni-Bucau <rm...@gmail.com>.
that's what i suggested, it is even worse, pojo can be recorded to create
the camelcontext and have not to be always injectable
@Charles: could even create a new API to create camel route where you
inject beans instead of endpoint and beans represent endpoints!
- Romain
2012/7/12 Arne Limburg <ar...@openknowledge.de>
> Hi,
>
> can't you just listen to the ProcessAnnotatedType event, inspect it and if
> you find an @EndpointInject i.e. add an @Inject to the AnnotatedType?
>
> Cheers,
> Arne
>
> -----Ursprüngliche Nachricht-----
> Von: Charles Moulliard [mailto:cmoulliard@gmail.com]
> Gesendet: Donnerstag, 12. Juli 2012 14:22
> An: deltaspike-dev@incubator.apache.org; user@openwebbeans.apache.org
> Betreff: Util class to find annotations in a class
>
> Hi,
>
> Is there a DeltaSpike or OpenWebbeans util class that I could use to scan
> classes and find annotations (which have been of course designed without
> CDI in mind) and next inject them ?
>
> Camel provides @EndpointInject(uri or ref), @Produce(uri) and @Consume
> annotations to inject Endpoint definition or Producer/ConsumerTemplate into
> CamelContext.
>
> We have to call getInjectionValue(type, uri, endpointRef,
> injectionPointName, null, null) method of CamelPostProcessorHelper tevery
> time such annotation is discovered o add such injected bean. Camel-guice,
> camel-spring and camel-blueprint projects proposes such impl (which is not
> CDI compliant). I would like to implement this in camel-cdi (where we
> already have defined a CamelInjector) and tries to find the best strategy.
>
> Is there something equivalent to what we have here in camel-guice ?
>
> bindAnnotationInjector(EndpointInject.class,
> EndpointInjector.class); where bindAnnotationInjector is a method of this
> class GuiceyFruitModule and EndpointInjectorClass is the class containing
> the code to find annotations wiithin a class
>
> public class EndpointInjector extends CamelPostProcessorHelper implements
> AnnotationMemberProvider<EndpointInject> {
>
> @Inject
> public EndpointInjector(CamelContext camelContext) {
> super(camelContext);
> }
>
> public Object provide(EndpointInject inject, TypeLiteral<?>
> typeLiteral, Field field) {
> Class<?> type = field.getType();
> String injectionPointName = field.getName();
> String uri = inject.uri();
> String endpointRef = inject.ref();
>
> return getInjectionValue(type, uri, endpointRef,
> injectionPointName, null, null);
> }
>
> Regards,
>
> Apache Committer
>
> Blog : http://cmoulliard.blogspot.com
> Twitter : http://twitter.com/cmoulliard
> Linkedin : http://www.linkedin.com/in/charlesmoulliard
> Skype: cmoulliard
>
Re: AW: Util class to find annotations in a class
Posted by Romain Manni-Bucau <rm...@gmail.com>.
No, i was thinking of sthg queryable easily by something else than class.
Le 12 juil. 2012 17:34, "Mark Struberg" <st...@yahoo.de> a écrit :
> We have such a 'cache' already: AnnotatedType!
>
> Any Extension shall NOT use Class#getDeclaredBlah to scan for this info!
>
> LieGrue,
> strub
>
>
>
> ----- Original Message -----
> > From: Romain Manni-Bucau <rm...@gmail.com>
> > To: deltaspike-dev@incubator.apache.org
> > Cc:
> > Sent: Thursday, July 12, 2012 5:09 PM
> > Subject: Re: AW: Util class to find annotations in a class
> >
> > about it and more DS oriented: should a common cache be created? each
> > extensions are browsing metamodel (classes of course but fields and
> > methods!!!) and it is time expensive :s:s
> >
> > doing it only once with a good querying structure could save a lot of
> time
> >
> > wdyt?
> >
> > - Romain
> >
> >
> > 2012/7/12 Mark Struberg <st...@yahoo.de>
> >
> >> +1
> >>
> >> public void initCamelContext(@Observes ProcessAnnotatedType<? extends
> >> CamelContext> pat) {...
> >>
> >> for example.
> >>
> >> Doing another scan manually is really performance intense!
> >>
> >>
> >> LieGrue,
> >> strub
> >>
> >>
> >>
> >> PS: please don't do cross posts to multiple lists at the same time.
> > just
> >> confuses users ;)
> >>
> >>
> >>
> >> ----- Original Message -----
> >> > From: Arne Limburg <ar...@openknowledge.de>
> >> > To: "deltaspike-dev@incubator.apache.org" <
> >> deltaspike-dev@incubator.apache.org>;
> > "user@openwebbeans.apache.org" <
> >> user@openwebbeans.apache.org>
> >> > Cc:
> >> > Sent: Thursday, July 12, 2012 2:37 PM
> >> > Subject: AW: Util class to find annotations in a class
> >> >
> >> > Hi,
> >> >
> >> > can't you just listen to the ProcessAnnotatedType event, inspect
> > it and
> >> if
> >> > you find an @EndpointInject i.e. add an @Inject to the AnnotatedType?
> >> >
> >> > Cheers,
> >> > Arne
> >> >
> >> > -----Ursprüngliche Nachricht-----
> >> > Von: Charles Moulliard [mailto:cmoulliard@gmail.com]
> >> > Gesendet: Donnerstag, 12. Juli 2012 14:22
> >> > An: deltaspike-dev@incubator.apache.org;
> user@openwebbeans.apache.org
> >> > Betreff: Util class to find annotations in a class
> >> >
> >> > Hi,
> >> >
> >> > Is there a DeltaSpike or OpenWebbeans util class that I could use to
> > scan
> >> > classes and find annotations (which have been of course designed
> > without
> >> CDI in
> >> > mind) and next inject them ?
> >> >
> >> > Camel provides @EndpointInject(uri or ref), @Produce(uri) and
> @Consume
> >> > annotations to inject Endpoint definition or
> Producer/ConsumerTemplate
> >> into
> >> > CamelContext.
> >> >
> >> > We have to call getInjectionValue(type, uri, endpointRef,
> >> injectionPointName,
> >> > null, null) method of CamelPostProcessorHelper tevery time such
> >> annotation is
> >> > discovered o add such injected bean. Camel-guice, camel-spring and
> >> > camel-blueprint projects proposes such impl (which is not CDI
> >> compliant). I
> >> > would like to implement this in camel-cdi (where we already have
> > defined
> >> a
> >> > CamelInjector) and tries to find the best strategy.
> >> >
> >> > Is there something equivalent to what we have here in camel-guice ?
> >> >
> >> > bindAnnotationInjector(EndpointInject.class,
> >> > EndpointInjector.class); where bindAnnotationInjector is a method of
> >> this class
> >> > GuiceyFruitModule and EndpointInjectorClass is the class containing
> > the
> >> code to
> >> > find annotations wiithin a class
> >> >
> >> > public class EndpointInjector extends CamelPostProcessorHelper
> > implements
> >> > AnnotationMemberProvider<EndpointInject> {
> >> >
> >> > @Inject
> >> > public EndpointInjector(CamelContext camelContext) {
> >> > super(camelContext);
> >> > }
> >> >
> >> > public Object provide(EndpointInject inject, TypeLiteral<?>
> >> > typeLiteral, Field field) {
> >> > Class<?> type = field.getType();
> >> > String injectionPointName = field.getName();
> >> > String uri = inject.uri();
> >> > String endpointRef = inject.ref();
> >> >
> >> > return getInjectionValue(type, uri, endpointRef,
> >> injectionPointName,
> >> > null, null);
> >> > }
> >> >
> >> > Regards,
> >> >
> >> > Apache Committer
> >> >
> >> > Blog : http://cmoulliard.blogspot.com
> >> > Twitter : http://twitter.com/cmoulliard
> >> > Linkedin : http://www.linkedin.com/in/charlesmoulliard
> >> > Skype: cmoulliard
> >> >
> >>
> >
>
Re: AW: Util class to find annotations in a class
Posted by Mark Struberg <st...@yahoo.de>.
We have such a 'cache' already: AnnotatedType!
Any Extension shall NOT use Class#getDeclaredBlah to scan for this info!
LieGrue,
strub
----- Original Message -----
> From: Romain Manni-Bucau <rm...@gmail.com>
> To: deltaspike-dev@incubator.apache.org
> Cc:
> Sent: Thursday, July 12, 2012 5:09 PM
> Subject: Re: AW: Util class to find annotations in a class
>
> about it and more DS oriented: should a common cache be created? each
> extensions are browsing metamodel (classes of course but fields and
> methods!!!) and it is time expensive :s:s
>
> doing it only once with a good querying structure could save a lot of time
>
> wdyt?
>
> - Romain
>
>
> 2012/7/12 Mark Struberg <st...@yahoo.de>
>
>> +1
>>
>> public void initCamelContext(@Observes ProcessAnnotatedType<? extends
>> CamelContext> pat) {...
>>
>> for example.
>>
>> Doing another scan manually is really performance intense!
>>
>>
>> LieGrue,
>> strub
>>
>>
>>
>> PS: please don't do cross posts to multiple lists at the same time.
> just
>> confuses users ;)
>>
>>
>>
>> ----- Original Message -----
>> > From: Arne Limburg <ar...@openknowledge.de>
>> > To: "deltaspike-dev@incubator.apache.org" <
>> deltaspike-dev@incubator.apache.org>;
> "user@openwebbeans.apache.org" <
>> user@openwebbeans.apache.org>
>> > Cc:
>> > Sent: Thursday, July 12, 2012 2:37 PM
>> > Subject: AW: Util class to find annotations in a class
>> >
>> > Hi,
>> >
>> > can't you just listen to the ProcessAnnotatedType event, inspect
> it and
>> if
>> > you find an @EndpointInject i.e. add an @Inject to the AnnotatedType?
>> >
>> > Cheers,
>> > Arne
>> >
>> > -----Ursprüngliche Nachricht-----
>> > Von: Charles Moulliard [mailto:cmoulliard@gmail.com]
>> > Gesendet: Donnerstag, 12. Juli 2012 14:22
>> > An: deltaspike-dev@incubator.apache.org; user@openwebbeans.apache.org
>> > Betreff: Util class to find annotations in a class
>> >
>> > Hi,
>> >
>> > Is there a DeltaSpike or OpenWebbeans util class that I could use to
> scan
>> > classes and find annotations (which have been of course designed
> without
>> CDI in
>> > mind) and next inject them ?
>> >
>> > Camel provides @EndpointInject(uri or ref), @Produce(uri) and @Consume
>> > annotations to inject Endpoint definition or Producer/ConsumerTemplate
>> into
>> > CamelContext.
>> >
>> > We have to call getInjectionValue(type, uri, endpointRef,
>> injectionPointName,
>> > null, null) method of CamelPostProcessorHelper tevery time such
>> annotation is
>> > discovered o add such injected bean. Camel-guice, camel-spring and
>> > camel-blueprint projects proposes such impl (which is not CDI
>> compliant). I
>> > would like to implement this in camel-cdi (where we already have
> defined
>> a
>> > CamelInjector) and tries to find the best strategy.
>> >
>> > Is there something equivalent to what we have here in camel-guice ?
>> >
>> > bindAnnotationInjector(EndpointInject.class,
>> > EndpointInjector.class); where bindAnnotationInjector is a method of
>> this class
>> > GuiceyFruitModule and EndpointInjectorClass is the class containing
> the
>> code to
>> > find annotations wiithin a class
>> >
>> > public class EndpointInjector extends CamelPostProcessorHelper
> implements
>> > AnnotationMemberProvider<EndpointInject> {
>> >
>> > @Inject
>> > public EndpointInjector(CamelContext camelContext) {
>> > super(camelContext);
>> > }
>> >
>> > public Object provide(EndpointInject inject, TypeLiteral<?>
>> > typeLiteral, Field field) {
>> > Class<?> type = field.getType();
>> > String injectionPointName = field.getName();
>> > String uri = inject.uri();
>> > String endpointRef = inject.ref();
>> >
>> > return getInjectionValue(type, uri, endpointRef,
>> injectionPointName,
>> > null, null);
>> > }
>> >
>> > Regards,
>> >
>> > Apache Committer
>> >
>> > Blog : http://cmoulliard.blogspot.com
>> > Twitter : http://twitter.com/cmoulliard
>> > Linkedin : http://www.linkedin.com/in/charlesmoulliard
>> > Skype: cmoulliard
>> >
>>
>
Re: AW: Util class to find annotations in a class
Posted by Romain Manni-Bucau <rm...@gmail.com>.
about it and more DS oriented: should a common cache be created? each
extensions are browsing metamodel (classes of course but fields and
methods!!!) and it is time expensive :s:s
doing it only once with a good querying structure could save a lot of time
wdyt?
- Romain
2012/7/12 Mark Struberg <st...@yahoo.de>
> +1
>
> public void initCamelContext(@Observes ProcessAnnotatedType<? extends
> CamelContext> pat) {...
>
> for example.
>
> Doing another scan manually is really performance intense!
>
>
> LieGrue,
> strub
>
>
>
> PS: please don't do cross posts to multiple lists at the same time. just
> confuses users ;)
>
>
>
> ----- Original Message -----
> > From: Arne Limburg <ar...@openknowledge.de>
> > To: "deltaspike-dev@incubator.apache.org" <
> deltaspike-dev@incubator.apache.org>; "user@openwebbeans.apache.org" <
> user@openwebbeans.apache.org>
> > Cc:
> > Sent: Thursday, July 12, 2012 2:37 PM
> > Subject: AW: Util class to find annotations in a class
> >
> > Hi,
> >
> > can't you just listen to the ProcessAnnotatedType event, inspect it and
> if
> > you find an @EndpointInject i.e. add an @Inject to the AnnotatedType?
> >
> > Cheers,
> > Arne
> >
> > -----Ursprüngliche Nachricht-----
> > Von: Charles Moulliard [mailto:cmoulliard@gmail.com]
> > Gesendet: Donnerstag, 12. Juli 2012 14:22
> > An: deltaspike-dev@incubator.apache.org; user@openwebbeans.apache.org
> > Betreff: Util class to find annotations in a class
> >
> > Hi,
> >
> > Is there a DeltaSpike or OpenWebbeans util class that I could use to scan
> > classes and find annotations (which have been of course designed without
> CDI in
> > mind) and next inject them ?
> >
> > Camel provides @EndpointInject(uri or ref), @Produce(uri) and @Consume
> > annotations to inject Endpoint definition or Producer/ConsumerTemplate
> into
> > CamelContext.
> >
> > We have to call getInjectionValue(type, uri, endpointRef,
> injectionPointName,
> > null, null) method of CamelPostProcessorHelper tevery time such
> annotation is
> > discovered o add such injected bean. Camel-guice, camel-spring and
> > camel-blueprint projects proposes such impl (which is not CDI
> compliant). I
> > would like to implement this in camel-cdi (where we already have defined
> a
> > CamelInjector) and tries to find the best strategy.
> >
> > Is there something equivalent to what we have here in camel-guice ?
> >
> > bindAnnotationInjector(EndpointInject.class,
> > EndpointInjector.class); where bindAnnotationInjector is a method of
> this class
> > GuiceyFruitModule and EndpointInjectorClass is the class containing the
> code to
> > find annotations wiithin a class
> >
> > public class EndpointInjector extends CamelPostProcessorHelper implements
> > AnnotationMemberProvider<EndpointInject> {
> >
> > @Inject
> > public EndpointInjector(CamelContext camelContext) {
> > super(camelContext);
> > }
> >
> > public Object provide(EndpointInject inject, TypeLiteral<?>
> > typeLiteral, Field field) {
> > Class<?> type = field.getType();
> > String injectionPointName = field.getName();
> > String uri = inject.uri();
> > String endpointRef = inject.ref();
> >
> > return getInjectionValue(type, uri, endpointRef,
> injectionPointName,
> > null, null);
> > }
> >
> > Regards,
> >
> > Apache Committer
> >
> > Blog : http://cmoulliard.blogspot.com
> > Twitter : http://twitter.com/cmoulliard
> > Linkedin : http://www.linkedin.com/in/charlesmoulliard
> > Skype: cmoulliard
> >
>
Re: AW: Util class to find annotations in a class
Posted by Romain Manni-Bucau <rm...@gmail.com>.
yep, that's the only way to do it properly
- Romain
2012/7/12 Charles Moulliard <cm...@gmail.com>
> Mark. Do you suggest to create a class implementing extension like we do
> for CDI SPI ?
>
> ProcessAnnotatedType
>
>
>
>
> On 12/07/12 17:07, Mark Struberg wrote:
>
>> +1
>>
>> public void initCamelContext(@Observes ProcessAnnotatedType<? extends
>> CamelContext> pat) {...
>>
>> for example.
>>
>> Doing another scan manually is really performance intense!
>>
>>
>> LieGrue,
>> strub
>>
>>
>>
>> PS: please don't do cross posts to multiple lists at the same time. just
>> confuses users ;)
>>
>>
>>
>> ----- Original Message -----
>>
>>> From: Arne Limburg<ar...@openknowledge.de>
>>> >
>>> To: "deltaspike-dev@incubator.**apache.org<de...@incubator.apache.org>
>>> "<de...@incubator.apache.org>>;
>>> "user@openwebbeans.apache.org"**<us...@openwebbeans.apache.org>
>>> Cc:
>>> Sent: Thursday, July 12, 2012 2:37 PM
>>> Subject: AW: Util class to find annotations in a class
>>>
>>> Hi,
>>>
>>> can't you just listen to the ProcessAnnotatedType event, inspect it and
>>> if
>>> you find an @EndpointInject i.e. add an @Inject to the AnnotatedType?
>>>
>>> Cheers,
>>> Arne
>>>
>>> -----Ursprüngliche Nachricht-----
>>> Von: Charles Moulliard [mailto:cmoulliard@gmail.com]
>>> Gesendet: Donnerstag, 12. Juli 2012 14:22
>>> An: deltaspike-dev@incubator.**apache.org<de...@incubator.apache.org>;
>>> user@openwebbeans.apache.org
>>> Betreff: Util class to find annotations in a class
>>>
>>> Hi,
>>>
>>> Is there a DeltaSpike or OpenWebbeans util class that I could use to scan
>>> classes and find annotations (which have been of course designed without
>>> CDI in
>>> mind) and next inject them ?
>>>
>>> Camel provides @EndpointInject(uri or ref), @Produce(uri) and @Consume
>>> annotations to inject Endpoint definition or Producer/ConsumerTemplate
>>> into
>>> CamelContext.
>>>
>>> We have to call getInjectionValue(type, uri, endpointRef,
>>> injectionPointName,
>>> null, null) method of CamelPostProcessorHelper tevery time such
>>> annotation is
>>> discovered o add such injected bean. Camel-guice, camel-spring and
>>> camel-blueprint projects proposes such impl (which is not CDI
>>> compliant). I
>>> would like to implement this in camel-cdi (where we already have defined
>>> a
>>> CamelInjector) and tries to find the best strategy.
>>>
>>> Is there something equivalent to what we have here in camel-guice ?
>>>
>>> bindAnnotationInjector(**EndpointInject.class,
>>> EndpointInjector.class); where bindAnnotationInjector is a method of
>>> this class
>>> GuiceyFruitModule and EndpointInjectorClass is the class containing the
>>> code to
>>> find annotations wiithin a class
>>>
>>> public class EndpointInjector extends CamelPostProcessorHelper implements
>>> AnnotationMemberProvider<**EndpointInject> {
>>>
>>> @Inject
>>> public EndpointInjector(CamelContext camelContext) {
>>> super(camelContext);
>>> }
>>>
>>> public Object provide(EndpointInject inject, TypeLiteral<?>
>>> typeLiteral, Field field) {
>>> Class<?> type = field.getType();
>>> String injectionPointName = field.getName();
>>> String uri = inject.uri();
>>> String endpointRef = inject.ref();
>>>
>>> return getInjectionValue(type, uri, endpointRef,
>>> injectionPointName,
>>> null, null);
>>> }
>>>
>>> Regards,
>>>
>>> Apache Committer
>>>
>>> Blog : http://cmoulliard.blogspot.com
>>> Twitter : http://twitter.com/cmoulliard
>>> Linkedin : http://www.linkedin.com/in/**charlesmoulliard<http://www.linkedin.com/in/charlesmoulliard>
>>> Skype: cmoulliard
>>>
>>>
Re: AW: Util class to find annotations in a class
Posted by Charles Moulliard <cm...@gmail.com>.
Mark. Do you suggest to create a class implementing extension like we do
for CDI SPI ?
ProcessAnnotatedType
On 12/07/12 17:07, Mark Struberg wrote:
> +1
>
> public void initCamelContext(@Observes ProcessAnnotatedType<? extends CamelContext> pat) {...
>
> for example.
>
> Doing another scan manually is really performance intense!
>
>
> LieGrue,
> strub
>
>
>
> PS: please don't do cross posts to multiple lists at the same time. just confuses users ;)
>
>
>
> ----- Original Message -----
>> From: Arne Limburg<ar...@openknowledge.de>
>> To: "deltaspike-dev@incubator.apache.org"<de...@incubator.apache.org>; "user@openwebbeans.apache.org"<us...@openwebbeans.apache.org>
>> Cc:
>> Sent: Thursday, July 12, 2012 2:37 PM
>> Subject: AW: Util class to find annotations in a class
>>
>> Hi,
>>
>> can't you just listen to the ProcessAnnotatedType event, inspect it and if
>> you find an @EndpointInject i.e. add an @Inject to the AnnotatedType?
>>
>> Cheers,
>> Arne
>>
>> -----Ursprüngliche Nachricht-----
>> Von: Charles Moulliard [mailto:cmoulliard@gmail.com]
>> Gesendet: Donnerstag, 12. Juli 2012 14:22
>> An: deltaspike-dev@incubator.apache.org; user@openwebbeans.apache.org
>> Betreff: Util class to find annotations in a class
>>
>> Hi,
>>
>> Is there a DeltaSpike or OpenWebbeans util class that I could use to scan
>> classes and find annotations (which have been of course designed without CDI in
>> mind) and next inject them ?
>>
>> Camel provides @EndpointInject(uri or ref), @Produce(uri) and @Consume
>> annotations to inject Endpoint definition or Producer/ConsumerTemplate into
>> CamelContext.
>>
>> We have to call getInjectionValue(type, uri, endpointRef, injectionPointName,
>> null, null) method of CamelPostProcessorHelper tevery time such annotation is
>> discovered o add such injected bean. Camel-guice, camel-spring and
>> camel-blueprint projects proposes such impl (which is not CDI compliant). I
>> would like to implement this in camel-cdi (where we already have defined a
>> CamelInjector) and tries to find the best strategy.
>>
>> Is there something equivalent to what we have here in camel-guice ?
>>
>> bindAnnotationInjector(EndpointInject.class,
>> EndpointInjector.class); where bindAnnotationInjector is a method of this class
>> GuiceyFruitModule and EndpointInjectorClass is the class containing the code to
>> find annotations wiithin a class
>>
>> public class EndpointInjector extends CamelPostProcessorHelper implements
>> AnnotationMemberProvider<EndpointInject> {
>>
>> @Inject
>> public EndpointInjector(CamelContext camelContext) {
>> super(camelContext);
>> }
>>
>> public Object provide(EndpointInject inject, TypeLiteral<?>
>> typeLiteral, Field field) {
>> Class<?> type = field.getType();
>> String injectionPointName = field.getName();
>> String uri = inject.uri();
>> String endpointRef = inject.ref();
>>
>> return getInjectionValue(type, uri, endpointRef, injectionPointName,
>> null, null);
>> }
>>
>> Regards,
>>
>> Apache Committer
>>
>> Blog : http://cmoulliard.blogspot.com
>> Twitter : http://twitter.com/cmoulliard
>> Linkedin : http://www.linkedin.com/in/charlesmoulliard
>> Skype: cmoulliard
>>
Re: AW: Util class to find annotations in a class
Posted by Mark Struberg <st...@yahoo.de>.
+1
public void initCamelContext(@Observes ProcessAnnotatedType<? extends CamelContext> pat) {...
for example.
Doing another scan manually is really performance intense!
LieGrue,
strub
PS: please don't do cross posts to multiple lists at the same time. just confuses users ;)
----- Original Message -----
> From: Arne Limburg <ar...@openknowledge.de>
> To: "deltaspike-dev@incubator.apache.org" <de...@incubator.apache.org>; "user@openwebbeans.apache.org" <us...@openwebbeans.apache.org>
> Cc:
> Sent: Thursday, July 12, 2012 2:37 PM
> Subject: AW: Util class to find annotations in a class
>
> Hi,
>
> can't you just listen to the ProcessAnnotatedType event, inspect it and if
> you find an @EndpointInject i.e. add an @Inject to the AnnotatedType?
>
> Cheers,
> Arne
>
> -----Ursprüngliche Nachricht-----
> Von: Charles Moulliard [mailto:cmoulliard@gmail.com]
> Gesendet: Donnerstag, 12. Juli 2012 14:22
> An: deltaspike-dev@incubator.apache.org; user@openwebbeans.apache.org
> Betreff: Util class to find annotations in a class
>
> Hi,
>
> Is there a DeltaSpike or OpenWebbeans util class that I could use to scan
> classes and find annotations (which have been of course designed without CDI in
> mind) and next inject them ?
>
> Camel provides @EndpointInject(uri or ref), @Produce(uri) and @Consume
> annotations to inject Endpoint definition or Producer/ConsumerTemplate into
> CamelContext.
>
> We have to call getInjectionValue(type, uri, endpointRef, injectionPointName,
> null, null) method of CamelPostProcessorHelper tevery time such annotation is
> discovered o add such injected bean. Camel-guice, camel-spring and
> camel-blueprint projects proposes such impl (which is not CDI compliant). I
> would like to implement this in camel-cdi (where we already have defined a
> CamelInjector) and tries to find the best strategy.
>
> Is there something equivalent to what we have here in camel-guice ?
>
> bindAnnotationInjector(EndpointInject.class,
> EndpointInjector.class); where bindAnnotationInjector is a method of this class
> GuiceyFruitModule and EndpointInjectorClass is the class containing the code to
> find annotations wiithin a class
>
> public class EndpointInjector extends CamelPostProcessorHelper implements
> AnnotationMemberProvider<EndpointInject> {
>
> @Inject
> public EndpointInjector(CamelContext camelContext) {
> super(camelContext);
> }
>
> public Object provide(EndpointInject inject, TypeLiteral<?>
> typeLiteral, Field field) {
> Class<?> type = field.getType();
> String injectionPointName = field.getName();
> String uri = inject.uri();
> String endpointRef = inject.ref();
>
> return getInjectionValue(type, uri, endpointRef, injectionPointName,
> null, null);
> }
>
> Regards,
>
> Apache Committer
>
> Blog : http://cmoulliard.blogspot.com
> Twitter : http://twitter.com/cmoulliard
> Linkedin : http://www.linkedin.com/in/charlesmoulliard
> Skype: cmoulliard
>
AW: Util class to find annotations in a class
Posted by Arne Limburg <ar...@openknowledge.de>.
Hi,
can't you just listen to the ProcessAnnotatedType event, inspect it and if you find an @EndpointInject i.e. add an @Inject to the AnnotatedType?
Cheers,
Arne
-----Ursprüngliche Nachricht-----
Von: Charles Moulliard [mailto:cmoulliard@gmail.com]
Gesendet: Donnerstag, 12. Juli 2012 14:22
An: deltaspike-dev@incubator.apache.org; user@openwebbeans.apache.org
Betreff: Util class to find annotations in a class
Hi,
Is there a DeltaSpike or OpenWebbeans util class that I could use to scan classes and find annotations (which have been of course designed without CDI in mind) and next inject them ?
Camel provides @EndpointInject(uri or ref), @Produce(uri) and @Consume annotations to inject Endpoint definition or Producer/ConsumerTemplate into CamelContext.
We have to call getInjectionValue(type, uri, endpointRef, injectionPointName, null, null) method of CamelPostProcessorHelper tevery time such annotation is discovered o add such injected bean. Camel-guice, camel-spring and camel-blueprint projects proposes such impl (which is not CDI compliant). I would like to implement this in camel-cdi (where we already have defined a CamelInjector) and tries to find the best strategy.
Is there something equivalent to what we have here in camel-guice ?
bindAnnotationInjector(EndpointInject.class,
EndpointInjector.class); where bindAnnotationInjector is a method of this class GuiceyFruitModule and EndpointInjectorClass is the class containing the code to find annotations wiithin a class
public class EndpointInjector extends CamelPostProcessorHelper implements
AnnotationMemberProvider<EndpointInject> {
@Inject
public EndpointInjector(CamelContext camelContext) {
super(camelContext);
}
public Object provide(EndpointInject inject, TypeLiteral<?> typeLiteral, Field field) {
Class<?> type = field.getType();
String injectionPointName = field.getName();
String uri = inject.uri();
String endpointRef = inject.ref();
return getInjectionValue(type, uri, endpointRef, injectionPointName, null, null);
}
Regards,
Apache Committer
Blog : http://cmoulliard.blogspot.com
Twitter : http://twitter.com/cmoulliard
Linkedin : http://www.linkedin.com/in/charlesmoulliard
Skype: cmoulliard
Re: Util class to find annotations in a class
Posted by Jean-Louis MONTEIRO <je...@gmail.com>.
Hi Charles,
There are different ways to do. xbean-finder is really great in that area
but I know a lot of projects have their own "framework".
That leads to over time consuming in TomEE for example because, JSF, CDI,
EJB, etc ... do class scanning looking for annotation for example.
I already discuss with Mark I guess and David for sure about that topic and
the opportunity to create a commons package.
BTW, for the moment, xbean is part of geronimo.
Jean-Louis
2012/7/12 Charles Moulliard <cm...@gmail.com>
> Hi,
>
> Is there a DeltaSpike or OpenWebbeans util class that I could use to scan
> classes and find annotations (which have been of course designed without
> CDI in mind) and next inject them ?
>
> Camel provides @EndpointInject(uri or ref), @Produce(uri) and @Consume
> annotations to inject Endpoint definition or Producer/ConsumerTemplate into
> CamelContext.
>
> We have to call getInjectionValue(type, uri, endpointRef,
> injectionPointName, null, null) method of CamelPostProcessorHelper tevery
> time such annotation is discovered o add such injected bean. Camel-guice,
> camel-spring and camel-blueprint projects proposes such impl (which is not
> CDI compliant). I would like to implement this in camel-cdi (where we
> already have defined a CamelInjector) and tries to find the best strategy.
>
> Is there something equivalent to what we have here in camel-guice ?
>
> bindAnnotationInjector(EndpointInject.class,
> EndpointInjector.class); where bindAnnotationInjector is a method of this
> class GuiceyFruitModule
> and EndpointInjectorClass is the class containing the code to find
> annotations wiithin a class
>
> public class EndpointInjector extends CamelPostProcessorHelper implements
> AnnotationMemberProvider<EndpointInject> {
>
> @Inject
> public EndpointInjector(CamelContext camelContext) {
> super(camelContext);
> }
>
> public Object provide(EndpointInject inject, TypeLiteral<?>
> typeLiteral, Field field) {
> Class<?> type = field.getType();
> String injectionPointName = field.getName();
> String uri = inject.uri();
> String endpointRef = inject.ref();
>
> return getInjectionValue(type, uri, endpointRef,
> injectionPointName, null, null);
> }
>
> Regards,
>
> Apache Committer
>
> Blog : http://cmoulliard.blogspot.com
> Twitter : http://twitter.com/cmoulliard
> Linkedin : http://www.linkedin.com/in/charlesmoulliard
> Skype: cmoulliard
>
Re: Util class to find annotations in a class
Posted by Jean-Louis MONTEIRO <je...@gmail.com>.
Hi Charles,
There are different ways to do. xbean-finder is really great in that area
but I know a lot of projects have their own "framework".
That leads to over time consuming in TomEE for example because, JSF, CDI,
EJB, etc ... do class scanning looking for annotation for example.
I already discuss with Mark I guess and David for sure about that topic and
the opportunity to create a commons package.
BTW, for the moment, xbean is part of geronimo.
Jean-Louis
2012/7/12 Charles Moulliard <cm...@gmail.com>
> Hi,
>
> Is there a DeltaSpike or OpenWebbeans util class that I could use to scan
> classes and find annotations (which have been of course designed without
> CDI in mind) and next inject them ?
>
> Camel provides @EndpointInject(uri or ref), @Produce(uri) and @Consume
> annotations to inject Endpoint definition or Producer/ConsumerTemplate into
> CamelContext.
>
> We have to call getInjectionValue(type, uri, endpointRef,
> injectionPointName, null, null) method of CamelPostProcessorHelper tevery
> time such annotation is discovered o add such injected bean. Camel-guice,
> camel-spring and camel-blueprint projects proposes such impl (which is not
> CDI compliant). I would like to implement this in camel-cdi (where we
> already have defined a CamelInjector) and tries to find the best strategy.
>
> Is there something equivalent to what we have here in camel-guice ?
>
> bindAnnotationInjector(EndpointInject.class,
> EndpointInjector.class); where bindAnnotationInjector is a method of this
> class GuiceyFruitModule
> and EndpointInjectorClass is the class containing the code to find
> annotations wiithin a class
>
> public class EndpointInjector extends CamelPostProcessorHelper implements
> AnnotationMemberProvider<EndpointInject> {
>
> @Inject
> public EndpointInjector(CamelContext camelContext) {
> super(camelContext);
> }
>
> public Object provide(EndpointInject inject, TypeLiteral<?>
> typeLiteral, Field field) {
> Class<?> type = field.getType();
> String injectionPointName = field.getName();
> String uri = inject.uri();
> String endpointRef = inject.ref();
>
> return getInjectionValue(type, uri, endpointRef,
> injectionPointName, null, null);
> }
>
> Regards,
>
> Apache Committer
>
> Blog : http://cmoulliard.blogspot.com
> Twitter : http://twitter.com/cmoulliard
> Linkedin : http://www.linkedin.com/in/charlesmoulliard
> Skype: cmoulliard
>
AW: Util class to find annotations in a class
Posted by Arne Limburg <ar...@openknowledge.de>.
Hi,
can't you just listen to the ProcessAnnotatedType event, inspect it and if you find an @EndpointInject i.e. add an @Inject to the AnnotatedType?
Cheers,
Arne
-----Ursprüngliche Nachricht-----
Von: Charles Moulliard [mailto:cmoulliard@gmail.com]
Gesendet: Donnerstag, 12. Juli 2012 14:22
An: deltaspike-dev@incubator.apache.org; user@openwebbeans.apache.org
Betreff: Util class to find annotations in a class
Hi,
Is there a DeltaSpike or OpenWebbeans util class that I could use to scan classes and find annotations (which have been of course designed without CDI in mind) and next inject them ?
Camel provides @EndpointInject(uri or ref), @Produce(uri) and @Consume annotations to inject Endpoint definition or Producer/ConsumerTemplate into CamelContext.
We have to call getInjectionValue(type, uri, endpointRef, injectionPointName, null, null) method of CamelPostProcessorHelper tevery time such annotation is discovered o add such injected bean. Camel-guice, camel-spring and camel-blueprint projects proposes such impl (which is not CDI compliant). I would like to implement this in camel-cdi (where we already have defined a CamelInjector) and tries to find the best strategy.
Is there something equivalent to what we have here in camel-guice ?
bindAnnotationInjector(EndpointInject.class,
EndpointInjector.class); where bindAnnotationInjector is a method of this class GuiceyFruitModule and EndpointInjectorClass is the class containing the code to find annotations wiithin a class
public class EndpointInjector extends CamelPostProcessorHelper implements
AnnotationMemberProvider<EndpointInject> {
@Inject
public EndpointInjector(CamelContext camelContext) {
super(camelContext);
}
public Object provide(EndpointInject inject, TypeLiteral<?> typeLiteral, Field field) {
Class<?> type = field.getType();
String injectionPointName = field.getName();
String uri = inject.uri();
String endpointRef = inject.ref();
return getInjectionValue(type, uri, endpointRef, injectionPointName, null, null);
}
Regards,
Apache Committer
Blog : http://cmoulliard.blogspot.com
Twitter : http://twitter.com/cmoulliard
Linkedin : http://www.linkedin.com/in/charlesmoulliard
Skype: cmoulliard
Re: Util class to find annotations in a class
Posted by Romain Manni-Bucau <rm...@gmail.com>.
my bean was a bean :p
- Romain
2012/7/12 Mark Struberg <st...@yahoo.de>
> Folks, it would be much easier if you follow the CDI spec defined naming.
>
> 1. Bean: an instance of Bean<T> which is used by the container to create
> Contextual Instances
> 2. Contextual Instance: the 'singleton' T instance which get's stored in a
> context.
> 3. Contextual Reference: the proxy to a Contextual Instance.
>
> If you use the term 'bean' for 1 AND 2 then others (including me) will get
> completely confused and don't know what you effectively mean ;)
>
> LieGrue,
> strub
>
>
>
> ----- Original Message -----
> > From: Romain Manni-Bucau <rm...@gmail.com>
> > To: deltaspike-dev@incubator.apache.org
> > Cc:
> > Sent: Thursday, July 12, 2012 2:29 PM
> > Subject: Re: Util class to find annotations in a class
> >
> > Hi,
> >
> > when beans are pojo (i know it is almost always the case but we can do
> > without) adding a beans.xml you'll get them in cdi lifecycle event then
> you
> > can simply replace standard beans by your own beans (Bean<?>) or use a
> > custom scope. The idea is simply to help cdi to manage these beans i
> think.
> >
> > You talked more about scanning but scanner depends on the environment
> (OWB
> > doesnt use the same scanner in standalone, osgi or tomee) and bringing
> > another scanner for camel is i think a pain and not mandatory.
> >
> > wdyt?
> >
> > - Romain
> >
> >
> > 2012/7/12 Charles Moulliard <cm...@gmail.com>
> >
> >> Hi,
> >>
> >> Is there a DeltaSpike or OpenWebbeans util class that I could use to
> scan
> >> classes and find annotations (which have been of course designed
> without
> >> CDI in mind) and next inject them ?
> >>
> >> Camel provides @EndpointInject(uri or ref), @Produce(uri) and @Consume
> >> annotations to inject Endpoint definition or Producer/ConsumerTemplate
> into
> >> CamelContext.
> >>
> >> We have to call getInjectionValue(type, uri, endpointRef,
> >> injectionPointName, null, null) method of CamelPostProcessorHelper
> tevery
> >> time such annotation is discovered o add such injected bean.
> Camel-guice,
> >> camel-spring and camel-blueprint projects proposes such impl (which is
> not
> >> CDI compliant). I would like to implement this in camel-cdi (where we
> >> already have defined a CamelInjector) and tries to find the best
> strategy.
> >>
> >> Is there something equivalent to what we have here in camel-guice ?
> >>
> >> bindAnnotationInjector(EndpointInject.class,
> >> EndpointInjector.class); where bindAnnotationInjector is a method of
> this
> >> class GuiceyFruitModule
> >> and EndpointInjectorClass is the class containing the code to find
> >> annotations wiithin a class
> >>
> >> public class EndpointInjector extends CamelPostProcessorHelper
> implements
> >> AnnotationMemberProvider<EndpointInject> {
> >>
> >> @Inject
> >> public EndpointInjector(CamelContext camelContext) {
> >> super(camelContext);
> >> }
> >>
> >> public Object provide(EndpointInject inject, TypeLiteral<?>
> >> typeLiteral, Field field) {
> >> Class<?> type = field.getType();
> >> String injectionPointName = field.getName();
> >> String uri = inject.uri();
> >> String endpointRef = inject.ref();
> >>
> >> return getInjectionValue(type, uri, endpointRef,
> >> injectionPointName, null, null);
> >> }
> >>
> >> Regards,
> >>
> >> Apache Committer
> >>
> >> Blog : http://cmoulliard.blogspot.com
> >> Twitter : http://twitter.com/cmoulliard
> >> Linkedin : http://www.linkedin.com/in/charlesmoulliard
> >> Skype: cmoulliard
> >>
> >
>
Re: Util class to find annotations in a class
Posted by Mark Struberg <st...@yahoo.de>.
Folks, it would be much easier if you follow the CDI spec defined naming.
1. Bean: an instance of Bean<T> which is used by the container to create Contextual Instances
2. Contextual Instance: the 'singleton' T instance which get's stored in a context.
3. Contextual Reference: the proxy to a Contextual Instance.
If you use the term 'bean' for 1 AND 2 then others (including me) will get completely confused and don't know what you effectively mean ;)
LieGrue,
strub
----- Original Message -----
> From: Romain Manni-Bucau <rm...@gmail.com>
> To: deltaspike-dev@incubator.apache.org
> Cc:
> Sent: Thursday, July 12, 2012 2:29 PM
> Subject: Re: Util class to find annotations in a class
>
> Hi,
>
> when beans are pojo (i know it is almost always the case but we can do
> without) adding a beans.xml you'll get them in cdi lifecycle event then you
> can simply replace standard beans by your own beans (Bean<?>) or use a
> custom scope. The idea is simply to help cdi to manage these beans i think.
>
> You talked more about scanning but scanner depends on the environment (OWB
> doesnt use the same scanner in standalone, osgi or tomee) and bringing
> another scanner for camel is i think a pain and not mandatory.
>
> wdyt?
>
> - Romain
>
>
> 2012/7/12 Charles Moulliard <cm...@gmail.com>
>
>> Hi,
>>
>> Is there a DeltaSpike or OpenWebbeans util class that I could use to scan
>> classes and find annotations (which have been of course designed without
>> CDI in mind) and next inject them ?
>>
>> Camel provides @EndpointInject(uri or ref), @Produce(uri) and @Consume
>> annotations to inject Endpoint definition or Producer/ConsumerTemplate into
>> CamelContext.
>>
>> We have to call getInjectionValue(type, uri, endpointRef,
>> injectionPointName, null, null) method of CamelPostProcessorHelper tevery
>> time such annotation is discovered o add such injected bean. Camel-guice,
>> camel-spring and camel-blueprint projects proposes such impl (which is not
>> CDI compliant). I would like to implement this in camel-cdi (where we
>> already have defined a CamelInjector) and tries to find the best strategy.
>>
>> Is there something equivalent to what we have here in camel-guice ?
>>
>> bindAnnotationInjector(EndpointInject.class,
>> EndpointInjector.class); where bindAnnotationInjector is a method of this
>> class GuiceyFruitModule
>> and EndpointInjectorClass is the class containing the code to find
>> annotations wiithin a class
>>
>> public class EndpointInjector extends CamelPostProcessorHelper implements
>> AnnotationMemberProvider<EndpointInject> {
>>
>> @Inject
>> public EndpointInjector(CamelContext camelContext) {
>> super(camelContext);
>> }
>>
>> public Object provide(EndpointInject inject, TypeLiteral<?>
>> typeLiteral, Field field) {
>> Class<?> type = field.getType();
>> String injectionPointName = field.getName();
>> String uri = inject.uri();
>> String endpointRef = inject.ref();
>>
>> return getInjectionValue(type, uri, endpointRef,
>> injectionPointName, null, null);
>> }
>>
>> Regards,
>>
>> Apache Committer
>>
>> Blog : http://cmoulliard.blogspot.com
>> Twitter : http://twitter.com/cmoulliard
>> Linkedin : http://www.linkedin.com/in/charlesmoulliard
>> Skype: cmoulliard
>>
>
Re: Util class to find annotations in a class
Posted by Shane Bryzak <sb...@redhat.com>.
Well, while we have it listed at [1] we haven't discussed it yet,
although I'm not sure there's much to discuss. It's a very small, self
contained utility which is only used by a couple of other modules.
Solder documentation for the feature is at [2] - I guess we can hold a
discussion on it and if there's no objections I'll refactor it into core
after I commit the security prototype to master.
[1]
https://cwiki.apache.org/confluence/display/DeltaSpike/SE+Feature+Ranking
[2]
http://docs.jboss.org/seam/3/solder/latest/reference/en-US/html/solder-properties.html
On 13/07/12 02:25, Charles Moulliard wrote:
> When do you plan to move this code in DS Shane ?
>
> On 12/07/12 17:00, Shane Bryzak wrote:
>> In Solder we had a "Property Query" feature which allowed you to
>> specify certain criteria for scanning class properties. I've ported
>> this into the security prototype for the time being [1] and it will
>> probably end up getting moved into DeltaSpike core. Usage is pretty
>> straight forward:
>>
>> Property<?> foo = PropertyQueries.createQuery(targetClass)
>> .addCriteria(new AnnotatedPropertyCriteria(MyAnnotation.class))
>> .getFirstResult();
>>
>> A Property is an encapsulation of either a field or getter/setter
>> methods matching the specified criteria, and provides methods for
>> reading the property name, getting and setting its value, and
>> examining various other metadata. It's quite simple to add new
>> criteria type also, the PropertyCriteria interface only defines two
>> methods which you need to implement, however the built in
>> AnnotatedPropertyCriteria may be sufficient for your requirements.
>>
>>
>> [1]
>> https://github.com/sbryzak/DeltaSpike/tree/security/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/util/properties
>>
>> - Shane
>>
>>
>> On 13/07/12 00:37, Charles Moulliard wrote:
>>> Scanning is not required as we know the class containing the
>>> annotations. Here is an example
>>>
>>> package org.fusesource.example.cdi.camel.deltaspike;
>>>
>>> import org.apache.camel.EndpointInject;
>>> import org.apache.camel.component.cdi.CdiCamelContext;
>>> import org.apache.deltaspike.core.api.config.annotation.ConfigProperty;
>>> import org.slf4j.Logger;
>>> import org.slf4j.LoggerFactory;
>>>
>>> import javax.enterprise.inject.Produces;
>>> import javax.inject.Inject;
>>>
>>> import static
>>> org.apache.deltaspike.core.api.provider.BeanProvider.injectFields;
>>>
>>> public class CamelConfigure {
>>>
>>> final private static Logger logger =
>>> LoggerFactory.getLogger(CamelConfigure.class);
>>>
>>> @Inject
>>> protected CdiCamelContext camelCtx;
>>>
>>> @Inject
>>> protected org.fusesource.example.cdi.camel.SimpleCamelRoute
>>> simpleRoute;
>>>
>>> @EndpointInject(uri = "timer://simple?fixedRate=true&period=5s")
>>> protected String timerEndpointDefinedUsingCamelAnnotation;
>>>
>>>
>>> On 12/07/12 14:29, Romain Manni-Bucau wrote:
>>>> Hi,
>>>>
>>>> when beans are pojo (i know it is almost always the case but we can do
>>>> without) adding a beans.xml you'll get them in cdi lifecycle event
>>>> then you
>>>> can simply replace standard beans by your own beans (Bean<?>) or use a
>>>> custom scope. The idea is simply to help cdi to manage these beans
>>>> i think.
>>>>
>>>> You talked more about scanning but scanner depends on the
>>>> environment (OWB
>>>> doesnt use the same scanner in standalone, osgi or tomee) and bringing
>>>> another scanner for camel is i think a pain and not mandatory.
>>>>
>>>> wdyt?
>>>>
>>>> - Romain
>>>>
>>>>
>>>> 2012/7/12 Charles Moulliard<cm...@gmail.com>
>>>>
>>>>> Hi,
>>>>>
>>>>> Is there a DeltaSpike or OpenWebbeans util class that I could use
>>>>> to scan
>>>>> classes and find annotations (which have been of course designed
>>>>> without
>>>>> CDI in mind) and next inject them ?
>>>>>
>>>>> Camel provides @EndpointInject(uri or ref), @Produce(uri) and
>>>>> @Consume
>>>>> annotations to inject Endpoint definition or
>>>>> Producer/ConsumerTemplate into
>>>>> CamelContext.
>>>>>
>>>>> We have to call getInjectionValue(type, uri, endpointRef,
>>>>> injectionPointName, null, null) method of CamelPostProcessorHelper
>>>>> tevery
>>>>> time such annotation is discovered o add such injected bean.
>>>>> Camel-guice,
>>>>> camel-spring and camel-blueprint projects proposes such impl
>>>>> (which is not
>>>>> CDI compliant). I would like to implement this in camel-cdi (where we
>>>>> already have defined a CamelInjector) and tries to find the best
>>>>> strategy.
>>>>>
>>>>> Is there something equivalent to what we have here in camel-guice ?
>>>>>
>>>>> bindAnnotationInjector(EndpointInject.class,
>>>>> EndpointInjector.class); where bindAnnotationInjector is a method
>>>>> of this
>>>>> class GuiceyFruitModule
>>>>> and EndpointInjectorClass is the class containing the code to find
>>>>> annotations wiithin a class
>>>>>
>>>>> public class EndpointInjector extends CamelPostProcessorHelper
>>>>> implements
>>>>> AnnotationMemberProvider<EndpointInject> {
>>>>>
>>>>> @Inject
>>>>> public EndpointInjector(CamelContext camelContext) {
>>>>> super(camelContext);
>>>>> }
>>>>>
>>>>> public Object provide(EndpointInject inject, TypeLiteral<?>
>>>>> typeLiteral, Field field) {
>>>>> Class<?> type = field.getType();
>>>>> String injectionPointName = field.getName();
>>>>> String uri = inject.uri();
>>>>> String endpointRef = inject.ref();
>>>>>
>>>>> return getInjectionValue(type, uri, endpointRef,
>>>>> injectionPointName, null, null);
>>>>> }
>>>>>
>>>>> Regards,
>>>>>
>>>>> Apache Committer
>>>>>
>>>>> Blog : http://cmoulliard.blogspot.com
>>>>> Twitter : http://twitter.com/cmoulliard
>>>>> Linkedin : http://www.linkedin.com/in/charlesmoulliard
>>>>> Skype: cmoulliard
>>>>>
>>
>>
Re: Util class to find annotations in a class
Posted by Charles Moulliard <cm...@gmail.com>.
When do you plan to move this code in DS Shane ?
On 12/07/12 17:00, Shane Bryzak wrote:
> In Solder we had a "Property Query" feature which allowed you to
> specify certain criteria for scanning class properties. I've ported
> this into the security prototype for the time being [1] and it will
> probably end up getting moved into DeltaSpike core. Usage is pretty
> straight forward:
>
> Property<?> foo = PropertyQueries.createQuery(targetClass)
> .addCriteria(new AnnotatedPropertyCriteria(MyAnnotation.class))
> .getFirstResult();
>
> A Property is an encapsulation of either a field or getter/setter
> methods matching the specified criteria, and provides methods for
> reading the property name, getting and setting its value, and
> examining various other metadata. It's quite simple to add new
> criteria type also, the PropertyCriteria interface only defines two
> methods which you need to implement, however the built in
> AnnotatedPropertyCriteria may be sufficient for your requirements.
>
>
> [1]
> https://github.com/sbryzak/DeltaSpike/tree/security/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/util/properties
>
> - Shane
>
>
> On 13/07/12 00:37, Charles Moulliard wrote:
>> Scanning is not required as we know the class containing the
>> annotations. Here is an example
>>
>> package org.fusesource.example.cdi.camel.deltaspike;
>>
>> import org.apache.camel.EndpointInject;
>> import org.apache.camel.component.cdi.CdiCamelContext;
>> import org.apache.deltaspike.core.api.config.annotation.ConfigProperty;
>> import org.slf4j.Logger;
>> import org.slf4j.LoggerFactory;
>>
>> import javax.enterprise.inject.Produces;
>> import javax.inject.Inject;
>>
>> import static
>> org.apache.deltaspike.core.api.provider.BeanProvider.injectFields;
>>
>> public class CamelConfigure {
>>
>> final private static Logger logger =
>> LoggerFactory.getLogger(CamelConfigure.class);
>>
>> @Inject
>> protected CdiCamelContext camelCtx;
>>
>> @Inject
>> protected org.fusesource.example.cdi.camel.SimpleCamelRoute
>> simpleRoute;
>>
>> @EndpointInject(uri = "timer://simple?fixedRate=true&period=5s")
>> protected String timerEndpointDefinedUsingCamelAnnotation;
>>
>>
>> On 12/07/12 14:29, Romain Manni-Bucau wrote:
>>> Hi,
>>>
>>> when beans are pojo (i know it is almost always the case but we can do
>>> without) adding a beans.xml you'll get them in cdi lifecycle event
>>> then you
>>> can simply replace standard beans by your own beans (Bean<?>) or use a
>>> custom scope. The idea is simply to help cdi to manage these beans i
>>> think.
>>>
>>> You talked more about scanning but scanner depends on the
>>> environment (OWB
>>> doesnt use the same scanner in standalone, osgi or tomee) and bringing
>>> another scanner for camel is i think a pain and not mandatory.
>>>
>>> wdyt?
>>>
>>> - Romain
>>>
>>>
>>> 2012/7/12 Charles Moulliard<cm...@gmail.com>
>>>
>>>> Hi,
>>>>
>>>> Is there a DeltaSpike or OpenWebbeans util class that I could use
>>>> to scan
>>>> classes and find annotations (which have been of course designed
>>>> without
>>>> CDI in mind) and next inject them ?
>>>>
>>>> Camel provides @EndpointInject(uri or ref), @Produce(uri) and @Consume
>>>> annotations to inject Endpoint definition or
>>>> Producer/ConsumerTemplate into
>>>> CamelContext.
>>>>
>>>> We have to call getInjectionValue(type, uri, endpointRef,
>>>> injectionPointName, null, null) method of CamelPostProcessorHelper
>>>> tevery
>>>> time such annotation is discovered o add such injected bean.
>>>> Camel-guice,
>>>> camel-spring and camel-blueprint projects proposes such impl (which
>>>> is not
>>>> CDI compliant). I would like to implement this in camel-cdi (where we
>>>> already have defined a CamelInjector) and tries to find the best
>>>> strategy.
>>>>
>>>> Is there something equivalent to what we have here in camel-guice ?
>>>>
>>>> bindAnnotationInjector(EndpointInject.class,
>>>> EndpointInjector.class); where bindAnnotationInjector is a method
>>>> of this
>>>> class GuiceyFruitModule
>>>> and EndpointInjectorClass is the class containing the code to find
>>>> annotations wiithin a class
>>>>
>>>> public class EndpointInjector extends CamelPostProcessorHelper
>>>> implements
>>>> AnnotationMemberProvider<EndpointInject> {
>>>>
>>>> @Inject
>>>> public EndpointInjector(CamelContext camelContext) {
>>>> super(camelContext);
>>>> }
>>>>
>>>> public Object provide(EndpointInject inject, TypeLiteral<?>
>>>> typeLiteral, Field field) {
>>>> Class<?> type = field.getType();
>>>> String injectionPointName = field.getName();
>>>> String uri = inject.uri();
>>>> String endpointRef = inject.ref();
>>>>
>>>> return getInjectionValue(type, uri, endpointRef,
>>>> injectionPointName, null, null);
>>>> }
>>>>
>>>> Regards,
>>>>
>>>> Apache Committer
>>>>
>>>> Blog : http://cmoulliard.blogspot.com
>>>> Twitter : http://twitter.com/cmoulliard
>>>> Linkedin : http://www.linkedin.com/in/charlesmoulliard
>>>> Skype: cmoulliard
>>>>
>
>
Re: Util class to find annotations in a class
Posted by Romain Manni-Bucau <rm...@gmail.com>.
hmm,
that's interesting but 2 notes:
1) needing the class limit it so an camelextension is still needed
2) in real usage of such a thing cache should be used about metadata
because camel will query a lof of stuff and we wouldnt want to browse the
classmeta each time
wdyt?
- Romain
2012/7/12 Charles Moulliard <cm...@gmail.com>
> Really interesting Shane. I will have a look. Thx.
>
>
> On 12/07/12 17:00, Shane Bryzak wrote:
>
>> In Solder we had a "Property Query" feature which allowed you to specify
>> certain criteria for scanning class properties. I've ported this into the
>> security prototype for the time being [1] and it will probably end up
>> getting moved into DeltaSpike core. Usage is pretty straight forward:
>>
>> Property<?> foo = PropertyQueries.createQuery(**targetClass)
>> .addCriteria(new AnnotatedPropertyCriteria(**MyAnnotation.class))
>> .getFirstResult();
>>
>> A Property is an encapsulation of either a field or getter/setter methods
>> matching the specified criteria, and provides methods for reading the
>> property name, getting and setting its value, and examining various other
>> metadata. It's quite simple to add new criteria type also, the
>> PropertyCriteria interface only defines two methods which you need to
>> implement, however the built in AnnotatedPropertyCriteria may be sufficient
>> for your requirements.
>>
>>
>> [1] https://github.com/sbryzak/**DeltaSpike/tree/security/**
>> deltaspike/modules/security/**impl/src/main/java/org/apache/**
>> deltaspike/security/impl/util/**properties<https://github.com/sbryzak/DeltaSpike/tree/security/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/util/properties>
>>
>> - Shane
>>
>>
>> On 13/07/12 00:37, Charles Moulliard wrote:
>>
>>> Scanning is not required as we know the class containing the
>>> annotations. Here is an example
>>>
>>> package org.fusesource.example.cdi.**camel.deltaspike;
>>>
>>> import org.apache.camel.**EndpointInject;
>>> import org.apache.camel.component.**cdi.CdiCamelContext;
>>> import org.apache.deltaspike.core.**api.config.annotation.**
>>> ConfigProperty;
>>> import org.slf4j.Logger;
>>> import org.slf4j.LoggerFactory;
>>>
>>> import javax.enterprise.inject.**Produces;
>>> import javax.inject.Inject;
>>>
>>> import static org.apache.deltaspike.core.**api.provider.BeanProvider.**
>>> injectFields;
>>>
>>> public class CamelConfigure {
>>>
>>> final private static Logger logger = LoggerFactory.getLogger(**
>>> CamelConfigure.class);
>>>
>>> @Inject
>>> protected CdiCamelContext camelCtx;
>>>
>>> @Inject
>>> protected org.fusesource.example.cdi.**camel.SimpleCamelRoute
>>> simpleRoute;
>>>
>>> @EndpointInject(uri = "timer://simple?fixedRate=**true&period=5s")
>>> protected String timerEndpointDefinedUsingCamel**Annotation;
>>>
>>>
>>> On 12/07/12 14:29, Romain Manni-Bucau wrote:
>>>
>>>> Hi,
>>>>
>>>> when beans are pojo (i know it is almost always the case but we can do
>>>> without) adding a beans.xml you'll get them in cdi lifecycle event then
>>>> you
>>>> can simply replace standard beans by your own beans (Bean<?>) or use a
>>>> custom scope. The idea is simply to help cdi to manage these beans i
>>>> think.
>>>>
>>>> You talked more about scanning but scanner depends on the environment
>>>> (OWB
>>>> doesnt use the same scanner in standalone, osgi or tomee) and bringing
>>>> another scanner for camel is i think a pain and not mandatory.
>>>>
>>>> wdyt?
>>>>
>>>> - Romain
>>>>
>>>>
>>>> 2012/7/12 Charles Moulliard<cmoulliard@gmail.com**>
>>>>
>>>> Hi,
>>>>>
>>>>> Is there a DeltaSpike or OpenWebbeans util class that I could use to
>>>>> scan
>>>>> classes and find annotations (which have been of course designed
>>>>> without
>>>>> CDI in mind) and next inject them ?
>>>>>
>>>>> Camel provides @EndpointInject(uri or ref), @Produce(uri) and @Consume
>>>>> annotations to inject Endpoint definition or Producer/ConsumerTemplate
>>>>> into
>>>>> CamelContext.
>>>>>
>>>>> We have to call getInjectionValue(type, uri, endpointRef,
>>>>> injectionPointName, null, null) method of CamelPostProcessorHelper
>>>>> tevery
>>>>> time such annotation is discovered o add such injected bean.
>>>>> Camel-guice,
>>>>> camel-spring and camel-blueprint projects proposes such impl (which is
>>>>> not
>>>>> CDI compliant). I would like to implement this in camel-cdi (where we
>>>>> already have defined a CamelInjector) and tries to find the best
>>>>> strategy.
>>>>>
>>>>> Is there something equivalent to what we have here in camel-guice ?
>>>>>
>>>>> bindAnnotationInjector(**EndpointInject.class,
>>>>> EndpointInjector.class); where bindAnnotationInjector is a method of
>>>>> this
>>>>> class GuiceyFruitModule
>>>>> and EndpointInjectorClass is the class containing the code to find
>>>>> annotations wiithin a class
>>>>>
>>>>> public class EndpointInjector extends CamelPostProcessorHelper
>>>>> implements
>>>>> AnnotationMemberProvider<**EndpointInject> {
>>>>>
>>>>> @Inject
>>>>> public EndpointInjector(CamelContext camelContext) {
>>>>> super(camelContext);
>>>>> }
>>>>>
>>>>> public Object provide(EndpointInject inject, TypeLiteral<?>
>>>>> typeLiteral, Field field) {
>>>>> Class<?> type = field.getType();
>>>>> String injectionPointName = field.getName();
>>>>> String uri = inject.uri();
>>>>> String endpointRef = inject.ref();
>>>>>
>>>>> return getInjectionValue(type, uri, endpointRef,
>>>>> injectionPointName, null, null);
>>>>> }
>>>>>
>>>>> Regards,
>>>>>
>>>>> Apache Committer
>>>>>
>>>>> Blog : http://cmoulliard.blogspot.com
>>>>> Twitter : http://twitter.com/cmoulliard
>>>>> Linkedin : http://www.linkedin.com/in/**charlesmoulliard<http://www.linkedin.com/in/charlesmoulliard>
>>>>> Skype: cmoulliard
>>>>>
>>>>>
>>
>>
Re: Util class to find annotations in a class
Posted by Charles Moulliard <cm...@gmail.com>.
Really interesting Shane. I will have a look. Thx.
On 12/07/12 17:00, Shane Bryzak wrote:
> In Solder we had a "Property Query" feature which allowed you to
> specify certain criteria for scanning class properties. I've ported
> this into the security prototype for the time being [1] and it will
> probably end up getting moved into DeltaSpike core. Usage is pretty
> straight forward:
>
> Property<?> foo = PropertyQueries.createQuery(targetClass)
> .addCriteria(new AnnotatedPropertyCriteria(MyAnnotation.class))
> .getFirstResult();
>
> A Property is an encapsulation of either a field or getter/setter
> methods matching the specified criteria, and provides methods for
> reading the property name, getting and setting its value, and
> examining various other metadata. It's quite simple to add new
> criteria type also, the PropertyCriteria interface only defines two
> methods which you need to implement, however the built in
> AnnotatedPropertyCriteria may be sufficient for your requirements.
>
>
> [1]
> https://github.com/sbryzak/DeltaSpike/tree/security/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/util/properties
>
> - Shane
>
>
> On 13/07/12 00:37, Charles Moulliard wrote:
>> Scanning is not required as we know the class containing the
>> annotations. Here is an example
>>
>> package org.fusesource.example.cdi.camel.deltaspike;
>>
>> import org.apache.camel.EndpointInject;
>> import org.apache.camel.component.cdi.CdiCamelContext;
>> import org.apache.deltaspike.core.api.config.annotation.ConfigProperty;
>> import org.slf4j.Logger;
>> import org.slf4j.LoggerFactory;
>>
>> import javax.enterprise.inject.Produces;
>> import javax.inject.Inject;
>>
>> import static
>> org.apache.deltaspike.core.api.provider.BeanProvider.injectFields;
>>
>> public class CamelConfigure {
>>
>> final private static Logger logger =
>> LoggerFactory.getLogger(CamelConfigure.class);
>>
>> @Inject
>> protected CdiCamelContext camelCtx;
>>
>> @Inject
>> protected org.fusesource.example.cdi.camel.SimpleCamelRoute
>> simpleRoute;
>>
>> @EndpointInject(uri = "timer://simple?fixedRate=true&period=5s")
>> protected String timerEndpointDefinedUsingCamelAnnotation;
>>
>>
>> On 12/07/12 14:29, Romain Manni-Bucau wrote:
>>> Hi,
>>>
>>> when beans are pojo (i know it is almost always the case but we can do
>>> without) adding a beans.xml you'll get them in cdi lifecycle event
>>> then you
>>> can simply replace standard beans by your own beans (Bean<?>) or use a
>>> custom scope. The idea is simply to help cdi to manage these beans i
>>> think.
>>>
>>> You talked more about scanning but scanner depends on the
>>> environment (OWB
>>> doesnt use the same scanner in standalone, osgi or tomee) and bringing
>>> another scanner for camel is i think a pain and not mandatory.
>>>
>>> wdyt?
>>>
>>> - Romain
>>>
>>>
>>> 2012/7/12 Charles Moulliard<cm...@gmail.com>
>>>
>>>> Hi,
>>>>
>>>> Is there a DeltaSpike or OpenWebbeans util class that I could use
>>>> to scan
>>>> classes and find annotations (which have been of course designed
>>>> without
>>>> CDI in mind) and next inject them ?
>>>>
>>>> Camel provides @EndpointInject(uri or ref), @Produce(uri) and @Consume
>>>> annotations to inject Endpoint definition or
>>>> Producer/ConsumerTemplate into
>>>> CamelContext.
>>>>
>>>> We have to call getInjectionValue(type, uri, endpointRef,
>>>> injectionPointName, null, null) method of CamelPostProcessorHelper
>>>> tevery
>>>> time such annotation is discovered o add such injected bean.
>>>> Camel-guice,
>>>> camel-spring and camel-blueprint projects proposes such impl (which
>>>> is not
>>>> CDI compliant). I would like to implement this in camel-cdi (where we
>>>> already have defined a CamelInjector) and tries to find the best
>>>> strategy.
>>>>
>>>> Is there something equivalent to what we have here in camel-guice ?
>>>>
>>>> bindAnnotationInjector(EndpointInject.class,
>>>> EndpointInjector.class); where bindAnnotationInjector is a method
>>>> of this
>>>> class GuiceyFruitModule
>>>> and EndpointInjectorClass is the class containing the code to find
>>>> annotations wiithin a class
>>>>
>>>> public class EndpointInjector extends CamelPostProcessorHelper
>>>> implements
>>>> AnnotationMemberProvider<EndpointInject> {
>>>>
>>>> @Inject
>>>> public EndpointInjector(CamelContext camelContext) {
>>>> super(camelContext);
>>>> }
>>>>
>>>> public Object provide(EndpointInject inject, TypeLiteral<?>
>>>> typeLiteral, Field field) {
>>>> Class<?> type = field.getType();
>>>> String injectionPointName = field.getName();
>>>> String uri = inject.uri();
>>>> String endpointRef = inject.ref();
>>>>
>>>> return getInjectionValue(type, uri, endpointRef,
>>>> injectionPointName, null, null);
>>>> }
>>>>
>>>> Regards,
>>>>
>>>> Apache Committer
>>>>
>>>> Blog : http://cmoulliard.blogspot.com
>>>> Twitter : http://twitter.com/cmoulliard
>>>> Linkedin : http://www.linkedin.com/in/charlesmoulliard
>>>> Skype: cmoulliard
>>>>
>
>
Re: Util class to find annotations in a class
Posted by Shane Bryzak <sb...@redhat.com>.
In Solder we had a "Property Query" feature which allowed you to specify
certain criteria for scanning class properties. I've ported this into
the security prototype for the time being [1] and it will probably end
up getting moved into DeltaSpike core. Usage is pretty straight forward:
Property<?> foo = PropertyQueries.createQuery(targetClass)
.addCriteria(new AnnotatedPropertyCriteria(MyAnnotation.class))
.getFirstResult();
A Property is an encapsulation of either a field or getter/setter
methods matching the specified criteria, and provides methods for
reading the property name, getting and setting its value, and examining
various other metadata. It's quite simple to add new criteria type
also, the PropertyCriteria interface only defines two methods which you
need to implement, however the built in AnnotatedPropertyCriteria may be
sufficient for your requirements.
[1]
https://github.com/sbryzak/DeltaSpike/tree/security/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/util/properties
- Shane
On 13/07/12 00:37, Charles Moulliard wrote:
> Scanning is not required as we know the class containing the
> annotations. Here is an example
>
> package org.fusesource.example.cdi.camel.deltaspike;
>
> import org.apache.camel.EndpointInject;
> import org.apache.camel.component.cdi.CdiCamelContext;
> import org.apache.deltaspike.core.api.config.annotation.ConfigProperty;
> import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
>
> import javax.enterprise.inject.Produces;
> import javax.inject.Inject;
>
> import static
> org.apache.deltaspike.core.api.provider.BeanProvider.injectFields;
>
> public class CamelConfigure {
>
> final private static Logger logger =
> LoggerFactory.getLogger(CamelConfigure.class);
>
> @Inject
> protected CdiCamelContext camelCtx;
>
> @Inject
> protected org.fusesource.example.cdi.camel.SimpleCamelRoute
> simpleRoute;
>
> @EndpointInject(uri = "timer://simple?fixedRate=true&period=5s")
> protected String timerEndpointDefinedUsingCamelAnnotation;
>
>
> On 12/07/12 14:29, Romain Manni-Bucau wrote:
>> Hi,
>>
>> when beans are pojo (i know it is almost always the case but we can do
>> without) adding a beans.xml you'll get them in cdi lifecycle event
>> then you
>> can simply replace standard beans by your own beans (Bean<?>) or use a
>> custom scope. The idea is simply to help cdi to manage these beans i
>> think.
>>
>> You talked more about scanning but scanner depends on the environment
>> (OWB
>> doesnt use the same scanner in standalone, osgi or tomee) and bringing
>> another scanner for camel is i think a pain and not mandatory.
>>
>> wdyt?
>>
>> - Romain
>>
>>
>> 2012/7/12 Charles Moulliard<cm...@gmail.com>
>>
>>> Hi,
>>>
>>> Is there a DeltaSpike or OpenWebbeans util class that I could use to
>>> scan
>>> classes and find annotations (which have been of course designed
>>> without
>>> CDI in mind) and next inject them ?
>>>
>>> Camel provides @EndpointInject(uri or ref), @Produce(uri) and @Consume
>>> annotations to inject Endpoint definition or
>>> Producer/ConsumerTemplate into
>>> CamelContext.
>>>
>>> We have to call getInjectionValue(type, uri, endpointRef,
>>> injectionPointName, null, null) method of CamelPostProcessorHelper
>>> tevery
>>> time such annotation is discovered o add such injected bean.
>>> Camel-guice,
>>> camel-spring and camel-blueprint projects proposes such impl (which
>>> is not
>>> CDI compliant). I would like to implement this in camel-cdi (where we
>>> already have defined a CamelInjector) and tries to find the best
>>> strategy.
>>>
>>> Is there something equivalent to what we have here in camel-guice ?
>>>
>>> bindAnnotationInjector(EndpointInject.class,
>>> EndpointInjector.class); where bindAnnotationInjector is a method of
>>> this
>>> class GuiceyFruitModule
>>> and EndpointInjectorClass is the class containing the code to find
>>> annotations wiithin a class
>>>
>>> public class EndpointInjector extends CamelPostProcessorHelper
>>> implements
>>> AnnotationMemberProvider<EndpointInject> {
>>>
>>> @Inject
>>> public EndpointInjector(CamelContext camelContext) {
>>> super(camelContext);
>>> }
>>>
>>> public Object provide(EndpointInject inject, TypeLiteral<?>
>>> typeLiteral, Field field) {
>>> Class<?> type = field.getType();
>>> String injectionPointName = field.getName();
>>> String uri = inject.uri();
>>> String endpointRef = inject.ref();
>>>
>>> return getInjectionValue(type, uri, endpointRef,
>>> injectionPointName, null, null);
>>> }
>>>
>>> Regards,
>>>
>>> Apache Committer
>>>
>>> Blog : http://cmoulliard.blogspot.com
>>> Twitter : http://twitter.com/cmoulliard
>>> Linkedin : http://www.linkedin.com/in/charlesmoulliard
>>> Skype: cmoulliard
>>>
Re: Util class to find annotations in a class
Posted by Charles Moulliard <cm...@gmail.com>.
Scanning is not required as we know the class containing the
annotations. Here is an example
package org.fusesource.example.cdi.camel.deltaspike;
import org.apache.camel.EndpointInject;
import org.apache.camel.component.cdi.CdiCamelContext;
import org.apache.deltaspike.core.api.config.annotation.ConfigProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import static
org.apache.deltaspike.core.api.provider.BeanProvider.injectFields;
public class CamelConfigure {
final private static Logger logger =
LoggerFactory.getLogger(CamelConfigure.class);
@Inject
protected CdiCamelContext camelCtx;
@Inject
protected org.fusesource.example.cdi.camel.SimpleCamelRoute
simpleRoute;
@EndpointInject(uri = "timer://simple?fixedRate=true&period=5s")
protected String timerEndpointDefinedUsingCamelAnnotation;
On 12/07/12 14:29, Romain Manni-Bucau wrote:
> Hi,
>
> when beans are pojo (i know it is almost always the case but we can do
> without) adding a beans.xml you'll get them in cdi lifecycle event then you
> can simply replace standard beans by your own beans (Bean<?>) or use a
> custom scope. The idea is simply to help cdi to manage these beans i think.
>
> You talked more about scanning but scanner depends on the environment (OWB
> doesnt use the same scanner in standalone, osgi or tomee) and bringing
> another scanner for camel is i think a pain and not mandatory.
>
> wdyt?
>
> - Romain
>
>
> 2012/7/12 Charles Moulliard<cm...@gmail.com>
>
>> Hi,
>>
>> Is there a DeltaSpike or OpenWebbeans util class that I could use to scan
>> classes and find annotations (which have been of course designed without
>> CDI in mind) and next inject them ?
>>
>> Camel provides @EndpointInject(uri or ref), @Produce(uri) and @Consume
>> annotations to inject Endpoint definition or Producer/ConsumerTemplate into
>> CamelContext.
>>
>> We have to call getInjectionValue(type, uri, endpointRef,
>> injectionPointName, null, null) method of CamelPostProcessorHelper tevery
>> time such annotation is discovered o add such injected bean. Camel-guice,
>> camel-spring and camel-blueprint projects proposes such impl (which is not
>> CDI compliant). I would like to implement this in camel-cdi (where we
>> already have defined a CamelInjector) and tries to find the best strategy.
>>
>> Is there something equivalent to what we have here in camel-guice ?
>>
>> bindAnnotationInjector(EndpointInject.class,
>> EndpointInjector.class); where bindAnnotationInjector is a method of this
>> class GuiceyFruitModule
>> and EndpointInjectorClass is the class containing the code to find
>> annotations wiithin a class
>>
>> public class EndpointInjector extends CamelPostProcessorHelper implements
>> AnnotationMemberProvider<EndpointInject> {
>>
>> @Inject
>> public EndpointInjector(CamelContext camelContext) {
>> super(camelContext);
>> }
>>
>> public Object provide(EndpointInject inject, TypeLiteral<?>
>> typeLiteral, Field field) {
>> Class<?> type = field.getType();
>> String injectionPointName = field.getName();
>> String uri = inject.uri();
>> String endpointRef = inject.ref();
>>
>> return getInjectionValue(type, uri, endpointRef,
>> injectionPointName, null, null);
>> }
>>
>> Regards,
>>
>> Apache Committer
>>
>> Blog : http://cmoulliard.blogspot.com
>> Twitter : http://twitter.com/cmoulliard
>> Linkedin : http://www.linkedin.com/in/charlesmoulliard
>> Skype: cmoulliard
>>
Re: Util class to find annotations in a class
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi,
when beans are pojo (i know it is almost always the case but we can do
without) adding a beans.xml you'll get them in cdi lifecycle event then you
can simply replace standard beans by your own beans (Bean<?>) or use a
custom scope. The idea is simply to help cdi to manage these beans i think.
You talked more about scanning but scanner depends on the environment (OWB
doesnt use the same scanner in standalone, osgi or tomee) and bringing
another scanner for camel is i think a pain and not mandatory.
wdyt?
- Romain
2012/7/12 Charles Moulliard <cm...@gmail.com>
> Hi,
>
> Is there a DeltaSpike or OpenWebbeans util class that I could use to scan
> classes and find annotations (which have been of course designed without
> CDI in mind) and next inject them ?
>
> Camel provides @EndpointInject(uri or ref), @Produce(uri) and @Consume
> annotations to inject Endpoint definition or Producer/ConsumerTemplate into
> CamelContext.
>
> We have to call getInjectionValue(type, uri, endpointRef,
> injectionPointName, null, null) method of CamelPostProcessorHelper tevery
> time such annotation is discovered o add such injected bean. Camel-guice,
> camel-spring and camel-blueprint projects proposes such impl (which is not
> CDI compliant). I would like to implement this in camel-cdi (where we
> already have defined a CamelInjector) and tries to find the best strategy.
>
> Is there something equivalent to what we have here in camel-guice ?
>
> bindAnnotationInjector(EndpointInject.class,
> EndpointInjector.class); where bindAnnotationInjector is a method of this
> class GuiceyFruitModule
> and EndpointInjectorClass is the class containing the code to find
> annotations wiithin a class
>
> public class EndpointInjector extends CamelPostProcessorHelper implements
> AnnotationMemberProvider<EndpointInject> {
>
> @Inject
> public EndpointInjector(CamelContext camelContext) {
> super(camelContext);
> }
>
> public Object provide(EndpointInject inject, TypeLiteral<?>
> typeLiteral, Field field) {
> Class<?> type = field.getType();
> String injectionPointName = field.getName();
> String uri = inject.uri();
> String endpointRef = inject.ref();
>
> return getInjectionValue(type, uri, endpointRef,
> injectionPointName, null, null);
> }
>
> Regards,
>
> Apache Committer
>
> Blog : http://cmoulliard.blogspot.com
> Twitter : http://twitter.com/cmoulliard
> Linkedin : http://www.linkedin.com/in/charlesmoulliard
> Skype: cmoulliard
>