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