Package br.gov.frameworkdemoiselle.context

Examples of br.gov.frameworkdemoiselle.context.ViewContext


    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();
      }
     
      if (viewActivatedHere){
        tempViewContext.deactivate();
      }
     
      if (conversationActivatedHere){
        tempConversationContext.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()));
     
      viewContext.activate();
    }

    if (!sessionContext.isActive()){
      logger.debug(bundle.getString("management-debug-starting-custom-context",
          sessionContext.getClass().getCanonicalName(), managedType.getCanonicalName()));
View Full Code Here

    }
  }

  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()));
     
      viewContext.deactivate();
    }

    if (!sessionContext.isActive()){
      logger.debug(bundle.getString("management-debug-stoping-custom-context",
          sessionContext.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());
      }
     
     
      if (conversationContext!=null){
        startedContextHere.put("conversation", conversationContext.activate());
      }
     
      //Contexto temporário de visão precisa de tratamento especial
      //para evitar conflito com o contexto presente na extensão demoiselle-jsf
      if (viewContext!=null){
        if (TemporaryViewContextImpl.class.isInstance(viewContext)){
          startedContextHere.put("view", viewContext.activate());
        }
        else{
          //Precisamos desativar temporariamente o contexto
          if (viewContext.isActive()){
            backupContext = viewContext;
            viewContext.deactivate();
           
            CustomContextBootstrap customContextBootstrap = Beans.getReference(CustomContextBootstrap.class);
            for (CustomContext customContext : customContextBootstrap.getCustomContexts()){
              if ( TemporaryViewContextImpl.class.isInstance(customContext) ){
                startedContextHere.put("view", customContext.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();
      }
     
      if (conversationContext!=null && Boolean.TRUE.equals(startedContextHere.get("conversation"))){
        conversationContext.deactivate();
      }
     
      //Contexto temporário de visão precisa de tratamento especial
      //para evitar conflito com o contexto presente na extensão demoiselle-jsf
      if (viewContext!=null){
        if (TemporaryViewContextImpl.class.isInstance(viewContext) && startedContextHere.get("view")){
          viewContext.deactivate();
         
          if (backupContext!=null){
            backupContext.activate();
            backupContext = null;
          }
View Full Code Here

public class SeBootstrap implements Extension {

  public void addContexts(@Observes final AfterDeploymentValidation event) {
    RequestContext requestContext = Beans.getReference(RequestContext.class);
    SessionContext sessionContext = Beans.getReference(SessionContext.class);
    ViewContext viewContext = Beans.getReference(ViewContext.class);
    ConversationContext conversationContext = Beans.getReference(ConversationContext.class);
   
    requestContext.activate();
    sessionContext.activate();
    viewContext.activate();
    conversationContext.activate();
  }
View Full Code Here

  }

  public void removeContexts(@Observes AfterShutdownProccess event) {
    RequestContext requestContext = Beans.getReference(RequestContext.class);
    SessionContext sessionContext = Beans.getReference(SessionContext.class);
    ViewContext viewContext = Beans.getReference(ViewContext.class);
    ConversationContext conversationContext = Beans.getReference(ConversationContext.class);
   
    requestContext.deactivate();
    sessionContext.deactivate();
    viewContext.deactivate();
    conversationContext.activate();
  }
View Full Code Here

    return deployment;
  }
 
  @Test
  public void produceOneEntityManagerPerView() {
    ViewContext ctx = Beans.getReference(ViewContext.class);
    ctx.activate();
   
    EntityManager m1 = Beans.getReference(EntityManager.class, new NameQualifier("pu"));

    assertNotNull(m1);
    assertEquals(EntityManagerProxy.class, m1.getClass());

    EntityManager m2 = Beans.getReference(EntityManager.class, new NameQualifier("pu"));

    assertNotNull(m2);
    assertEquals(EntityManagerProxy.class, m2.getClass());

    MyEntity entity = new MyEntity();
    entity.setId(createId("testID"));

    m1.persist(entity);

    assertTrue(m2.contains(entity));
   
    ctx.deactivate();
  }
View Full Code Here

    ctx.deactivate();
  }
 
  @Test(expected=ContextNotActiveException.class)
  public void errorWhenContextNotActive() {
    ViewContext ctx = Beans.getReference(ViewContext.class);
    if (ctx.isActive()){
      ctx.deactivate();
    }
   
    EntityManager m1 = Beans.getReference(EntityManager.class, new NameQualifier("pu"));

    assertNotNull(m1);
View Full Code Here

TOP

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

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.