Java 类javax.enterprise.inject.spi.AfterBeanDiscovery 实例源码

项目:wildfly-microprofile-config    文件:ConfigExtension.java   
public void registerConfigProducer(@Observes AfterBeanDiscovery abd, BeanManager bm) {
    // excludes type that are already produced by ConfigProducer
    Set<Class> types = injectionPoints.stream()
            .filter(ip -> ip.getType() instanceof Class
                    && ip.getType() != String.class
                    && ip.getType() != Boolean.class
                    && ip.getType() != Boolean.TYPE
                    && ip.getType() != Integer.class
                    && ip.getType() != Integer.TYPE
                    && ip.getType() != Long.class
                    && ip.getType() != Long.TYPE
                    && ip.getType() != Float.class
                    && ip.getType() != Float.TYPE
                    && ip.getType() != Double.class
                    && ip.getType() != Double.TYPE
                    && ip.getType() != Duration.class
                    && ip.getType() != LocalDate.class
                    && ip.getType() != LocalTime.class
                    && ip.getType() != LocalDateTime.class)
            .map(ip -> (Class) ip.getType())
            .collect(Collectors.toSet());
    types.forEach(type -> abd.addBean(new ConfigInjectionBean(bm, type)));
}
项目:wildfly-nosql    文件:CassandraExtension.java   
/**
 */
void registerNoSQLSourceBeans(@Observes AfterBeanDiscovery abd, BeanManager bm) {

    if (bm.getBeans(clusterClass, DefaultLiteral.INSTANCE).isEmpty()) {
        // Iterate profiles and create Cluster/Session bean for each profile, that application code can @Inject
        for(String profile: getService().profileNames()) {
            log.log(Level.INFO, "Registering bean for profile {0}", profile);
            abd.addBean(bm.createBean(
                    new ClusterBeanAttributes(bm.createBeanAttributes(bm.createAnnotatedType(clusterClass)), profile),
                    clusterClass, new ClusterProducerFactory(profile, clusterClass)));
            abd.addBean(bm.createBean(
                    new SessionBeanAttributes(bm.createBeanAttributes(bm.createAnnotatedType(sessionClass)), profile),
                    sessionClass, new SessionProducerFactory(profile, sessionClass)));
        }
     } else {
        log.log(Level.INFO, "Application contains a default Cluster Bean, automatic registration will be disabled");
    }
}
项目:wildfly-nosql    文件:MongoExtension.java   
void registerNoSQLSourceBeans(@Observes AfterBeanDiscovery abd, BeanManager bm) {
    if (bm.getBeans(mongoClientClass, DefaultLiteral.INSTANCE).isEmpty()) {
        // Iterate profiles and create Cluster/Session bean for each profile, that application code can @Inject
        for(String profile: getService().profileNames()) {
            log.log(Level.INFO, "Registering bean for profile {0}", profile);
            abd.addBean(bm.createBean(
                    new MongoClientBeanAttributes(bm.createBeanAttributes(bm.createAnnotatedType(mongoClientClass)), profile),
                    mongoClientClass, new MongoClientProducerFactory(profile, mongoClientClass)));
            abd.addBean(bm.createBean(
                    new MongoDatabaseBeanAttributes(bm.createBeanAttributes(bm.createAnnotatedType(mongoDatabaseClass)), profile),
                    mongoDatabaseClass, new MongoDatabaseProducerFactory(profile, mongoDatabaseClass)));
        }
     } else {
        log.log(Level.INFO, "Application contains a default MongoClient Bean, automatic registration will be disabled");
    }
}
项目:command-context-example    文件:CommandExtension.java   
void afterBeanDiscovery(@Observes AfterBeanDiscovery event, BeanManager beanManager) {

        final CommandContextImpl commandContext = new CommandContextImpl();

        // Register the command context
        event.addContext(commandContext);

        // Register the command context bean using CDI 2 configurators API
        event.addBean()
            .addType(CommandContext.class)
            .createWith(ctx -> new InjectableCommandContext(commandContext, beanManager))
            .addQualifier(Default.Literal.INSTANCE)
            .scope(Dependent.class)
            .beanClass(CommandExtension.class);

        // Register the CommandExecution bean using CDI 2 configurators API
        event.addBean()
            .createWith(ctx -> commandContext.getCurrentCommandExecution())
            .addType(CommandExecution.class)
            .addQualifier(Default.Literal.INSTANCE)
            .scope(CommandScoped.class)
            .beanClass(CommandExtension.class);
    }
