Return-Path: Delivered-To: apmail-openwebbeans-user-archive@www.apache.org Received: (qmail 86435 invoked from network); 26 May 2010 15:18:15 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 26 May 2010 15:18:15 -0000 Received: (qmail 15639 invoked by uid 500); 26 May 2010 15:18:15 -0000 Delivered-To: apmail-openwebbeans-user-archive@openwebbeans.apache.org Received: (qmail 15600 invoked by uid 500); 26 May 2010 15:18:15 -0000 Mailing-List: contact user-help@openwebbeans.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@openwebbeans.apache.org Delivered-To: mailing list user@openwebbeans.apache.org Received: (qmail 15592 invoked by uid 99); 26 May 2010 15:18:15 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 26 May 2010 15:18:15 +0000 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [209.191.124.147] (HELO web38204.mail.mud.yahoo.com) (209.191.124.147) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 26 May 2010 15:18:05 +0000 Received: (qmail 23028 invoked by uid 60001); 26 May 2010 15:17:44 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1274887063; bh=59P0asnXBb9WtF4yd8S4Q1bB4erbrjRYJoC9reEepfs=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:References:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type; b=RL/muUVTcwVfn7MQ/PUlHsIzsZKHdGI2x6y1toXe1izVojcaK+3dTXhj4govFefFblSZX97MjqSAi2Ce7njuK2FxHYtAwTZyWhG3pe/V1xbwq8x8Bia5X6ZO62RaLBRCI9wKB8pQ8f72JemjgE6sEJTgqADAUZg/bSlBZft6RFk= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:X-YMail-OSG:Received:X-Mailer:References:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type; b=E/gXWsYfWkvJVab3clqcGbi6qT/kYQSp4XvyawW0GoqmpwBNZSfp4sEgvYd03umy718juaf0vg0BB6CbzMfxScUU3Dc0qlYCQWq1KeD3/QBpSljKbiBppGGS67KSMU33rn7Fs/s297WKrF6RBbSFLn3F5TaR5QbZk0mvNVBOTw0=; Message-ID: <987067.22650.qm@web38204.mail.mud.yahoo.com> X-YMail-OSG: 4HrUUJMVM1mbo7Qt46UsUPMzv7eESr42Rt_J8bPkKZQND9x wsqrja2TZkU8EjbEQgxQ5bZGPRxxYgn7KDsttBrDVOSnErjxThFHwyD8kpYg yAvE4NX25d_2fwvvSh3koZDQKq7uiaUBw7xrFzbn51oMwzHL09JxPIYb89m7 sZqwDJnHBtS6HGfrEQoIhUKYoKWRm2qinETeJ6gGSa5ZbWgFnn5fWfkb0iIO oVnvHjqITXtcaI9FMe9zTbgGM0sqagggrzYlLzg2RA_ygNK2A1rwPrvAXcHd tWl77SRlfw0IujdwUGxJgDfd3wAMb_oyd9xNdSTFl6IsvsxB_NCnHxECdUze VtDc- Received: from [78.186.14.202] by web38204.mail.mud.yahoo.com via HTTP; Wed, 26 May 2010 08:17:43 PDT X-Mailer: YahooMailRC/374.4 YahooMailWebService/0.8.103.269680 References: Date: Wed, 26 May 2010 08:17:43 -0700 (PDT) From: Gurkan Erdogdu Subject: Re: Creating a contextual managed bean by using BeanManager? To: user@openwebbeans.apache.org In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-1265172589-1274887063=:22650" X-Virus-Checked: Checked by ClamAV on apache.org --0-1265172589-1274887063=:22650 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello Bryant;=0A=0AAFAIK from your context, you want to add your own JSR-29= 9 beans into the container. So you can extend the container beans with usin= g Extensions. So, you create a class that implements javax.enterprise.injec= t.spi.Extension and put it into the classpath "META-INF/services" with fil= e name "javax.enterprise.inject.spi.Extension" name.=0A=0AIn this class, yo= u could observe the AfterBeanDiscoveryEvent event like this=0A=0Apublic cla= ss MyExtensionForCustomBean implements javax.enterprise.inject.spi.Extensi= on=0A{=0A public void observe(@Observes AfterBeanDiscoveryEvent event){= =0A event.addBean("Your custom bean") =0A }=0A}= =0A=0AYour custom bean might be=0Apublic class MyCustomBean extends OwbBean= or Bean {=0A=0A Add your bean methods=0A}=0A=0A=0ABeanManager#createAn= notatedType=0ABeanManager#createInjectionTarget=0A=0Amethods are used for n= on-contextual components for injecting the JSR-299 dependencies. For exampl= e, if you have a servlet instance and would like to inject JSR-299 dependen= cies for it, you could do this with above methods like we did for Apache To= mcat integration.=0A=0AFor example : We have a non-contextual servlet insta= nce ServletInstance=0A=0ACreate injection target with BeanManager#createInk= ectionTarget(....)=0AInjectionTarget.inject(servletInstance)=0A=0AWhen serv= let instance is destroyed, its dependencies must also be destroyed via call= to=0ACreationalContext # release(). So you have to call CreationalContext#= release method.=0A=0AI hope it helps;=0A=0AThanks;=0A=0A--Gurkan=0A=0A=0A= =0A=0A________________________________=0AFrom: Bryant Luk =0ATo: openwebbeans-user =0ASent: Wed, M= ay 26, 2010 5:52:52 PM=0ASubject: Creating a contextual managed bean by usi= ng BeanManager?=0A=0AHi,=0A=0AI was looking to create managed bean instance= s dynamically for an=0AApache Wink (JAX-RS) plugin.=0A=0AI found the BeanMa= nager interface and was hoping that would be a good=0Away to get my instanc= es via a programmatic interface. Is that a=0Apossible route for me to take= ?=0A=0ASo pseudcode-ish, I would do:=0A=0ABeanManager beanManager =3D ...= =0AClass managedBeanClass =3D ...=0AAnnotatedType aType =3D beanManager.= createAnnotatedType(managedBeanclass);=0AInjectionTarget iTarget =3D bea= nManager.createInjectionTarget(aType);=0A=0A/* is this the way to get the r= ight creational context? */=0ASet> beans =3D beanManager.getBeans(m= anagedBeanClass, (any=0Aqualifier annotations here));=0ABean bean =3D beans= .iterator().next();=0ACreationalContext creationalContext =3D beanManager.c= reateCreationalContext(bean);=0A=0AT instance =3D iTarget.produce(creationa= lContext);=0AiTarget.inject(instance, creationalContext);=0AiTarget.postCon= struct(instance);=0A=0A/* ...use the instance... */=0A=0AiTarget.preDestroy= (instance);=0AiTarget.dispose(instance);=0A=0A/* do I need to do a creation= alContext.release()? */=0A=0AI'm hoping the created instance will be correc= tly injected/disposed of=0Aand would be correctly scoped (i.e. if it's in a= servlet container and=0Athe managed bean was @ApplicationScoped then the a= bove code would=0Astill "do the right thing" instead of creating a new inst= ance).=0A=0AThanks for any pointers anyone can provide.=0A=0A=0A --0-1265172589-1274887063=:22650 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
Hello Bryant;

