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