本文整理匯總了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);
}
示例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;
}