List of usage examples for org.springframework.context.support FileSystemXmlApplicationContext getBeansOfType
@Override public <T> Map<String, T> getBeansOfType(@Nullable Class<T> type) throws BeansException
From source file:com.predic8.membrane.annot.bean.MCUtil.java
@SuppressWarnings("unchecked") public static <T> T fromXML(Class<T> clazz, final String xml) { final String MAGIC = "magic.xml"; FileSystemXmlApplicationContext fsxacApplicationContext = new FileSystemXmlApplicationContextExtension( MAGIC, xml);//from w ww . ja v a 2s. com fsxacApplicationContext.setConfigLocation(MAGIC); fsxacApplicationContext.refresh(); Object bean = null; if (fsxacApplicationContext.containsBean("main")) { bean = fsxacApplicationContext.getBean("main"); } else { Collection<T> beans = fsxacApplicationContext.getBeansOfType(clazz).values(); if (beans.size() > 1) throw new InvalidParameterException( "There is more than one bean of type '" + clazz.getName() + "'."); bean = beans.iterator().next(); } if (bean == null) throw new InvalidParameterException("Did not find bean with ID 'main'."); if (!clazz.isAssignableFrom(bean.getClass())) throw new InvalidParameterException("Bean 'main' is not a " + clazz.getName() + " ."); return (T) bean; }
From source file:org.pentaho.agilebi.spoon.visualizations.VisualizationManager.java
protected void loadVisualizationFile(File file) { try {// ww w. ja v a 2 s . c o m FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext( new String[] { file.getPath() }, false); context.setClassLoader(getClass().getClassLoader()); context.refresh(); Map beans = context.getBeansOfType(IVisualization.class); for (Object key : beans.keySet()) { IVisualization vis = (IVisualization) beans.get(key); if (vis.getOrder() >= 0) { visualizations.add(vis); } } } catch (XmlBeanDefinitionStoreException e) { // TODO: introduce logging e.printStackTrace(); } }
From source file:org.apache.oodt.cas.catalog.cli.action.LoadCatalogsCliAction.java
@Override public void execute(ActionMessagePrinter printer) throws CmdLineActionException { try {/* w w w.j a v a2 s .c o m*/ Validate.notNull(beanRepo, "Must specify beanRepo"); FileSystemXmlApplicationContext repoAppContext = new FileSystemXmlApplicationContext( new String[] { this.beanRepo }, false); repoAppContext.setClassLoader(new Serializer().getClassLoader()); repoAppContext.refresh(); @SuppressWarnings("unchecked") Map<String, Catalog> catalogs = repoAppContext.getBeansOfType(Catalog.class); for (Catalog catalog : catalogs.values()) { printer.println("Adding catalog: " + catalog.getId()); getClient().addCatalog(catalog); } } catch (Exception e) { throw new CmdLineActionException("Failed to load catalogs : " + e.getMessage(), e); } }
From source file:org.apache.oodt.cas.protocol.config.SpringProtocolConfig.java
private void loadFactories(FileSystemXmlApplicationContext appContext) { Collection<ProtocolFactory> protocolFactories = appContext.getBeansOfType(ProtocolFactory.class).values(); for (ProtocolFactory factory : protocolFactories) { List<ProtocolFactory> factories = factoryMap.get(factory.getSchema()); if (factories == null) { factories = new ArrayList<ProtocolFactory>(); }//from w w w . j ava 2 s. c o m factories.add(factory); factoryMap.put(factory.getSchema(), factories); } }