當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。