You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by Gurkan Erdogdu <gu...@yahoo.com> on 2010/09/17 18:28:41 UTC

Managed Bean Support

Hi;

I am looking the ManagedBean implementation. I think that currently it does not 
support the injection of managed beans via @Resource? Is it correct or I am 
wrong?


Thanks;

--Gurkan



Re: Managed Bean Support

Posted by Gurkan Erdogdu <gu...@yahoo.com>.
Currently ManagedBeans are injected via proxy that implements Managed Bean 
interfaces. But, Java EE 6 spec says that Managed Beans could be injected in 2 
ways

1* Via interface
2* Via managed bean class

In the second case, we get cast exception because OpenEJB always returns proxy 
that implements interfaces.

So ,we  have to manage this siutation also,



----- Original Message ----
From: David Blevins <da...@visi.com>
To: dev@openejb.apache.org
Sent: Sat, September 18, 2010 12:19:50 AM
Subject: Re: Managed Bean Support


On Sep 17, 2010, at 9:28 AM, Gurkan Erdogdu wrote:

> Hi;
> 
> I am looking the ManagedBean implementation. I think that currently it does not 
>
> support the injection of managed beans via @Resource? Is it correct or I am 
> wrong?

I don't think that's in there yet, but referring to them via @EJB does work as a 
side affect of us treating @ManagedBean as a kind of session bean.  Up for grabs 
if you want to work on it.

Definitely feel encouraged to throw out implementation ideas before digging.  I 
imagine that we'll not want a second copy of "resolve by interface" code and 
will want to somehow leverage the EjbResolver code we have.

We could probably make it so you can refer to any EJB via @Resource to keep 
things consistent.  Maybe we just detect that the @Resource ref is a bean ref 
and internally record it as a org.apache.openejb.jee.EjbLocalRef.


-David



Re: Managed Bean Support

Posted by David Blevins <da...@visi.com>.
That looks good.

On Sep 17, 2010, at 5:35 PM, Gurkan Erdogdu wrote:

> Hello David;
> 
> What I am thinking is that 
> 
> 1- Supress checkings in "AutoConfig" class
> 
>   private void processJndiRefs(String moduleId, JndiConsumer jndiConsumer, 
> AppResources appResources, ClassLoader loader) throws OpenEJBException {
>       // Resource reference
>       for (ResourceRef ref : jndiConsumer.getResourceRef()) {
> 
>           try {
>               Class clazz = Class.forName(ref.getType(),true,loader);
>               if(clazz.isAnnotationPresent(ManagedBean.class)){
>                   continue;
>               }
>           } catch (ClassNotFoundException e) {
>               throw new OpenEJBException("Class not found : " + 
> ref.getType(),e);
>           }
> ....
> }
> 
> 2- Updating JndiEncBuilder for ResourceReferenceInfo processing. If @Resource 
> type is annotated with @ManagedBean, we can directly add "location" info to the 
> resource reference info. Because, managed beans are bound to 
> java:module/bean_name  and java:app/module/bean_name contexts. Therefore it has 
> always been resolved correctly whether or not "lookup" defined on @Resource.
> 
>       for (ResourceReferenceInfo referenceInfo : jndiEnc.resourceRefs) {
>           Reference reference = null;
> 
>           String refType = referenceInfo.referenceType;
>           boolean mb = false;
>           Class clazz;
>           try {
>               clazz = Class.forName(refType, true, classLoader);
>               mb = clazz.isAnnotationPresent(ManagedBean.class);
>           } catch (ClassNotFoundException e) {
>               throw new OpenEJBException("Class not found : " + refType,e);
>           }
> 
>           if(mb){
>               String location = referenceInfo.location.jndiName;
>               if(location == null){
>                   ManagedBean managedBean = 
> (ManagedBean)clazz.getAnnotation(ManagedBean.class);
>                   String name = managedBean.value();
>                   if(name == null || name.equals("")){
>                       name = clazz.getSimpleName();
>                   }
>                   referenceInfo.location = new ReferenceLocationInfo();        
> 
> 
>                   referenceInfo.location.jndiName = "module/" + name;
>               }
>           }
> 
> 
> WDYT?
> 
> --Gurkan
> 
> 
> 
> ----- Original Message ----
> From: David Blevins <da...@visi.com>
> To: dev@openejb.apache.org
> Sent: Sat, September 18, 2010 12:19:50 AM
> Subject: Re: Managed Bean Support
> 
> 
> On Sep 17, 2010, at 9:28 AM, Gurkan Erdogdu wrote:
> 
>> Hi;
>> 
>> I am looking the ManagedBean implementation. I think that currently it does not 
>> 
>> support the injection of managed beans via @Resource? Is it correct or I am 
>> wrong?
> 
> I don't think that's in there yet, but referring to them via @EJB does work as a 
> side affect of us treating @ManagedBean as a kind of session bean.  Up for grabs 
> if you want to work on it.
> 
> Definitely feel encouraged to throw out implementation ideas before digging.  I 
> imagine that we'll not want a second copy of "resolve by interface" code and 
> will want to somehow leverage the EjbResolver code we have.
> 
> We could probably make it so you can refer to any EJB via @Resource to keep 
> things consistent.  Maybe we just detect that the @Resource ref is a bean ref 
> and internally record it as a org.apache.openejb.jee.EjbLocalRef.
> 
> 
> -David
> 
> 
> 


Re: Managed Bean Support

Posted by Gurkan Erdogdu <gu...@yahoo.com>.
Hello David;

What I am thinking is that 

1- Supress checkings in "AutoConfig" class

    private void processJndiRefs(String moduleId, JndiConsumer jndiConsumer, 
AppResources appResources, ClassLoader loader) throws OpenEJBException {
        // Resource reference
        for (ResourceRef ref : jndiConsumer.getResourceRef()) {
            
            try {
                Class clazz = Class.forName(ref.getType(),true,loader);
                if(clazz.isAnnotationPresent(ManagedBean.class)){
                    continue;
                }
            } catch (ClassNotFoundException e) {
                throw new OpenEJBException("Class not found : " + 
ref.getType(),e);
            }
 ....
}

2- Updating JndiEncBuilder for ResourceReferenceInfo processing. If @Resource 
type is annotated with @ManagedBean, we can directly add "location" info to the 
resource reference info. Because, managed beans are bound to 
java:module/bean_name  and java:app/module/bean_name contexts. Therefore it has 
always been resolved correctly whether or not "lookup" defined on @Resource.

        for (ResourceReferenceInfo referenceInfo : jndiEnc.resourceRefs) {
            Reference reference = null;

            String refType = referenceInfo.referenceType;
            boolean mb = false;
            Class clazz;
            try {
                clazz = Class.forName(refType, true, classLoader);
                mb = clazz.isAnnotationPresent(ManagedBean.class);
            } catch (ClassNotFoundException e) {
                throw new OpenEJBException("Class not found : " + refType,e);
            }
            
            if(mb){
                String location = referenceInfo.location.jndiName;
                if(location == null){
                    ManagedBean managedBean = 
(ManagedBean)clazz.getAnnotation(ManagedBean.class);
                    String name = managedBean.value();
                    if(name == null || name.equals("")){
                        name = clazz.getSimpleName();
                    }
                    referenceInfo.location = new ReferenceLocationInfo();        
            

                    referenceInfo.location.jndiName = "module/" + name;
                }
            }


WDYT?

--Gurkan



----- Original Message ----
From: David Blevins <da...@visi.com>
To: dev@openejb.apache.org
Sent: Sat, September 18, 2010 12:19:50 AM
Subject: Re: Managed Bean Support


On Sep 17, 2010, at 9:28 AM, Gurkan Erdogdu wrote:

> Hi;
> 
> I am looking the ManagedBean implementation. I think that currently it does not 
>
> support the injection of managed beans via @Resource? Is it correct or I am 
> wrong?

I don't think that's in there yet, but referring to them via @EJB does work as a 
side affect of us treating @ManagedBean as a kind of session bean.  Up for grabs 
if you want to work on it.

Definitely feel encouraged to throw out implementation ideas before digging.  I 
imagine that we'll not want a second copy of "resolve by interface" code and 
will want to somehow leverage the EjbResolver code we have.

We could probably make it so you can refer to any EJB via @Resource to keep 
things consistent.  Maybe we just detect that the @Resource ref is a bean ref 
and internally record it as a org.apache.openejb.jee.EjbLocalRef.


-David



Re: Managed Bean Support

Posted by David Blevins <da...@visi.com>.
On Sep 17, 2010, at 9:28 AM, Gurkan Erdogdu wrote:

> Hi;
> 
> I am looking the ManagedBean implementation. I think that currently it does not 
> support the injection of managed beans via @Resource? Is it correct or I am 
> wrong?

I don't think that's in there yet, but referring to them via @EJB does work as a side affect of us treating @ManagedBean as a kind of session bean.  Up for grabs if you want to work on it.

Definitely feel encouraged to throw out implementation ideas before digging.  I imagine that we'll not want a second copy of "resolve by interface" code and will want to somehow leverage the EjbResolver code we have.

We could probably make it so you can refer to any EJB via @Resource to keep things consistent.  Maybe we just detect that the @Resource ref is a bean ref and internally record it as a org.apache.openejb.jee.EjbLocalRef.


-David