org.springframework.beans.factory.ListableBeanFactory

Here are the examples of the java api org.springframework.beans.factory.ListableBeanFactory taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

154 Examples 7

19 Source : ArtemisConnectionFactoryFactory.java
with Apache License 2.0
from yuanmabiji

/**
 * Factory to create an Artemis {@link ActiveMQConnectionFactory} instance from properties
 * defined in {@link ArtemisProperties}.
 *
 * @author Eddú Meléndez
 * @author Phillip Webb
 * @author Stephane Nicoll
 */
clreplaced ArtemisConnectionFactoryFactory {

    static final String EMBEDDED_JMS_CLreplaced = "org.apache.activemq.artemis.jms.server.embedded.EmbeddedJMS";

    private final ArtemisProperties properties;

    private final ListableBeanFactory beanFactory;

    ArtemisConnectionFactoryFactory(ListableBeanFactory beanFactory, ArtemisProperties properties) {
        replacedert.notNull(beanFactory, "BeanFactory must not be null");
        replacedert.notNull(properties, "Properties must not be null");
        this.beanFactory = beanFactory;
        this.properties = properties;
    }

    public <T extends ActiveMQConnectionFactory> T createConnectionFactory(Clreplaced<T> factoryClreplaced) {
        try {
            startEmbeddedJms();
            return doCreateConnectionFactory(factoryClreplaced);
        } catch (Exception ex) {
            throw new IllegalStateException("Unable to create " + "ActiveMQConnectionFactory", ex);
        }
    }

    private void startEmbeddedJms() {
        if (ClreplacedUtils.isPresent(EMBEDDED_JMS_CLreplaced, null)) {
            try {
                this.beanFactory.getBeansOfType(Clreplaced.forName(EMBEDDED_JMS_CLreplaced));
            } catch (Exception ex) {
            // Ignore
            }
        }
    }

    private <T extends ActiveMQConnectionFactory> T doCreateConnectionFactory(Clreplaced<T> factoryClreplaced) throws Exception {
        ArtemisMode mode = this.properties.getMode();
        if (mode == null) {
            mode = deduceMode();
        }
        if (mode == ArtemisMode.EMBEDDED) {
            return createEmbeddedConnectionFactory(factoryClreplaced);
        }
        return createNativeConnectionFactory(factoryClreplaced);
    }

    /**
     * Deduce the {@link ArtemisMode} to use if none has been set.
     * @return the mode
     */
    private ArtemisMode deduceMode() {
        if (this.properties.getEmbedded().isEnabled() && ClreplacedUtils.isPresent(EMBEDDED_JMS_CLreplaced, null)) {
            return ArtemisMode.EMBEDDED;
        }
        return ArtemisMode.NATIVE;
    }

    private <T extends ActiveMQConnectionFactory> T createEmbeddedConnectionFactory(Clreplaced<T> factoryClreplaced) throws Exception {
        try {
            TransportConfiguration transportConfiguration = new TransportConfiguration(InVMConnectorFactory.clreplaced.getName(), this.properties.getEmbedded().generateTransportParameters());
            ServerLocator serviceLocator = ActiveMQClient.createServerLocatorWithoutHA(transportConfiguration);
            return factoryClreplaced.getConstructor(ServerLocator.clreplaced).newInstance(serviceLocator);
        } catch (NoClreplacedDefFoundError ex) {
            throw new IllegalStateException("Unable to create InVM " + "Artemis connection, ensure that artemis-jms-server.jar " + "is in the clreplacedpath", ex);
        }
    }

    private <T extends ActiveMQConnectionFactory> T createNativeConnectionFactory(Clreplaced<T> factoryClreplaced) throws Exception {
        Map<String, Object> params = new HashMap<>();
        params.put(TransportConstants.HOST_PROP_NAME, this.properties.getHost());
        params.put(TransportConstants.PORT_PROP_NAME, this.properties.getPort());
        TransportConfiguration transportConfiguration = new TransportConfiguration(NettyConnectorFactory.clreplaced.getName(), params);
        Constructor<T> constructor = factoryClreplaced.getConstructor(boolean.clreplaced, TransportConfiguration[].clreplaced);
        T connectionFactory = constructor.newInstance(false, new TransportConfiguration[] { transportConfiguration });
        String user = this.properties.getUser();
        if (StringUtils.hasText(user)) {
            connectionFactory.setUser(user);
            connectionFactory.setPreplacedword(this.properties.getPreplacedword());
        }
        return connectionFactory;
    }
}

19 Source : ManagementWebServerFactoryCustomizer.java
with Apache License 2.0
from yuanmabiji

/**
 * {@link WebServerFactoryCustomizer} that customizes the {@link WebServerFactory} used to
 * create the management context's web server.
 *
 * @param <T> the type of web server factory to customize
 * @author Andy Wilkinson
 * @since 2.0.0
 */
public abstract clreplaced ManagementWebServerFactoryCustomizer<T extends ConfigurableWebServerFactory> implements WebServerFactoryCustomizer<T>, Ordered {

    private final ListableBeanFactory beanFactory;

    private final Clreplaced<? extends WebServerFactoryCustomizer<?>>[] customizerClreplacedes;

    @SafeVarargs
    protected ManagementWebServerFactoryCustomizer(ListableBeanFactory beanFactory, Clreplaced<? extends WebServerFactoryCustomizer<?>>... customizerClreplacedes) {
        this.beanFactory = beanFactory;
        this.customizerClreplacedes = customizerClreplacedes;
    }

    @Override
    public int getOrder() {
        return 0;
    }

    @Override
    public final void customize(T factory) {
        ManagementServerProperties managementServerProperties = BeanFactoryUtils.beanOfTypeIncludingAncestors(this.beanFactory, ManagementServerProperties.clreplaced);
        // Customize as per the parent context first (so e.g. the access logs go to
        // the same place)
        customizeSameAsParentContext(factory);
        // Then reset the error pages
        factory.setErrorPages(Collections.emptySet());
        // and add the management-specific bits
        ServerProperties serverProperties = BeanFactoryUtils.beanOfTypeIncludingAncestors(this.beanFactory, ServerProperties.clreplaced);
        customize(factory, managementServerProperties, serverProperties);
    }

    private void customizeSameAsParentContext(T factory) {
        List<WebServerFactoryCustomizer<?>> customizers = Arrays.stream(this.customizerClreplacedes).map(this::getCustomizer).filter(Objects::nonNull).collect(Collectors.toList());
        invokeCustomizers(factory, customizers);
    }

    private WebServerFactoryCustomizer<?> getCustomizer(Clreplaced<? extends WebServerFactoryCustomizer<?>> customizerClreplaced) {
        try {
            return BeanFactoryUtils.beanOfTypeIncludingAncestors(this.beanFactory, customizerClreplaced);
        } catch (NoSuchBeanDefinitionException ex) {
            return null;
        }
    }

    @SuppressWarnings("unchecked")
    private void invokeCustomizers(T factory, List<WebServerFactoryCustomizer<?>> customizers) {
        LambdaSafe.callbacks(WebServerFactoryCustomizer.clreplaced, customizers, factory).invoke((customizer) -> customizer.customize(factory));
    }

    protected void customize(T factory, ManagementServerProperties managementServerProperties, ServerProperties serverProperties) {
        factory.setPort(managementServerProperties.getPort());
        Ssl ssl = managementServerProperties.getSsl();
        if (ssl != null) {
            factory.setSsl(ssl);
        }
        factory.setServerHeader(serverProperties.getServerHeader());
        factory.setAddress(managementServerProperties.getAddress());
        factory.addErrorPages(new ErrorPage(serverProperties.getError().getPath()));
    }
}

19 Source : ServletContextInitializerBeans.java
with Apache License 2.0
from yuanmabiji

protected <T> void addAsRegistrationBean(ListableBeanFactory beanFactory, Clreplaced<T> type, RegistrationBeanAdapter<T> adapter) {
    addAsRegistrationBean(beanFactory, type, type, adapter);
}

19 Source : MBeanExporter.java
with MIT License
from Vip-Augus

/**
 * Return whether the specified bean definition should be considered as lazy-init.
 * @param beanFactory the bean factory that is supposed to contain the bean definition
 * @param beanName the name of the bean to check
 * @see org.springframework.beans.factory.config.ConfigurableListableBeanFactory#getBeanDefinition
 * @see org.springframework.beans.factory.config.BeanDefinition#isLazyInit
 */
protected boolean isBeanDefinitionLazyInit(ListableBeanFactory beanFactory, String beanName) {
    return (beanFactory instanceof ConfigurableListableBeanFactory && beanFactory.containsBeanDefinition(beanName) && ((ConfigurableListableBeanFactory) beanFactory).getBeanDefinition(beanName).isLazyInit());
}

19 Source : MBeanExporter.java
with MIT License
from Vip-Augus

/**
 * Return whether the specified bean definition should be considered as abstract.
 */
private boolean isBeanDefinitionAbstract(ListableBeanFactory beanFactory, String beanName) {
    return (beanFactory instanceof ConfigurableListableBeanFactory && beanFactory.containsBeanDefinition(beanName) && ((ConfigurableListableBeanFactory) beanFactory).getBeanDefinition(beanName).isAbstract());
}

19 Source : BeanFactoryUtils.java
with Apache License 2.0
from spring-projects-experimental

public static <T> ObjectProvider<T[]> array(ListableBeanFactory beans, Clreplaced<T> type) {
    return new ObjectProvider<T[]>() {

        @SuppressWarnings("unchecked")
        private T[] prototype = (T[]) Array.newInstance(type, 0);

        @Override
        public T[] getObject() throws BeansException {
            return beans.getBeanProvider(type).orderedStream().collect(Collectors.toList()).toArray(prototype);
        }

        @Override
        public T[] getObject(Object... args) throws BeansException {
            return getObject();
        }

        @Override
        public T[] getIfAvailable() throws BeansException {
            return getObject();
        }

        @Override
        public T[] getIfUnique() throws BeansException {
            return getObject();
        }
    };
}

19 Source : BeanFactoryUtils.java
with Apache License 2.0
from spring-projects-experimental

