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


Java Context.get方法代码示例

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


在下文中一共展示了Context.get方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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
 */
public static void reinitialize(Context ctx, Contextual<Object> contextual) {
    try {
        ManagedBean<Object> managedBean = ManagedBean.class.cast(contextual);
        LOGGER.debug("Re-Initializing........ {},: {}", managedBean, ctx);
        Object get = ctx.get(managedBean);
        if (get != null) {
            LOGGER.debug("Bean injection points are reinitialized '{}'", managedBean);
            managedBean.getProducer().inject(get, managedBean.getBeanManager().createCreationalContext(managedBean));
        }
    } catch (Exception e) {
        LOGGER.error("Error reinitializing bean {},: {}", e, contextual, ctx);
    }
}
 
开发者ID:HotswapProjects,项目名称:HotswapAgent,代码行数:20,代码来源:ContextualReloadHelper.java

示例7: doReinjectBeanInstance

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

示例8: getSessionBeanProxy

import javax.enterprise.context.spi.Context; //导入方法依赖的package包/类
@Override
public Object getSessionBeanProxy(final Bean<?> inBean, final Class<?> interfce, final CreationalContext<?> creationalContext) {
    Object instance = cacheProxies.get(inBean);
    if (instance != null) {
        return instance;
    }

    synchronized (inBean) { // singleton for the app so safe to sync on it
        instance = cacheProxies.get(inBean);
        if (instance != null) {
            return instance;
        }

        final Class<? extends Annotation> scopeClass = inBean.getScope();
        final CdiEjbBean<Object> cdiEjbBean = (CdiEjbBean<Object>) inBean;
        final CreationalContext<Object> cc = (CreationalContext<Object>) creationalContext;

        if (scopeClass == null || Dependent.class == scopeClass) { // no need to add any layer, null = @New
            return cdiEjbBean.createEjb(cc);
        }

        // only stateful normally
        final InstanceBean<Object> bean = new InstanceBean<Object>(cdiEjbBean);
        if (webBeansContext.getBeanManagerImpl().isNormalScope(scopeClass)) {
            final BeanContext beanContext = cdiEjbBean.getBeanContext();
            final Provider provider = webBeansContext.getNormalScopeProxyFactory().getInstanceProvider(beanContext.getClassLoader(), cdiEjbBean);

            if (!beanContext.isLocalbean()) {
                final List<Class> interfaces = new ArrayList<Class>();
                final InterfaceType type = beanContext.getInterfaceType(interfce);
                if (type != null) {
                    interfaces.addAll(beanContext.getInterfaces(type));
                } else { // can happen when looked up from impl instead of API in OWB -> default to business local
                    interfaces.addAll(beanContext.getInterfaces(InterfaceType.BUSINESS_LOCAL));
                }
                interfaces.add(Serializable.class);
                interfaces.add(IntraVmProxy.class);
                if (BeanType.STATEFUL.equals(beanContext.getComponentType()) || BeanType.MANAGED.equals(beanContext.getComponentType())) {
                    interfaces.add(BeanContext.Removable.class);
                }

                try {
                    instance = ProxyManager.newProxyInstance(interfaces.toArray(new Class<?>[interfaces.size()]), new InvocationHandler() {
                        @Override
                        public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
                            try {
                                return method.invoke(provider.get(), args);
                            } catch (final InvocationTargetException ite) {
                                throw ite.getCause();
                            }
                        }
                    });
                } catch (final IllegalAccessException e) {
                    throw new OpenEJBRuntimeException(e);
                }

            } else {
                final NormalScopeProxyFactory normalScopeProxyFactory = webBeansContext.getNormalScopeProxyFactory();
                final Class<?> proxyClass = normalScopeProxyFactory.createProxyClass(beanContext.getClassLoader(), beanContext.getBeanClass());
                instance = normalScopeProxyFactory.createProxyInstance(proxyClass, provider);
            }

            cacheProxies.put(inBean, instance);
        } else {
            final Context context = webBeansContext.getBeanManagerImpl().getContext(scopeClass);
            instance = context.get(bean, cc);
        }
        bean.setOwbProxy(instance);
        return instance;
    }
}
 
开发者ID:apache,项目名称:tomee,代码行数:72,代码来源:CdiPlugin.java

示例9: createAndMutate

import javax.enterprise.context.spi.Context; //导入方法依赖的package包/类
private <T extends Message> T createAndMutate(final Context context, final Class<T> beanType) {

        final Bean<T> bean = (Bean<T>) beanManager.getBeans(beanType).iterator().next();

        // We haven't created anything yet, so the instance should not exist in the context
        assertNull(context.get(bean));


        final CreationalContext<T> cc1 = beanManager.createCreationalContext(bean);

        // This should create the instance and put it in the context
        final T instance = context.get(bean, cc1);


        // Assert the instance is now in the context and can be generically retrieved
        assertNotNull(context.get(bean));


        final String prefix = beanType.getSimpleName();

        // Mutate the instance...
        instance.setMessage(prefix + ": hello application");

        // Now check the reference in the context
        assertEquals(prefix + ": hello application", context.get(bean, cc1).getMessage());

        // Attempt to create a second instance (should not work)
        final CreationalContext<T> cc2 = beanManager.createCreationalContext(bean);

        // We should still have the same mutated instance as before
        assertEquals(prefix + ": hello application", context.get(bean, cc2).getMessage());

        // Mutate the instance one more time
        instance.setMessage(prefix + ": hello again application");

        // And double check that we still just have the single instance in the context
        assertEquals(prefix + ": hello again application", context.get(bean).getMessage());
        assertEquals(prefix + ": hello again application", context.get(bean, null).getMessage());
        assertEquals(prefix + ": hello again application", context.get(bean, cc1).getMessage());
        assertEquals(prefix + ": hello again application", context.get(bean, cc2).getMessage());

        return instance;
    }
 
开发者ID:apache,项目名称:tomee,代码行数:44,代码来源:ApplicationScopedTest.java


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