Context singleContext = singleContextMap.get(scopeType);
if (singleContext != null)
{
if (!singleContext.isActive())
{
throw new ContextNotActiveException("WebBeans context with scope type annotation @" + scopeType.getSimpleName() + " does not exist within current thread");
}
return singleContext;
}
// the spec also allows for multiple contexts existing for the same scope type
// but in this case only one must be active at a time (for the current thread)
List<Context> others = contextMap.get(scopeType);
Context found = null;
if(others != null)
{
for(Context otherContext : others)
{
if(otherContext.isActive())
{
if (found != null)
{
throw new IllegalStateException("More than one active context exists with scope type annotation @" + scopeType.getSimpleName());
}
found = otherContext;
}
}
}
if (found == null)
{
throw new ContextNotActiveException("WebBeans context with scope type annotation @" + scopeType.getSimpleName() + " does not exist within current thread");
}
return found;
}