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


Java Bean.getScope方法代码示例

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


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

示例1: processBean

import javax.enterprise.inject.spi.Bean; //导入方法依赖的package包/类
/**
 * Process a bean. Checks the bean for @Service annotation and if it is found, verifies
 * the bean scope and marks it for export as service at a later stage.
 *
 * @param event The process bean event. See CDI specification
 * @param <T> The type of the bean
 */
public <T> void processBean(@Observes ProcessBean<T> event) {
    Bean<T> bean = event.getBean();
    Service service = BeanExporter.getServiceDefinition(bean);
    if (service == null) {
        return;
    }
    // Check the scope. Must be global.
    Class<? extends Annotation> scope = bean.getScope();
    if (!scope.equals(ComponentScoped.class) && !scope.equals(ApplicationScoped.class)) {
        // Set an error.
        event.addDefinitionError(new Exception("beans annotated with @Service must have a global scope"));
        return;
    }
    // Mark the bean as exportable.
    exportedBeans.put(bean, null);
}
 
开发者ID:arievanwi,项目名称:osgi.ee,代码行数:24,代码来源:ServiceExtension.java

示例2: lookup

import javax.enterprise.inject.spi.Bean; //导入方法依赖的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


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