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


Java Bean.create方法代码示例

本文整理汇总了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;
}
 
开发者ID:dajudge,项目名称:testee.fi,代码行数:22,代码来源:DependencyInjectionRealm.java

示例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"));
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:27,代码来源:SystemConfigProducerTest.java

示例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;
}
 
开发者ID:shillner,项目名称:maven-cdi-plugin-utils,代码行数:21,代码来源:CDIUtil.java

示例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;
    }

}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:35,代码来源:BusinessProcessContext.java

示例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;
    }
}
 
开发者ID:Salaboy,项目名称:drools-workshop,代码行数:12,代码来源:BusinessScopeContext.java

示例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;
	}
 
开发者ID:bessemHmidi,项目名称:AngularBeans,代码行数:41,代码来源:BeanLocator.java

示例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;
  }

}
 
开发者ID:logicalhacking,项目名称:SecureBPMN,代码行数:36,代码来源:BusinessProcessContext.java

示例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;
  }
}
 
开发者ID:logicalhacking,项目名称:SecureBPMN,代码行数:14,代码来源:ThreadContext.java

示例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;
    }
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:32,代码来源:WorkspaceScopeContext.java

示例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);
        }
    }
 
开发者ID:undertow-io,项目名称:undertow.js,代码行数:13,代码来源:CDIInjectionProvider.java


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