deltaspike-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Charles Moulliard <cmoulli...@gmail.com>
Subject Re: Util class to find annotations in a class
Date Thu, 12 Jul 2012 15:01:54 GMT
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<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
>>>> Skype: cmoulliard
>>>>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message