项目:maven-cdi-plugin-utils    文件:AbstractCDIMojo.java   
@SuppressWarnings("unused")
 // will be called automatically by the CDI container once the bean discovery has finished
 private void processMojoCdiProducerFields(@Observes AfterBeanDiscovery event, BeanManager beanManager)
     throws MojoExecutionException {

Class<?> cls = getClass();
   Set<Field> fields = Sets.newHashSet();

   while (cls != AbstractCDIMojo.class) {
    fields.addAll(Sets.newHashSet(cls.getFields()));
    fields.addAll(Sets.newHashSet(cls.getDeclaredFields()));
    cls = cls.getSuperclass();
   }

   for (Field f : fields) {
     if (f.isAnnotationPresent(MojoProduces.class)) {
       try {
         f.setAccessible(true);
         event.addBean(
             new CdiBeanWrapper<Object>(f.get(this), f.getGenericType(), f.getType(), CDIUtil.getCdiQualifiers(f)));
       } catch (Throwable t) {
         throw new MojoExecutionException("Could not process CDI producer field of the Mojo.", t);
       }
     }
   }
 }
项目:maven-cdi-plugin-utils    文件:AbstractCDIMojo.java   
@SuppressWarnings({ "unused", "unchecked", "rawtypes" })
// will be called automatically by the CDI container once the bean discovery has finished
private void processMojoCdiProducerMethods(@Observes AfterBeanDiscovery event, BeanManager beanManager)
    throws MojoExecutionException {
  // no method parameter injection possible at the moment since the container is not yet initialized at this point!
  Class<?> cls = getClass();
  Set<Method> methods = Sets.newHashSet();

  while (cls != AbstractCDIMojo.class) {
    methods.addAll(Sets.newHashSet(cls.getMethods()));
    methods.addAll(Sets.newHashSet(cls.getDeclaredMethods()));
    cls = cls.getSuperclass();
  }

  for (Method m : methods) {
    if (m.getReturnType() != Void.class && m.isAnnotationPresent(MojoProduces.class)) {
      try {
        event.addBean(new CdiProducerBean(m, this, beanManager, m.getGenericReturnType(), m.getReturnType(),
            CDIUtil.getCdiQualifiers(m)));
      } catch (Throwable t) {
        throw new MojoExecutionException("Could not process CDI producer method of the Mojo.", t);
      }
    }
  }
}
项目:wildfly-swarm    文件:CommandLineArgsExtension.java   
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd) {
    CommonBean<String[]> stringBean = CommonBeanBuilder.newBuilder(String[].class)
            .beanClass(CommandLineArgsExtension.class)
            .scope(Dependent.class)
            .createSupplier(() -> args)
            .addQualifier(CommandLineArgs.Literal.INSTANCE)
            .addType(String[].class)
            .addType(Object.class).build();
    abd.addBean(stringBean);
    CommonBean<List> listBean = CommonBeanBuilder.newBuilder(List.class)
            .beanClass(CommandLineArgsExtension.class)
            .scope(Dependent.class)
            .createSupplier(() -> argsList)
            .addQualifier(DefaultLiteral.INSTANCE)
            .addType(List.class)
            .addType(Object.class).build();
    abd.addBean(listBean);
}
项目:appformer    文件:SystemConfigProducer.java   
void afterBeanDiscovery(@Observes final AfterBeanDiscovery abd,
                        final BeanManager bm) {

    if (systemFSNotExists) {
        buildSystemFS(abd,
                      bm);
    }

    if (ioStrategyBeanNotFound) {
        buildIOStrategy(abd,
                        bm);
    }

    if (!CDI_METHOD.equalsIgnoreCase(START_METHOD)) {
        buildStartableBean(abd,
                           bm);
    }
}
项目:jcache-cdi    文件:ExtraJCacheExtension.java   
public void addJCacheBeans(final @Observes AfterBeanDiscovery afterBeanDiscovery)
{
    if (!ACTIVATED)
    {
        return;
    }

    if (cacheManagerFound && cacheProviderFound) {
        return;
    }

    cachingProvider = Caching.getCachingProvider();
    if (!cacheManagerFound)
    {
        cacheManager = cachingProvider.getCacheManager(
                cachingProvider.getDefaultURI(),
                cachingProvider.getDefaultClassLoader(),
                new Properties());
        afterBeanDiscovery.addBean(new CacheManagerBean(cacheManager));
    }
    if (!cacheProviderFound)
    {
        afterBeanDiscovery.addBean(new CacheProviderBean(cachingProvider));
    }
}
项目:switchyard    文件:SwitchYardCDIServiceDiscovery.java   
/**
 * {@link javax.enterprise.inject.spi.ProcessBean} CDI event observer.
 *
 * @param afterEvent  CDI Event instance.
 */