public static <T> ObjectProvider<Map<String, T>> map(ListableBeanFactory beans, Clreplaced<T> type) {
    return new ObjectProvider<Map<String, T>>() {

        @Override
        public Map<String, T> getObject() throws BeansException {
            return beans.getBeansOfType(type);
        }

        @Override
        public Map<String, T> getObject(Object... args) throws BeansException {
            return getObject();
        }

        @Override
        public Map<String, T> getIfAvailable() throws BeansException {
            return getObject();
        }

        @Override
        public Map<String, T> getIfUnique() throws BeansException {
            return getObject();
        }
    };
}

19 Source : ResourceServerPropertiesTests.java
with Apache License 2.0
from spring-projects

private void setListableBeanFactory() {
    ListableBeanFactory beanFactory = new StaticWebApplicationContext() {

        @Override
        public String[] getBeanNamesForType(Clreplaced<?> type, boolean includeNonSingletons, boolean allowEagerInit) {
            if (type.isreplacedignableFrom(ResourceServerTokenServicesConfiguration.clreplaced)) {
                return new String[] { "ResourceServerTokenServicesConfiguration" };
            }
            return new String[0];
        }
    };
    this.properties.setBeanFactory(beanFactory);
}

19 Source : DataSourceBeanFactoryPostProcessor.java
with Apache License 2.0
from sofastack

private Iterable<String> getBeanNames(ListableBeanFactory beanFactory, Clreplaced clazzType) {
    return new HashSet<>(Arrays.asList(BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, clazzType, true, false)));
}

19 Source : BaseManager.java
with GNU General Public License v2.0
from rackshift

public clreplaced BaseManager {

    private Clreplaced<? extends Annotation> pluginAnnotationType;

    private String pluginBasePackage;

    private ListableBeanFactory context;

    public BaseManager(Clreplaced<? extends Annotation> pluginAnnotationType, String pluginBasePackage) {
        this.pluginAnnotationType = pluginAnnotationType;
        this.pluginBasePackage = pluginBasePackage;
    }

    public void init() {
        loadContext();
    }

    private void loadContext() {
        if (context == null) {
            // Create a parent context containing all beans provided to plugins
            // More on that below in the article...
            GenericApplicationContext parentContext = new GenericApplicationContext();
            parentContext.refresh();
            // Create the annotation-based context
            AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
            context.setParent(parentContext);
            // Scan for clreplacedes annotated with @<PluginAnnotaionType>,
            // do not include standard Spring annotations in scan
            ClreplacedPathBeanDefinitionScanner scanner = new ClreplacedPathBeanDefinitionScanner(context, false);
            scanner.addIncludeFilter(new AnnotationTypeFilter(pluginAnnotationType));
            scanner.scan(pluginBasePackage);
            context.refresh();
            this.context = context;
        }
    }

    private Collection getPluginDescriptors(ListableBeanFactory context) {
        return context.getBeansWithAnnotation(pluginAnnotationType).values();
    }

    public String getPluginBasePackage() {
        return pluginBasePackage;
    }

    protected Collection getPlugins() {
        loadContext();
        return getPluginDescriptors(context);
    }
}

19 Source : BaseManager.java
with GNU General Public License v2.0
from rackshift

private Collection getPluginDescriptors(ListableBeanFactory context) {
    return context.getBeansWithAnnotation(pluginAnnotationType).values();
}

19 Source : CompositeMessageServiceRegistrar.java
with Apache License 2.0
from penggle

/**
 * @author pengpeng
 * @version 1.0
 * @date 2020/9/16 20:38
 */
public clreplaced CompositeMessageServiceRegistrar implements ImportBeanDefinitionRegistrar, BeanFactoryAware {

    private ListableBeanFactory beanFactory;

    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClreplacedMetadata, BeanDefinitionRegistry registry) {
        System.out.println(String.format("【CompositeMessageServiceRegistrar】>>> registerBeanDefinitions(%s, %s)", importingClreplacedMetadata, registry));
        String[] candidateNames = beanFactory.getBeanNamesForType(MessageService.clreplaced);
        String beanName = "compositeMessageService";
        if (!ArrayUtils.isEmpty(candidateNames) && !registry.containsBeanDefinition(beanName)) {
            registry.registerBeanDefinition(beanName, new RootBeanDefinition(CompositeMessageService.clreplaced));
        }
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println(String.format("【CompositeMessageServiceRegistrar】>>> setBeanFactory(%s)", beanFactory));
        this.beanFactory = (ListableBeanFactory) beanFactory;
    }
}

19 Source : PersistenceExceptionTranslationInterceptor.java
with Apache License 2.0
from langtianya

/**
 * AOP Alliance MethodInterceptor that provides persistence exception translation
 * based on a given PersistenceExceptionTranslator.
 *
 * <p>Delegates to the given {@link PersistenceExceptionTranslator} to translate
 * a RuntimeException thrown into Spring's DataAccessException hierarchy
 * (if appropriate). If the RuntimeException in question is declared on the
 * target method, it is always propagated as-is (with no translation applied).
 *
 * @author Rod Johnson
 * @author Juergen Hoeller
 * @since 2.0
 * @see PersistenceExceptionTranslator
 */
public clreplaced PersistenceExceptionTranslationInterceptor implements MethodInterceptor, BeanFactoryAware, InitializingBean {

    private volatile PersistenceExceptionTranslator persistenceExceptionTranslator;

    private boolean alwaysTranslate = false;

    private ListableBeanFactory beanFactory;

    /**
     * Create a new PersistenceExceptionTranslationInterceptor.
     * Needs to be configured with a PersistenceExceptionTranslator afterwards.
     * @see #setPersistenceExceptionTranslator
     */
    public PersistenceExceptionTranslationInterceptor() {
    }

    /**
     * Create a new PersistenceExceptionTranslationInterceptor
     * for the given PersistenceExceptionTranslator.
     * @param pet the PersistenceExceptionTranslator to use
     */
    public PersistenceExceptionTranslationInterceptor(PersistenceExceptionTranslator pet) {
        replacedert.notNull(pet, "PersistenceExceptionTranslator must not be null");
        this.persistenceExceptionTranslator = pet;
    }

    /**
     * Create a new PersistenceExceptionTranslationInterceptor, autodetecting
     * PersistenceExceptionTranslators in the given BeanFactory.
     * @param beanFactory the ListableBeanFactory to obtaining all
     * PersistenceExceptionTranslators from
     */
    public PersistenceExceptionTranslationInterceptor(ListableBeanFactory beanFactory) {
        replacedert.notNull(beanFactory, "ListableBeanFactory must not be null");
        this.beanFactory = beanFactory;
    }

    /**
     * Specify the PersistenceExceptionTranslator to use.
     * <p>Default is to autodetect all PersistenceExceptionTranslators
     * in the containing BeanFactory, using them in a chain.
     * @see #detectPersistenceExceptionTranslators
     */
    public void setPersistenceExceptionTranslator(PersistenceExceptionTranslator pet) {
        this.persistenceExceptionTranslator = pet;
    }

    /**
     * Specify whether to always translate the exception ("true"), or whether throw the
     * raw exception when declared, i.e. when the originating method signature's exception
     * declarations allow for the raw exception to be thrown ("false").
     * <p>Default is "false". Switch this flag to "true" in order to always translate
     * applicable exceptions, independent from the originating method signature.
     * <p>Note that the originating method does not have to declare the specific exception.
     * Any base clreplaced will do as well, even {@code throws Exception}: As long as the
     * originating method does explicitly declare compatible exceptions, the raw exception
     * will be rethrown. If you would like to avoid throwing raw exceptions in any case,
     * switch this flag to "true".
     */
    public void setAlwaysTranslate(boolean alwaysTranslate) {
        this.alwaysTranslate = alwaysTranslate;
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        if (this.persistenceExceptionTranslator == null) {
            // No explicit exception translator specified - perform autodetection.
            if (!(beanFactory instanceof ListableBeanFactory)) {
                throw new IllegalArgumentException("Cannot use PersistenceExceptionTranslator autodetection without ListableBeanFactory");
            }
            this.beanFactory = (ListableBeanFactory) beanFactory;
        }
    }

    @Override
    public void afterPropertiesSet() {
        if (this.persistenceExceptionTranslator == null && this.beanFactory == null) {
            throw new IllegalArgumentException("Property 'persistenceExceptionTranslator' is required");
        }
    }

    @Override
    public Object invoke(MethodInvocation mi) throws Throwable {
        try {
            return mi.proceed();
        } catch (RuntimeException ex) {
            // Let it throw raw if the type of the exception is on the throws clause of the method.
            if (!this.alwaysTranslate && ReflectionUtils.declaresException(mi.getMethod(), ex.getClreplaced())) {
                throw ex;
            } else {
                if (this.persistenceExceptionTranslator == null) {
                    this.persistenceExceptionTranslator = detectPersistenceExceptionTranslators(this.beanFactory);
                }
                throw DataAccessUtils.translateIfNecessary(ex, this.persistenceExceptionTranslator);
            }
        }
    }

    /**
     * Detect all PersistenceExceptionTranslators in the given BeanFactory.
     * @param beanFactory the ListableBeanFactory to obtaining all
     * PersistenceExceptionTranslators from
     * @return a chained PersistenceExceptionTranslator, combining all
     * PersistenceExceptionTranslators found in the factory
     * @see ChainedPersistenceExceptionTranslator
     */
    protected PersistenceExceptionTranslator detectPersistenceExceptionTranslators(ListableBeanFactory beanFactory) {
        // Find all translators, being careful not to activate FactoryBeans.
        Map<String, PersistenceExceptionTranslator> pets = BeanFactoryUtils.beansOfTypeIncludingAncestors(beanFactory, PersistenceExceptionTranslator.clreplaced, false, false);
        ChainedPersistenceExceptionTranslator cpet = new ChainedPersistenceExceptionTranslator();
        for (PersistenceExceptionTranslator pet : pets.values()) {
            cpet.addDelegate(pet);
        }
        return cpet;
    }
}

