本文整理汇总了Java中javax.enterprise.inject.spi.Bean类的典型用法代码示例。如果您正苦于以下问题:Java Bean类的具体用法?Java Bean怎么用?Java Bean使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Bean类属于javax.enterprise.inject.spi包,在下文中一共展示了Bean类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: shouldDeployDefaultCamelContext
import javax.enterprise.inject.spi.Bean; //导入依赖的package包/类
private boolean shouldDeployDefaultCamelContext(Set<Bean<?>> beans) {
return beans.stream()
// Is there a Camel bean with the @Default qualifier?
// Excluding internal components...
.filter(bean -> !bean.getBeanClass().getPackage().equals(getClass().getPackage()))
.filter(hasType(CamelContextAware.class).or(hasType(Component.class))
.or(hasType(RouteContainer.class).or(hasType(RoutesBuilder.class))))
.map(Bean::getQualifiers)
.flatMap(Set::stream)
.filter(isEqual(DEFAULT))
.findAny()
.isPresent()
// Or a bean with Camel annotations?
|| concat(camelBeans.stream().map(AnnotatedType::getFields),
camelBeans.stream().map(AnnotatedType::getMethods))
.flatMap(Set::stream)
.map(Annotated::getAnnotations)
.flatMap(Set::stream)
.filter(isAnnotationType(Consume.class).and(a -> ((Consume) a).context().isEmpty())
.or(isAnnotationType(BeanInject.class).and(a -> ((BeanInject) a).context().isEmpty()))
.or(isAnnotationType(EndpointInject.class).and(a -> ((EndpointInject) a).context().isEmpty()))
.or(isAnnotationType(Produce.class).and(a -> ((Produce) a).context().isEmpty()))
.or(isAnnotationType(PropertyInject.class).and(a -> ((PropertyInject) a).context().isEmpty())))
.findAny()
.isPresent()
// Or an injection point for Camel primitives?
|| beans.stream()
// Excluding internal components...
.filter(bean -> !bean.getBeanClass().getPackage().equals(getClass().getPackage()))
.map(Bean::getInjectionPoints)
.flatMap(Set::stream)
.filter(ip -> getRawType(ip.getType()).getName().startsWith("org.apache.camel"))
.map(InjectionPoint::getQualifiers)
.flatMap(Set::stream)
.filter(isAnnotationType(Uri.class).or(isAnnotationType(Mock.class)).or(isEqual(DEFAULT)))
.findAny()
.isPresent();
}
开发者ID:HydAu,项目名称:Camel,代码行数:39,代码来源:CdiCamelExtension.java
示例2: 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
示例3: unique
import javax.enterprise.inject.spi.Bean; //导入依赖的package包/类
private <T> T unique(final Class clazz, final Collection<T> set) {
if (set.isEmpty()) {
final Set<Bean<?>> allBeans = container().beanDeploymentArchives().values().stream()
.map(BeanManagerImpl::getBeans)
.flatMap(Collection::stream)
.collect(toSet());
throw new TestEEfiException("No matching bean found for class "
+ clazz.getName()
+ ", available beans are: "
+ allBeans
);
} else if (set.size() > 1) {
throw new TestEEfiException("Multiple ambiguous beans found for class " + clazz.getName());
} else {
return set.iterator().next();
}
}
开发者ID:dajudge,项目名称:testee.fi,代码行数:18,代码来源:DependencyInjectionRealm.java
示例4: factory
import javax.enterprise.inject.spi.Bean; //导入依赖的package包/类
private <T> ProducerFactory<T> factory(final Object mock) {
return new ProducerFactory<T>() {
@Override
public <T1> Producer<T1> createProducer(final Bean<T1> bean) {
return new Producer<T1>() {
@Override
public T1 produce(final CreationalContext<T1> ctx) {
return (T1) mock;
}
@Override
public void dispose(final T1 instance) {
}
@Override
public Set<InjectionPoint> getInjectionPoints() {
return Collections.emptySet();
}
};
}
};
}
开发者ID:dajudge,项目名称:testee.fi,代码行数:24,代码来源:MockingExtension.java
示例5: testIfExists
import javax.enterprise.inject.spi.Bean; //导入依赖的package包/类
/**
* Tests if exists observer injection in a jar archive
*/
@Test
public void testIfExists() {
logger.info("starting if exists event test");
// To test the IF_EXISTS Reception I need to inject the observer bean so
// it will be instantiated and ready to use
Set<Bean<?>> beans = beanManager.getBeans(IfExistsObserver.class);
assertEquals(beans.size(), 1);
@SuppressWarnings("unchecked")
Bean<IfExistsObserver> bean = (Bean<IfExistsObserver>) beans.iterator().next();
CreationalContext<IfExistsObserver> ctx = beanManager.createCreationalContext(bean);
beanManager.getReference(bean, IfExistsObserver.class, ctx);
Bill bill = fire();
assertEquals("The id generation passes through the always and if_exists observers and it is incremented", 10,
bill.getId());
}
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:19,代码来源:EventTestCase.java
示例6: testProducer
import javax.enterprise.inject.spi.Bean; //导入依赖的package包/类
@Test
public void testProducer() {
logger.info("starting producer spi test");
CDI<Object> cdi = current();
BeanManager beanManager = cdi.select(BeanManager.class).get();
AnnotatedField<? super AnotherFactory> field = this
.<AnotherFactory, AnnotatedField<AnotherFactory>>getAnnotatedMember(AnotherFactory.class, "jessie",
beanManager);
Bean<AnotherFactory> declaringBean = cast(beanManager.resolve(beanManager.getBeans(AnotherFactory.class)));
ProducerFactory<AnotherFactory> producerFactory = beanManager.getProducerFactory(field, declaringBean);
Producer<Toy> producer = cast(producerFactory.createProducer(null));
assertNotNull(producer);
assertTrue(producer.getInjectionPoints().isEmpty());
Toy jessie = producer.produce(beanManager.<Toy>createCreationalContext(null));
assertEquals("Jessie", jessie.getName());
}
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:18,代码来源:InjectSPITestCase.java
示例7: decorateContext
import javax.enterprise.inject.spi.Bean; //导入依赖的package包/类
private <X> AnnotatedField<X> decorateContext(AnnotatedField<X> field) {
final PersistenceContext persistenceContext = field.getAnnotation(PersistenceContext.class);
final UniqueIdentifier identifier = UniqueIdentifierLitteral.random();
Set<Annotation> templateQualifiers = new HashSet<>();
templateQualifiers.add(ServiceLiteral.SERVICE);
if (hasUnitName(persistenceContext)) {
templateQualifiers.add(new FilterLiteral("(osgi.unit.name=" + persistenceContext.unitName() + ")"));
}
Bean<JpaTemplate> bean = manager.getExtension(OsgiExtension.class)
.globalDependency(JpaTemplate.class, templateQualifiers);
Set<Annotation> qualifiers = new HashSet<>();
qualifiers.add(identifier);
Bean<EntityManager> b = new SimpleBean<>(EntityManager.class, Dependent.class, Collections.singleton(EntityManager.class), qualifiers, () -> {
CreationalContext<JpaTemplate> context = manager.createCreationalContext(bean);
JpaTemplate template = (JpaTemplate) manager.getReference(bean, JpaTemplate.class, context);
return EntityManagerProducer.create(template);
});
beans.add(b);
Set<Annotation> fieldAnnotations = new HashSet<>();
fieldAnnotations.add(InjectLiteral.INJECT);
fieldAnnotations.add(identifier);
return new SyntheticAnnotatedField<>(field, fieldAnnotations);
}
开发者ID:apache,项目名称:aries-jpa,代码行数:27,代码来源:PersistenceAnnotatedType.java
示例8: decorateUnit
import javax.enterprise.inject.spi.Bean; //导入依赖的package包/类
private <X> AnnotatedField<X> decorateUnit(AnnotatedField<X> field) {
final PersistenceUnit persistenceUnit = field.getAnnotation(PersistenceUnit.class);
final UniqueIdentifier identifier = UniqueIdentifierLitteral.random();
Set<Annotation> templateQualifiers = new HashSet<>();
templateQualifiers.add(ServiceLiteral.SERVICE);
if (hasUnitName(persistenceUnit)) {
templateQualifiers.add(new FilterLiteral("(osgi.unit.name=" + persistenceUnit.unitName() + ")"));
}
Bean<EntityManagerFactory> bean = manager.getExtension(OsgiExtension.class)
.globalDependency(EntityManagerFactory.class, templateQualifiers);
Set<Annotation> qualifiers = new HashSet<>();
qualifiers.add(identifier);
Bean<EntityManagerFactory> b = new SimpleBean<>(EntityManagerFactory.class, Dependent.class, Collections.singleton(EntityManagerFactory.class), qualifiers, () -> {
CreationalContext<EntityManagerFactory> context = manager.createCreationalContext(bean);
return (EntityManagerFactory) manager.getReference(bean, EntityManagerFactory.class, context);
});
beans.add(b);
Set<Annotation> fieldAnnotations = new HashSet<>();
fieldAnnotations.add(InjectLiteral.INJECT);
fieldAnnotations.add(identifier);
return new SyntheticAnnotatedField<>(field, fieldAnnotations);
}
开发者ID:apache,项目名称:aries-jpa,代码行数:26,代码来源:PersistenceAnnotatedType.java
示例9: getServices
import javax.enterprise.inject.spi.Bean; //导入依赖的package包/类
/**
* Retrieves the services that are available for use with the description for each service.
* The Services are determined by looking up all of the implementations of the
* Customer Service interface that are using the DataService qualifier annotation.
* The DataService annotation contains the service name and description information.
* @return Map containing a list of services available and a description of each one.
*/
public Map<String,String> getServices (){
TreeMap<String,String> services = new TreeMap<String,String>();
logger.fine("Getting CustomerService Impls");
Set<Bean<?>> beans = beanManager.getBeans(CustomerService.class,new AnnotationLiteral<Any>() {
private static final long serialVersionUID = 1L;});
for (Bean<?> bean : beans) {
for (Annotation qualifer: bean.getQualifiers()){
if(DataService.class.getName().equalsIgnoreCase(qualifer.annotationType().getName())){
DataService service = (DataService) qualifer;
logger.fine(" name="+service.name()+" description="+service.description());
services.put(service.name(), service.description());
}
}
}
return services;
}
开发者ID:ibmruntimes,项目名称:acmeair-modular,代码行数:24,代码来源:ServiceLocator.java
示例10: getInstancesByType
import javax.enterprise.inject.spi.Bean; //导入依赖的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
示例11: 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
示例12: createBeanAdapter
import javax.enterprise.inject.spi.Bean; //导入依赖的package包/类
/**
*
* @param ip
* @param beanManager
* @return
*/
private <T> Bean<T> createBeanAdapter(InjectionPoint ip, BeanManager beanManager) {
final Type type = ip.getType();
final Class<T> rawType = ReflectionUtils.getRawType(type);
final ContextualLifecycle<T> lifecycleAdapter = new BodyLifecycle<T>(ip, beanManager);
final BeanBuilder<T> beanBuilder = new BeanBuilder<T>(beanManager)
.readFromType(new AnnotatedTypeBuilder<T>().readFromType(rawType).create())
.beanClass(Body.class) // see https://issues.jboss.org/browse/WELD-2165
.name(ip.getMember().getName())
.qualifiers(ip.getQualifiers())
.beanLifecycle(lifecycleAdapter)
.scope(Dependent.class)
.passivationCapable(false)
.alternative(false)
.nullable(true)
.id("BodyBean#" + type.toString())
.addType(type); //java.lang.Object needs to be present (as type) in any case
return beanBuilder.create();
}
开发者ID:dansiviter,项目名称:cito,代码行数:25,代码来源:BodyProducerExtension.java
示例13: initialiseContexts
import javax.enterprise.inject.spi.Bean; //导入依赖的package包/类
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void initialiseContexts() {
final WebSocketContext webSocketContext = mock(WebSocketContext.class);
ReflectionUtil.set(this.extension, "webSocketContext", webSocketContext);
final AfterDeploymentValidation afterDeploymentValidation = mock(AfterDeploymentValidation.class);
final Bean<?> bean = mock(Bean.class);
when(this.beanManager.getBeans(WebSocketSessionHolder.class)).thenReturn(Collections.singleton(bean));
when(this.beanManager.resolve(any(Set.class))).thenReturn(bean);
final CreationalContext creationalContext = mock(CreationalContext.class);
when(this.beanManager.createCreationalContext(bean)).thenReturn(creationalContext);
final WebSocketSessionHolder webSocketSessionHolder = mock(WebSocketSessionHolder.class);
when(this.beanManager.getReference(bean, WebSocketSessionHolder.class, creationalContext)).thenReturn(webSocketSessionHolder);
this.extension.initialiseContexts(afterDeploymentValidation, this.beanManager);
verify(this.beanManager).getBeans(WebSocketSessionHolder.class);
verify(this.beanManager).resolve(any(Set.class));
verify(this.beanManager).createCreationalContext(bean);
verify(this.beanManager).getReference(bean, WebSocketSessionHolder.class, creationalContext);
verify(webSocketContext).init(webSocketSessionHolder);
verifyNoMoreInteractions(webSocketContext, afterDeploymentValidation, bean, creationalContext, webSocketSessionHolder);
}
开发者ID:dansiviter,项目名称:cito,代码行数:24,代码来源:ExtensionTest.java
示例14: getBean
import javax.enterprise.inject.spi.Bean; //导入依赖的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
示例15: afterProcessViewEvent
import javax.enterprise.inject.spi.Bean; //导入依赖的package包/类
/**
* Perform the work we need to do at AfterProcessViewEvent time.
*
* @param event the event.
*/
public void afterProcessViewEvent(@Observes AfterProcessViewEvent event) {
if (request.getAttribute(SCOPE_ID) != null) {
String scopeId = (String) request.getAttribute(SCOPE_ID);
HttpSession session = request.getSession();
final String sessionKey = SCOPE_ID + "-" + scopeId;
Map<String, Object> scopeMap = (Map<String, Object>) session.getAttribute(sessionKey);
if (null != scopeMap) {
scopeMap.entrySet().stream().forEach((entrySet) -> {
String key = entrySet.getKey();
Object value = entrySet.getValue();
if (key.startsWith(INSTANCE)) {
BeanManager beanManager = CdiUtils.getApplicationBeanManager();
Bean<?> bean = beanManager.resolve(beanManager.getBeans(value.getClass()));
destroy(bean);
}
});
scopeMap.clear();
session.removeAttribute(sessionKey);
}
}
}
开发者ID:mvc-spec,项目名称:ozark,代码行数:27,代码来源:RedirectScopeManager.java
示例16: 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
示例17: mockInjectionPoint
import javax.enterprise.inject.spi.Bean; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private InjectionPoint mockInjectionPoint(Property property,
Type type,
Class<? extends Member> memberType,
String memberName,
int memberPosition) {
InjectionPoint injectionPoint = mock(InjectionPoint.class);
Member member = mock(memberType);
when(injectionPoint.getType()).thenReturn(type);
when(injectionPoint.getMember()).thenReturn(member);
when(member.getName()).thenReturn(memberName);
@SuppressWarnings("rawtypes")
Bean mockBean = mock(Bean.class);
when(injectionPoint.getBean()).thenReturn(mockBean);
when(mockBean.getBeanClass()).thenReturn(getClass());
AnnotatedParameter<?> annotated = mock(AnnotatedParameter.class);
when(annotated.getPosition()).thenReturn(memberPosition);
when(injectionPoint.getAnnotated()).thenReturn(annotated);
when(annotated.getAnnotation(Property.class)).thenReturn(property);
return injectionPoint;
}
开发者ID:xlate,项目名称:property-inject,代码行数:27,代码来源:PropertyProducerBeanTest.java
示例18: mockInjectionPoint
import javax.enterprise.inject.spi.Bean; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private InjectionPoint mockInjectionPoint(Property property,
Class<? extends Member> memberType,
String memberName,
int memberPosition) {
InjectionPoint injectionPoint = mock(InjectionPoint.class);
Member member = mock(memberType);
when(injectionPoint.getMember()).thenReturn(member);
when(member.getName()).thenReturn(memberName);
@SuppressWarnings("rawtypes")
Bean mockBean = mock(Bean.class);
when(injectionPoint.getBean()).thenReturn(mockBean);
when(mockBean.getBeanClass()).thenReturn(getClass());
AnnotatedParameter<?> annotated = mock(AnnotatedParameter.class);
when(annotated.getPosition()).thenReturn(memberPosition);
when(injectionPoint.getAnnotated()).thenReturn(annotated);
when(annotated.getAnnotation(Property.class)).thenReturn(property);
return injectionPoint;
}
开发者ID:xlate,项目名称:property-inject,代码行数:25,代码来源:PropertyFactoryTest.java
示例19: execute
import javax.enterprise.inject.spi.Bean; //导入依赖的package包/类
@Override
public void execute( JobExecutionContext context )
throws JobExecutionException
{
JobDetail d = context.getJobDetail();
JobDataMap m = d.getJobDataMap();
String name = m.getString( "bean" );
Method meth = (Method) m.get( "method" );
try {
Bean<Object> bean = CDIUtils.getBean( name );
Object job = CDIUtils.getInstance( (Bean<Object>) bean, Object.class );
LOG.log( Level.INFO, () -> "job " + job );
meth.invoke( job );
}
catch( IllegalAccessException |
IllegalArgumentException |
InvocationTargetException ex ) {
LOG.log( Level.SEVERE, ex, () -> "Failed running " + name + " " + meth );
throw new JobExecutionException( ex, false );
}
}
开发者ID:peter-mount,项目名称:opendata-common,代码行数:25,代码来源:MethodAdapter.java
示例20: execute
import javax.enterprise.inject.spi.Bean; //导入依赖的package包/类
@Override
public void execute( JobExecutionContext context )
throws JobExecutionException
{
JobDetail d = context.getJobDetail();
JobDataMap m = d.getJobDataMap();
String name = m.getString( "bean" );
LOG.log( Level.INFO, () -> "name " + name );
Bean<?> bean = CDIUtils.getBean( name );
LOG.log( Level.INFO, () -> "bean " + bean );
@SuppressWarnings( "unchecked" )
Job job = CDIUtils.getInstance( (Bean<Job>) bean, Job.class );
LOG.log( Level.INFO, () -> "job " + job );
job.execute( context );
}
开发者ID:peter-mount,项目名称:opendata-common,代码行数:19,代码来源:JobAdapter.java
注:本文中的javax.enterprise.inject.spi.Bean类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论