當前位置: 首頁>>代碼示例>>Java>>正文


Java BeanManager.createCreationalContext方法代碼示例

本文整理匯總了Java中javax.enterprise.inject.spi.BeanManager.createCreationalContext方法的典型用法代碼示例。如果您正苦於以下問題:Java BeanManager.createCreationalContext方法的具體用法?Java BeanManager.createCreationalContext怎麽用?Java BeanManager.createCreationalContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.enterprise.inject.spi.BeanManager的用法示例。


在下文中一共展示了BeanManager.createCreationalContext方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testInjectionTarget

import javax.enterprise.inject.spi.BeanManager; //導入方法依賴的package包/類
@Test
public void testInjectionTarget() {
	BeanManager beanManager = current().getBeanManager();
	// CDI uses an AnnotatedType object to read the annotations of a class
	AnnotatedType<String> type = beanManager.createAnnotatedType(String.class);
	// The extension uses an InjectionTarget to delegate instantiation,
	// dependency injection
	// and lifecycle callbacks to the CDI container
	InjectionTarget<String> it = beanManager.createInjectionTarget(type);
	// each instance needs its own CDI CreationalContext
	CreationalContext<String> ctx = beanManager.createCreationalContext(null);
	// instantiate the framework component and inject its dependencies
	String instance = it.produce(ctx); // call the constructor
	it.inject(instance, ctx); // call initializer methods and perform field
								// injection
	it.postConstruct(instance); // call the @PostConstruct method
	// destroy the framework component instance and clean up dependent
	// objects
	assertNotNull("the String instance is injected now", instance);
	assertTrue("the String instance is injected now but it's empty", instance.isEmpty());
	it.preDestroy(instance); // call the @PreDestroy method
	it.dispose(instance); // it is now safe to discard the instance
	ctx.release(); // clean up dependent objects
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Java-EE-Development-with-WildFly,代碼行數:25,代碼來源:InjectSPITestCase.java

示例2: getInstancesByType

import javax.enterprise.inject.spi.BeanManager; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public <T> List<T> getInstancesByType(Class<T> clazz) {
	BeanManager beanManager = getBeanManager();

	Type type = clazz;
	if (clazz == JsonApiExceptionMapper.class) {
		TypeLiteral<JsonApiExceptionMapper<?>> typeLiteral = new TypeLiteral<JsonApiExceptionMapper<?>>() {
		};
		type = typeLiteral.getType();
	}

	Set<Bean<?>> beans = beanManager.getBeans(type);
	List<T> list = new ArrayList<>();
	for (Bean<?> bean : beans) {
		CreationalContext<?> creationalContext = beanManager.createCreationalContext(bean);
		T object = (T) beanManager.getReference(bean, type, creationalContext);
		list.add(object);
	}
	return list;
}
 
開發者ID:crnk-project,項目名稱:crnk-framework,代碼行數:22,代碼來源:CdiServiceDiscovery.java

示例3: getInstancesByAnnotation

import javax.enterprise.inject.spi.BeanManager; //導入方法依賴的package包/類
@Override
public <A extends Annotation> List<Object> getInstancesByAnnotation(Class<A> annotationClass) {
	BeanManager beanManager = getBeanManager();
	Set<Bean<?>> beans = beanManager.getBeans(Object.class);
	List<Object> list = new ArrayList<>();
	for (Bean<?> bean : beans) {
		Class<?> beanClass = bean.getBeanClass();
		Optional<A> annotation = ClassUtils.getAnnotation(beanClass, annotationClass);
		if (annotation.isPresent()) {
			CreationalContext<?> creationalContext = beanManager.createCreationalContext(bean);
			Object object = beanManager.getReference(bean, beanClass, creationalContext);
			list.add(object);
		}
	}
	return list;
}
 
開發者ID:crnk-project,項目名稱:crnk-framework,代碼行數:17,代碼來源:CdiServiceDiscovery.java

示例4: getBean

import javax.enterprise.inject.spi.BeanManager; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public static <T> T getBean(Class<T> clazz) {
	BeanManager bm = getBeanManager();
	Set<Bean<?>> beans = bm.getBeans(clazz);

	if (beans == null || beans.isEmpty()) {
		return null;
	}

	Bean<T> bean = (Bean<T>) beans.iterator().next();

	CreationalContext<T> ctx = bm.createCreationalContext(bean);
	T o = (T) bm.getReference(bean, clazz, ctx);

	return o;
}
 
開發者ID:marcelothebuilder,項目名稱:webpedidos,代碼行數:17,代碼來源:CDIServiceLocator.java

示例5: getInstancesByAnnotation

import javax.enterprise.inject.spi.BeanManager; //導入方法依賴的package包/類
@Override
public <A extends Annotation> List<Object> getInstancesByAnnotation(Class<A> annotationClass) {
	BeanManager beanManager = CDI.current().getBeanManager();
	Set<Bean<?>> beans = beanManager.getBeans(Object.class);
	List<Object> list = new ArrayList<>();
	for (Bean<?> bean : beans) {
		Class<?> beanClass = bean.getBeanClass();
		Optional<A> annotation = ClassUtils.getAnnotation(beanClass, annotationClass);
		if (annotation.isPresent()) {
			CreationalContext<?> creationalContext = beanManager.createCreationalContext(bean);
			Object object = beanManager.getReference(bean, beanClass, creationalContext);
			list.add(object);
		}
	}
	return list;
}
 
開發者ID:katharsis-project,項目名稱:katharsis-framework,代碼行數:17,代碼來源:CdiServiceDiscovery.java

示例6: inject

import javax.enterprise.inject.spi.BeanManager; //導入方法依賴的package包/類
void inject() {
    BeanManager beanManager = container.getBeanManager();
    CreationalContext<Object> ctx = beanManager.createCreationalContext(null);
    @SuppressWarnings("unchecked")
    InjectionTarget<Object> injectionTarget = (InjectionTarget<Object>) beanManager
            .getInjectionTargetFactory(beanManager.createAnnotatedType(instance.getClass())).createInjectionTarget(null);
    injectionTarget.inject(instance, ctx);
    creationalContext = ctx;
}
 
開發者ID:weld,項目名稱:weld-junit,代碼行數:10,代碼來源:AbstractWeldInitiator.java

示例7: locate

import javax.enterprise.inject.spi.BeanManager; //導入方法依賴的package包/類
@Override
public JsonDriver locate(Annotation[] fieldAnnotations, Optional<String> name) {
    final BeanManager bm = CDI.current().getBeanManager();        
    final Annotation[] qualifiers = Arrays.stream(fieldAnnotations).filter(a -> searchAnnotation(a, Qualifier.class).isPresent()).toArray(n -> new Annotation[n]);
    JsonDriverNotFound.failIf(qualifiers.length > 0 && name.isPresent(), "found both @Qualifiers and @WithDriver.value()");
    final Set<Bean<?>> beans = name.map(n -> bm.getBeans(n)).orElseGet(() -> bm.getBeans(JsonDriver.class, qualifiers));
    JsonDriverNotFound.failIf(beans.isEmpty(), "no JsonDriver found in BeanManager");
    JsonDriverNotFound.failIf(beans.size() > 1, "more than one JsonDriver found in BeanManager, use @JsonType.WithDriver to disambiguate");
    final Bean<?> bean = beans.iterator().next();
    final CreationalContext<?> ctx = bm.createCreationalContext(bean);
    return (JsonDriver) bm.getReference(bean, JsonDriver.class, ctx);	        
}
 
開發者ID:optionfactory,項目名稱:hibernate-json,代碼行數:13,代碼來源:CdiDriverLocator.java

示例8: getInstancesByType

import javax.enterprise.inject.spi.BeanManager; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public <T> List<T> getInstancesByType(Class<T> clazz) {
	BeanManager beanManager = CDI.current().getBeanManager();
	Set<Bean<?>> beans = beanManager.getBeans(clazz);
	List<T> list = new ArrayList<>();
	for (Bean<?> bean : beans) {
		CreationalContext<?> creationalContext = beanManager.createCreationalContext(bean);
		T object = (T) beanManager.getReference(bean, clazz, creationalContext);
		list.add(object);
	}
	return list;
}
 
開發者ID:katharsis-project,項目名稱:katharsis-framework,代碼行數:14,代碼來源:CdiServiceDiscovery.java

示例9: HandlerInstance

import javax.enterprise.inject.spi.BeanManager; //導入方法依賴的package包/類
HandlerInstance(AnnotatedType<T> annotatedType, BeanManager beanManager) {
    this.annotatedType = annotatedType;
    this.injectionTarget = beanManager.getInjectionTargetFactory(annotatedType).createInjectionTarget(null);
    this.creationalContext = beanManager.createCreationalContext(null);
    this.instance = injectionTarget.produce(creationalContext);
    injectionTarget.inject(instance, creationalContext);
    injectionTarget.postConstruct(instance);
}
 
開發者ID:weld,項目名稱:weld-vertx,代碼行數:9,代碼來源:RouteExtension.java

示例10: inject

import javax.enterprise.inject.spi.BeanManager; //導入方法依賴的package包/類
/**
 * Perform injection into a non-CDI managed bean.
 * <p>
 * An example of this is a JSP Tag
 * <p>
 * @param <T>
 * @param bean
 */
public static <T> T inject( T bean )
{
    BeanManager beanManager = getBeanManager();
    AnnotatedType<T> annotatedType = beanManager.<T>createAnnotatedType( (Class<T>) bean.getClass() );
    InjectionTarget<T> injectionTarget = beanManager.createInjectionTarget( annotatedType );
    CreationalContext ctx = beanManager.createCreationalContext( null );
    injectionTarget.inject( bean, ctx );
    return bean;
}
 
開發者ID:peter-mount,項目名稱:opendata-common,代碼行數:18,代碼來源:CDIUtils.java

示例11: get

import javax.enterprise.inject.spi.BeanManager; //導入方法依賴的package包/類
protected CamelContext get(String name) {
      BeanManager beanManager = BeanManagerLookup.getBeanManager();
      Set<Bean<?>> beans = beanManager.getBeans(name);
      if(beans.isEmpty())
      	return null;
@SuppressWarnings("unchecked")
      Bean<CamelContext> bean = (Bean<CamelContext>) beans.iterator().next();
      CreationalContext<CamelContext> ctx = beanManager.createCreationalContext(bean);
      return (CamelContext) beanManager.getReference(bean, CamelContext.class, ctx);
  }
 
開發者ID:flowable,項目名稱:flowable-engine,代碼行數:11,代碼來源:CdiCamelBehavior.java

示例12: lookup

import javax.enterprise.inject.spi.BeanManager; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public static <T> T lookup(Class<T> clazz, BeanManager bm) {
    Iterator<Bean<?>> iter = bm.getBeans(clazz).iterator();
    if (!iter.hasNext()) {
        throw new IllegalStateException("CDI BeanManager cannot find an instance of requested type " + clazz.getName());
    }
    Bean<T> bean = (Bean<T>) iter.next();
    CreationalContext<T> ctx = bm.createCreationalContext(bean);
    T dao = (T) bm.getReference(bean, clazz, ctx);
    return dao;
}
 
開發者ID:flowable,項目名稱:flowable-engine,代碼行數:12,代碼來源:ProgrammaticBeanLookup.java

示例13: onStartup

import javax.enterprise.inject.spi.BeanManager; //導入方法依賴的package包/類
@SuppressWarnings({ "rawtypes", "unchecked" })
public void onStartup(@Observes @Initialized WebApplication webApplication, BeanManager beanManager)
   {

   	for( Bean bean : beanManager.getBeans(Startup.class) )
   	{
   		CreationalContext context = beanManager.createCreationalContext(bean);
   		Startup st = (Startup) beanManager.getReference(bean, Startup.class, context);
   		st.init();
   	}
   }
 
開發者ID:Inspiredsoft,項目名稱:parco,代碼行數:12,代碼來源:BeanStartupHelper.java

示例14: newBean

import javax.enterprise.inject.spi.BeanManager; //導入方法依賴的package包/類
/**
 * Create a new CDI bean given its class and a bean manager. The bean is created
 * in the context defined by the scope annotation on the class.
 *
 * @param bm The BeanManager.
 * @param clazz CDI class.
 * @param <T>   class parameter.
 * @return newly allocated CDI bean.
 */
public static <T> T newBean(BeanManager bm, Class<T> clazz) {
    Set<Bean<?>> beans = bm.getBeans(clazz);
    final Bean<T> bean = (Bean<T>) bm.resolve(beans);
    final CreationalContext<T> ctx = bm.createCreationalContext(bean);
    return (T) bm.getReference(bean, clazz, ctx);
}
 
開發者ID:mvc-spec,項目名稱:ozark,代碼行數:16,代碼來源:CdiUtils.java

示例15: getInstance

import javax.enterprise.inject.spi.BeanManager; //導入方法依賴的package包/類
/**
 * Get the instance of a bean
 *
 * @param <T>   type of bean
 * @param bean  Bean
 * @param clazz class of bean
 *
 * @return
 */
public static <T> T getInstance( Bean<T> bean, Class<T> clazz )
{
    BeanManager beanManager = getBeanManager();
    CreationalContext<T> ctx = beanManager.createCreationalContext( bean );
    return (T) beanManager.getReference( bean, clazz, ctx );
}
 
開發者ID:peter-mount,項目名稱:opendata-common,代碼行數:16,代碼來源:CDIUtils.java


注:本文中的javax.enterprise.inject.spi.BeanManager.createCreationalContext方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。