19 Source : OrderServiceClient.java
with Apache License 2.0
from IBM-Cloud

/**
 * Demo client clreplaced for remote OrderServices, to be invoked as standalone
 * program from the command line, e.g. via "client.bat" or "run.xml".
 *
 * <p>You need to specify an order ID and optionally a number of calls,
 * e.g. for order ID 1000: 'client 1000' for a single call per service or
 * 'client 1000 10' for 10 calls each".
 *
 * <p>Reads in the application context from a "clientContext.xml" file in
 * the VM execution directory, calling all OrderService proxies defined in it.
 * See that file for details.
 *
 * @author Juergen Hoeller
 * @since 26.12.2003
 * @see org.springframework.samples.jpetstore.domain.logic.OrderService
 */
public clreplaced OrderServiceClient {

    public static final String CLIENT_CONTEXT_CONFIG_LOCATION = "clientContext.xml";

    private final ListableBeanFactory beanFactory;

    public OrderServiceClient(ListableBeanFactory beanFactory) {
        this.beanFactory = beanFactory;
    }

    public void invokeOrderServices(int orderId, int nrOfCalls) {
        StopWatch stopWatch = new StopWatch(nrOfCalls + " OrderService call(s)");
        Map orderServices = this.beanFactory.getBeansOfType(OrderService.clreplaced);
        for (Iterator it = orderServices.keySet().iterator(); it.hasNext(); ) {
            String beanName = (String) it.next();
            OrderService orderService = (OrderService) orderServices.get(beanName);
            System.out.println("Calling OrderService '" + beanName + "' with order ID " + orderId);
            stopWatch.start(beanName);
            Order order = null;
            for (int i = 0; i < nrOfCalls; i++) {
                order = orderService.getOrder(orderId);
            }
            stopWatch.stop();
            if (order != null) {
                printOrder(order);
            } else {
                System.out.println("Order with ID " + orderId + " not found");
            }
            System.out.println();
        }
        System.out.println(stopWatch.prettyPrint());
    }

    protected void printOrder(Order order) {
        System.out.println("Got order with order ID " + order.getOrderId() + " and order date " + order.getOrderDate());
        System.out.println("Shipping address is: " + order.getShipAddress1());
        for (Iterator lineItems = order.getLineItems().iterator(); lineItems.hasNext(); ) {
            LineItem lineItem = (LineItem) lineItems.next();
            System.out.println("LineItem " + lineItem.getLineNumber() + ": " + lineItem.getQuanreplacedy() + " piece(s) of item " + lineItem.gereplacedemId());
        }
    }

    public static void main(String[] args) {
        if (args.length == 0 || "".equals(args[0])) {
            System.out.println("You need to specify an order ID and optionally a number of calls, e.g. for order ID 1000: " + "'client 1000' for a single call per service or 'client 1000 10' for 10 calls each");
        } else {
            int orderId = Integer.parseInt(args[0]);
            int nrOfCalls = 1;
            if (args.length > 1 && !"".equals(args[1])) {
                nrOfCalls = Integer.parseInt(args[1]);
            }
            ListableBeanFactory beanFactory = new FileSystemXmlApplicationContext(CLIENT_CONTEXT_CONFIG_LOCATION);
            OrderServiceClient client = new OrderServiceClient(beanFactory);
            client.invokeOrderServices(orderId, nrOfCalls);
        }
    }
}

19 Source : ArtemisConnectionFactoryFactory.java
with Apache License 2.0
from hello-shf

/**
 * Factory to create an Artemis {@link ActiveMQConnectionFactory} instance from properties
 * defined in {@link ArtemisProperties}.
 *
 * @author Eddú Meléndez
 * @author Phillip Webb
 * @author Stephane Nicoll
 */
clreplaced ArtemisConnectionFactoryFactory {

    static final String EMBEDDED_JMS_CLreplaced = "org.apache.activemq.artemis.jms.server.embedded.EmbeddedJMS";

    private final ArtemisProperties properties;

    private final ListableBeanFactory beanFactory;

    ArtemisConnectionFactoryFactory(ListableBeanFactory beanFactory, ArtemisProperties properties) {
        replacedert.notNull(beanFactory, "BeanFactory must not be null");
        replacedert.notNull(properties, "Properties must not be null");
        this.beanFactory = beanFactory;
        this.properties = properties;
    }

    public <T extends ActiveMQConnectionFactory> T createConnectionFactory(Clreplaced<T> factoryClreplaced) {
        try {
            startEmbeddedJms();
            return doCreateConnectionFactory(factoryClreplaced);
        } catch (Exception ex) {
            throw new IllegalStateException("Unable to create " + "ActiveMQConnectionFactory", ex);
        }
    }

    private void startEmbeddedJms() {
        if (ClreplacedUtils.isPresent(EMBEDDED_JMS_CLreplaced, null)) {
            try {
                this.beanFactory.getBeansOfType(Clreplaced.forName(EMBEDDED_JMS_CLreplaced));
            } catch (Exception ex) {
            // Ignore
            }
        }
    }

    private <T extends ActiveMQConnectionFactory> T doCreateConnectionFactory(Clreplaced<T> factoryClreplaced) throws Exception {
        ArtemisMode mode = this.properties.getMode();
        if (mode == null) {
            mode = deduceMode();
        }
        if (mode == ArtemisMode.EMBEDDED) {
            return createEmbeddedConnectionFactory(factoryClreplaced);
        }
        return createNativeConnectionFactory(factoryClreplaced);
    }

    /**
     * Deduce the {@link ArtemisMode} to use if none has been set.
     *
     * @return the mode
     */
    private ArtemisMode deduceMode() {
        if (this.properties.getEmbedded().isEnabled() && ClreplacedUtils.isPresent(EMBEDDED_JMS_CLreplaced, null)) {
            return ArtemisMode.EMBEDDED;
        }
        return ArtemisMode.NATIVE;
    }

    private <T extends ActiveMQConnectionFactory> T createEmbeddedConnectionFactory(Clreplaced<T> factoryClreplaced) throws Exception {
        try {
            TransportConfiguration transportConfiguration = new TransportConfiguration(InVMConnectorFactory.clreplaced.getName(), this.properties.getEmbedded().generateTransportParameters());
            ServerLocator serviceLocator = ActiveMQClient.createServerLocatorWithoutHA(transportConfiguration);
            return factoryClreplaced.getConstructor(ServerLocator.clreplaced).newInstance(serviceLocator);
        } catch (NoClreplacedDefFoundError ex) {
            throw new IllegalStateException("Unable to create InVM " + "Artemis connection, ensure that artemis-jms-server.jar " + "is in the clreplacedpath", ex);
        }
    }

    private <T extends ActiveMQConnectionFactory> T createNativeConnectionFactory(Clreplaced<T> factoryClreplaced) throws Exception {
        Map<String, Object> params = new HashMap<>();
        params.put(TransportConstants.HOST_PROP_NAME, this.properties.getHost());
        params.put(TransportConstants.PORT_PROP_NAME, this.properties.getPort());
        TransportConfiguration transportConfiguration = new TransportConfiguration(NettyConnectorFactory.clreplaced.getName(), params);
        Constructor<T> constructor = factoryClreplaced.getConstructor(boolean.clreplaced, TransportConfiguration[].clreplaced);
        T connectionFactory = constructor.newInstance(false, new TransportConfiguration[] { transportConfiguration });
        String user = this.properties.getUser();
        if (StringUtils.hasText(user)) {
            connectionFactory.setUser(user);
            connectionFactory.setPreplacedword(this.properties.getPreplacedword());
        }
        return connectionFactory;
    }
}

19 Source : ServletContextInitializerBeans.java
with Apache License 2.0
from hello-shf

private <T> void addAsRegistrationBean(ListableBeanFactory beanFactory, Clreplaced<T> type, RegistrationBeanAdapter<T> adapter) {
    addAsRegistrationBean(beanFactory, type, type, adapter);
}

19 Source : RollbackContext.java
with Apache License 2.0
from codeabovelab

/**
 */
public clreplaced RollbackContext {

    // see ScopedProxyUtils.getTargetBeanName
    private static final String SCOPED_TARGET = "scopedTarget.";

    private final ListableBeanFactory beanFactory;

    private final JobsManager manager;

    private final JobContext jobContext;

    RollbackContext(ListableBeanFactory beanFactory, JobsManager manager, JobContext jobContext) {
        this.beanFactory = beanFactory;
        this.manager = manager;
        this.jobContext = jobContext;
    }

    public JobsManager getManager() {
        return manager;
    }

    public JobContext getContext() {
        return jobContext;
    }

    public <T> T getBean(Clreplaced<T> type) {
        return beanFactory.getBean(type);
    }

    public <T> T getBean(Clreplaced<T> type, String name) {
        return beanFactory.getBean(name, type);
    }

    /**
     * A {@link #setBean(Object, Clreplaced)} variant, for cases when bean definition point to implementation type.
     * Equal code: <code>setBean(bean, bean.getClreplaced())</code>
     * @param bean
     */
    public void setBean(final Object bean) {
        setBean(bean, bean.getClreplaced());
    }

    /**
     * Put specified bean into context
     * @param type type of bean, note that it not always same as bean type, usual it super
     *             type of bean, for example: bean is a 'clreplaced SomeImpl' but type is 'interface Some'
     * @param bean instance of bean
     */
    public void setBean(final Object bean, Clreplaced<?> type) {
        replacedert.notNull(type, "type is null");
        replacedert.notNull(bean, "bean is null");
        String name = resolveName(type);
        Scope scope = beanFactory.findAnnotationOnBean(name, Scope.clreplaced);
        String scopeName = (String) AnnotationUtils.getValue(scope);
        ScopeBeans beans;
        if (JobScopeIteration.SCOPE_NAME.equals(scopeName)) {
            beans = JobScopeIteration.getBeans();
        } else {
            beans = jobContext.getScopeBeans();
        }
        beans.putBean(name, bean);
    }

    private String resolveName(Clreplaced<?> type) {
        String[] names = beanFactory.getBeanNamesForType(type);
        replacedert.isTrue(names.length != 0, "Can not find bean names for " + type);
        String name = null;
        for (String potentialName : names) {
            if (isScopedVariant(name, potentialName)) {
                // we prefer name with scopeTarget prefix
                name = potentialName;
                continue;
            }
            if (name != null) {
                if (isScopedVariant(potentialName, name)) {
                    // if potentialName a variant of current + prefix, then we simply skip it
                    continue;
                }
                throw new IllegalStateException("Can not resolve appropriate bean: " + name + " and " + potentialName);
            }
            name = potentialName;
        }
        return name;
    }

    /**
     * Check that second value is a scoped variant (differ only by prefix) of first argument.
     * @param original name
     * @param scoped name
     * @return true if '{@link #SCOPED_TARGET} + original  == scoped'
     */
    private boolean isScopedVariant(String original, String scoped) {
        if (original == null || scoped == null) {
            return false;
        }
        return scoped.startsWith(SCOPED_TARGET) && scoped.regionMatches(SCOPED_TARGET.length(), original, 0, original.length());
    }
}

