當前位置: 首頁>>代碼示例>>Java>>正文


Java RequestScoped類代碼示例

本文整理匯總了Java中javax.enterprise.context.RequestScoped的典型用法代碼示例。如果您正苦於以下問題:Java RequestScoped類的具體用法?Java RequestScoped怎麽用?Java RequestScoped使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RequestScoped類屬於javax.enterprise.context包,在下文中一共展示了RequestScoped類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: producePrincipal

import javax.enterprise.context.RequestScoped; //導入依賴的package包/類
@Produces
@RequestScoped
@Named("userPrincipal")
public UserPrincipal producePrincipal() {
    Object principal = SecurityUtils.getSubject().getPrincipal();
    UserPrincipal result = null;
    if (principal instanceof UserPrincipal) {

        result = (UserPrincipal) principal;
    }
    /*
    FIXME
    if (principal instanceof SystemAccountPrincipal) {
        SystemAccountPrincipal systemAccountPrincipal = (SystemAccountPrincipal) principal;
        String identifier = systemAccountPrincipal.getIdentifier();
        result = new UserPrincipal(identifier);
    }
    */
    if (principal == null) {
        result = new UserPrincipal();
    }
    return result;
}
 
開發者ID:atbashEE,項目名稱:atbash-octopus,代碼行數:24,代碼來源:ProducerBean.java

示例2: resolveScopeMetadata

import javax.enterprise.context.RequestScoped; //導入依賴的package包/類
@Override
public ScopeMetadata resolveScopeMetadata(final BeanDefinition definition) {

    if (definition instanceof AnnotatedBeanDefinition) {
        final AnnotatedBeanDefinition beanDefinition = (AnnotatedBeanDefinition) definition;
        final ScopeMetadata metadata = new ScopeMetadata();
        final Set<String> annotationTypes = beanDefinition.getMetadata().getAnnotationTypes();

        if (annotationTypes.contains(RequestScoped.class
            .getName())) {
            metadata.setScopeName("request");
            metadata.setScopedProxyMode(ScopedProxyMode.TARGET_CLASS);
        } else if (annotationTypes
            .contains(ApplicationScoped.class.getName())) {
            metadata.setScopeName("singleton");
        } else {
            return super.resolveScopeMetadata(definition);
        }
        return metadata;
    } else {
        return super.resolveScopeMetadata(definition);
    }
}
 
開發者ID:trajano,項目名稱:app-ms,代碼行數:24,代碼來源:CdiScopeMetadataResolver.java

示例3: applyBeforeFeatureConfig

import javax.enterprise.context.RequestScoped; //導入依賴的package包/類
void applyBeforeFeatureConfig(Class testClass) {
    CdiContainer container = CdiContainerLoader.getCdiContainer();

    if (!isContainerStarted()) {
        container.boot(CdiTestSuiteRunner.getTestContainerConfig());
        containerStarted = true;
        bootExternalContainers(testClass);
    }

    List<Class<? extends Annotation>> restrictedScopes = new ArrayList<Class<? extends Annotation>>();

    //controlled by the container and not supported by weld:
    restrictedScopes.add(ApplicationScoped.class);
    restrictedScopes.add(Singleton.class);

    if (this.parent == null && this.testControl.getClass().equals(TestControlLiteral.class)) {
        //skip scope-handling if @TestControl isn't used explicitly on the test-class -> TODO re-visit it
        restrictedScopes.add(RequestScoped.class);
        restrictedScopes.add(SessionScoped.class);
    }

    this.previousProjectStage = ProjectStageProducer.getInstance().getProjectStage();
    ProjectStageProducer.setProjectStage(this.projectStage);

    startScopes(container, testClass, null, restrictedScopes.toArray(new Class[restrictedScopes.size()]));
}
 
開發者ID:database-rider,項目名稱:database-rider,代碼行數:27,代碼來源:CdiCucumberTestRunner.java

示例4: createClient

import javax.enterprise.context.RequestScoped; //導入依賴的package包/類
@Produces
@RequestScoped
public BlazeStorage createClient() {
	URI uri = URI.create(httpServletRequest.getRequestURL().toString());
	String contextPath = httpServletRequest.getContextPath();
	String basePath = "/api";
	
	if (contextPath != null) {
		basePath = contextPath + basePath;
	}
	
	try {
		uri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), basePath, null, null);
    } catch (URISyntaxException x) {
        throw new IllegalArgumentException(x.getMessage(), x);
    }
	
	return BlazeStorageClient.getInstance(uri.toString());
}
 
開發者ID:Blazebit,項目名稱:blaze-storage,代碼行數:20,代碼來源:AlwaysAdminBlazeStorageProducer.java

示例5: getStorageQuotaPlanItems

