List of usage examples for org.springframework.context.support FileSystemXmlApplicationContext getBean
@Override public <T> T getBean(String name, Class<T> requiredType) throws BeansException
From source file:de.uniwue.dmir.heatmap.EntryPoint.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public static void main(String[] args) { String settingsFile;/* w w w. j a v a 2 s.c om*/ if (args.length > 0 && args[0] != null) { settingsFile = args[0]; } else { settingsFile = SETTINGS_FILE; } LOGGER.debug("Reading settings file: {}", settingsFile); FileSystemXmlApplicationContext appContext = new FileSystemXmlApplicationContext(settingsFile); IHeatmap heatmap = appContext.getBean(HEATMAP_BEAN, IHeatmap.class); ITileProcessor tileProcessor = appContext.getBean(WRITER_BEAN, ITileProcessor.class); heatmap.processTiles(tileProcessor); tileProcessor.close(); appContext.close(); }
From source file:com.croer.javaaccess.ItemBusqTest.java
public static void main(String[] args) { FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext( "C:\\Users\\IBM_ADMIN\\Documents\\@Projects_Eli\\201309 Finder&Getter\\_NBP\\digitalcatalog\\JavaAccess\\src\\main\\java\\springXMLConfig.xml"); ItembusqManagement bean3 = context.getBean("itembusqManagement", ItembusqManagement.class); OrtogramaRepository ortoRepo = context.getBean("ortogramaRepository", OrtogramaRepository.class); ItembusqRepository itemRepo = context.getBean("itembusqRepository", ItembusqRepository.class); Ortograma ortoTmp = ortoRepo.findOne("vaca"); List<Ortograma> ortoList = new ArrayList<>(); ortoList.add(ortoTmp);//ww w . ja v a2 s.c o m Itembusq itembusq = itemRepo.findOne(new ItembusqPK("Producto", "99")); bean3.borraOrtograma(ortoList, itembusq); }
From source file:com.px100systems.data.utility.RestoreUtility.java
public static void main(String[] args) { if (args.length < 3) { System.err.println("Usage: java -cp ... com.px100systems.data.utility.RestoreUtility " + "<springXmlConfigFile> <persisterBeanName> <backupDirectory> [compare]"); return;//w w w . j a va 2 s . c o m } FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext("file:" + args[0]); try { PersistenceProvider persister = ctx.getBean(args[1], PersistenceProvider.class); File directory = new File(args[2]); if (!directory.isDirectory()) { System.err.println(directory.getName() + " is not a directory"); return; } List<File> files = new ArrayList<File>(); //noinspection ConstantConditions for (File file : directory.listFiles()) if (BackupFile.isBackup(file)) files.add(file); if (files.isEmpty()) { System.err.println(directory.getName() + " directory has no backup files"); return; } if (args.length == 4 && args[3].equalsIgnoreCase("compare")) { final Map<String, Map<Long, RawRecord>> units = new HashMap<String, Map<Long, RawRecord>>(); for (String storage : persister.storage()) { System.out.println("Storage " + storage); persister.loadByStorage(storage, new PersistenceProvider.LoadCallback() { @Override public void process(RawRecord record) { Map<Long, RawRecord> unitList = units.get(record.getUnitName()); if (unitList == null) { unitList = new HashMap<Long, RawRecord>(); units.put(record.getUnitName(), unitList); } unitList.put(record.getId(), record); } }); for (final Map.Entry<String, Map<Long, RawRecord>> unit : units.entrySet()) { BackupFile file = null; for (int i = 0, n = files.size(); i < n; i++) if (BackupFile.isBackup(files.get(i), unit.getKey())) { file = new BackupFile(files.get(i)); files.remove(i); break; } if (file == null) throw new RuntimeException("Could not find backup file for unit " + unit.getKey()); final Long[] count = new Long[] { 0L }; file.read(new PersistenceProvider.LoadCallback() { @Override public void process(RawRecord record) { RawRecord r = unit.getValue().get(record.getId()); if (r == null) throw new RuntimeException("Could not find persisted record " + record.getId() + " for unit " + unit.getKey()); if (!r.equals(record)) throw new RuntimeException( "Record " + record.getId() + " mismatch for unit " + unit.getKey()); count[0] = count[0] + 1; } }); if (count[0] != unit.getValue().size()) throw new RuntimeException("Extra persisted records for unit " + unit.getKey()); System.out.println(" Unit " + unit.getKey() + ": OK"); } units.clear(); } if (!files.isEmpty()) { System.err.println("Extra backups: "); for (File file : files) System.err.println(" " + file.getName()); } } else { persister.init(); for (File file : files) { InMemoryDatabase.readBackupFile(file, persister); System.out.println("Loaded " + file.getName()); } } } catch (Exception e) { throw new RuntimeException(e); } finally { ctx.close(); } }
From source file:net.itransformers.idiscover.v2.core.Main.java
public static void main(String[] args) throws MalformedURLException { logger.debug("iDiscover v2. gearing up"); Map<String, String> params = CmdLineParser.parseCmdLine(args); // String connectionDetailsFileName = params.get("-f"); // if (connectionDetailsFileName == null) { // printUsage("fileName"); return; // }//from ww w . j a v a 2 s. c o m String depthCmdArg = params.get("-d"); // if (depthCmdArg == null) { // printUsage("depth"); return; // } String projectPath = params.get("-p"); if (projectPath == null) { File cwd = new File("."); System.out.println("Project path is not specified. Will use current dir: " + cwd.getAbsolutePath()); projectPath = cwd.getAbsolutePath(); } File workingDir = new File(projectPath); if (!workingDir.exists()) { System.out.println("Invalid project path!"); return; } System.out.println("Loading beans!!"); File conDetails = new File(projectPath, "iDiscover/conf/txt/connection-details.txt"); File generic = new File(projectPath, "iDiscover/conf/xml/generic.xml"); String genericContextPath = generic.toURI().toURL().toString(); File snmpDiscovery = new File(projectPath, "iDiscover/conf/xml/snmpNetworkDiscovery.xml"); String snmpDiscoveryContextPath = snmpDiscovery.toURI().toURL().toString(); File connectionsDetails = new File(projectPath, "iDiscover/conf/xml/connectionsDetails.xml"); String connectionsDetailsContextPath = connectionsDetails.toURI().toURL().toString(); DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); BeanDefinition beanDefinition = BeanDefinitionBuilder.rootBeanDefinition(String.class) .addConstructorArgValue(projectPath).getBeanDefinition(); String labelDirName = autolabel(projectPath); BeanDefinition beanDefinition2 = BeanDefinitionBuilder.rootBeanDefinition(String.class) .addConstructorArgValue(labelDirName).getBeanDefinition(); beanFactory.registerBeanDefinition("projectPath", beanDefinition); beanFactory.registerBeanDefinition("labelDirName", beanDefinition2); GenericApplicationContext cmdArgCxt = new GenericApplicationContext(beanFactory); // Must call refresh to initialize context cmdArgCxt.refresh(); String[] paths = new String[] { genericContextPath, snmpDiscoveryContextPath, connectionsDetailsContextPath }; // ,project.getAbsolutePath()+project.getAbsolutePath()+File.separator+"iDiscover/conf/xml/snmpNetworkDiscovery.xml", project.getAbsolutePath()+File.separator+"iDiscover/src/main/resources/connectionsDetails.xml" FileSystemXmlApplicationContext applicationContext = new FileSystemXmlApplicationContext(paths, cmdArgCxt); // ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(workingDir+File.separator+"iDiscover/conf/xml/generic.xml",workingDir+File.separator+"/iDiscover/conf/xml/snmpNetworkDiscovery.xml","connectionsDetails.xml"); // NetworkDiscoverer discoverer = fileApplicationContext.getBean("bgpPeeringMapDiscovery", NetworkDiscoverer.class); //NetworkDiscoverer discoverer = fileApplicationContext.getBean("floodLightNodeDiscoverer", NetworkDiscoverer.class); NetworkDiscoverer discoverer = applicationContext.getBean("snmpDiscovery", NetworkDiscoverer.class); LinkedHashMap<String, ConnectionDetails> connectionList = (LinkedHashMap) applicationContext .getBean("connectionList", conDetails); int depth = (Integer) applicationContext.getBean("discoveryDepth", depthCmdArg == null ? "-1" : depthCmdArg); NetworkDiscoveryResult result = discoverer .discoverNetwork(new ArrayList<ConnectionDetails>(connectionList.values()), depth); if (result != null) { for (String s : result.getNodes().keySet()) { System.out.println("\nNode: " + s); } } // }
From source file:com.intertech.tests.ServiceTest.java
/** * Test contact service./*from www. j av a2 s .com*/ */ public static void testContactService() { FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext( new String[] { "spring-beans.xml", "test-beans.xml" }); context.registerShutdownHook(); ContactList list = context.getBean("testList", ContactList.class); ContactService service = context.getBean("contactService", ContactService.class); List<Contact> contacts = list.getContacts(); for (Contact contact : contacts) { service.addContact(contact); System.out.println("Test: " + contact + " was added to the Contact DB"); } System.out.println("Test: Married contacts: " + marriedContacts(contacts)); }
From source file:maltcms.ui.fileHandles.properties.tools.SceneParser.java
/** * Supports both absolute and relative paths and also arbitrary combinations * of the two. In case of relative paths, the location of the file * containing the pipeline configuration is used as basedir to resolve the * relative path./*w w w . ja v a2s. c om*/ * * Example for relative path: * <pre>pipelines.properties = fragmentCommands/myClassName.properties</pre> * Example for absolute path: * <pre>pipelines.properties = /home/juser/myFunkyDir/myClassName.properties</pre> * * <pre>pipeline.properties</pre> accepts multiple entries, separated by a * ',' (comma) character. Example: * <pre>pipeline.properties = fragmentCommands/myClassName.properties,/home/juser/myFunkyDir/myClassName.properties</pre> * * @param filename the filename of the base configuration, which contains * the pipeline= and pipeline.properties keys. * @param cfg the configuration object resembling the content of filename. * @param scene the graph scene into which to load the configuration. */ public static void parseIntoScene(String filename, Configuration cfg, PipelineGraphScene scene) { Logger.getLogger(SceneParser.class.getName()) .info("###################################################################"); Logger.getLogger(SceneParser.class.getName()).info("Creating graph scene from file"); File f = new File(filename); //Get pipeline from configuration cfg.addProperty("config.basedir", f.getParentFile().getAbsoluteFile().toURI().getPath()); String pipelineXml = cfg.getString("pipeline.xml"); FileSystemXmlApplicationContext fsxmac = new FileSystemXmlApplicationContext(new String[] { pipelineXml }, true); ICommandSequence commandSequence = fsxmac.getBean("commandPipeline", cross.datastructures.pipeline.CommandPipeline.class); // String[] pipes = pipeline.toArray(new String[]{}); Logger.getLogger(SceneParser.class.getName()).log(Level.INFO, "Pipeline elements: {0}", commandSequence.getCommands()); PipelineGeneralConfigWidget pgcw = (PipelineGeneralConfigWidget) scene.createGeneralWidget(); pgcw.setProperties(cfg); String lastNode = null; String edge; int edgeCounter = 0; int nodeCounter = 0; Configuration pipeHash = new PropertiesConfiguration(); for (IFragmentCommand command : commandSequence.getCommands()) { Collection<String> configKeys = cross.annotations.AnnotationInspector .getRequiredConfigKeys(command.getClass()); // for (String pipe : pipes) { String nodeId = command.getClass().getCanonicalName() + "" + nodeCounter; PipelineElementWidget node = (PipelineElementWidget) scene.addNode(nodeId); // node.setPropertyFile(); // System.out.println("Parsing pipeline element " + pipeCfg.getAbsolutePath()); node.setBean(command); node.setLabel(command.getClass().getSimpleName()); node.setCurrentClassProperties(); Configuration prop = node.getProperties(); // pipeHash = PropertyLoader.getHash(pipeCfg.getAbsolutePath()); // node.setPropertyFile(pipeCfg.getAbsolutePath()); Iterator iter = pipeHash.getKeys(); while (iter.hasNext()) { String key = (String) iter.next(); prop.setProperty(key, pipeHash.getProperty(key)); } node.setProperties(prop); if (lastNode != null) { edge = "Ledge" + edgeCounter++; scene.addEdge(edge); Logger.getLogger(SceneParser.class.getName()).log(Level.INFO, "Adding edge between lastNode {0} and {1}", new Object[] { lastNode, nodeId }); scene.setEdgeSource(edge, lastNode); scene.setEdgeTarget(edge, nodeId); scene.validate(); } // x += dx; // y += dy; scene.validate(); lastNode = nodeId; nodeCounter++; } scene.validate(); SceneLayouter.layoutVertical(scene); }
From source file:com.emc.vipr.sync.ViPRSync.java
/** * Initializes a Spring Application Context from the given file and * bootstraps the ViPRSync object from there. */// w ww .j ava 2s . c o m protected static ViPRSync springBootstrap(String pathToSpringXml) { File springXml = new File(pathToSpringXml); if (!springXml.exists()) { throw new ConfigurationException("the Spring XML file: " + springXml + " does not exist"); } l4j.info("loading configuration from Spring XML file: " + springXml); FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(pathToSpringXml); if (!ctx.containsBean(ROOT_SPRING_BEAN)) { throw new ConfigurationException("your Spring XML file: " + springXml + " must contain one bean named '" + ROOT_SPRING_BEAN + "' that initializes an ViPRSync object"); } return ctx.getBean(ROOT_SPRING_BEAN, ViPRSync.class); }
From source file:org.apache.oodt.cas.catalog.cli.action.LoadCatalogRepositoryCliAction.java
@Override public void execute(ActionMessagePrinter printer) throws CmdLineActionException { try {/* ww w. j a v a 2s . com*/ Validate.notNull(catalogRepositoryId, "Must specify catalogRepositoryId"); Validate.notNull(beanRepo, "Must specify beanRepo"); FileSystemXmlApplicationContext appContext = new FileSystemXmlApplicationContext( new String[] { this.beanRepo }, false); appContext.setClassLoader(new Serializer().getClassLoader()); appContext.refresh(); CatalogRepositoryFactory factory = (CatalogRepositoryFactory) appContext .getBean(this.catalogRepositoryId, CatalogRepositoryFactory.class); CatalogRepository catalogRepository = factory.createRepository(); Set<Catalog> catalogs = catalogRepository.deserializeAllCatalogs(); printer.println("Deserialized Catalogs: " + catalogs.toString()); for (Catalog catalog : catalogs) { printer.println("Adding Catalog: " + catalog); getClient().addCatalog(catalog); } } catch (Exception e) { throw new CmdLineActionException("Failed to load catalogs from bean repo : " + e.getMessage(), e); } }