19 Source : BeanUtils.java
with Apache License 2.0
from alibaba

/**
 * Is Bean Present or not?
 *
 * @param beanFactory   {@link ListableBeanFactory}
 * @param beanClreplacedName The  name of {@link Clreplaced} of Bean
 * @return If present , return <code>true</code> , or <code>false</code>
 */
public static boolean isBeanPresent(ListableBeanFactory beanFactory, String beanClreplacedName) {
    return isBeanPresent(beanFactory, beanClreplacedName, false);
}

19 Source : BeanUtils.java
with Apache License 2.0
from alibaba

/**
 * Is Bean Present or not?
 *
 * @param beanFactory        {@link ListableBeanFactory}
 * @param beanClreplaced          The  {@link Clreplaced} of Bean
 * @param includingAncestors including ancestors or not
 * @return If present , return <code>true</code> , or <code>false</code>
 */
public static boolean isBeanPresent(ListableBeanFactory beanFactory, Clreplaced<?> beanClreplaced, boolean includingAncestors) {
    String[] beanNames = getBeanNames(beanFactory, beanClreplaced, includingAncestors);
    return !ObjectUtils.isEmpty(beanNames);
}

19 Source : BeanUtils.java
with Apache License 2.0
from alibaba

/**
 * Get Optional Bean by {@link Clreplaced}.
 *
 * @param beanFactory {@link ListableBeanFactory}
 * @param beanClreplaced   The  {@link Clreplaced} of Bean
 * @param <T>         The  {@link Clreplaced} of Bean
 * @return Bean object if found , or return <code>null</code>.
 * @throws NoUniqueBeanDefinitionException if more than one bean of the given type was found
 */
public static <T> T getOptionalBean(ListableBeanFactory beanFactory, Clreplaced<T> beanClreplaced) throws BeansException {
    return getOptionalBean(beanFactory, beanClreplaced, false);
}

19 Source : BeanUtils.java
with Apache License 2.0
from alibaba

/**
 * Is Bean Present or not?
 *
 * @param beanFactory {@link ListableBeanFactory}
 * @param beanClreplaced   The  {@link Clreplaced} of Bean
 * @return If present , return <code>true</code> , or <code>false</code>
 */
public static boolean isBeanPresent(ListableBeanFactory beanFactory, Clreplaced<?> beanClreplaced) {
    return isBeanPresent(beanFactory, beanClreplaced, false);
}

19 Source : BeanUtils.java
with Apache License 2.0
from alibaba

/**
 * Get Bean Names from {@link ListableBeanFactory} by type.
 *
 * @param beanFactory {@link ListableBeanFactory}
 * @param beanClreplaced   The  {@link Clreplaced} of Bean
 * @return If found , return the array of Bean Names , or empty array.
 */
public static String[] getBeanNames(ListableBeanFactory beanFactory, Clreplaced<?> beanClreplaced) {
    return getBeanNames(beanFactory, beanClreplaced, false);
}

19 Source : PublicServiceAccessServiceImpl.java
with GNU Lesser General Public License v3.0
from Alfresco

public clreplaced PublicServiceAccessServiceImpl implements PublicServiceAccessService, BeanFactoryAware {

    private ListableBeanFactory beanFactory;

    public AccessStatus hasAccess(String publicService, String methodName, Object... args) {
        Object interceptor = beanFactory.getBean(publicService + "_security");
        if (interceptor == null) {
            throw new UnsupportedOperationException("Unknown public service security implementation " + publicService);
        }
        if (interceptor instanceof AlwaysProceedMethodInterceptor) {
            return AccessStatus.ALLOWED;
        }
        if (interceptor instanceof MethodSecurityInterceptor) {
            MethodSecurityInterceptor msi = (MethodSecurityInterceptor) interceptor;
            MethodInvocation methodInvocation = null;
            Object publicServiceImpl = beanFactory.getBean(publicService);
            NEXT_METHOD: for (Method method : publicServiceImpl.getClreplaced().getMethods()) {
                if (method.getName().equals(methodName)) {
                    if (method.getParameterTypes().length == args.length) {
                        // check argument types are replacedignable
                        int parameterPosition = 0;
                        for (Clreplaced<?> clazz : method.getParameterTypes()) {
                            if (args[parameterPosition] == null) {
                                if (clazz.isPrimitive()) {
                                    continue NEXT_METHOD;
                                } else {
                                // OK, null replacedigns to any non-primitive type
                                }
                            } else {
                                if (clazz.isPrimitive()) {
                                    if (clazz.getName().equals("boolean")) {
                                        if (args[parameterPosition].getClreplaced().getName().equals("java.lang.Boolean")) {
                                        // OK
                                        } else {
                                            continue NEXT_METHOD;
                                        }
                                    } else if (clazz.getName().equals("byte")) {
                                        if (args[parameterPosition].getClreplaced().getName().equals("java.lang.Byte")) {
                                        // OK
                                        } else {
                                            continue NEXT_METHOD;
                                        }
                                    } else if (clazz.getName().equals("char")) {
                                        if (args[parameterPosition].getClreplaced().getName().equals("java.lang.Char")) {
                                        // OK
                                        } else {
                                            continue NEXT_METHOD;
                                        }
                                    } else if (clazz.getName().equals("short")) {
                                        if (args[parameterPosition].getClreplaced().getName().equals("java.lang.Short")) {
                                        // OK
                                        } else {
                                            continue NEXT_METHOD;
                                        }
                                    } else if (clazz.getName().equals("int")) {
                                        if (args[parameterPosition].getClreplaced().getName().equals("java.lang.Integer")) {
                                        // OK
                                        } else {
                                            continue NEXT_METHOD;
                                        }
                                    } else if (clazz.getName().equals("long")) {
                                        if (args[parameterPosition].getClreplaced().getName().equals("java.lang.Long")) {
                                        // OK
                                        } else {
                                            continue NEXT_METHOD;
                                        }
                                    } else if (clazz.getName().equals("float")) {
                                        if (args[parameterPosition].getClreplaced().getName().equals("java.lang.Float")) {
                                        // OK
                                        } else {
                                            continue NEXT_METHOD;
                                        }
                                    } else if (clazz.getName().equals("double")) {
                                        if (args[parameterPosition].getClreplaced().getName().equals("java.lang.Double")) {
                                        // OK
                                        } else {
                                            continue NEXT_METHOD;
                                        }
                                    } else {
                                        continue NEXT_METHOD;
                                    }
                                } else if (!(clazz.isreplacedignableFrom(args[parameterPosition].getClreplaced()))) {
                                    continue NEXT_METHOD;
                                }
                            }
                            parameterPosition++;
                        }
                        methodInvocation = new ReflectiveMethodInvocation(null, null, method, args, null, null) {
                        };
                    }
                }
            }
            if (methodInvocation == null) {
                throw new UnsupportedOperationException("Unknown public service security implementation " + publicService + "." + methodName + " with arguments " + Arrays.toString(args));
            }
            return msi.pre(methodInvocation);
        }
        throw new UnsupportedOperationException("Unknown security interceptor " + interceptor.getClreplaced());
    }

    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        this.beanFactory = (ListableBeanFactory) beanFactory;
    }
}

18 Source : ArtemisXAConnectionFactoryConfiguration.java
with Apache License 2.0
from yuanmabiji

@Bean
public ActiveMQXAConnectionFactory nonXaJmsConnectionFactory(ListableBeanFactory beanFactory, ArtemisProperties properties) {
    return new ArtemisConnectionFactoryFactory(beanFactory, properties).createConnectionFactory(ActiveMQXAConnectionFactory.clreplaced);
}

18 Source : OnBeanCondition.java
with Apache License 2.0
from yuanmabiji

private void collectBeanNamesForAnnotation(Set<String> names, ListableBeanFactory beanFactory, Clreplaced<? extends Annotation> annotationType, boolean considerHierarchy) {
    BeanTypeRegistry registry = BeanTypeRegistry.get(beanFactory);
    names.addAll(registry.getNamesForAnnotation(annotationType));
    if (considerHierarchy) {
        BeanFactory parent = ((HierarchicalBeanFactory) beanFactory).getParentBeanFactory();
        if (parent instanceof ListableBeanFactory) {
            collectBeanNamesForAnnotation(names, (ListableBeanFactory) parent, annotationType, considerHierarchy);
        }
    }
}

18 Source : WebMvcEndpointChildContextConfiguration.java
with Apache License 2.0
from yuanmabiji

@Bean(name = DispatcherServlet.HANDLER_ADAPTER_BEAN_NAME)
public CompositeHandlerAdapter compositeHandlerAdapter(ListableBeanFactory beanFactory) {
    return new CompositeHandlerAdapter(beanFactory);
}

18 Source : ServletManagementChildContextConfiguration.java
with Apache License 2.0
from yuanmabiji

@Bean
public ServletManagementWebServerFactoryCustomizer servletManagementWebServerFactoryCustomizer(ListableBeanFactory beanFactory) {
    return new ServletManagementWebServerFactoryCustomizer(beanFactory);
}

18 Source : CompositeHandlerAdapter.java
with Apache License 2.0
from yuanmabiji

