List of usage examples for org.springframework.beans.factory ListableBeanFactory getBeanNamesForType
String[] getBeanNamesForType(@Nullable Class<?> type);
From source file:com.saysth.commons.quartz.SchedulerAccessorBean.java
protected Scheduler findScheduler(String schedulerName) throws SchedulerException { if (this.beanFactory instanceof ListableBeanFactory) { ListableBeanFactory lbf = (ListableBeanFactory) this.beanFactory; String[] beanNames = lbf.getBeanNamesForType(Scheduler.class); for (int i = 0; i < beanNames.length; i++) { Scheduler schedulerBean = (Scheduler) lbf.getBean(beanNames[i]); if (schedulerName.equals(schedulerBean.getSchedulerName())) { return schedulerBean; }/*from ww w . j a v a2 s .co m*/ } } Scheduler schedulerInRepo = SchedulerRepository.getInstance().lookup(schedulerName); if (schedulerInRepo == null) { throw new IllegalStateException("No Scheduler named '" + schedulerName + "' found"); } return schedulerInRepo; }
From source file:com.alacoder.lion.rpc.springsupport.RefererConfigBean.java
/** * ?basicConfig/* w ww .j a va2s . c om*/ */ private void checkAndConfigBasicConfig() { if (getBasicReferer() == null) { if (LionNamespaceHandler.basicRefererConfigDefineNames.size() == 0) { if (beanFactory instanceof ListableBeanFactory) { ListableBeanFactory listableBeanFactory = (ListableBeanFactory) beanFactory; String[] basicRefererConfigNames = listableBeanFactory .getBeanNamesForType(BasicRefererInterfaceConfig.class); LionNamespaceHandler.basicRefererConfigDefineNames .addAll(Arrays.asList(basicRefererConfigNames)); } } for (String name : LionNamespaceHandler.basicRefererConfigDefineNames) { BasicRefererInterfaceConfig biConfig = beanFactory.getBean(name, BasicRefererInterfaceConfig.class); if (biConfig == null) { continue; } if (LionNamespaceHandler.basicRefererConfigDefineNames.size() == 1) { setBasicReferer(biConfig); } else if (biConfig.isDefault() != null && biConfig.isDefault().booleanValue()) { setBasicReferer(biConfig); } } } }
From source file:com.alacoder.lion.rpc.springsupport.ServiceConfigBean.java
/** * ?basicConfig/*from www. j ava 2 s. co m*/ */ private void checkAndConfigBasicConfig() { if (getBasicServiceConfig() == null) { if (LionNamespaceHandler.basicServiceConfigDefineNames.size() == 0) { if (beanFactory instanceof ListableBeanFactory) { ListableBeanFactory listableBeanFactory = (ListableBeanFactory) beanFactory; String[] basicServiceConfigNames = listableBeanFactory .getBeanNamesForType(BasicServiceInterfaceConfig.class); LionNamespaceHandler.basicServiceConfigDefineNames .addAll(Arrays.asList(basicServiceConfigNames)); } } for (String name : LionNamespaceHandler.basicServiceConfigDefineNames) { BasicServiceInterfaceConfig biConfig = beanFactory.getBean(name, BasicServiceInterfaceConfig.class); if (biConfig == null) { continue; } if (LionNamespaceHandler.basicServiceConfigDefineNames.size() == 1) { setBasicServiceConfig(biConfig); } else if (biConfig.isDefault() != null && biConfig.isDefault().booleanValue()) { setBasicServiceConfig(biConfig); } } } }
From source file:com.weibo.api.motan.config.springsupport.ServiceConfigBean.java
/** * ?basicConfig//from ww w .j ava 2 s .c om */ private void checkAndConfigBasicConfig() { if (getBasicServiceConfig() == null) { if (MotanNamespaceHandler.basicServiceConfigDefineNames.size() == 0) { if (beanFactory instanceof ListableBeanFactory) { ListableBeanFactory listableBeanFactory = (ListableBeanFactory) beanFactory; String[] basicServiceConfigNames = listableBeanFactory .getBeanNamesForType(BasicServiceInterfaceConfig.class); MotanNamespaceHandler.basicServiceConfigDefineNames .addAll(Arrays.asList(basicServiceConfigNames)); } } for (String name : MotanNamespaceHandler.basicServiceConfigDefineNames) { BasicServiceInterfaceConfig biConfig = beanFactory.getBean(name, BasicServiceInterfaceConfig.class); if (biConfig == null) { continue; } if (MotanNamespaceHandler.basicServiceConfigDefineNames.size() == 1) { setBasicServiceConfig(biConfig); } else if (biConfig.isDefault() != null && biConfig.isDefault().booleanValue()) { setBasicServiceConfig(biConfig); } } } }
From source file:org.entando.entando.aps.system.init.DatabaseManager.java
private String[] extractBeanNames(Class beanClass) { ListableBeanFactory factory = (ListableBeanFactory) this.getBeanFactory(); return factory.getBeanNamesForType(beanClass); }
From source file:org.entando.entando.aps.system.services.guifragment.api.ApiGuiFragmentInterface.java
public void deleteGuiFragment(Properties properties) throws ApiException, Throwable { String code = properties.getProperty("code"); try {//from w ww .ja v a 2 s. com GuiFragment guiFragment = this.getGuiFragmentManager().getGuiFragment(code); if (null == guiFragment) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "GuiFragment with code '" + code + "' does not exist", Response.Status.CONFLICT); } if (guiFragment.isLocked()) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "GuiFragment with code '" + code + "' are locked", Response.Status.CONFLICT); } Map<String, List<Object>> references = new HashMap<String, List<Object>>(); ListableBeanFactory factory = (ListableBeanFactory) this.getBeanFactory(); String[] defNames = factory.getBeanNamesForType(GuiFragmentUtilizer.class); for (int i = 0; i < defNames.length; i++) { Object service = null; try { service = this.getBeanFactory().getBean(defNames[i]); } catch (Throwable t) { _logger.error("error extracting bean with name '{}'", defNames[i], t); throw new ApsSystemException("error extracting bean with name '" + defNames[i] + "'", t); } if (service != null) { GuiFragmentUtilizer guiFragUtilizer = (GuiFragmentUtilizer) service; List<Object> utilizers = guiFragUtilizer.getGuiFragmentUtilizers(code); if (utilizers != null && !utilizers.isEmpty()) { references.put(guiFragUtilizer.getName(), utilizers); } } } if (!references.isEmpty()) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "GuiFragment with code " + code + " has references with other object", Response.Status.CONFLICT); } this.getGuiFragmentManager().deleteGuiFragment(code); } catch (ApiException ae) { throw ae; } catch (Throwable t) { _logger.error("Error deleting fragment throw api", t); throw t; } }
From source file:org.openadaptor.spring.SpringAdaptor.java
/** * Returns the {@link Adaptor} bean from the Spring context. * /*from w ww .ja v a 2 s . c o m*/ * @see org.openadaptor.spring.SpringAdaptor#getRunnableBean(org.springframework.beans.factory.ListableBeanFactory) */ protected Runnable getRunnableBean(ListableBeanFactory factory) { String beanId = getBeanId(); if (beanId == null) { String[] ids = factory.getBeanNamesForType(Adaptor.class); if (ids.length == 1) { beanId = ids[0]; setBeanId(beanId); } else if (ids.length == 0) { beanId = registerAdaptor(factory, DEFAULT_ADAPTOR_ID); //Should be set by now. } else if (ids.length > 1) { throw new RuntimeException("Mulitple Adaptor beans found in config"); } } return (Runnable) factory.getBean(beanId); }
From source file:org.openadaptor.spring.SpringAdaptor.java
private static void setComponentIds(ListableBeanFactory factory) { String[] beanNames = factory.getBeanNamesForType(IComponent.class); for (int i = 0; i < beanNames.length; i++) { Object bean = factory.getBean(beanNames[i]); if (bean instanceof IComponent) { IComponent component = (IComponent) bean; if (component.getId() == null) { component.setId(beanNames[i]); log.debug("setting IComponent id for " + beanNames[i]); } else { log.debug("IComponent id is already set for " + beanNames[i]); }// w w w. jav a 2 s. com } else { log.debug("bean " + beanNames[i] + " is not an IComponent"); } } }
From source file:org.openadaptor.spring.SpringAdaptor.java
/** * Registers an instance of an {@link Adaptor} with the Spring context. * <p>/*from w w w . j a va 2s . c om*/ * Common OpenAdaptor configurations include an {@link Adaptor} with a * {@link Router} which defines an ordered list of {@link IComponent}s. If * no adaptor bean is explicitly registered, this method will auto-configure * and register one. * <p> * If a {@link Router} is explicitly registered in the Spring context, that * will be autowired as the {@link Adaptor}'s <code>messageProcessor</code>. * Otherwise, a {@link Router} will be automatically configured and registered. * * @param factory the ListableBeanFactory Spring context factory * @param id - String containing the id to use for the adaptor * @return String containing the id for the Adaptor ( */ protected String registerAdaptor(ListableBeanFactory factory, String id) { String[] ids = factory.getBeanNamesForType(Router.class); Router router = null; if (ids.length == 1) { router = (Router) factory.getBean(ids[0]); } else if (ids.length == 0) { router = registerRouter(factory); } MutablePropertyValues properties = new MutablePropertyValues(); properties.addPropertyValue("messageProcessor", router); RootBeanDefinition beanDefinition = new RootBeanDefinition(Adaptor.class); beanDefinition.setPropertyValues(properties); ((GenericApplicationContext) factory).registerBeanDefinition(id, beanDefinition); setBeanId(id); return id; }
From source file:org.openadaptor.spring.SpringAdaptor.java
/** * Registers an instance of a {@link Router} with the Spring context. * <p>/*from ww w .ja v a 2 s .c o m*/ * This method adds all beans registered in the Spring context that are * instances of {@link IComponent} to the router's <code>processors</code> * list in <strong>the order in which they are declared in the Spring * configuration</strong>. * <p> * The only exception is any bean with an id of <code>ExceptionProcessor</code>, * which is set as the <code>exceptionProcessor</code> property of the * {@link Router}. * <p> * Note that this means only basic, single pipeline router configurations * may be auto-configured in this way. Complex configurations that require * a <code>processMap</code> must be defined explicitly. * * @param factory the ListableBeanFactory Spring context factory * @return a configured Router */ protected Router registerRouter(ListableBeanFactory factory) { String[] ids = factory.getBeanNamesForType(IComponent.class); if (ids.length == 0) { throw new RuntimeException("No Component beans found in config"); } List processors = new ArrayList(ids.length); Object exceptionProcessor = null; for (int i = 0; i < ids.length; i++) { if (!ids[i].equals(DEFAULT_EXCEPTION_PROCESSOR_ID)) { processors.add(factory.getBean(ids[i])); } else { exceptionProcessor = factory.getBean(ids[i]); } } MutablePropertyValues properties = new MutablePropertyValues(); properties.addPropertyValue("processors", processors); if (exceptionProcessor != null) { properties.addPropertyValue("exceptionProcessor", exceptionProcessor); } RootBeanDefinition beanDefinition = new RootBeanDefinition(Router.class); beanDefinition.setPropertyValues(properties); ((GenericApplicationContext) factory).registerBeanDefinition(DEFAULT_ROUTER_ID, beanDefinition); return (Router) factory.getBean(DEFAULT_ROUTER_ID); }