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


Java Bean.getBeanClass方法代码示例

本文整理汇总了Java中javax.enterprise.inject.spi.Bean.getBeanClass方法的典型用法代码示例。如果您正苦于以下问题:Java Bean.getBeanClass方法的具体用法?Java Bean.getBeanClass怎么用?Java Bean.getBeanClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.enterprise.inject.spi.Bean的用法示例。


在下文中一共展示了Bean.getBeanClass方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getInstancesByAnnotation

import javax.enterprise.inject.spi.Bean; //导入方法依赖的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

示例2: getInstancesByAnnotation

import javax.enterprise.inject.spi.Bean; //导入方法依赖的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

示例3: getInstanceFromStaticBeanManager

import javax.enterprise.inject.spi.Bean; //导入方法依赖的package包/类
/**
 * Method which uses the static instance of the bean manager cached in this class. This method
 * should only be used by objects which are not created by Weld. Objects created by Weld should
 * preferably use the @Inject annotation to get an instance of the WeldUtils injected.
 * 
 * @see WeldUtils#getInstance(Class)
 */
@SuppressWarnings("unchecked")
public static <T> T getInstanceFromStaticBeanManager(Class<T> type) {
  final BeanManager theBeanManager = getStaticInstanceBeanManager();
  final Set<Bean<?>> beans = theBeanManager.getBeans(type, ANY_LITERAL);
  for (Bean<?> bean : beans) {
    if (bean.getBeanClass() == type) {
      return (T) theBeanManager.getReference(bean, type,
          theBeanManager.createCreationalContext(bean));
    }
  }
  throw new IllegalArgumentException("No bean found for type " + type);
}
 
开发者ID:mauyr,项目名称:openbravo-brazil,代码行数:20,代码来源:WeldUtils.java

示例4: getInstance

import javax.enterprise.inject.spi.Bean; //导入方法依赖的package包/类
/**
 * Return an instance which has the requested class. Ignores inheritance, so if a class A extends
 * a class B, if B is requested then an instance of B is returned and not an instance of A.
 * 
 * @param <T>
 *          the expected class
 * @param type
 *          the type to search, this type and all its subtypes are searched
 * @return an instance of the requested type
 */
@SuppressWarnings("unchecked")
public <T> T getInstance(Class<T> type) {
  final Set<Bean<?>> beans = beanManager.getBeans(type, ANY_LITERAL);
  for (Bean<?> bean : beans) {
    if (bean.getBeanClass() == type) {
      return (T) beanManager.getReference(bean, type, beanManager.createCreationalContext(bean));
    }
  }
  throw new IllegalArgumentException("No bean found for type " + type);
}
 
开发者ID:mauyr,项目名称:openbravo-brazil,代码行数:21,代码来源:WeldUtils.java

示例5: serviceExporterBean

import javax.enterprise.inject.spi.Bean; //导入方法依赖的package包/类
private SyntheticBean<?> serviceExporterBean(Bean<?> context, CamelServiceExporterDefinition exporter, URL url) {
    // TODO: replace with CreationException
    requireNonNull(exporter.getServiceRef(),
        () -> format("Missing [%s] attribute for imported bean [%s] from resource [%s]",
            "serviceRef", Objects.toString(exporter.getId(), "export"), url));

    Class<?> type;
    if (exporter.getServiceInterface() != null) {
        type = exporter.getServiceInterface();
    } else {
        Bean<?> bean = manager.resolve(manager.getBeans(exporter.getServiceRef()));
        if (bean != null) {
            type = bean.getBeanClass();
        } else {
            requireNonNull(exporter.getServiceInterface(),
                () -> format("Missing [%s] attribute for imported bean [%s] from resource [%s]",
                    "serviceInterface", Objects.toString(exporter.getId(), "export"), url));
            type = exporter.getServiceInterface();
        }
    }

    Set<Type> types = new HashSet<>(manager.createAnnotatedType(type).getTypeClosure());
    // Weld does not add Object.class for interfaces as they do not extend Object.class.
    // Though let's add it so that it's possible to lookup by bean type Object.class
    // beans whose bean class is an interface (for startup beans).
    types.add(Object.class);

    return new XmlServiceExporterBean<>(manager,
        new SyntheticAnnotated(type, types, APPLICATION_SCOPED, ANY, STARTUP,
            hasId(exporter) ? NamedLiteral.of(exporter.getId()) : DEFAULT),
        type, bean ->
            "imported bean [" + Objects.toString(exporter.getId(), "export") + "] "
            + "from resource [" + url + "] "
            + "with qualifiers " + bean.getQualifiers(),
        context, exporter);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:37,代码来源:XmlCdiBeanFactory.java

示例6: getLogger

import javax.enterprise.inject.spi.Bean; //导入方法依赖的package包/类
/**
 * Produces an instance of a slf4j logger for the given injection point.
 * @param injectionPoint to use
 * @return a logger
 */
@Produces
public Logger getLogger(final InjectionPoint injectionPoint) {
	//The injection point is used to instantiate the correct logger for the
	//caller class.
	Bean<?> bean = injectionPoint.getBean();
	Logger l = null;
	if (bean != null) {
		Class<?> beanClass =  bean.getBeanClass();
		l = LoggerFactory.getLogger(beanClass);
	} else {
		l = LoggerFactory.getLogger("Default logger");	
	}
    return l;
}
 
开发者ID:hostettler,项目名称:JEE7-Demo,代码行数:20,代码来源:LoggerProducer.java

示例7: AxonConfigInfo

import javax.enterprise.inject.spi.Bean; //导入方法依赖的package包/类
protected AxonConfigInfo(final Bean<?> bean) {
	this(bean.getBeanClass(), bean);
}
 
开发者ID:kamaladafrica,项目名称:axon-cdi,代码行数:4,代码来源:AxonConfigInfo.java

示例8: isServiceBean

import javax.enterprise.inject.spi.Bean; //导入方法依赖的package包/类
private boolean isServiceBean(Bean<?> bean) {
    Class<?> beanClass = bean.getBeanClass();
    return (Modifier.isPublic(beanClass.getModifiers()) && beanClass.isAnnotationPresent(Service.class));
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:5,代码来源:SwitchYardCDIServiceDiscovery.java


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