/**
 * Composite {@link HandlerAdapter}.
 *
 * @author Andy Wilkinson
 * @author Stephane Nicoll
 * @author Phillip Webb
 */
clreplaced CompositeHandlerAdapter implements HandlerAdapter {

    private final ListableBeanFactory beanFactory;

    private List<HandlerAdapter> adapters;

    CompositeHandlerAdapter(ListableBeanFactory beanFactory) {
        this.beanFactory = beanFactory;
    }

    @Override
    public boolean supports(Object handler) {
        return getAdapter(handler).isPresent();
    }

    @Override
    public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Optional<HandlerAdapter> adapter = getAdapter(handler);
        if (adapter.isPresent()) {
            return adapter.get().handle(request, response, handler);
        }
        return null;
    }

    @Override
    public long getLastModified(HttpServletRequest request, Object handler) {
        Optional<HandlerAdapter> adapter = getAdapter(handler);
        if (adapter.isPresent()) {
            return adapter.get().getLastModified(request, handler);
        }
        return 0;
    }

    private Optional<HandlerAdapter> getAdapter(Object handler) {
        if (this.adapters == null) {
            this.adapters = extractAdapters();
        }
        return this.adapters.stream().filter((a) -> a.supports(handler)).findFirst();
    }

    private List<HandlerAdapter> extractAdapters() {
        List<HandlerAdapter> list = new ArrayList<>();
        list.addAll(this.beanFactory.getBeansOfType(HandlerAdapter.clreplaced).values());
        list.remove(this);
        AnnotationAwareOrderComparator.sort(list);
        return list;
    }
}

18 Source : ReactiveManagementChildContextConfiguration.java
with Apache License 2.0
from yuanmabiji

@Bean
public ReactiveManagementWebServerFactoryCustomizer reactiveManagementWebServerFactoryCustomizer(ListableBeanFactory beanFactory) {
    return new ReactiveManagementWebServerFactoryCustomizer(beanFactory);
}

18 Source : WebServerFactoryCustomizerBeanPostProcessorTests.java
with Apache License 2.0
from yuanmabiji

/**
 * Tests for {@link WebServerFactoryCustomizerBeanPostProcessor}.
 *
 * @author Phillip Webb
 */
public clreplaced WebServerFactoryCustomizerBeanPostProcessorTests {

    private WebServerFactoryCustomizerBeanPostProcessor processor = new WebServerFactoryCustomizerBeanPostProcessor();

    @Mock
    private ListableBeanFactory beanFactory;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        this.processor.setBeanFactory(this.beanFactory);
    }

    @Test
    public void setBeanFactoryWhenNotListableShouldThrowException() {
        replacedertThatIllegalArgumentException().isThrownBy(() -> this.processor.setBeanFactory(mock(BeanFactory.clreplaced))).withMessageContaining("WebServerCustomizerBeanPostProcessor can only " + "be used with a ListableBeanFactory");
    }

    @Test
    public void postProcessBeforeShouldReturnBean() {
        addMockBeans(Collections.emptyMap());
        Object bean = new Object();
        Object result = this.processor.postProcessBeforeInitialization(bean, "foo");
        replacedertThat(result).isSameAs(bean);
    }

    @Test
    public void postProcessAfterShouldReturnBean() {
        addMockBeans(Collections.emptyMap());
        Object bean = new Object();
        Object result = this.processor.postProcessAfterInitialization(bean, "foo");
        replacedertThat(result).isSameAs(bean);
    }

    @Test
    public void postProcessAfterShouldCallInterfaceCustomizers() {
        Map<String, Object> beans = addInterfaceBeans();
        addMockBeans(beans);
        postProcessBeforeInitialization(WebServerFactory.clreplaced);
        replacedertThat(wasCalled(beans, "one")).isFalse();
        replacedertThat(wasCalled(beans, "two")).isFalse();
        replacedertThat(wasCalled(beans, "all")).isTrue();
    }

    @Test
    public void postProcessAfterWhenWebServerFactoryOneShouldCallInterfaceCustomizers() {
        Map<String, Object> beans = addInterfaceBeans();
        addMockBeans(beans);
        postProcessBeforeInitialization(WebServerFactoryOne.clreplaced);
        replacedertThat(wasCalled(beans, "one")).isTrue();
        replacedertThat(wasCalled(beans, "two")).isFalse();
        replacedertThat(wasCalled(beans, "all")).isTrue();
    }

    @Test
    public void postProcessAfterWhenWebServerFactoryTwoShouldCallInterfaceCustomizers() {
        Map<String, Object> beans = addInterfaceBeans();
        addMockBeans(beans);
        postProcessBeforeInitialization(WebServerFactoryTwo.clreplaced);
        replacedertThat(wasCalled(beans, "one")).isFalse();
        replacedertThat(wasCalled(beans, "two")).isTrue();
        replacedertThat(wasCalled(beans, "all")).isTrue();
    }

    private Map<String, Object> addInterfaceBeans() {
        WebServerFactoryOneCustomizer oneCustomizer = new WebServerFactoryOneCustomizer();
        WebServerFactoryTwoCustomizer twoCustomizer = new WebServerFactoryTwoCustomizer();
        WebServerFactoryAllCustomizer allCustomizer = new WebServerFactoryAllCustomizer();
        Map<String, Object> beans = new LinkedHashMap<>();
        beans.put("one", oneCustomizer);
        beans.put("two", twoCustomizer);
        beans.put("all", allCustomizer);
        return beans;
    }

    @Test
    public void postProcessAfterShouldCallLambdaCustomizers() {
        List<String> called = new ArrayList<>();
        addLambdaBeans(called);
        postProcessBeforeInitialization(WebServerFactory.clreplaced);
        replacedertThat(called).containsExactly("all");
    }

    @Test
    public void postProcessAfterWhenWebServerFactoryOneShouldCallLambdaCustomizers() {
        List<String> called = new ArrayList<>();
        addLambdaBeans(called);
        postProcessBeforeInitialization(WebServerFactoryOne.clreplaced);
        replacedertThat(called).containsExactly("one", "all");
    }

    @Test
    public void postProcessAfterWhenWebServerFactoryTwoShouldCallLambdaCustomizers() {
        List<String> called = new ArrayList<>();
        addLambdaBeans(called);
        postProcessBeforeInitialization(WebServerFactoryTwo.clreplaced);
        replacedertThat(called).containsExactly("two", "all");
    }

    private void addLambdaBeans(List<String> called) {
        WebServerFactoryCustomizer<WebServerFactoryOne> one = (f) -> called.add("one");
        WebServerFactoryCustomizer<WebServerFactoryTwo> two = (f) -> called.add("two");
        WebServerFactoryCustomizer<WebServerFactory> all = (f) -> called.add("all");
        Map<String, Object> beans = new LinkedHashMap<>();
        beans.put("one", one);
        beans.put("two", two);
        beans.put("all", all);
        addMockBeans(beans);
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    private void addMockBeans(Map<String, ?> beans) {
        given(this.beanFactory.getBeansOfType(WebServerFactoryCustomizer.clreplaced, false, false)).willReturn((Map<String, WebServerFactoryCustomizer>) beans);
    }

    private void postProcessBeforeInitialization(Clreplaced<?> type) {
        this.processor.postProcessBeforeInitialization(mock(type), "foo");
    }

    private boolean wasCalled(Map<String, ?> beans, String name) {
        return ((MockWebServerFactoryCustomizer<?>) beans.get(name)).wasCalled();
    }

    private interface WebServerFactoryOne extends WebServerFactory {
    }

    private interface WebServerFactoryTwo extends WebServerFactory {
    }

    private static clreplaced MockWebServerFactoryCustomizer<T extends WebServerFactory> implements WebServerFactoryCustomizer<T> {

        private boolean called;

        @Override
        public void customize(T factory) {
            this.called = true;
        }

        public boolean wasCalled() {
            return this.called;
        }
    }

    private static clreplaced WebServerFactoryOneCustomizer extends MockWebServerFactoryCustomizer<WebServerFactoryOne> {
    }

    private static clreplaced WebServerFactoryTwoCustomizer extends MockWebServerFactoryCustomizer<WebServerFactoryTwo> {
    }

    private static clreplaced WebServerFactoryAllCustomizer extends MockWebServerFactoryCustomizer<WebServerFactory> {
    }
}

18 Source : ServletContextInitializerBeans.java
with Apache License 2.0
from yuanmabiji

private void addServletContextInitializerBean(Clreplaced<?> type, String beanName, ServletContextInitializer initializer, ListableBeanFactory beanFactory, Object source) {
    this.initializers.add(type, initializer);
    if (source != null) {
        // Mark the underlying source as seen in case it wraps an existing bean
        this.seen.add(source);
    }
    if (ServletContextInitializerBeans.logger.isDebugEnabled()) {
        String resourceDescription = getResourceDescription(beanName, beanFactory);
        int order = getOrder(initializer);
        ServletContextInitializerBeans.logger.debug("Added existing " + type.getSimpleName() + " initializer bean '" + beanName + "'; order=" + order + ", resource=" + resourceDescription);
    }
}

18 Source : ServletContextInitializerBeans.java
with Apache License 2.0
from yuanmabiji

private <T> List<Entry<String, T>> getOrderedBeansOfType(ListableBeanFactory beanFactory, Clreplaced<T> type) {
    return getOrderedBeansOfType(beanFactory, type, Collections.emptySet());
}

18 Source : ServletContextInitializerBeans.java
with Apache License 2.0
from yuanmabiji

private MultipartConfigElement getMultipartConfig(ListableBeanFactory beanFactory) {
    List<Entry<String, MultipartConfigElement>> beans = getOrderedBeansOfType(beanFactory, MultipartConfigElement.clreplaced);
    return beans.isEmpty() ? null : beans.get(0).getValue();
}

18 Source : WebServerFactoryCustomizerBeanPostProcessor.java
with Apache License 2.0
from yuanmabiji

/**
 * {@link BeanPostProcessor} that applies all {@link WebServerFactoryCustomizer} beans
 * from the bean factory to {@link WebServerFactory} beans.
 *
 * @author Dave Syer
 * @author Phillip Webb
 * @author Stephane Nicoll
 * @since 2.0.0
 */