AFAIK from your context, you want to add your = own JSR-299 beans into the container. So you can extend the container beans= with using Extensions. So, you create a class that implements javax.enterp= rise.inject.spi.Extension and put it into  the classpath "META-INF/ser= vices" with file name "javax.enterprise.inject.spi.Extension" name.

= In this class, you could observe the AfterBeanDiscoveryEvent event like thi= s

public class MyExtensionForCustomBean implements javax.enterprise= .inject.spi.Extension
{
     public void observe(= @Observes AfterBeanDiscoveryEvent event){
        &n= bsp;    event.addBean("Your custom bean")     = ;       
   }
}

Your custom bean might be
public class MyCustomBean exten= ds OwbBean or Bean {

     Add your bean methods<= br>}


BeanManager#createAnnotatedType
BeanManager#createInject= ionTarget

methods are used for non-contextual components for injecti= ng the JSR-299 dependencies. For example, if you have a servlet instance an= d would like to inject JSR-299 dependencies for it, you could do this with = above methods like we did for Apache Tomcat integration.

For example= : We have a non-contextual servlet instance ServletInstance

Create = injection target with BeanManager#createInkectionTarget(....)
InjectionT= arget.inject(servletInstance)

When servlet instance is destroyed, it= s dependencies must also be destroyed via call to
CreationalContext # re= lease(). So you have to call CreationalContext#release method.

I hop= e it helps;

Thanks;

--Gurkan


From: Bryant Luk <bryant.luk@gmail.com>
To: openwebbeans-user <openwebb= eans-user@apache.org>
Sent: Wed, May 26, 2010 5:52:52 PM
Subject: Creating a contextual managed bean by using BeanMana= ger?

Hi,

I was looking to create managed bean instance= s dynamically for an
Apache Wink (JAX-RS) plugin.

I found the Bea= nManager interface and was hoping that would be a good
way to get my ins= tances via a programmatic interface.  Is that a
possible route for = me to take?

So pseudcode-ish, I would do:

BeanManager beanMan= ager =3D ...
Class<T> managedBeanClass =3D ...
AnnotatedType aType =3D = beanManager.createAnnotatedType(managedBeanclass);
InjectionTarget<T&= gt; iTarget =3D beanManager.createInjectionTarget(aType);

/* is this= the way to get the right creational context? */
Set<Bean<?>>= ; beans =3D beanManager.getBeans(managedBeanClass, (any
qualifier annota= tions here));
Bean bean =3D beans.iterator().next();
CreationalContex= t creationalContext =3D beanManager.createCreationalContext(bean);

T= instance =3D iTarget.produce(creationalContext);
iTarget.inject(instanc= e, creationalContext);
iTarget.postConstruct(instance);

/* ...use= the instance... */

iTarget.preDestroy(instance);
iTarget.dispose= (instance);

/* do I need to do a creationalContext.release()? */
=
I'm hoping the created instance will be correctly injected/disposed of<= br>and would be correctly scoped (i.e. if it's in a servlet container andthe managed bean was @ApplicationScoped then the above code would
still "do= the right thing" instead of creating a new instance).

Thanks for an= y pointers anyone can provide.
=0A
--0-1265172589-1274887063=:22650--