public void afterBeanDiscovery(@Observes AfterBeanDiscovery afterEvent) {
    for (ClientProxyBean proxyBean : _createdProxyBeans) {
        _logger.debug("Adding ClientProxyBean for bean Service " + proxyBean.getServiceName() + ".  Service Interface type is " + proxyBean.getServiceInterface().getName());
        afterEvent.addBean(proxyBean);
        _beanDeploymentMetaData.addClientProxy(proxyBean);
    }

    for (ReferenceInvokerBean invokerBean : _createdInvokerBeans) {
        _logger.debug("Adding ReferenceInvokerBean for bean Service " + invokerBean.getServiceName());
        afterEvent.addBean(invokerBean);
        _beanDeploymentMetaData.addReferenceInvoker(invokerBean);
    }

    afterEvent.addBean(new BeanDeploymentMetaDataCDIBean(_beanDeploymentMetaData));
    afterEvent.addBean(new ContextBean());
    afterEvent.addBean(new MessageBean());
    afterEvent.addBean(new ExchangeBean());

    _logger.debug("CDI Bean discovery process completed.");
}
项目:deltaspike    文件:ConverterAndValidatorProxyExtension.java   
public <X> void createBeans(@Observes AfterBeanDiscovery afterBeanDiscovery, BeanManager beanManager)
{
    if (!this.isActivated)
    {
        return;
    }

    for (Class<?> originalClass : this.classesToProxy)
    {
        Bean bean = createBean(originalClass, beanManager);

        if (bean != null)
        {
            afterBeanDiscovery.addBean(bean);
        }
    }

    this.classesToProxy.clear();
}
项目:deltaspike    文件:SchedulerExtension.java   
private void initScheduler(AfterBeanDiscovery afterBeanDiscovery)
{
    List<Scheduler> availableSchedulers = ServiceUtils.loadServiceImplementations(Scheduler.class, true);

    this.scheduler = findScheduler(availableSchedulers, this.jobClass);

    if (this.scheduler != null)
    {
        try
        {
            this.scheduler.start();
        }
        catch (Throwable t)
        {
            afterBeanDiscovery.addDefinitionError(t);
        }
    }
    else if (!this.foundManagedJobClasses.isEmpty())
    {
        LOG.warning(
            this.foundManagedJobClasses.size() + " scheduling-jobs found, but there is no configured scheduler");
    }
}
项目:deltaspike    文件:MessageBundleExtension.java   
@SuppressWarnings("UnusedDeclaration")
protected void installMessageBundleProducerBeans(@Observes AfterBeanDiscovery abd, BeanManager beanManager)
{
    if (!deploymentErrors.isEmpty())
    {
        abd.addDefinitionError(new IllegalArgumentException("The following MessageBundle problems where found: " +
                Arrays.toString(deploymentErrors.toArray())));
        return;
    }

    MessageBundleExtension parentExtension = ParentExtensionStorage.getParentExtension(this);
    if (parentExtension != null)
    {
        messageBundleTypes.addAll(parentExtension.messageBundleTypes);
    }

    for (AnnotatedType<?> type : messageBundleTypes)
    {
        abd.addBean(createMessageBundleBean(type, beanManager));
    }
}
项目:deltaspike    文件:ConfigurationExtension.java   
public void addDynamicBeans(@Observes AfterBeanDiscovery afterBeanDiscovery, BeanManager bm)
{
    if (dynamicProducer != null && !dynamicConfigTypes.isEmpty())
    {
        afterBeanDiscovery.addBean(new DynamicBean(dynamicProducer, dynamicConfigTypes));
    }
    for (final Class<?> proxyType : dynamicConfigurationBeanClasses)
    {
        afterBeanDiscovery.addBean(new BeanBuilder(null)
                .types(proxyType, Object.class)
                .qualifiers(new DefaultLiteral(), new AnyLiteral())
                .beanLifecycle(new ProxyConfigurationLifecycle(proxyType))
                .scope(ApplicationScoped.class)
                .passivationCapable(true)
                .id("DeltaSpikeConfiguration#" + proxyType.getName())
                .beanClass(proxyType)
                .create());
    }
}
项目:weld-junit    文件:WeldCDIExtension.java   
void afterBeandiscovery(@Observes AfterBeanDiscovery event) {
    if (scopesToActivate != null) {
        for (Class<? extends Annotation> scope : scopesToActivate) {
            ContextImpl ctx = new ContextImpl(scope);
            contexts.add(ctx);
            event.addContext(ctx);
        }
    }
    if (beans != null) {
        for (Bean<?> bean : beans) {
            event.addBean(bean);
        }
    }
}
项目:reactive-cdi-events    文件:ReactorExtension.java   
public void addRegistryBean(@Observes AfterBeanDiscovery afterBeanDiscovery) {
    afterBeanDiscovery.addBean()
            .types(ReactorObserverRegistry.class)
            .produceWith((Function<Instance<Object>, Object>) f -> REGISTRY)
            .scope(ApplicationScoped.class);
    eventTypes.forEach(ip -> afterBeanDiscovery.addBean()
            .types(ip.getType())
            .scope(Dependent.class)
            .produceWith((Function<Instance<Object>, Object>) inst -> {
                ParameterizedType type = (ParameterizedType) ip.getType();
                Class<?> s = (Class<?>) type.getActualTypeArguments()[0];
                Class<?> r = (Class<?>) type.getActualTypeArguments()[1];
                return new ReactorEventImpl<>(s,r,ip.getQualifiers(),REGISTRY);
            }));
}
项目:cito    文件:BodyProducerExtensionTest.java   
@Test
public void addBeans() {
    final AfterBeanDiscovery abd = mock(AfterBeanDiscovery.class);
    final Bean<?> bean = mock(Bean.class);

    final List<Bean<?>> found = ReflectionUtil.get(this.extension, "found");
    found.add(bean);

    this.extension.addBeans(abd);

    assertTrue(found.isEmpty());

    verify(abd).addBean(bean);
    verifyNoMoreInteractions(abd, bean);
}
项目:cito    文件:ExtensionTest.java   
@Test
public void registerContexts() {
    final AfterBeanDiscovery afterBeanDiscovery = mock(AfterBeanDiscovery.class);

    this.extension.registerContexts(afterBeanDiscovery, this.beanManager);

    verify(afterBeanDiscovery).addContext(any(WebSocketContext.class));
    verify(this.beanManager).isPassivatingScope(WebSocketScope.class);
    verifyNoMoreInteractions(afterBeanDiscovery);
}
项目:wildfly-nosql    文件:Neo4jExtension.java   
void registerNoSQLSourceBeans(@Observes AfterBeanDiscovery abd, BeanManager bm) {
        if (bm.getBeans(driverClass, DefaultLiteral.INSTANCE).isEmpty()) {
            for(String profile: getService().profileNames()) {
                log.log(Level.INFO, "Registering bean for profile {0}", profile);
                abd.addBean(bm.createBean(
                        new DriverBeanAttributes(bm.createBeanAttributes(bm.createAnnotatedType(driverClass)), profile),
                        driverClass, new DriverProducerFactory(profile, driverClass)));
//                TODO: uncomment or delete the following.
//                abd.addBean(bm.createBean(new SessionBeanAttributes(bm.createBeanAttributes(bm.createAnnotatedType(Session.class)),profile),
//                        Session.class, new SessionProducerFactory(profile)));
            }
         } else {
            log.log(Level.INFO, "Application contains a default Driver Bean, automatic registration will be disabled");
        }
    }
