code: @SuppressWarnings("unchecked")
      public static <T> T lookup(BeanManager bm, Class<T> clazz)
      {
          Iterator<Bean< ?>> iter = bm.getBeans(clazz).iterator();
          if (!iter.hasNext())
          {
              throw new IllegalStateException(
                  "CDI BeanManager cannot find an instance of requested type " + 
                  clazz.getName());
          }
          Bean<T> bean = (Bean<T>) iter.next();
          CreationalContext<T> ctx = bm.createCreationalContext(bean);
          T dao = (T) bm.getReference(bean, clazz, ctx);
          return dao;
      }
docs: /*
  public static BeanManager getBeanManagerFromJNDI()
  {
  try
  {
  in an application server
  return (BeanManager) InitialContext.doLookup("java:comp/BeanManager");
  }
  catch (NamingException e)
  {
  silently ignore
  }
  
  try
  {
  in a servlet container
  return (BeanManager) InitialContext.doLookup("java:comp/env/BeanManager");
  }
  catch (NamingException e)
  {
  silently ignore
  }
  return null;
  }