public clreplaced WebServerFactoryCustomizerBeanPostProcessor implements BeanPostProcessor, BeanFactoryAware {

    private ListableBeanFactory beanFactory;

    private List<WebServerFactoryCustomizer<?>> customizers;

    @Override
    public void setBeanFactory(BeanFactory beanFactory) {
        replacedert.isInstanceOf(ListableBeanFactory.clreplaced, beanFactory, "WebServerCustomizerBeanPostProcessor can only be used " + "with a ListableBeanFactory");
        this.beanFactory = (ListableBeanFactory) beanFactory;
    }

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof WebServerFactory) {
            postProcessBeforeInitialization((WebServerFactory) bean);
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }

    @SuppressWarnings("unchecked")
    private void postProcessBeforeInitialization(WebServerFactory webServerFactory) {
        LambdaSafe.callbacks(WebServerFactoryCustomizer.clreplaced, getCustomizers(), webServerFactory).withLogger(WebServerFactoryCustomizerBeanPostProcessor.clreplaced).invoke((customizer) -> customizer.customize(webServerFactory));
    }

    private Collection<WebServerFactoryCustomizer<?>> getCustomizers() {
        if (this.customizers == null) {
            // Look up does not include the parent context
            this.customizers = new ArrayList<>(getWebServerFactoryCustomizerBeans());
            this.customizers.sort(AnnotationAwareOrderComparator.INSTANCE);
            this.customizers = Collections.unmodifiableList(this.customizers);
        }
        return this.customizers;
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    private Collection<WebServerFactoryCustomizer<?>> getWebServerFactoryCustomizerBeans() {
        return (Collection) this.beanFactory.getBeansOfType(WebServerFactoryCustomizer.clreplaced, false, false).values();
    }
}

18 Source : ErrorPageRegistrarBeanPostProcessor.java
with Apache License 2.0
from yuanmabiji

/**
 * {@link BeanPostProcessor} that applies all {@link ErrorPageRegistrar}s from the bean
 * factory to {@link ErrorPageRegistry} beans.
 *
 * @author Phillip Webb
 * @author Stephane Nicoll
 * @since 2.0.0
 */
public clreplaced ErrorPageRegistrarBeanPostProcessor implements BeanPostProcessor, BeanFactoryAware {

    private ListableBeanFactory beanFactory;

    private List<ErrorPageRegistrar> registrars;

    @Override
    public void setBeanFactory(BeanFactory beanFactory) {
        replacedert.isInstanceOf(ListableBeanFactory.clreplaced, beanFactory, "ErrorPageRegistrarBeanPostProcessor can only be used " + "with a ListableBeanFactory");
        this.beanFactory = (ListableBeanFactory) beanFactory;
    }

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof ErrorPageRegistry) {
            postProcessBeforeInitialization((ErrorPageRegistry) bean);
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }

    private void postProcessBeforeInitialization(ErrorPageRegistry registry) {
        for (ErrorPageRegistrar registrar : getRegistrars()) {
            registrar.registerErrorPages(registry);
        }
    }

    private Collection<ErrorPageRegistrar> getRegistrars() {
        if (this.registrars == null) {
            // Look up does not include the parent context
            this.registrars = new ArrayList<>(this.beanFactory.getBeansOfType(ErrorPageRegistrar.clreplaced, false, false).values());
            this.registrars.sort(AnnotationAwareOrderComparator.INSTANCE);
            this.registrars = Collections.unmodifiableList(this.registrars);
        }
        return this.registrars;
    }
}

18 Source : PersistenceExceptionTranslationInterceptor.java
with MIT License
from Vip-Augus

/**
 * AOP Alliance MethodInterceptor that provides persistence exception translation
 * based on a given PersistenceExceptionTranslator.
 *
 * <p>Delegates to the given {@link PersistenceExceptionTranslator} to translate
 * a RuntimeException thrown into Spring's DataAccessException hierarchy
 * (if appropriate). If the RuntimeException in question is declared on the
 * target method, it is always propagated as-is (with no translation applied).
 *
 * @author Rod Johnson
 * @author Juergen Hoeller
 * @since 2.0
 * @see PersistenceExceptionTranslator
 */
public clreplaced PersistenceExceptionTranslationInterceptor implements MethodInterceptor, BeanFactoryAware, InitializingBean {

    @Nullable
    private volatile PersistenceExceptionTranslator persistenceExceptionTranslator;

    private boolean alwaysTranslate = false;

    @Nullable
    private ListableBeanFactory beanFactory;

    /**
     * Create a new PersistenceExceptionTranslationInterceptor.
     * Needs to be configured with a PersistenceExceptionTranslator afterwards.
     * @see #setPersistenceExceptionTranslator
     */
    public PersistenceExceptionTranslationInterceptor() {
    }

    /**
     * Create a new PersistenceExceptionTranslationInterceptor
     * for the given PersistenceExceptionTranslator.
     * @param pet the PersistenceExceptionTranslator to use
     */
    public PersistenceExceptionTranslationInterceptor(PersistenceExceptionTranslator pet) {
        replacedert.notNull(pet, "PersistenceExceptionTranslator must not be null");
        this.persistenceExceptionTranslator = pet;
    }

    /**
     * Create a new PersistenceExceptionTranslationInterceptor, autodetecting
     * PersistenceExceptionTranslators in the given BeanFactory.
     * @param beanFactory the ListableBeanFactory to obtaining all
     * PersistenceExceptionTranslators from
     */
    public PersistenceExceptionTranslationInterceptor(ListableBeanFactory beanFactory) {
        replacedert.notNull(beanFactory, "ListableBeanFactory must not be null");
        this.beanFactory = beanFactory;
    }

    /**
     * Specify the PersistenceExceptionTranslator to use.
     * <p>Default is to autodetect all PersistenceExceptionTranslators
     * in the containing BeanFactory, using them in a chain.
     * @see #detectPersistenceExceptionTranslators
     */
    public void setPersistenceExceptionTranslator(PersistenceExceptionTranslator pet) {
        this.persistenceExceptionTranslator = pet;
    }

    /**
     * Specify whether to always translate the exception ("true"), or whether throw the
     * raw exception when declared, i.e. when the originating method signature's exception
     * declarations allow for the raw exception to be thrown ("false").
     * <p>Default is "false". Switch this flag to "true" in order to always translate
     * applicable exceptions, independent from the originating method signature.
     * <p>Note that the originating method does not have to declare the specific exception.
     * Any base clreplaced will do as well, even {@code throws Exception}: As long as the
     * originating method does explicitly declare compatible exceptions, the raw exception
     * will be rethrown. If you would like to avoid throwing raw exceptions in any case,
     * switch this flag to "true".
     */
    public void setAlwaysTranslate(boolean alwaysTranslate) {
        this.alwaysTranslate = alwaysTranslate;
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        if (this.persistenceExceptionTranslator == null) {
            // No explicit exception translator specified - perform autodetection.
            if (!(beanFactory instanceof ListableBeanFactory)) {
                throw new IllegalArgumentException("Cannot use PersistenceExceptionTranslator autodetection without ListableBeanFactory");
            }
            this.beanFactory = (ListableBeanFactory) beanFactory;
        }
    }

    @Override
    public void afterPropertiesSet() {
        if (this.persistenceExceptionTranslator == null && this.beanFactory == null) {
            throw new IllegalArgumentException("Property 'persistenceExceptionTranslator' is required");
        }
    }

    @Override
    public Object invoke(MethodInvocation mi) throws Throwable {
        try {
            return mi.proceed();
        } catch (RuntimeException ex) {
            // Let it throw raw if the type of the exception is on the throws clause of the method.
            if (!this.alwaysTranslate && ReflectionUtils.declaresException(mi.getMethod(), ex.getClreplaced())) {
                throw ex;
            } else {
                PersistenceExceptionTranslator translator = this.persistenceExceptionTranslator;
                if (translator == null) {
                    replacedert.state(this.beanFactory != null, "No PersistenceExceptionTranslator set");
                    translator = detectPersistenceExceptionTranslators(this.beanFactory);
                    this.persistenceExceptionTranslator = translator;
                }
                throw DataAccessUtils.translateIfNecessary(ex, translator);
            }
        }
    }

    /**
     * Detect all PersistenceExceptionTranslators in the given BeanFactory.
     * @param beanFactory the ListableBeanFactory to obtaining all
     * PersistenceExceptionTranslators from
     * @return a chained PersistenceExceptionTranslator, combining all
     * PersistenceExceptionTranslators found in the factory
     * @see ChainedPersistenceExceptionTranslator
     */
    protected PersistenceExceptionTranslator detectPersistenceExceptionTranslators(ListableBeanFactory beanFactory) {
        // Find all translators, being careful not to activate FactoryBeans.
        Map<String, PersistenceExceptionTranslator> pets = BeanFactoryUtils.beansOfTypeIncludingAncestors(beanFactory, PersistenceExceptionTranslator.clreplaced, false, false);
        ChainedPersistenceExceptionTranslator cpet = new ChainedPersistenceExceptionTranslator();
        for (PersistenceExceptionTranslator pet : pets.values()) {
            cpet.addDelegate(pet);
        }
        return cpet;
    }
}

18 Source : BeanFactoryHelper.java
with Apache License 2.0
from TinkoffCreditSystems

/**
 * @return key: 'alias', value: 'name'
 */
public <T> Map<String, String> getAliases(ListableBeanFactory beanFactory, Clreplaced<T> clazz) {
    return beanFactory.getBeansOfType(clazz).keySet().stream().map(name -> getAliasEntrySet(beanFactory, name)).flatMap(Collection::stream).collect(toMap(Map.Entry::getKey, Map.Entry::getValue));
}

18 Source : BeanFactoryHelper.java
with Apache License 2.0
from TinkoffCreditSystems