项目:wildfly-nosql    文件:OrientExtension.java   
public void registerNoSQLSourceBeans(@Observes AfterBeanDiscovery afterBeanDiscovery, BeanManager beanManager) {
    if (beanManager.getBeans(oPartitionedDatabasePoolClass, DefaultLiteral.INSTANCE).isEmpty()) {
        for(String profile: getService().profileNames()) {
            LOGGER.log(Level.INFO, "Registering " + oPartitionedDatabasePoolClass + " bean for profile {0}", profile);
            afterBeanDiscovery.addBean(getBean(beanManager, oPartitionedDatabasePoolClass, profile));
        }
    } else {
        LOGGER.log(Level.INFO, "Application contains a default " + oPartitionedDatabasePoolClass
                + " Bean, automatic registration will be disabled");
    }
}
项目:ee8-sandbox    文件:CdiConfig.java   
public void addABean(@Observes AfterBeanDiscovery event) {
    // get an instance of BeanConfigurator
    event.addBean()
            // set the desired data
            .types(Greeter.class)
            .scope(ApplicationScoped.class)
            .addQualifier(Default.Literal.INSTANCE)
            //.addQualifier(Custom.CustomLiteral.INSTANCE);
            //finally, add a callback to tell CDI how to instantiate this bean
            .produceWith(obj -> new Greeter());
}
项目:weld-vertx    文件:VertxExtension.java   
public void registerBeansAfterBeanDiscovery(@Observes AfterBeanDiscovery event) {
    if (vertx == null) {
        // Do no register beans - no Vertx instance available during bootstrap
        return;
    }
    // Allow to inject Vertx used to deploy the WeldVerticle
    event.addBean().types(getBeanTypes(vertx.getClass(), Vertx.class)).addQualifiers(Any.Literal.INSTANCE, Default.Literal.INSTANCE)
            .scope(ApplicationScoped.class).createWith(c -> vertx);
    // Allow to inject Context of the WeldVerticle
    event.addBean().types(getBeanTypes(context.getClass(), Context.class)).addQualifiers(Any.Literal.INSTANCE, Default.Literal.INSTANCE)
            .scope(ApplicationScoped.class).createWith(c -> context);
}
项目:opendata-common    文件:HazelcastExtension.java   
public void afterBeanDiscovery( @Observes AfterBeanDiscovery type )
{
    LOG.log( Level.INFO, "Getting CachingProvider" );
    provider = Caching.getCachingProvider();

    // Obtain the CacheManager - this will force Hazelcast to start up.
    // We'll report the available cache names anyhow
    LOG.log( Level.INFO, "Getting CacheManager" );
    provider.getCacheManager().
            getCacheNames().
            forEach( cacheName -> LOG.log( Level.INFO, () -> "Found cache: " + cacheName ) );

    LOG.log( Level.INFO, "Hazelcast & JCache started" );
}
项目:wildfly-swarm    文件:MPJWTExtension.java   
/**
 * Create producer methods for each ClaimValue injection site
 *
 * @param event       - AfterBeanDiscovery
 * @param beanManager - CDI bean manager
 */