import javax.enterprise.context.RequestScoped; //導入依賴的package包/類
@Produces
@Named("storageQuotaPlanItems")
@RequestScoped
public List<SelectItem> getStorageQuotaPlanItems() {
	List<StorageQuotaModelListElementRepresentation> quotaModels = storage.storageQuotaModels().get();
	List<SelectItem> quotaModelPlanItems = new ArrayList<>(quotaModels.size());
	
	for (StorageQuotaModelListElementRepresentation quotaModel : quotaModels) {
		SelectItemGroup group = new SelectItemGroup(quotaModel.getName());
		List<SelectItem> groupItems = new ArrayList<>(quotaModel.getLimits().size());
		
		for (Integer limit : quotaModel.getLimits()) {
			groupItems.add(new SelectItem(new StorageQuotaPlanChoiceRepresentation(quotaModel.getId(), limit), limit + " GB"));
		}
		
		group.setSelectItems(groupItems.toArray(new SelectItem[groupItems.size()]));
		quotaModelPlanItems.add(group);
	}
	
	return quotaModelPlanItems;
}
 
開發者ID:Blazebit,項目名稱:blaze-storage,代碼行數:22,代碼來源:QuotaSupport.java

示例6: releaseResources

import javax.enterprise.context.RequestScoped; //導入依賴的package包/類
@Override
protected void releaseResources() {
    for (Listener l : listenerList) {
        try {
            l.onDestroy(this);
        } catch (Exception e) {
            warn(e, "error calling listener onDestroy method");
        }
    }
    Destroyable.Util.destroyAll(destroyableList, RequestScoped.class);
    Destroyable.Util.tryDestroyAll(attributes.values(), RequestScoped.class);
    this.attributes.clear();
    this.renderArgs.clear();
    this.template = null;
    this.app = null;
    this.template = null;
    this.listenerList.clear();
    this.destroyableList.clear();
    this.violations.clear();
    // note we can't destroy progress as it might still be used
    // by background thread
    //this.progress.destroy();
}
 
開發者ID:actframework,項目名稱:actframework,代碼行數:24,代碼來源:ActContext.java

示例7: scope

import javax.enterprise.context.RequestScoped; //導入依賴的package包/類
public Class<? extends Annotation> scope() {
    if (null == scope) {
        synchronized (this) {
            if (null == scope) {
                Class<?> c = getClass();
                if (c.isAnnotationPresent(RequestScoped.class)) {
                    scope = RequestScoped.class;
                } else if (c.isAnnotationPresent(SessionScoped.class)) {
                    scope = SessionScoped.class;
                } else if (c.isAnnotationPresent(ApplicationScoped.class)) {
                    scope = ApplicationScoped.class;
                } else {
                    scope = NormalScope.class;
                }
            }
        }
    }
    return scope;
}
 
開發者ID:actframework,項目名稱:actframework,代碼行數:20,代碼來源:DestroyableBase.java

示例8: startRequestScope

import javax.enterprise.context.RequestScoped; //導入依賴的package包/類
@AroundInvoke
public Object startRequestScope(final InvocationContext ctx) throws Exception {
    Object result = null;
    ContextControl contextControl = null;
    if(!isRequestScopeActive()) {
        contextControl = CDI.current().select(ContextControl.class).get();
        contextControl.startContext(RequestScoped.class);
    }
    try {
        result = ctx.proceed();
    }
    finally {
        if(contextControl != null) {
            contextControl.stopContext(RequestScoped.class);
        }
    }
    return result;
}
 
開發者ID:johnament,項目名稱:restful-and-beyond-tut2184,代碼行數:19,代碼來源:RequestScopeInterceptor.java

示例9: testRequestScopedBeanPerformance

import javax.enterprise.context.RequestScoped; //導入依賴的package包/類
@Test(priority = 3)
public void testRequestScopedBeanPerformance() throws InterruptedException
{
    final SimpleRequestScopedBeanWithoutInterceptor underTest = getInstance(cdiContainer.getBeanManager(), SimpleRequestScopedBeanWithoutInterceptor.class);
    final ContextControl contextControl = cdiContainer.getContextControl();
    contextControl.startContext(RequestScoped.class);
    Assert.assertEquals(underTest.theMeaningOfLife(), 42);
    contextControl.stopContext(RequestScoped.class);

    executeInParallel("invocation on @RequestScoped bean", new Runnable()
    {

        @Override
        public void run()
        {
            contextControl.startContext(RequestScoped.class);
            for (int i = 0; i < NUM_ITERATION; i++)
            {
                // this line does the actual bean invocation.
                underTest.theMeaningOfLife();
            }
            contextControl.stopContext(RequestScoped.class);
        }
    });
}
 
開發者ID:struberg,項目名稱:cdi-performance,代碼行數:26,代碼來源:CdiPerformanceTest.java

示例10: provide

import javax.enterprise.context.RequestScoped; //導入依賴的package包/類
/**
 * Provides an EntityManager for this Model.
 *
 * @return new EntityManager
 */
@Override
@RequestScoped
public EntityManager provide() {
  // hk2
  final EntityManager instance = getEntityManager();

  if (closeableService != null) {
    closeableService.add(new Closeable() {
      @Override
      public void close() throws IOException {
        dispose(instance);
      }
    });
  }
  return instance;
}
 
開發者ID:vita-us,項目名稱:ViTA,代碼行數:22,代碼來源:Model.java

示例11: checkDependentScope

