本文整理汇总了Java中javax.enterprise.inject.spi.Bean.create方法的典型用法代码示例。如果您正苦于以下问题:Java Bean.create方法的具体用法?Java Bean.create怎么用?Java Bean.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.enterprise.inject.spi.Bean
的用法示例。
在下文中一共展示了Bean.create方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newInstance
import javax.enterprise.inject.spi.Bean; //导入方法依赖的package包/类
private <T> T newInstance(final Bean<T> bean, final ReleaseCallbackHandler handler) {
final CreationalContextImpl<T> ctx = contextFor(bean, handler);
final T instance = bean.create(ctx);
ctx.addDependentInstance(new ContextualInstance<T>() {
@Override
public T getInstance() {
return instance;
}
@Override
public CreationalContext<T> getCreationalContext() {
return ctx;
}
@Override
public Contextual<T> getContextual() {
return bean;
}
});
return instance;
}
示例2: createAndDestroyFSShouldRegisterUnregisterOnPriorityDisposableRegistry
import javax.enterprise.inject.spi.Bean; //导入方法依赖的package包/类
@Test
public void createAndDestroyFSShouldRegisterUnregisterOnPriorityDisposableRegistry() throws Exception {
when(bm.getBeans("configIO")).thenReturn(configIOBeans);
when(bm.getReference(eq(ioServiceBean),
eq(IOService.class),
any(CreationalContext.class)))
.thenReturn(ioServiceMock);
when(ioServiceMock.newFileSystem(any(URI.class),
any(Map.class)))
.thenReturn(fs);
final Bean fileSystemBean = producer.createFileSystemBean(bm,
mock(InjectionTarget.class));
assertNull(PriorityDisposableRegistry.get("systemFS"));
fileSystemBean.create(mock(CreationalContext.class));
assertNotNull(PriorityDisposableRegistry.get("systemFS"));
fileSystemBean.destroy(fs,
mock(CreationalContext.class));
assertNull(PriorityDisposableRegistry.get("systemFS"));
}
示例3: getAllBeansOfType
import javax.enterprise.inject.spi.Bean; //导入方法依赖的package包/类
/**
* Searches the container for all beans of a certain type without respecting qualifiers.
*
* @param weldContainer the container providing the beans.
* @param type the type of the beans to search for.
* @return a collection of all found beans of the specified type.
*/
public static <T> Collection<T> getAllBeansOfType(WeldContainer weldContainer, Class<T> type) {
Collection<T> beans = Lists.newArrayList();
Set<Bean<?>> cdiBeans = weldContainer.getBeanManager().getBeans(type, AnyLiteral.INSTANCE);
// searches all beans for beans that have the matching goal name, ...
for (Bean<?> b : cdiBeans) {
@SuppressWarnings("unchecked")
Bean<T> b2 = (Bean<T>) b;
CreationalContext<T> creationalContext = weldContainer.getBeanManager().createCreationalContext(b2);
T bean = b2.create(creationalContext);
beans.add(bean);
}
return beans;
}
示例4: get
import javax.enterprise.inject.spi.Bean; //导入方法依赖的package包/类
@Override
public <T> T get(Contextual<T> contextual, CreationalContext<T> arg1) {
Bean<T> bean = (Bean<T>) contextual;
String variableName = bean.getName();
BusinessProcess businessProcess = getBusinessProcess();
Object variable = businessProcess.getVariable(variableName);
if (variable != null) {
if (LOGGER.isDebugEnabled()) {
if (businessProcess.isAssociated()) {
LOGGER.debug("Getting instance of bean '{}' from Execution[{}]", variableName, businessProcess.getExecutionId());
} else {
LOGGER.debug("Getting instance of bean '{}' from transient bean store", variableName);
}
}
return (T) variable;
} else {
if (LOGGER.isDebugEnabled()) {
if (businessProcess.isAssociated()) {
LOGGER.debug("Creating instance of bean '{}' in business process context representing Execution[{}]", variableName, businessProcess.getExecutionId());
} else {
LOGGER.debug("Creating instance of bean '{}' in transient bean store", variableName);
}
}
T beanInstance = bean.create(arg1);
businessProcess.setVariable(variableName, beanInstance);
return beanInstance;
}
}
示例5: get
import javax.enterprise.inject.spi.Bean; //导入方法依赖的package包/类
public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) {
Bean bean = (Bean) contextual;
// you can store the bean somewhere
if (somewhere.containsKey(bean.getName())) {
return (T) somewhere.get(bean.getName());
} else {
T t = (T) bean.create(creationalContext);
somewhere.put(bean.getName(), t);
return t;
}
}
示例6: 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;
}
示例7: get
import javax.enterprise.inject.spi.Bean; //导入方法依赖的package包/类
@Override
public <T> T get(Contextual<T> contextual, CreationalContext<T> arg1) {
Bean<T> bean = (Bean<T>) contextual;
String variableName = bean.getName();
BusinessProcess businessProcess = getBusinessProcess();
Object variable = businessProcess.getVariable(variableName);
if (variable != null) {
if (logger.isLoggable(Level.FINE)) {
if(businessProcess.isAssociated()) {
logger.fine("Getting instance of bean '" + variableName + "' from Execution[" + businessProcess.getExecutionId() + "].");
} else {
logger.fine("Getting instance of bean '" + variableName + "' from transient bean store");
}
}
return (T) variable;
} else {
if (logger.isLoggable(Level.FINE)) {
if(businessProcess.isAssociated()) {
logger.fine("Creating instance of bean '" + variableName + "' in business process context representing Execution["
+ businessProcess.getExecutionId() + "].");
} else {
logger.fine("Creating instance of bean '" + variableName + "' in transient bean store");
}
}
T beanInstance = bean.create(arg1);
businessProcess.setVariable(bean.getName(), beanInstance);
return beanInstance;
}
}
示例8: get
import javax.enterprise.inject.spi.Bean; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T get(Contextual<T> contextual, CreationalContext<T> arg1) {
Bean<T> bean = (Bean<T>) contextual;
String variableName = bean.getName();
Object variable = getBeanStore().getContextualInstance(variableName);
if (variable != null) {
return (T) variable;
} else {
T beanInstance = bean.create(arg1);
getBeanStore().put(variableName, beanInstance);
return beanInstance;
}
}
示例9: get
import javax.enterprise.inject.spi.Bean; //导入方法依赖的package包/类
@Override
public <T> T get(final Contextual<T> contextual,
final CreationalContext<T> creationalContext) {
Bean<T> bean = getBean(contextual);
Workspace workspace = this.getWorkspaceManager().getOrCreateWorkspace(getWorkspaceName());
final T instance = getWorkspaceManager().getBean(workspace,
bean.getBeanClass().getCanonicalName());
if (instance == null) {
if (logger.isTraceEnabled()) {
logger.trace("Creating Bean <<{}>> with creational context for workspace <<{}>>",
bean.getBeanClass(),
workspace.getName());
}
final T created = bean.create(creationalContext);
this.getWorkspaceManager().putBean(workspace,
bean.getBeanClass().getCanonicalName(),
created);
return created;
} else {
if (logger.isTraceEnabled()) {
logger.trace("Bean <<{}>> found for workspace <<{}>>",
bean.getBeanClass(),
workspace.getName());
}
Thread.currentThread().setName("WorkspaceScopeContext" + "-" + workspace.getName());
return instance;
}
}
示例10: getReference
import javax.enterprise.inject.spi.Bean; //导入方法依赖的package包/类
private <T> Object getReference(final Bean<T> bean, InjectionContext injectionContext) {
final CreationalContext<T> creationalContext = beanManager.createCreationalContext(bean);
if (Dependent.class.equals(bean.getScope())) {
final T reference = bean.create(creationalContext);
injectionContext.setRequestHandledCallback(() -> bean.destroy(reference, creationalContext));
return reference;
} else {
return beanManager.getReference(bean, Object.class, creationalContext);
}
}