You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@openwebbeans.apache.org by Lars-Fredrik Smedberg <it...@gmail.com> on 2015/03/26 17:42:18 UTC

Question on ContextUtils

Hi

Curious, I saw the following in the ContextUtils sourcecode when I was
looking for some ideas to solve a problem....

    public static boolean isContextActive(Class<? extends Annotation>
scopeAnnotationClass, BeanManager beanManager)
    {
        try
        {
            if (beanManager.getContext(scopeAnnotationClass) == null
                    ||
!beanManager.getContext(scopeAnnotationClass).isActive())
            {
                return false;
            }
        }
        catch (ContextNotActiveException e)
        {
            return false;
        }

        return true;
    }

When I looked at the documentation for BeanManager I saw that getContext
always returns a Context or throw a ContextNotActiveException (amongst
other exceptions), so the null check should not be needed or?

The documenation also mention that the getContext method always return an
active context...

Is the code there to solve some compatibility issues or for other
historical reasons or should it read (or similar):

    public static boolean isContextActive(Class<? extends Annotation>
scopeAnnotationClass, BeanManager beanManager)
    {
        try
        {
    beanManager.getContext(scopeAnnotationClass);
    return true;
        }
        catch (ContextNotActiveException e)
        {
            return false;
        }
    }

Regards
LF

Re: Question on ContextUtils

Posted by Lars-Fredrik Smedberg <it...@gmail.com>.
Sorry, was supposed to go to the DeltaSpike mailinglist....
On Mar 26, 2015 5:42 PM, "Lars-Fredrik Smedberg" <it...@gmail.com> wrote:

> Hi
>
> Curious, I saw the following in the ContextUtils sourcecode when I was
> looking for some ideas to solve a problem....
>
>     public static boolean isContextActive(Class<? extends Annotation>
> scopeAnnotationClass, BeanManager beanManager)
>     {
>         try
>         {
>             if (beanManager.getContext(scopeAnnotationClass) == null
>                     ||
> !beanManager.getContext(scopeAnnotationClass).isActive())
>             {
>                 return false;
>             }
>         }
>         catch (ContextNotActiveException e)
>         {
>             return false;
>         }
>
>         return true;
>     }
>
> When I looked at the documentation for BeanManager I saw that getContext
> always returns a Context or throw a ContextNotActiveException (amongst
> other exceptions), so the null check should not be needed or?
>
> The documenation also mention that the getContext method always return an
> active context...
>
> Is the code there to solve some compatibility issues or for other
> historical reasons or should it read (or similar):
>
>     public static boolean isContextActive(Class<? extends Annotation>
> scopeAnnotationClass, BeanManager beanManager)
>     {
>         try
>         {
>     beanManager.getContext(scopeAnnotationClass);
>     return true;
>         }
>         catch (ContextNotActiveException e)
>         {
>             return false;
>         }
>     }
>
> Regards
> LF
>