Esempio n. 1
0
  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;
  }
Esempio n. 2
0
 public boolean isActive(Scope scope) {
   RequestContext ctx = currentContext.get();
   if (ctx == null) throw new ContextNotActiveException();
   return scope.isActive(ctx);
 }