public <T> Map<String, T> collectToOrderedMap(ListableBeanFactory beanFactory, Clreplaced<T> clazz, List<T> orderedBeans) {
    Map<String, T> beansOfType = beanFactory.getBeansOfType(clazz);
    return orderedBeans.stream().collect(toMap(bean -> buildKey(beansOfType, bean), idenreplacedy(), this::mergeBeans, LinkedHashMap::new));
}

18 Source : RSocketClientFactoryBean.java
with Apache License 2.0
from spring-projects-experimental

/**
 * @author <a href="mailto:[email protected]">Josh Long</a>
 */
@Log4j2
clreplaced RSocketClientFactoryBean implements BeanFactoryAware, FactoryBean<Object> {

    private Clreplaced<?> type;

    private ListableBeanFactory context;

    private static RSocketRequester forInterface(Clreplaced<?> clientInterface, ListableBeanFactory context) {
        Map<String, RSocketRequester> rSocketRequestersInContext = context.getBeansOfType(RSocketRequester.clreplaced);
        int rSocketRequestersCount = rSocketRequestersInContext.size();
        replacedert.state(rSocketRequestersCount > 0, () -> "there should be at least one " + RSocketRequester.clreplaced.getName() + " in the context. Please consider defining one.");
        RSocketRequester rSocketRequester = null;
        replacedert.notNull(clientInterface, "the client interface must be non-null");
        replacedert.notNull(context, () -> "the " + ListableBeanFactory.clreplaced.getName() + " interface must be non-null");
        MergedAnnotation<Qualifier> qualifier = MergedAnnotations.from(clientInterface).get(Qualifier.clreplaced);
        if (qualifier.isPresent()) {
            String valueOfQualifierAnnotation = qualifier.getString(MergedAnnotation.VALUE);
            Map<String, RSocketRequester> beans = BeanFactoryAnnotationUtils.qualifiedBeansOfType(context, RSocketRequester.clreplaced, valueOfQualifierAnnotation);
            replacedert.state(beans.size() == 1, () -> "I need just one " + RSocketRequester.clreplaced.getName() + " but I got " + beans.keySet());
            for (Map.Entry<String, RSocketRequester> entry : beans.entrySet()) {
                rSocketRequester = entry.getValue();
                if (log.isDebugEnabled()) {
                    log.debug("found " + rSocketRequester + " with bean name " + entry.getKey() + " for @" + RSocketClient.clreplaced.getName() + " interface " + clientInterface.getName() + '.');
                }
            }
        } else {
            replacedert.state(rSocketRequestersCount == 1, () -> "there should be no more and no less than one unqualified " + RSocketRequester.clreplaced.getName() + " instances in the context.");
            return rSocketRequestersInContext.values().iterator().next();
        }
        replacedert.notNull(rSocketRequester, () -> "we could not find an " + RSocketRequester.clreplaced.getName() + " for the @RSocketClient interface " + clientInterface.getName() + '.');
        return rSocketRequester;
    }

    @SneakyThrows
    public void setType(String type) {
        this.type = Clreplaced.forName(type);
    }

    @Override
    public Object getObject() {
        RSocketRequester rSocketRequester = forInterface(this.type, this.context);
        RSocketClientBuilder clientBuilder = this.context.getBean(RSocketClientBuilder.clreplaced);
        return clientBuilder.buildClientFor(this.type, rSocketRequester);
    }

    @Override
    public Clreplaced<?> getObjectType() {
        return this.type;
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        replacedert.state(beanFactory instanceof ListableBeanFactory, () -> "the " + BeanFactory.clreplaced.getName() + " is not an instance of a " + ListableBeanFactory.clreplaced.getName());
        this.context = (ListableBeanFactory) beanFactory;
    }
}

18 Source : SubscriptionEnabledClientServerIntegrationTestsConfiguration.java
with Apache License 2.0
from spring-projects

@Bean
BeanPostProcessor clientServerReadyBeanPostProcessor(ListableBeanFactory beanFactory, @Value("${" + GEMFIRE_CACHE_SERVER_PORT_PROPERTY + ":40404}") int port) {
    return new BeanPostProcessor() {

        private final AtomicBoolean verifyGemFireServerIsRunning = new AtomicBoolean(true);

        @Nullable
        @Override
        @SuppressWarnings("all")
        public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
            if (isGemFireServerRunningVerificationEnabled(bean, beanName)) {
                try {
                    verifyClientCacheMemberJoined();
                    verifyClientCacheSubscriptionQueueConnectionsEstablished();
                } catch (InterruptedException cause) {
                    Thread.currentThread().interrupt();
                }
            }
            return bean;
        }

        private boolean isGemFireServerRunningVerificationEnabled(Object bean, String beanName) {
            return isVeryImportantBean(bean, beanName) && verifyGemFireServerIsRunning.compareAndSet(true, false);
        }

        private boolean isVeryImportantBean(Object bean, String beanName) {
            return isContinuousQueryListenerContainer(bean) || isClientProxyRegion(bean);
        }

        private boolean isContinuousQueryListenerContainer(Object bean) {
            return bean instanceof ContinuousQueryListenerContainer;
        }

        private boolean isClientProxyRegion(Object bean) {
            if (bean instanceof ClientRegionFactoryBean) {
                ClientRegionFactoryBean<?, ?> clientRegionFactoryBean = (ClientRegionFactoryBean) bean;
                return clientRegionFactoryBean.getPoolName().filter(StringUtils::hasText).map(it -> true).orElseGet(() -> resolveClientRegionShortcut(clientRegionFactoryBean).map(ClientRegionShortcutWrapper::valueOf).filter(ClientRegionShortcutWrapper::isProxy).isPresent());
            }
            return false;
        }

        @SuppressWarnings("unchecked")
        private Optional<ClientRegionShortcut> resolveClientRegionShortcut(ClientRegionFactoryBean<?, ?> clientRegionFactoryBean) {
            try {
                Method resolveClientRegionShortcut = ClientRegionFactoryBean.clreplaced.getDeclaredMethod("resolveClientRegionShortcut");
                resolveClientRegionShortcut.setAccessible(true);
                return Optional.ofNullable((ClientRegionShortcut) ReflectionUtils.invokeMethod(resolveClientRegionShortcut, clientRegionFactoryBean));
            } catch (Throwable ignore) {
                return Optional.empty();
            }
        }

        @SuppressWarnings("all")
        private void verifyClientCacheMemberJoined() throws InterruptedException {
            String errorMessage = String.format("CacheServer failed to start on host [%s] and port [%d]", LOCALHOST, port);
            replacedert.state(LATCH.await(resolveTimeout(), TimeUnit.MILLISECONDS), errorMessage);
        }

        @SuppressWarnings("all")
        private void verifyClientCacheSubscriptionQueueConnectionsEstablished() {
            resolvePools().stream().filter(pool -> pool.getSubscriptionEnabled()).filter(pool -> pool instanceof PoolImpl).map(pool -> (PoolImpl) pool).forEach(pool -> {
                long timeout = System.currentTimeMillis() + resolveTimeout();
                while (System.currentTimeMillis() < timeout && !pool.isPrimaryUpdaterAlive()) {
                    synchronized (pool) {
                        ObjectUtils.doOperationSafely(() -> {
                            TimeUnit.MILLISECONDS.timedWait(pool, 500L);
                            return null;
                        });
                    }
                }
                String errorMessage = String.format("ClientCache subscription queue connection not established;" + " Pool [%s] has configuration [locators = %s, servers = %s]", pool, pool.getLocators(), pool.getServers());
                if (isThrowExceptionOnSubscriptionQueueConnectionFailure()) {
                    replacedert.state(pool.isPrimaryUpdaterAlive(), errorMessage);
                } else if (getLogger().isWarnEnabled()) {
                    getLogger().warn(errorMessage);
                }
            });
        }

        // TODO: PoolManager.getAll() will not include the "DEFAULT" Pool
        private Collection<Pool> resolvePools() {
            eagerlyInitializeSpringManagedPoolBeans();
            return nullSafeMap(PoolManager.getAll()).values();
        }

        private void eagerlyInitializeSpringManagedPoolBeans() {
            beanFactory.getBeansOfType(PoolFactoryBean.clreplaced).keySet().forEach(beanName -> beanFactory.getBean(beanName, Pool.clreplaced));
        }
    };
}

18 Source : VertxManagementChildContextConfiguration.java
with Apache License 2.0
from snowdrop

@Bean
public VertxManagementChildContextConfiguration.VertxManagementWebServerFactoryCustomizer vertxManagementWebServerFactoryCustomizer(ListableBeanFactory beanFactory) {
    return new VertxManagementChildContextConfiguration.VertxManagementWebServerFactoryCustomizer(beanFactory);
}

18 Source : ReactivePersistenceExceptionTranslationInterceptor.java
with Apache License 2.0
from neo4j

/**
 * This method interceptor is modelled somewhat after {@link org.springframework.dao.support.PersistenceExceptionTranslationInterceptor},
 * but caters for reactive needs: If the method identified by the pointcut returns a supported reactive type (either {@link Mono} or {@link Flux}),
 * it installs an error mapping function with {@code onErrorMap} that tries to translate the given exception
 * into Spring's hierarchy.
 * <p>
 * The interceptor uses all {@link PersistenceExceptionTranslator persistence exception translators} it finds in the context
 * through a {@link ChainedPersistenceExceptionTranslator}. Translations is eventually done with
 * {@link DataAccessUtils#translateIfNecessary(RuntimeException, PersistenceExceptionTranslator)} which returns the original
 * exception in case translation is not possible (the translator returned null).
 *
 * @author Michael J. Simons
 * @soundtrack Fatoni - Andorra
 * @since 1.0
 */
