当前位置: 首页>>代码示例>>Java>>正文


Java Context类代码示例

本文整理汇总了Java中javax.enterprise.context.spi.Context的典型用法代码示例。如果您正苦于以下问题:Java Context类的具体用法?Java Context怎么用?Java Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Context类属于javax.enterprise.context.spi包,在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import javax.enterprise.context.spi.Context; //导入依赖的package包/类
@Override
public void run() {
    if (firstInit) {
        Context theContext = beanManager.getContext(bean.getScope());
        instance = theContext.get(bean);
        if (instance == null) {
            CreationalContext theCreational = beanManager.createCreationalContext(bean);
            instance = beanManager.getReference(bean, bean.getBeanClass(), theCreational);
        }
        firstInit = false;
    }
    try {
        method.invoke(instance, new Object[0]);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:mirkosertic,项目名称:cdicron,代码行数:18,代码来源:BeanMethodInvocationRunnable.java

示例2: addToReloadSet

import javax.enterprise.context.spi.Context; //导入依赖的package包/类
/**
 * Tries to add the bean in the context so it is reloaded in the next activation of the context.
 *
 * @param ctx
 * @param managedBean
 * @return
 */
@SuppressWarnings("unchecked")
public static boolean addToReloadSet(Context ctx,  Contextual<?> managedBean)  {
    try {
        LOGGER.debug("Adding bean '{}' to context '{}'", managedBean, ctx.getClass());
        Field toRedefine = ctx.getClass().getField("$$ha$toReloadOwb");
        Set toReload = Set.class.cast(toRedefine.get(ctx));
        if (toReload == null) {
            toReload = new HashSet();
            toRedefine.set(ctx, toReload);
        }
        toReload.add(managedBean);
        return true;
    } catch(Exception e) {
        LOGGER.warning("Context '{}' is not patched. Can not add bean '{}' to reload set", e, ctx, managedBean);
    }
    return false;
}
 
开发者ID:HotswapProjects,项目名称:HotswapAgent,代码行数:25,代码来源:ContextualReloadHelper.java

示例3: reinitialize

import javax.enterprise.context.spi.Context; //导入依赖的package包/类
/**
 * Will re-inject any managed beans in the target. Will not call any other life-cycle methods
 *
 * @param ctx
 * @param managedBean
 */
@SuppressWarnings("unchecked")
static void reinitialize(Context ctx, Contextual<Object> contextual) {
    try {
        ManagedBean<Object> managedBean = ManagedBean.class.cast(contextual);
        LOGGER.debug("Re-Initializing bean '{}' in context '{}'", managedBean, ctx);
        Object get = ctx.get(managedBean);
        if (get != null) {
            LOGGER.debug("Bean injection points are reinitialized '{}'", managedBean);
            CreationalContextImpl<Object> creationalContext = managedBean.getWebBeansContext().getCreationalContextFactory().getCreationalContext(managedBean);
            managedBean.getProducer().inject(get, creationalContext);
        }
    } catch (Exception e) {
        LOGGER.error("Error reinitializing bean '{}' in context '{}'", e, contextual, ctx);
    }
}
 
开发者ID:HotswapProjects,项目名称:HotswapAgent,代码行数:22,代码来源:ContextualReloadHelper.java

示例4: addToReloadSet

import javax.enterprise.context.spi.Context; //导入依赖的package包/类
/**
 * Tries to add the bean in the context so it is reloaded in the next activation of the context.
 *
 * @param ctx
 * @param managedBean
 * @return
 */
public static boolean addToReloadSet(Context ctx,  Contextual<Object> managedBean)  {
    try {
        LOGGER.debug("Adding bean in '{}' : {}", ctx.getClass(), managedBean);
        Field toRedefine = ctx.getClass().getDeclaredField("$$ha$toReloadWeld");
        Set toReload = Set.class.cast(toRedefine.get(ctx));
        if (toReload == null) {
            toReload = new HashSet();
            toRedefine.set(ctx, toReload);
        }
        toReload.add(managedBean);
        return true;
    } catch(Exception e) {
        LOGGER.warning("Context {} is not patched. Can not add {} to reload set", e, ctx, managedBean);
    }
    return false;
}
 
开发者ID:HotswapProjects,项目名称:HotswapAgent,代码行数:24,代码来源:ContextualReloadHelper.java

示例5: doReinjectSessionBasedBean

import javax.enterprise.context.spi.Context; //导入依赖的package包/类
private static void doReinjectSessionBasedBean(BeanManagerImpl beanManager, Class<?> beanClass, AbstractClassBean<?> bean) {
    Map<Class<? extends Annotation>, List<Context>> contexts = getContexts(beanManager);
    List<Context> contextList = contexts.get(SessionScoped.class);

    if (contextList != null && !contextList.isEmpty()) {
        for (Context ctx: contextList) {
            Context sessionCtx = PassivatingContextWrapper.unwrap(ctx);
            if (sessionCtx instanceof HttpSessionContextImpl) {
                doReinjectHttpSessionBasedBean(beanManager, beanClass, bean, (HttpSessionContextImpl) sessionCtx);
            } else if (sessionCtx instanceof BoundSessionContextImpl) {
                doReinjectBoundSessionBasedBean(beanManager, beanClass, bean, (BoundSessionContextImpl) sessionCtx);
            } else if (sessionCtx instanceof HttpSessionDestructionContext) {
                // HttpSessionDestructionContext is temporary used for HttpSession context destruction, we don't handle it
            } else {
                LOGGER.warning("Unexpected session context class '{}'.", sessionCtx.getClass().getName());
            }
        }
    } else {
        LOGGER.warning("No session context found in BeanManager.");
    }
}
 
开发者ID:HotswapProjects,项目名称:HotswapAgent,代码行数:22,代码来源:BeanReloadExecutor.java

示例6: iterator

import javax.enterprise.context.spi.Context; //导入依赖的package包/类
@Override
public Iterator<Object> iterator() {
    BeanManager beanManager = CDI.current().getBeanManager();

    Bean<WindowBeanHolder> bean = resolveBean(beanManager, WindowBeanHolder.class);
    if (bean != null) {
        Context sessionContext = beanManager.getContext(bean.getScope());
        if (sessionContext != null) {
            WindowBeanHolder beanHolder = sessionContext.get(bean);
            Map<String, ContextualStorage> storageMap = (Map<String, ContextualStorage>) ReflectionHelper.get(beanHolder, "storageMap");
            if (storageMap != null) {
                return new WindowContextsIterator(new ArrayList<String>(storageMap.keySet()));
            }
        } else {
            LOGGER.debug("No WindowBeanHolder found, no active session context.");
        }
    }
    return null;
}
 
开发者ID:HotswapProjects,项目名称:HotswapAgent,代码行数:20,代码来源:WindowContextsTracker.java

示例7: contextEntered

import javax.enterprise.context.spi.Context; //导入依赖的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

示例8: ensureRequestContextCanBeRestarted

import javax.enterprise.context.spi.Context; //导入依赖的package包/类
@Test
public void ensureRequestContextCanBeRestarted() throws Exception {
    final ApplicationComposers composers = new ApplicationComposers(EnsureRequestScopeThreadLocalIsCleanUpTest.class);
    composers.before(this);
    final CdiAppContextsService contextsService = CdiAppContextsService.class.cast(WebBeansContext.currentInstance().getService(ContextsService.class));
    final Context req1 = contextsService.getCurrentContext(RequestScoped.class);
    assertNotNull(req1);
    final Context session1 = contextsService.getCurrentContext(SessionScoped.class);
    assertNotNull(session1);
    contextsService.endContext(RequestScoped.class, null);
    contextsService.startContext(RequestScoped.class, null);
    final Context req2 = contextsService.getCurrentContext(RequestScoped.class);
    assertNotSame(req1, req2);
    final Context session2 = contextsService.getCurrentContext(SessionScoped.class);
    assertSame(session1, session2);
    composers.after();
    assertNull(contextsService.getCurrentContext(RequestScoped.class));
    assertNull(contextsService.getCurrentContext(SessionScoped.class));
}
 
开发者ID:apache,项目名称:tomee,代码行数:20,代码来源:EnsureRequestScopeThreadLocalIsCleanUpTest.java

示例9: testContextRegistered

import javax.enterprise.context.spi.Context; //导入依赖的package包/类
@Test
public void testContextRegistered() {
    JoynrJeeMessageContext.getInstance().activate();

    Context result = beanManager.getContext(JoynrJeeMessageScoped.class);

    assertNotNull(result);
    assertTrue(result instanceof JoynrJeeMessageContext);

    JoynrJeeMessageContext.getInstance().deactivate();
    try {
        result = beanManager.getContext(JoynrJeeMessageScoped.class);
        fail("Shouldn't get it after deactivation.");
    } catch (ContextNotActiveException e) {
        logger.trace("Context not available after deactivation as expected.");
    }
}
 
开发者ID:bmwcarit,项目名称:joynr,代码行数:18,代码来源:JoynrJeeMessageContextTest.java

示例10: lookup

import javax.enterprise.context.spi.Context; //导入依赖的package包/类
public Object lookup(String beanName, String sessionID) {

		NGSessionScopeContext.setCurrentContext(sessionID);

		Set<Bean<?>> beans = beanManager.getBeans(beanName);

		Class beanClass = CommonUtils.beanNamesHolder.get(beanName);
		if (beans.isEmpty()) {
			beans = beanManager.getBeans(beanClass, new AnnotationLiteral<Any>() { //
			});
		}

		Bean bean = beanManager.resolve(beans);

		Class scopeAnnotationClass = bean.getScope();
		Context context;

		if (scopeAnnotationClass.equals(RequestScoped.class)) {
			context = beanManager.getContext(scopeAnnotationClass);
			if (context == null)
				return bean.create(beanManager.createCreationalContext(bean));

		} else {

			if (scopeAnnotationClass.equals(NGSessionScopeContext.class)) {
				context = NGSessionScopeContext.getINSTANCE();
			} else {
				context = beanManager.getContext(scopeAnnotationClass);
			}

		}
		CreationalContext creationalContext = beanManager.createCreationalContext(bean);
		Object reference = context.get(bean, creationalContext);

		// if(reference==null && scopeAnnotationClass.equals(RequestScoped.class)){
		// reference= bean.create(beanManager.createCreationalContext(bean));
		// }

		return reference;
	}
 
开发者ID:bessemHmidi,项目名称:AngularBeans,代码行数:41,代码来源:BeanLocator.java

示例11: doReinjectSessionBasedBean

import javax.enterprise.context.spi.Context; //导入依赖的package包/类
private static void doReinjectSessionBasedBean(BeanManagerImpl beanManager, Class<?> beanClass, InjectionTargetBean<?> bean) {

        ContextsService contextsService = beanManager.getWebBeansContext().getContextsService();

        // SessionContextsTracker can't be directly used here, since it may not be in the visible class loader (Tomee)
        // therefore inner Iterator is used as workaround
        Object sessionContextsTracker =
                ReflectionHelper.get(contextsService, WebBeansContextsServiceTransformer.SESSION_CONTEXTS_TRACKER_FIELD);

        if (sessionContextsTracker != null) {
            try {
                Iterator<?> sessionContextIterator = ((Iterable<?> ) sessionContextsTracker).iterator();
                while (sessionContextIterator.hasNext()) {
                    sessionContextIterator.next(); // Set next active session context
                    Context sessionContext = beanManager.getContext(SessionScoped.class);
                    if (bean.getScope() == SessionScoped.class) {
                        doReinjectBeanInstance(beanManager, beanClass, bean, sessionContext);
                    } else {
                        doReinjectCustomScopedBean(beanManager, beanClass, bean, sessionContext);
                    }
                    SessionScopedBeanInterceptorHandler.removeThreadLocals();
                }
            } finally {
                contextsService.removeThreadLocals();
            }
        } else {
            LOGGER.error("Field '{}' not found in class '{}'", WebBeansContextsServiceTransformer.SESSION_CONTEXTS_TRACKER_FIELD,
                    contextsService.getClass().getName());
        }
    }
 
开发者ID:HotswapProjects,项目名称:HotswapAgent,代码行数:31,代码来源:BeanClassRefreshAgent.java

示例12: doReinjectBeanInstance

import javax.enterprise.context.spi.Context; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
private static void doReinjectBeanInstance(BeanManagerImpl beanManager, Class<?> beanClass, InjectionTargetBean bean, Context context) {
    Object instance = context.get(bean);
    if (instance != null) {
        bean.getProducer().inject(instance, beanManager.createCreationalContext(bean));
        LOGGER.info("Bean '{}' injection points was reinjected.", beanClass.getName());
    }
}
 
开发者ID:HotswapProjects,项目名称:HotswapAgent,代码行数:9,代码来源:BeanClassRefreshAgent.java

示例13: getContextMap

import javax.enterprise.context.spi.Context; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
private static Map<Class<? extends Annotation>, List<Context>> getContextMap(BeanManagerImpl beanManagerImpl){
    try {
        Field contextsField = BeanManagerImpl.class.getField("contextMap");
        contextsField.setAccessible(true);
        return (Map) contextsField.get(beanManagerImpl);
    } catch (IllegalAccessException |IllegalArgumentException | NoSuchFieldException | SecurityException e) {
        LOGGER.warning("Field BeanManagerImpl.contextMap is not accessible", e);
    }
    return Collections.emptyMap();
}
 
开发者ID:HotswapProjects,项目名称:HotswapAgent,代码行数:12,代码来源:BeanClassRefreshAgent.java

示例14: getSingleContextMap

import javax.enterprise.context.spi.Context; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
private static Map<Class<? extends Annotation>, Context> getSingleContextMap(BeanManagerImpl beanManagerImpl){
    try {
        Field contextsField = BeanManagerImpl.class.getField("singleContextMap");
        contextsField.setAccessible(true);
        return (Map) contextsField.get(beanManagerImpl);
    } catch (IllegalAccessException |IllegalArgumentException | NoSuchFieldException | SecurityException e) {
        LOGGER.warning("Field BeanManagerImpl.singleContextMap is not accessible", e);
    }
    return Collections.emptyMap();
}
 
开发者ID:HotswapProjects,项目名称:HotswapAgent,代码行数:12,代码来源:BeanClassRefreshAgent.java

示例15: doReloadBeanInContext

import javax.enterprise.context.spi.Context; //导入依赖的package包/类
private static void doReloadBeanInContext(BeanManagerImpl beanManager, Class<?> beanClass, InjectionTargetBean bean, Context context) {
    if (ContextualReloadHelper.addToReloadSet(context, bean)) {
        LOGGER.debug("Bean {}, added to reload set in context '{}'", bean, context.getClass());
    } else {
        // fallback: try to reinitialize injection points instead...
        doReinjectBeanInstance(beanManager, beanClass, bean, context);
    }
}
 
开发者ID:HotswapProjects,项目名称:HotswapAgent,代码行数:9,代码来源:BeanClassRefreshAgent.java


注:本文中的javax.enterprise.context.spi.Context类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。