import javax.enterprise.context.RequestScoped; //導入依賴的package包/類
/**
 * Checks if a custom resolver method injected parameter scope is {@link Dependent}
 * 
 * @param type
 *            The parameter type being checked
 * @return Returns true if the paraeter scope is {@link Dependent}
 */
private boolean checkDependentScope(Class<?> type) {
    for (Annotation annotation : type.getAnnotations()) {
        if (annotation.annotationType().equals(SessionScoped.class) || annotation.annotationType().equals(RequestScoped.class)
                || annotation.annotationType().equals(ApplicationScoped.class)) {
            return false;
        }
        Class<?> viewScopedClass = null;
        try {
            // Account for JEE 7 @ViewScoped scope
            viewScopedClass = Class.forName("javax.faces.view.ViewScoped");
        } catch (Exception e) {
            // JEE 6 environment
            if (logger.isDebugEnabled()) {
                logger.debug("Class javax.faces.view.ViewScoped was not found: Running in a Java EE 6 environment.");
            }
        }
        if (viewScopedClass != null) {
            if (annotation.annotationType().equals(viewScopedClass)) {
                return false;
            }
        }
    }
    return true;
}
 
開發者ID:gonmarques,項目名稱:cdi-properties,代碼行數:32,代碼來源:DependentResolverMethodParametersVerifier.java

示例12: beforeStopApplication

import javax.enterprise.context.RequestScoped; //導入依賴的package包/類
public void beforeStopApplication(Object endObject)
{
    WebBeansContext webBeansContext = getWebBeansContext();
    ContextsService contextsService = webBeansContext.getContextsService();
    contextsService.endContext(Singleton.class, null);
    contextsService.endContext(ApplicationScoped.class, null);
    contextsService.endContext(RequestScoped.class, null);
    contextsService.endContext(SessionScoped.class, mockHttpSession);

    ELContextStore elStore = ELContextStore.getInstance(false);
    if (elStore == null)
    {
        return;
    }
    elStore.destroyELContextStore();
}
 
開發者ID:HotswapProjects,項目名稱:HotswapAgent,代碼行數:17,代碼來源:HAOpenWebBeansTestLifeCycle.java

示例13: requestInitialized

import javax.enterprise.context.RequestScoped; //導入依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public void requestInitialized(final ServletRequestEvent event) {
    final Object oldContext = ThreadSingletonServiceImpl.enter(this.webBeansContext);
    if (event != null) {
        event.getServletRequest().setAttribute(contextKey, oldContext);
    }

    try {
        if (logger.isDebugEnabled()) {
            logger.debug("Starting a new request : [{0}]", event == null ? "null" : event.getServletRequest().getRemoteAddr());
        }

        if (webBeansContext instanceof WebappWebBeansContext) { // start before child
            ((WebappWebBeansContext) webBeansContext).getParent().getContextsService().startContext(RequestScoped.class, event);
        }
        contextsService.startContext(RequestScoped.class, event);

        // we don't initialise the Session here but do it lazily if it gets requested
        // the first time. See OWB-457

    } catch (final Exception e) {
        logger.error(OWBLogConst.ERROR_0019, event == null ? "null" : event.getServletRequest());
        WebBeansUtil.throwRuntimeExceptions(e);
    }
}
 
開發者ID:apache,項目名稱:tomee,代碼行數:29,代碼來源:BeginWebBeansListener.java

示例14: startContext

import javax.enterprise.context.RequestScoped; //導入依賴的package包/類
@Override
public void startContext(Class<? extends Annotation> scopeClass)
{
    if (scopeClass.isAssignableFrom(ApplicationScoped.class))
    {
        startApplicationScope();
    }
    else if (scopeClass.isAssignableFrom(SessionScoped.class))
    {
        startSessionScope();
    }
    else if (scopeClass.isAssignableFrom(RequestScoped.class))
    {
        startRequestScope();
    }
    else if (scopeClass.isAssignableFrom(ConversationScoped.class))
    {
        startConversationScope(null);
    }
}
 
開發者ID:apache,項目名稱:deltaspike,代碼行數:21,代碼來源:WeldContextControl.java

示例15: contextEntered

import javax.enterprise.context.RequestScoped; //導入依賴的package包/類
@Override
public void contextEntered(final ThreadContext oldContext, final ThreadContext newContext) {

    final BeanContext beanContext = newContext.getBeanContext();

    final WebBeansContext webBeansContext = beanContext.getModuleContext().getAppContext().getWebBeansContext();
    if (webBeansContext == null) {
        return;
    }

    final ContextsService contextsService = webBeansContext.getContextsService();

    final Context requestContext = CdiAppContextsService.class.cast(contextsService).getRequestContext(false);

    if (requestContext == null) {
        contextsService.startContext(RequestScoped.class, CdiAppContextsService.EJB_REQUEST_EVENT);
        newContext.set(DestroyContext.class, new DestroyContext(contextsService, newContext));
    }
}
 
開發者ID:apache,項目名稱:tomee,代碼行數:20,代碼來源:RequestScopedThreadContextListener.java


注:本文中的javax.enterprise.context.RequestScoped類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。