final clreplaced ReactivePersistenceExceptionTranslationInterceptor implements MethodInterceptor {

    private final ListableBeanFactory beanFactory;

    private volatile PersistenceExceptionTranslator persistenceExceptionTranslator;

    /**
     * Create a new PersistenceExceptionTranslationInterceptor, autodetecting
     * PersistenceExceptionTranslators in the given BeanFactory.
     *
     * @param beanFactory the ListableBeanFactory to obtaining all
     *                    PersistenceExceptionTranslators from
     */
    ReactivePersistenceExceptionTranslationInterceptor(ListableBeanFactory beanFactory) {
        replacedert.notNull(beanFactory, "ListableBeanFactory must not be null");
        this.beanFactory = beanFactory;
    }

    @Override
    public Object invoke(MethodInvocation mi) throws Throwable {
        // Invoke the method potentially returning a reactive type
        Object m = mi.proceed();
        PersistenceExceptionTranslator translator = getPersistenceExceptionTranslator();
        if (translator == null) {
            return m;
        } else {
            // Add the translation. Nothing will happen if no-one subscribe the reactive result.
            Function<RuntimeException, Throwable> errorMappingFunction = t -> t instanceof DataAccessException ? t : DataAccessUtils.translateIfNecessary(t, translator);
            if (m instanceof Mono) {
                return ((Mono<?>) m).onErrorMap(RuntimeException.clreplaced, errorMappingFunction);
            } else if (m instanceof Flux) {
                return ((Flux<?>) m).onErrorMap(RuntimeException.clreplaced, errorMappingFunction);
            } else {
                return m;
            }
        }
    }

    PersistenceExceptionTranslator getPersistenceExceptionTranslator() {
        PersistenceExceptionTranslator translator = this.persistenceExceptionTranslator;
        if (translator == null) {
            synchronized (this) {
                translator = this.persistenceExceptionTranslator;
                if (translator == null) {
                    this.persistenceExceptionTranslator = detectPersistenceExceptionTranslators();
                    translator = this.persistenceExceptionTranslator;
                }
            }
        }
        return translator;
    }

    /**
     * Detect all PersistenceExceptionTranslators in the given BeanFactory.
     *
     * @return a chained PersistenceExceptionTranslator, combining all
     * PersistenceExceptionTranslators found in the factory
     * @see ChainedPersistenceExceptionTranslator
     */
    private PersistenceExceptionTranslator detectPersistenceExceptionTranslators() {
        // Find all translators, being careful not to activate FactoryBeans.
        Map<String, PersistenceExceptionTranslator> pets = BeanFactoryUtils.beansOfTypeIncludingAncestors(beanFactory, PersistenceExceptionTranslator.clreplaced, false, false);
        ChainedPersistenceExceptionTranslator cpet = new ChainedPersistenceExceptionTranslator();
        pets.values().forEach(cpet::addDelegate);
        return cpet;
    }
}

18 Source : TypeSafetyDependencyLookupDemo.java
with Apache License 2.0
from mercyblitz

private static void displayListableBeanFactoryGetBeansOfType(ListableBeanFactory beanFactory) {
    printBeansException("displayListableBeanFactoryGetBeansOfType", () -> beanFactory.getBeansOfType(User.clreplaced));
}

18 Source : RSocketClientFactoryBean.java
with Apache License 2.0
from joshlong

/**
 * @author <a href="mailto:[email protected]">Josh Long</a>
 */
@Log4j2
clreplaced RSocketClientFactoryBean implements BeanFactoryAware, FactoryBean<Object> {

    private Clreplaced<?> type;

    private ListableBeanFactory context;

    private static RSocketRequester forInterface(Clreplaced<?> clientInterface, ListableBeanFactory context) {
        Map<String, RSocketRequester> rSocketRequestersInContext = context.getBeansOfType(RSocketRequester.clreplaced);
        int rSocketRequestersCount = rSocketRequestersInContext.size();
        replacedert.state(rSocketRequestersCount > 0, () -> "there should be at least one " + RSocketRequester.clreplaced.getName() + " in the context. Please consider defining one.");
        RSocketRequester rSocketRequester = null;
        replacedert.notNull(clientInterface, "the client interface must be non-null");
        replacedert.notNull(context, () -> "the " + ListableBeanFactory.clreplaced.getName() + " interface must be non-null");
        MergedAnnotation<Qualifier> qualifier = MergedAnnotations.from(clientInterface).get(Qualifier.clreplaced);
        if (qualifier.isPresent()) {
            String valueOfQualifierAnnotation = qualifier.getString(MergedAnnotation.VALUE);
            Map<String, RSocketRequester> beans = BeanFactoryAnnotationUtils.qualifiedBeansOfType(context, RSocketRequester.clreplaced, valueOfQualifierAnnotation);
            replacedert.state(beans.size() == 1, () -> "I need just one " + RSocketRequester.clreplaced.getName() + " but I got " + beans.keySet());
            for (Map.Entry<String, RSocketRequester> entry : beans.entrySet()) {
                rSocketRequester = entry.getValue();
                if (log.isDebugEnabled()) {
                    log.debug("found " + rSocketRequester + " with bean name " + entry.getKey() + " for @" + RSocketClient.clreplaced.getName() + " interface " + clientInterface.getName() + '.');
                }
            }
        } else {
            replacedert.state(rSocketRequestersCount == 1, () -> "there should be no more and no less than one unqualified " + RSocketRequester.clreplaced.getName() + " instances in the context.");
            return rSocketRequestersInContext.values().iterator().next();
        }
        replacedert.notNull(rSocketRequester, () -> "we could not find an " + RSocketRequester.clreplaced.getName() + " for the @RSocketClient interface " + clientInterface.getName() + '.');
        return rSocketRequester;
    }

    @SneakyThrows
    public void setType(String type) {
        this.type = Clreplaced.forName(type);
    }

    @Override
    public Object getObject() {
        RSocketRequester rSocketRequester = forInterface(this.type, this.context);
        RSocketClientBuilder clientBuilder = this.context.getBean(RSocketClientBuilder.clreplaced);
        return clientBuilder.buildClientFor(this.type, rSocketRequester);
    }

    @Override
    public Clreplaced<?> getObjectType() {
        return this.type;
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        replacedert.state(beanFactory instanceof ListableBeanFactory, () -> "the BeanFactory is not an instance of a ListableBeanFactory");
        this.context = (ListableBeanFactory) beanFactory;
    }
}

18 Source : OrderServiceClient.java
with Apache License 2.0
from IBM-Cloud

public static void main(String[] args) {
    if (args.length == 0 || "".equals(args[0])) {
        System.out.println("You need to specify an order ID and optionally a number of calls, e.g. for order ID 1000: " + "'client 1000' for a single call per service or 'client 1000 10' for 10 calls each");
    } else {
        int orderId = Integer.parseInt(args[0]);
        int nrOfCalls = 1;
        if (args.length > 1 && !"".equals(args[1])) {
            nrOfCalls = Integer.parseInt(args[1]);
        }
        ListableBeanFactory beanFactory = new FileSystemXmlApplicationContext(CLIENT_CONTEXT_CONFIG_LOCATION);
        OrderServiceClient client = new OrderServiceClient(beanFactory);
        client.invokeOrderServices(orderId, nrOfCalls);
    }
}

18 Source : ArtemisConnectionFactoryConfiguration.java
with Apache License 2.0
from hello-shf

@Bean
public ActiveMQConnectionFactory jmsConnectionFactory(ListableBeanFactory beanFactory, ArtemisProperties properties) {
    return new ArtemisConnectionFactoryFactory(beanFactory, properties).createConnectionFactory(ActiveMQConnectionFactory.clreplaced);
}

18 Source : OnBeanCondition.java
with Apache License 2.0
from hello-shf

private void collectBeanNamesForType(Set<String> result, ListableBeanFactory beanFactory, Clreplaced<?> type, boolean considerHierarchy) {
    result.addAll(BeanTypeRegistry.get(beanFactory).getNamesForType(type));
    if (considerHierarchy && beanFactory instanceof HierarchicalBeanFactory) {
        BeanFactory parent = ((HierarchicalBeanFactory) beanFactory).getParentBeanFactory();
        if (parent instanceof ListableBeanFactory) {
            collectBeanNamesForType(result, (ListableBeanFactory) parent, type, considerHierarchy);
        }
    }
}

18 Source : OnBeanCondition.java
with Apache License 2.0
from hello-shf

private void collectBeanNamesForAnnotation(Set<String> names, ListableBeanFactory beanFactory, Clreplaced<? extends Annotation> annotationType, boolean considerHierarchy) {
    names.addAll(BeanTypeRegistry.get(beanFactory).getNamesForAnnotation(annotationType));
    if (considerHierarchy) {
        BeanFactory parent = ((HierarchicalBeanFactory) beanFactory).getParentBeanFactory();
        if (parent instanceof ListableBeanFactory) {
            collectBeanNamesForAnnotation(names, (ListableBeanFactory) parent, annotationType, considerHierarchy);
        }
    }
}

18 Source : RollbackJobBean.java
with Apache License 2.0
from codeabovelab

/**
 * Rollback any job which is support it.
 * @see RollbackHandle
 */
@JobBean(RollbackHandle.ROLLBACK_JOB)
public clreplaced RollbackJobBean implements Runnable {

    /**
     * Id of job which must be rollback
     */
    @JobParam(required = true)
    private String jobId;

    @Autowired
    private JobContext jobContext;

    @Autowired
    private ListableBeanFactory beanFactory;

    @Autowired
    private JobsManager jobsManager;

    @Override
    public void run() {
        JobInstance job = jobsManager.getJob(jobId);
        if (job == null) {
            throw new IllegalArgumentException("Can not find job for jobId:" + jobId);
        }
        JobContext jc = job.getJobContext();
        RollbackHandle rh = jc.getRollback();
        if (rh == null) {
            throw new IllegalArgumentException("Job (" + jobId + ") does not support rollback.");
        }
        RollbackContext rc = new RollbackContext(this.beanFactory, this.jobsManager, this.jobContext);
        rh.rollback(rc);
    }
}

18 Source : SpringBootAnnotationResolver.java
with Apache License 2.0
from baidu

private BrpcConfig getServiceConfig(ListableBeanFactory beanFactory, Clreplaced<?> serviceInterface) {
    if (brpcProperties == null) {
        brpcProperties = beanFactory.getBean(BrpcProperties.clreplaced);
        if (brpcProperties == null) {
            throw new RuntimeException("bean of BrpcProperties is null");
        }
    }
    return brpcProperties.getServiceConfig(serviceInterface);
}

See More Examples