void observesAfterBeanDiscovery(@Observes final AfterBeanDiscovery event, final BeanManager beanManager) {
    log.debugf("observesAfterBeanDiscovery, %s", claims);
    installClaimValueProducerMethodsViaSyntheticBeans(event, beanManager);

    //installClaimValueProducesViaTemplateType(event, beanManager);
}
项目:wildfly-swarm    文件:ConfigViewProducingExtension.java   
@SuppressWarnings("unused")
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager beanManager) throws Exception {
    try (AutoCloseable handle = Performance.time("ConfigViewProducingExtension.afterBeanDiscovery")) {
        CommonBean<ConfigView> configViewBean = CommonBeanBuilder.newBuilder(ConfigView.class)
                .beanClass(ConfigViewProducingExtension.class)
                .scope(Singleton.class)
                .addQualifier(DefaultLiteral.INSTANCE)
                .createSupplier(() -> configView)
                .addType(ConfigView.class)
                .addType(Object.class).build();
        abd.addBean(configViewBean);
    }
}
项目:wildfly-swarm    文件:XMLConfigProducingExtension.java   
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager beanManager) throws Exception {
    try (AutoCloseable handle = Performance.time("XMLConfigProducingExtension.afterBeanDiscovery")) {
        CommonBean<URL> urlBean = CommonBeanBuilder.newBuilder(URL.class)
                .beanClass(XMLConfigProducingExtension.class)
                .scope(Dependent.class)
                .addQualifier(XMLConfig.Literal.INSTANCE)
                .createSupplier(this::getXMLConfig)
                .addType(URL.class)
                .addType(Object.class).build();
        abd.addBean(urlBean);
    }
}
项目:wildfly-swarm    文件:SocketBindingExtension.java   
@SuppressWarnings("unused")
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager beanManager) throws Exception {
    try (AutoCloseable handle = Performance.time("SocketBindingExtension.afterBeanDiscovery")) {

        for (SocketBindingRequest each : this.bindings) {

            Supplier<Customizer> supplier = () -> (Customizer) () -> {
                Set<Bean<?>> groups = beanManager.getBeans(SocketBindingGroup.class, AnyLiteral.INSTANCE);

                groups.stream()
                        .map((Bean<?> e) -> {
                            CreationalContext<?> ctx = beanManager.createCreationalContext(e);
                            return (SocketBindingGroup) beanManager.getReference(e, SocketBindingGroup.class, ctx);
                        })
                        .filter(group -> group.name().equals(each.socketBindingGroup()))
                        .findFirst()
                        .ifPresent((group) -> group.socketBinding(each.socketBinding()));
            };

            CommonBean<Customizer> customizerBean = CommonBeanBuilder.newBuilder(Customizer.class)
                    .beanClass(SocketBindingExtension.class)
                    .scope(Singleton.class)
                    .addQualifier(new AnnotationLiteral<Pre>() {
                    })
                    .addQualifier(AnyLiteral.INSTANCE)
                    .createSupplier(supplier)
                    .addType(Customizer.class)
                    .addType(Object.class).build();
            abd.addBean(customizerBean);
        }
    }
}
项目:wildfly-swarm    文件:OutboundSocketBindingExtension.java   
@SuppressWarnings("unused")
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager beanManager) throws Exception {
    try (AutoCloseable handle = Performance.time("OutboundSocketBindingExtension.afterBeanDiscovery")) {
        for (OutboundSocketBindingRequest each : this.bindings) {

            Supplier<Customizer> customizerSupplier = () -> (Customizer) () -> {
                Set<Bean<?>> groups = beanManager.getBeans(SocketBindingGroup.class, AnyLiteral.INSTANCE);

                groups.stream()
                        .map((Bean<?> e) -> {
                            CreationalContext<?> ctx = beanManager.createCreationalContext(e);
                            return (SocketBindingGroup) beanManager.getReference(e, SocketBindingGroup.class, ctx);
                        })
                        .filter(group -> group.name().equals(each.socketBindingGroup()))
                        .findFirst()
                        .ifPresent((group) -> group.outboundSocketBinding(each.outboundSocketBinding()));
            };
            CommonBean<Customizer> customizerBean = CommonBeanBuilder.newBuilder(Customizer.class)
                    .beanClass(OutboundSocketBindingExtension.class)
                    .scope(Singleton.class)
                    .addQualifier(new AnnotationLiteral<Pre>() {
                    })
                    .addQualifier(AnyLiteral.INSTANCE)
                    .createSupplier(customizerSupplier)
                    .addType(Customizer.class)
                    .addType(Object.class).build();
            abd.addBean(customizerBean);
        }
    }
}
项目:wildfly-swarm    文件:SocketBindingGroupExtension.java   
@SuppressWarnings("unused")
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager beanManager) throws Exception {

    List<SimpleKey> configuredGroups = this.configView.simpleSubkeys(ROOT);
    for (SimpleKey groupName : configuredGroups) {
        Set<Bean<?>> groups = beanManager.getBeans(SocketBindingGroup.class, AnyLiteral.INSTANCE);
        AtomicBoolean producerRequired = new AtomicBoolean(false);
        if (groups
                .stream()
                .noneMatch(e -> e.getQualifiers()
                        .stream()
                        .anyMatch(anno -> anno instanceof Named && ((Named) anno).value().equals(groupName)))) {

            SocketBindingGroup group = new SocketBindingGroup(groupName.name(), null, "0");

            applyConfiguration(group);

            if (producerRequired.get()) {
                CommonBean<SocketBindingGroup> interfaceBean = CommonBeanBuilder.newBuilder(SocketBindingGroup.class)
                        .beanClass(SocketBindingGroupExtension.class)
                        .scope(ApplicationScoped.class)
                        .addQualifier(AnyLiteral.INSTANCE)
                        .addQualifier(new NamedLiteral(group.name()))
                        .createSupplier(() -> group)
                        .addType(SocketBindingGroup.class)
                        .addType(Object.class)
                        .build();

                abd.addBean(interfaceBean);
            }
        }
    }
}
项目:wildfly-swarm    文件:ConfigurableExtension.java   
@SuppressWarnings({"unused"})
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd) throws Exception {
    try (AutoCloseable handle = Performance.time("ConfigurationExtension.afterBeanDiscovery")) {
        CommonBean<ConfigurableManager> configurableManagerBean = CommonBeanBuilder.newBuilder(ConfigurableManager.class)
                .beanClass(ConfigurableManager.class)
                .scope(Singleton.class)
                .addQualifier(DefaultLiteral.INSTANCE)
                .createSupplier(() -> configurableManager)
                .addType(ConfigurableManager.class)
                .addType(Object.class).build();
        abd.addBean(configurableManagerBean);
    }
}
项目:wildfly-swarm    文件:InterfaceExtension.java   
@SuppressWarnings("unused")
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager beanManager) throws Exception {

    List<SimpleKey> configuredInterfaces = this.configView.simpleSubkeys(ROOT);

    for (SimpleKey interfaceName : configuredInterfaces) {

        Set<Bean<?>> ifaces = beanManager.getBeans(Interface.class, AnyLiteral.INSTANCE);

        AtomicBoolean producerRequired = new AtomicBoolean(false);

        if (ifaces
                .stream()
                .noneMatch(e -> e.getQualifiers()
                        .stream()
                        .anyMatch(anno -> anno instanceof Named && ((Named) anno).value().equals(interfaceName + "-interface")))) {

            Interface iface = new Interface(interfaceName.name(), "0.0.0.0");
            applyConfiguration(iface);
            if (producerRequired.get()) {
                CommonBean<Interface> interfaceBean = CommonBeanBuilder.newBuilder(Interface.class)
                        .beanClass(InterfaceExtension.class)
                        .scope(ApplicationScoped.class)
                        .addQualifier(AnyLiteral.INSTANCE)
                        .addQualifier(new NamedLiteral(interfaceName.name() + "-interface"))
                        .createSupplier(() -> iface)
                        .addType(Interface.class)
                        .addType(Object.class)
                        .build();

                abd.addBean(interfaceBean);
            }
        }
    }
}
项目:javaConfig    文件:ConfigExtension.java   
public void registerConfigProducer(@Observes AfterBeanDiscovery abd, BeanManager bm) {
    Set<Class> types = injectionPoints.stream()
            .filter(ip -> ip.getType() instanceof Class)
            .map(ip -> (Class) ip.getType())
            .collect(Collectors.toSet());

    // Provider and Optional are ParameterizedTypes and not a Class, so we need to add them manually
    types.add(Provider.class);
    types.add(Optional.class);

    types.forEach(type -> abd.addBean(new ConfigInjectionBean(bm, type)));
}
项目:appformer    文件:WorkspaceScopedExtension.java   
public void afterBeanDiscovery(@Observes AfterBeanDiscovery abd,
                               BeanManager beanManager) {
    if (logger.isDebugEnabled()) {
        logger.debug("After bean discovery, adding WorkspaceScopeContext");
    }

    abd.addContext(new WorkspaceScopeContext(beanManager));
}
项目:appformer    文件:SystemConfigProducer.java   
private void buildSystemFS(final AfterBeanDiscovery abd,
                           final BeanManager bm) {
    final InjectionTarget<DummyFileSystem> it = bm.createInjectionTarget(bm.createAnnotatedType(DummyFileSystem.class));

    abd.addBean(createFileSystemBean(bm,
                                     it));
}
项目:osgi.ee    文件:ScopeExtension.java   
/**
 * Handling of the after bean discovery event as fired by the bean manager. The handling creates
 * contexts for the session and request scopes.
 * 
 * @param event The event that can be used for the actions
 */
