`

ScopeType

    博客分类:
  • seam
阅读更多
 ScopeType与Context相关

/*
 * JBoss, Home of Professional Open Source
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jboss.seam;

import org.jboss.seam.contexts.Context;
import org.jboss.seam.contexts.Contexts;

/**
 * The scopes defined by Seam.
 * 
 * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
 */
public enum ScopeType
{
   /**
    * The stateless pseudo-context.
    */
   STATELESS,
   /**
    * The method context. Each call to a session bean or 
    * JavaBean component puts a new method context onto
    * the stack of method contexts associated with the
    * current thread. The context is destroyed (and the
    * stack popped) when the method returns.
    */
   METHOD,
   /**
    * The event (request) context. Spans a server request,
    * from restore view to render response.
    */
   EVENT,
   /**
    * The page context. Begins during the invoke application
    * phase prior to rendering a page, and lasts until the end 
    * of any invoke application phase of a faces request 
    * originating from that page. Non-faces requests do not
    * propagate the page scope.
    */
   PAGE,
   /**
    * The conversation context. Spans multiple requests from
    * the same browser window, demarcated by @Begin and @End
    * methods. A conversation context is propagated by
    * any faces request, or by any request that specifies
    * a conversation id as a request parameter. The conversation
    * context is not available during the restore view phase.
    */
   CONVERSATION,
   /**
    * The session context. (A servlet login session.)
    */
   SESSION,
   /**
    * The application context (Servlet context.)
    */
   APPLICATION,
   /**
    * The business process context. Spans multiple conversations
    * with multiple users, demarcated by the start and end states
    * of the business process definition.
    */
   BUSINESS_PROCESS,
   /**
    * Indicates that the scope is implied.
    */
   UNSPECIFIED;
   
   private final String prefix;

   private ScopeType()
   {
      prefix = "org.jboss.seam." + toString();
   }
   
   public boolean isContextActive()
   {
      switch (this)
      {
         case STATELESS:
            return true;
         case METHOD:
            return Contexts.isMethodContextActive();
         case EVENT:
            return Contexts.isEventContextActive();
         case PAGE:
            return Contexts.isPageContextActive();
         case CONVERSATION:
            return Contexts.isConversationContextActive();
         case SESSION:
            return Contexts.isSessionContextActive();
         case APPLICATION:
            return Contexts.isApplicationContextActive();
         case BUSINESS_PROCESS:
            return Contexts.isBusinessProcessContextActive();
         default: 
            throw new IllegalArgumentException();
      }
   }
   
   /**
    * @return the Context object for this scope
    */
   public Context getContext() {
      switch (this)
      {
         case STATELESS: 
            throw new UnsupportedOperationException("Stateless pseudo-scope does not have a Context object");
         case METHOD: 
            if ( !Contexts.isMethodContextActive() )
            {
               throw new IllegalStateException("No method context active");
            }
            return Contexts.getMethodContext();
         case EVENT: 
            if ( !Contexts.isEventContextActive() )
            {
               throw new IllegalStateException("No event context active");
            }
            return Contexts.getEventContext();
         case PAGE:
            if ( !Contexts.isPageContextActive() )
            {
               throw new IllegalStateException("No page context active");
            }
            return Contexts.getPageContext();
         case CONVERSATION: 
            if ( !Contexts.isConversationContextActive() )
            {
               throw new IllegalStateException("No conversation context active");
            }
            return Contexts.getConversationContext();
         case SESSION: 
            if ( !Contexts.isSessionContextActive() )
            {
               throw new IllegalStateException("No session context active");
            }
             return Contexts.getSessionContext();
         case APPLICATION: 
            if ( !Contexts.isApplicationContextActive() )
            {
               throw new IllegalStateException("No application context active");
            }
             return Contexts.getApplicationContext();
         case BUSINESS_PROCESS: 
            if ( !Contexts.isBusinessProcessContextActive() )
            {
               throw new IllegalStateException("No process context active");
            }
             return Contexts.getBusinessProcessContext();
         default: 
            throw new IllegalArgumentException();
      }
   }
   
   public String getPrefix()
   {
      return prefix;
   }

}



分享到:
评论

相关推荐

    seam 注解 pdf

    @Role(name="currentUser", scope=ScopeType.CONVERSATION) }) public class UserComponent { // 组件实现代码 } ``` - **解释**:使用`@Roles`注解可以更加简洁地定义多个额外的角色,提高代码的可读性。 ##...

    jboss-seam 注解

    `@Scope`注解用于定义组件的作用域,默认情况下,组件的作用域是由`ScopeType`枚举类型中的某个值来确定的。常见的作用域包括但不限于: - **EVENT**:每次请求时创建新的实例。 - **PAGE**:页面加载时创建并保留...

    Seam 例子 Hello World

    - `@ScopeType("conversation")`:指定组件的作用域为会话范围,这意味着它会在用户会话期间保持状态。 #### 八、配置和部署 - **Ant构建脚本**:使用Ant构建工具来编译项目,并生成可部署的`.ear`文件。 - **部署...

    struts中数据在action与jsp中的传递总结.pdf

    其形式是 setAttribute(“pageName”, orginName, scopeType);其中设置的 Bean,可以是一个任意的对象,或者对象组。这样我们就可以传输多条记录了。也可以使简单的类型。然后再 JSP 页面中,通过 JSP 标签,将数据...

    structs bean 标签

    &lt;s:bean name="beanName" action="actionName" scope="scopeType"&gt; &lt;!-- 可选的属性参数 --&gt; ``` - `name`:此属性指定JavaBean的名称,或者是在struts.xml配置文件中定义的Action的全限定类名。它是唯一标识bean...

    rdl:Ruby的类型,类型检查和协定

    在RDL中,类型可用于装饰方法: require 'rdl'extend RDL :: Annotate # add annotation methods to current scopetype '(Integer, Integer) -&gt; String'def m ( x , y ) ... end 这表明如果给定两个Integer参数,则...

    naturalize:Naturalize项目的源代码

    归化 Naturalize建议为源代码使用自然名称。 归化是根据BSD许可发布的。 该项目取决于三个内部(Maven)模块: a)b)c)d) 其余依赖项在maven依赖项中声明。 基本用法 ... ScopeType . SCOPE_LO

Global site tag (gtag.js) - Google Analytics