The statics are only used instead of new BeanManagerProvider{} ... they are not a problem and can go away. Is there another complaint?

On Wed, Apr 14, 2010 at 2:59 PM, Nicklas Karlsson <nickarls@gmail.com> wrote:
Reverting & repenting

It's for the JSF -> CDI event bridge. I need a BeanManager to propagate the events to but the problem is that the first JSF global system event is a PostApplicationConstructed which is pretty soon.

First I try to look for it in a servlet context attribute (which the seam-servlet puts there but it's not there yet in this case)
Then I try to look in JNDI (sure, it's there but you recommended we should try to avoid this to make this available in as many places as possible)
Then I tried the static one as a last effort.


On Wed, Apr 14, 2010 at 5:54 PM, Pete Muir <pmuir@redhat.com> wrote:
Guys,

We cannot rely on statics in Seam 3. Please don't add code like this. If you have a problem accessing the BeanManager from your code, please ask here about the best solution.

Nik, can you revert this please. And then explain what situation you are trying to address.

Thanks.

Begin forwarded message:

> From: seam-commits@lists.jboss.org
> Date: 14 April 2010 13:50:21 GMT+01:00
> To: seam-commits@lists.jboss.org
> Subject: [seam-commits] Seam SVN: r12493 - in modules/faces/trunk/impl/src/main: resources/META-INF/services and 1 other directory.
> Reply-To: seam-commits@lists.jboss.org
>
> Author: nickarls
> Date: 2010-04-14 08:50:21 -0400 (Wed, 14 Apr 2010)
> New Revision: 12493
>
> Added:
>   modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerPickupExtension.java
>   modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/SingletonBeanManagerProvider.java
> Modified:
>   modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerAware.java
>   modules/faces/trunk/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
> Log:
> Last attempt singletonish approach when others fail. Yes, I'm ashamed.
>
> Modified: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerAware.java
> ===================================================================
> --- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerAware.java     2010-04-14 12:21:26 UTC (rev 12492)
> +++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerAware.java     2010-04-14 12:50:21 UTC (rev 12493)
> @@ -45,6 +45,7 @@
>       beanManagerProviders.add(ServletContextBeanManagerProvider.DEFAULT);
>       beanManagerProviders.add(JndiBeanManagerProvider.DEFAULT);
>       beanManagerProviders.add(JndiBeanManagerProvider.JBOSS_HACK);
> +      beanManagerProviders.add(SingletonBeanManagerProvider.DEFAULT);
>    }
>
>    protected BeanManager getBeanManager()
>
> Added: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerPickupExtension.java
> ===================================================================
> --- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerPickupExtension.java                           (rev 0)
> +++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerPickupExtension.java   2010-04-14 12:50:21 UTC (rev 12493)
> @@ -0,0 +1,56 @@
> +/*
> + * JBoss, Home of Professional Open Source
> + * Copyright 2010, Red Hat, Inc., and individual contributors
> + * by the @authors tag. See the copyright.txt in the distribution for a
> + * full listing of individual contributors.
> + *
> + * This is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU Lesser General Public License as
> + * published by the Free Software Foundation; either version 2.1 of
> + * the License, or (at your option) any later version.
> + *
> + * This software is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this software; if not, write to the Free
> + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
> + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
> + */
> +package org.jboss.seam.faces.cdi;
> +
> +import javax.enterprise.event.Observes;
> +import javax.enterprise.inject.spi.AfterBeanDiscovery;
> +import javax.enterprise.inject.spi.BeanManager;
> +import javax.enterprise.inject.spi.Extension;
> +
> +/**
> + * Singleton(ish) extension that observes the AfterBeanDiscovery event and stores the BeanManager for access
> + * in places where injection is not available and JNDI or ServletContext access is not preferable.
> + *
> + * @author Nicklas Karlsson
> + *
> + */
> +public class BeanManagerPickupExtension implements Extension
> +{
> +   private static BeanManagerPickupExtension instance;
> +   private volatile BeanManager beanManager;
> +
> +   public BeanManager getBeanManager()
> +   {
> +      return beanManager;
> +   }
> +
> +   public static BeanManagerPickupExtension getInstance()
> +   {
> +      return instance;
> +   }
> +
> +   public void pickupBeanManager(@Observes AfterBeanDiscovery e, BeanManager beanManager)
> +   {
> +      this.beanManager = beanManager;
> +      BeanManagerPickupExtension.instance = this;
> +   }
> +}
>
> Added: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/SingletonBeanManagerProvider.java
> ===================================================================
> --- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/SingletonBeanManagerProvider.java                         (rev 0)
> +++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/SingletonBeanManagerProvider.java 2010-04-14 12:50:21 UTC (rev 12493)
> @@ -0,0 +1,43 @@
> +/*
> + * JBoss, Home of Professional Open Source
> + * Copyright 2010, Red Hat, Inc., and individual contributors
> + * by the @authors tag. See the copyright.txt in the distribution for a
> + * full listing of individual contributors.
> + *
> + * This is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU Lesser General Public License as
> + * published by the Free Software Foundation; either version 2.1 of
> + * the License, or (at your option) any later version.
> + *
> + * This software is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this software; if not, write to the Free
> + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
> + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
> + */
> +package org.jboss.seam.faces.cdi;
> +
> +import javax.enterprise.inject.spi.BeanManager;
> +
> +/**
> + * A BeanManager provider for an extension provided singleton
> + *
> + * @author Nicklas Karlsson
> + *
> + */
> +public class SingletonBeanManagerProvider implements BeanManagerProvider
> +{
> +
> +   public static final BeanManagerProvider DEFAULT = new SingletonBeanManagerProvider();
> +
> +   @Override
> +   public BeanManager getBeanManager()
> +   {
> +      return BeanManagerPickupExtension.getInstance().getBeanManager();
> +   }
> +
> +}
>
> Modified: modules/faces/trunk/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
> ===================================================================
> --- modules/faces/trunk/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension       2010-04-14 12:21:26 UTC (rev 12492)
> +++ modules/faces/trunk/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension       2010-04-14 12:50:21 UTC (rev 12493)
> @@ -1,3 +1,4 @@
> org.jboss.seam.faces.context.ViewScopedExtension
> org.jboss.seam.faces.context.FlashScopedExtension
> -org.jboss.seam.faces.context.FacesAnnotationsAdapterExtension
> \ No newline at end of file
> +org.jboss.seam.faces.context.FacesAnnotationsAdapterExtension
> +org.jboss.seam.faces.cdi.BeanManagerPickupExtension
>
> _______________________________________________
> seam-commits mailing list
> seam-commits@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/seam-commits


_______________________________________________
seam-dev mailing list
seam-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/seam-dev



--
---
Nik

_______________________________________________
seam-dev mailing list
seam-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/seam-dev




--
Lincoln Baxter, III
http://ocpsoft.com
http://scrumshark.com
"Keep it Simple"