public <T> T get(Scope scope, Contextual<T> contextual, CreationalContext<T> creationalContext) { RequestContext ctx = currentContext.get(); if (ctx == null) throw new ContextNotActiveException(); if (!scope.isActive(ctx)) throw new ContextNotActiveException(); Object o = ctx.getContextualValue(scope, contextual); if (o == null) { if (creationalContext != null) { o = contextual.create(creationalContext); ctx.setContextualValue(scope, contextual, o); } } return (T) o; }
public boolean isActive(Scope scope) { RequestContext ctx = currentContext.get(); if (ctx == null) throw new ContextNotActiveException(); return scope.isActive(ctx); }