public void afterBeanDiscovery(@Observes AfterBeanDiscovery event) {
    // Register the session scope context.
    event.addContext(registerContext(addContext(new MultiInstanceContext(SessionScoped.class, null))));
    // And the request scope context.
    event.addContext(registerContext(addContext(new MultiInstanceContext(RequestScoped.class, null))));
    // And the bundle scope.
    event.addContext(addContext(new BasicContext(ComponentScoped.class, null)));
    // And the view scope.
    event.addContext(registerContext(addContext(new MultiInstanceContext(ViewScoped.class, null))));
}
项目:javaee-nosql    文件:MongoExtension.java   
/**
 * If the application has a {@link MongoClientDefinition} register the bean for it unless user has defined a bean or a
 * producer for a <code>MongoClient</code>
 */
void registerDataSourceBeans(@Observes AfterBeanDiscovery abd, BeanManager bm) {

    if (mongoDef != null) {
        if (bm.getBeans(MongoClient.class, DefaultLiteral.INSTANCE).isEmpty()) {
            log.log(Level.INFO, "Registering bean for MongoDB datasource {0}", mongoDef.name());
            MongoClientURI uri = new MongoClientURI(mongoDef.url());
            abd.addBean(bm.createBean(new MongoClientBeanAttributes(bm.createBeanAttributes(bm.createAnnotatedType
                    (MongoClient.class))), MongoClient.class, new MongoClientProducerFactory(uri)));
        } else {
            log.log(Level.INFO, "Application contains a default MongoClient Bean, automatic registration will be disabled");
        }
    }
}
项目:portals-pluto    文件:PortletCDIExtension.java   
/**
 * Add the context for the custom scope implementations.
 * 
 * @param abd
 */
