Package br.gov.frameworkdemoiselle.context

Examples of br.gov.frameworkdemoiselle.context.RequestContext


    getLogger().debug(getBundle().getString("executing-all", getAnnotationClass().getSimpleName()));

    Collections.sort(processors);
    Exception failure = null;
   
    RequestContext tempRequestContext = Beans.getReference(RequestContext.class);
    SessionContext tempSessionContext = Beans.getReference(SessionContext.class);
    ViewContext tempViewContext = Beans.getReference(ViewContext.class);
    ConversationContext tempConversationContext = Beans.getReference(ConversationContext.class);

    boolean requestActivatedHere = !tempRequestContext.isActive();
    boolean sessionActivatedHere = !tempSessionContext.isActive();
    boolean viewActivatedHere = !tempViewContext.isActive();
    boolean conversationActivatedHere = !tempConversationContext.isActive();
   
    if (!registered) {
      if (!tempRequestContext.isActive())
        tempRequestContext.activate();
     
      if (!tempSessionContext.isActive())
        tempSessionContext.activate();
     
      if (!tempViewContext.isActive())
        tempViewContext.activate();
     
      if (!tempConversationContext.isActive())
        tempConversationContext.activate();

      registered = true;
    }

    for (Iterator<AnnotatedMethodProcessor> iter = processors.iterator(); iter.hasNext();) {
      AnnotatedMethodProcessor<?> processor = iter.next();

      try {
        ClassLoader classLoader = Reflections.getClassLoaderForClass(processor.getAnnotatedMethod()
            .getDeclaringType().getJavaClass().getCanonicalName());

        if (Thread.currentThread().getContextClassLoader().equals(classLoader)) {
          processor.process();
          iter.remove();
        }

      } catch (Exception cause) {
        failure = cause;
      }
    }

    if (processors.isEmpty()) {
      if (requestActivatedHere){
        tempRequestContext.deactivate();
      }
     
      if (sessionActivatedHere){
        tempSessionContext.deactivate();
      }
View Full Code Here


  }

  private void activateContexts(Class<?> managedType) {
   
    RequestContext requestContext = Beans.getReference(RequestContext.class);
    ViewContext viewContext = Beans.getReference(ViewContext.class);
    SessionContext sessionContext = Beans.getReference(SessionContext.class);
    ConversationContext conversationContext = Beans.getReference(ConversationContext.class);
   
    if (!requestContext.isActive()){
      logger.debug(bundle.getString("management-debug-starting-custom-context",
          requestContext.getClass().getCanonicalName(), managedType.getCanonicalName()));
     
      requestContext.activate();
    }
   
    if (!viewContext.isActive()){
      logger.debug(bundle.getString("management-debug-starting-custom-context",
          viewContext.getClass().getCanonicalName(), managedType.getCanonicalName()));
View Full Code Here

      conversationContext.activate();
    }
  }

  private void deactivateContexts(Class<?> managedType) {
    RequestContext requestContext = Beans.getReference(RequestContext.class);
    ViewContext viewContext = Beans.getReference(ViewContext.class);
    SessionContext sessionContext = Beans.getReference(SessionContext.class);
    ConversationContext conversationContext = Beans.getReference(ConversationContext.class);
   
    if (requestContext.isActive()){
      logger.debug(bundle.getString("management-debug-stoping-custom-context",
          requestContext.getClass().getCanonicalName(), managedType.getCanonicalName()));
     
      requestContext.deactivate();
    }
   
    if (!viewContext.isActive()){
      logger.debug(bundle.getString("management-debug-stoping-custom-context",
          viewContext.getClass().getCanonicalName(), managedType.getCanonicalName()));
View Full Code Here

    }

  }

  private void activateContexts(Class<?> managedType) {
    RequestContext requestContext = Beans.getReference(RequestContext.class);
    ConversationContext conversationContext = Beans.getReference(ConversationContext.class);
   
    if (!requestContext.isActive()){
      logger.debug(bundle.getString("management-debug-starting-custom-context",
          requestContext.getClass().getCanonicalName(), managedType.getCanonicalName()));
     
      requestContext.activate();
    }
   
    if (!conversationContext.isActive()){
      logger.debug(bundle.getString("management-debug-starting-custom-context",
          conversationContext.getClass().getCanonicalName(), managedType.getCanonicalName()));
View Full Code Here

      conversationContext.activate();
    }
  }

  private void deactivateContexts(Class<?> managedType) {
    RequestContext requestContext = Beans.getReference(RequestContext.class);
    ConversationContext conversationContext = Beans.getReference(ConversationContext.class);
   
    if (requestContext.isActive()){
      logger.debug(bundle.getString("management-debug-stoping-custom-context",
          requestContext.getClass().getCanonicalName(), managedType.getCanonicalName()));
     
      requestContext.deactivate();
    }
   
    if (conversationContext.isActive()){
      logger.debug(bundle.getString("management-debug-stoping-custom-context",
          conversationContext.getClass().getCanonicalName(), managedType.getCanonicalName()));
View Full Code Here

    }
  }
 
  private void startContexts(){
    if (!registered){
      RequestContext requestContext = Beans.getReference(RequestContext.class);
      SessionContext sessionContext = Beans.getReference(SessionContext.class);
      ViewContext viewContext = Beans.getReference(ViewContext.class);
      ConversationContext conversationContext = Beans.getReference(ConversationContext.class);
     
      if (requestContext!=null){
        startedContextHere.put("request", requestContext.activate());
      }
     
      if (sessionContext!=null){
        startedContextHere.put("session", sessionContext.activate());
      }
View Full Code Here

    }
  }
 
  private void stopContexts(){
    if (registered){
      RequestContext requestContext = Beans.getReference(RequestContext.class);
      SessionContext sessionContext = Beans.getReference(SessionContext.class);
      ViewContext viewContext = Beans.getReference(ViewContext.class);
      ConversationContext conversationContext = Beans.getReference(ConversationContext.class);
     
      if (requestContext!=null && Boolean.TRUE.equals(startedContextHere.get("request"))){
        requestContext.deactivate();
      }
     
      if (sessionContext!=null && Boolean.TRUE.equals(startedContextHere.get("session"))){
        sessionContext.deactivate();
      }
View Full Code Here

    assertNull(context.getUser());
  }

  @Test
  public void loginProcess() {
    RequestContext ctx = Beans.getReference(RequestContext.class);
    ctx.activate();

    context.login();
    assertTrue(context.isLoggedIn());
    assertNotNull(observer.getEvent());
    assertEquals("demoiselle", context.getUser().getId());

    ctx.deactivate();
  }
View Full Code Here

    ctx.deactivate();
  }

  @Test
  public void logoutProcess() {
    RequestContext ctx = Beans.getReference(RequestContext.class);
    ctx.activate();

    context.login();
    context.logout();
    assertFalse(context.isLoggedIn());
    assertNull(context.getUser());

    ctx.deactivate();
  }
View Full Code Here

    return deployment;
  }
 
  @Test
  public void denyWrongCredentials() {
    RequestContext ctx = Beans.getReference(RequestContext.class);
    ctx.activate();
   
    Credentials credentials = Beans.getReference(Credentials.class);
    credentials.setLogin("wronglogin");
   
    try{
      context.login();
      Assert.fail("Authenticator aceitou credenciais erradas");
    }
    catch(AuthenticationException ae){
      //Erro esperado
    }
    finally{
      ctx.deactivate();
    }

  }
View Full Code Here

TOP

Related Classes of br.gov.frameworkdemoiselle.context.RequestContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.