本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例7: AxonConfigInfo
import javax.enterprise.inject.spi.Bean; //导入方法依赖的package包/类
protected AxonConfigInfo(final Bean<?> bean) {
this(bean.getBeanClass(), bean);
}
示例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));
}