void addPortletCustomScopeContexts(@Observes AfterBeanDiscovery abd) {
   PortletSessionScopedContext pssc = new PortletSessionScopedContext();
   abd.addContext(pssc);

   PortletStateScopedContext pstsc = new PortletStateScopedContext();
   abd.addContext(pstsc);

   PortletRequestScopedContext prsc = new PortletRequestScopedContext();
   abd.addContext(prsc);
}
项目:camel-cdi    文件:CdiCamelExtension.java   
private <T> void addCdiEventObserver(AfterBeanDiscovery abd, CdiEventEndpoint<T> endpoint) {
    abd.<T>addObserverMethod()
        .beanClass(CdiEventComponent.class)
        .observedType(endpoint.getType())
        .qualifiers(endpoint.getQualifiers())
        // TODO: propagate the event metadata
        .notifyWith(context -> endpoint.notify(context.getEvent()));
}
项目:weld-se-scopes    文件:CustomScopeExtension.java   
public void afterBeanDiscovery(@Observes AfterBeanDiscovery event, BeanManager manager) {
    BeanStore beanStore = new HashMapBeanStore();
    final CustomContext customContext = new CustomContext();
    customContext.setBeanStore(beanStore);

    customContext.setActive(true);
    event.addContext(customContext);
    CUSTOM_CONTEXT = customContext;
}
项目:transaction-cdi    文件:TransactionExtension.java   
/**
 * Observes {@link AfterBeanDiscovery} event.
 *
 * @param event {@link AfterBeanDiscovery} event.
 * @param beanManager {@link BeanManager}.
 */
void afterBeanDiscovered(
    @Observes AfterBeanDiscovery event,
    BeanManager beanManager)
{
    event.addContext(new TransactionalContext(beanManager));
}