List of usage examples for org.springframework.context ApplicationContext getBean
Object getBean(String name) throws BeansException;
From source file:org.apache.s4.adapter.Adapter.java
public static void main(String args[]) { Options options = new Options(); options.addOption(OptionBuilder.withArgName("corehome").hasArg().withDescription("core home").create("c")); options.addOption(/*from w w w. ja va 2 s.co m*/ OptionBuilder.withArgName("instanceid").hasArg().withDescription("instance id").create("i")); options.addOption( OptionBuilder.withArgName("configtype").hasArg().withDescription("configuration type").create("t")); options.addOption(OptionBuilder.withArgName("userconfig").hasArg() .withDescription("user-defined legacy data adapter configuration file").create("d")); CommandLineParser parser = new GnuParser(); CommandLine commandLine = null; try { commandLine = parser.parse(options, args); } catch (ParseException pe) { System.err.println(pe.getLocalizedMessage()); System.exit(1); } int instanceId = -1; if (commandLine.hasOption("i")) { String instanceIdStr = commandLine.getOptionValue("i"); try { instanceId = Integer.parseInt(instanceIdStr); } catch (NumberFormatException nfe) { System.err.println("Bad instance id: %s" + instanceIdStr); System.exit(1); } } if (commandLine.hasOption("c")) { coreHome = commandLine.getOptionValue("c"); } String configType = "typical"; if (commandLine.hasOption("t")) { configType = commandLine.getOptionValue("t"); } String userConfigFilename = null; if (commandLine.hasOption("d")) { userConfigFilename = commandLine.getOptionValue("d"); } File userConfigFile = new File(userConfigFilename); if (!userConfigFile.isFile()) { System.err.println("Bad user configuration file: " + userConfigFilename); System.exit(1); } File coreHomeFile = new File(coreHome); if (!coreHomeFile.isDirectory()) { System.err.println("Bad core home: " + coreHome); System.exit(1); } if (instanceId > -1) { System.setProperty("instanceId", "" + instanceId); } else { System.setProperty("instanceId", "" + S4Util.getPID()); } String configBase = coreHome + File.separatorChar + "conf" + File.separatorChar + configType; String configPath = configBase + File.separatorChar + "adapter-conf.xml"; File configFile = new File(configPath); if (!configFile.exists()) { System.err.printf("adapter config file %s does not exist\n", configPath); System.exit(1); } // load adapter config xml ApplicationContext coreContext; coreContext = new FileSystemXmlApplicationContext("file:" + configPath); ApplicationContext context = coreContext; Adapter adapter = (Adapter) context.getBean("adapter"); ApplicationContext appContext = new FileSystemXmlApplicationContext( new String[] { "file:" + userConfigFilename }, context); Map listenerBeanMap = appContext.getBeansOfType(EventProducer.class); if (listenerBeanMap.size() == 0) { System.err.println("No user-defined listener beans"); System.exit(1); } EventProducer[] eventListeners = new EventProducer[listenerBeanMap.size()]; int index = 0; for (Iterator it = listenerBeanMap.keySet().iterator(); it.hasNext(); index++) { String beanName = (String) it.next(); System.out.println("Adding producer " + beanName); eventListeners[index] = (EventProducer) listenerBeanMap.get(beanName); } adapter.setEventListeners(eventListeners); }
From source file:inc.cygnus.app.MainSpring.java
public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { // Implementasi Konfigurasi Spring framework @SuppressWarnings("resource") ApplicationContext appContext = new ClassPathXmlApplicationContext("applicationContext.xml"); // Initialize service setCustomerService((CustomerService) appContext.getBean("customerService")); setProductService((ProductService) appContext.getBean("productService")); setPurchaseService((PurchaseService) appContext.getBean("purchaseService")); try { // After finish service initialize // Show Form Menu Master UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException ex) { Logger.getLogger(MainSpring.class.getName()).log(Level.SEVERE, null, ex); } catch (InstantiationException ex) { Logger.getLogger(MainSpring.class.getName()).log(Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { Logger.getLogger(MainSpring.class.getName()).log(Level.SEVERE, null, ex); } catch (UnsupportedLookAndFeelException ex) { Logger.getLogger(MainSpring.class.getName()).log(Level.SEVERE, null, ex); }/*from w w w . java 2 s . c o m*/ Menu mmv = new Menu(); mmv.setVisible(true); } catch (BeansException e) { e.printStackTrace(); } } }); }
From source file:be.kdg.repaircafemodel.TestRepairCafe.java
public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext( "be/kdg/repaircafemodel/spring/root-context.xml"); // Get userService from Spring Context UserService userService = (UserService) context.getBean("userService"); // Get repairService from Spring Context RepairService repairService = (RepairService) context.getBean("repairService"); // Create a client Address address1 = new Address("Nationalestraat", "5", "2000", "Antwerpen"); Person person1 = new Person("Jan", "Peeters", address1); Client client = new Client(person1, "jan.peeters@student.kdg.be", "jan"); // Create a repairer Address address2 = new Address("Nationalestraat", "5", "2000", "Antwerpen"); Person person2 = new Person("Wouter", "Deketelaere", address2); Repairer repairGuy = new Repairer(person2, "wouter.deketelaere@kdg.be", "jef", "Master"); try {//ww w . j av a2 s .com userService.addUser(client); userService.addUser(repairGuy); } catch (UserServiceException ex) { Logger.getLogger(TestRepairCafe.class.getName()).log(Level.SEVERE, null, ex); } // update een gebruiker met een nieuw wachtwoord try { userService.updatePassword(repairGuy, "jef", "wouter"); userService.checkLogin(repairGuy.getUsername(), "wouter"); } catch (UserServiceException ex) { Logger.getLogger(TestRepairCafe.class.getName()).log(Level.SEVERE, null, ex); } try { userService.checkLogin("wouter.deketelaere@kdg.be", "wouter"); } catch (UserServiceException ex) { Logger.getLogger(TestRepairCafe.class.getName()).log(Level.SEVERE, null, ex); } Repair repair = new Repair(new Item("G 4210 i", "Miele", "Vaatwasser"), new RepairDetails("Elektrisch", "Toestel stopt niet meer", RepairDetails.PriceModel.FIXED, new DateTime().plusWeeks(2))); repairService.submitRepair(client, repair); System.out.println(repairService.getAllCategories()); repairService.placeBid(repairGuy, repair, 200.0); System.out.println(repairService.findAllRepairsByClient(client)); repairService.placeBid(repairGuy, repair, 150); try { System.out.println(repairService.findRepairsByCategory("Vaatwasser")); System.out.println(repairService.findRepairsByDefect("Elektrisch")); System.out.println(repairService.getBids(repairGuy)); } catch (RepairServiceException ex) { Logger.getLogger(TestRepairCafe.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.sandag.popsyn.PopulationSynthesizer.java
/** * Begins execution of PopSyn/*from ww w .j av a 2 s .c o m*/ * @param args not used * @throws Exception */ public static void main(String[] args) throws Exception { double startTime = System.currentTimeMillis(); // load ApplicationContext appCtx = new ClassPathXmlApplicationContext("applicationContext-mybatis.xml"); PopulationSynthesizer popSyn = appCtx.getBean(PopulationSynthesizer.class); // do work popSyn.synthesizePopulation(); // time stamp LOGGER.info("Completed in: " + (float) (((System.currentTimeMillis() - startTime) / 1000.0) / 60.0) + " minutes."); }
From source file:SpringInAction4Edition.MainApp.java
public static void main(String[] args) { ApplicationContext context = new AnnotationConfigApplicationContext(CDConfig.class); Environment env = context.getEnvironment(); System.err.println("environment : ime : " + env.getProperty("ime")); System.err.println("environment : prezime : " + env.getProperty("prezime")); KutijaCD cd_ovi = context.getBean(KutijaCD.class); CDPlayer cDPlayer = context.getBean(CDPlayer.class); cd_ovi.getCds().stream().forEach((cd) -> { cd.play();/*from www. j av a 2 s .c om*/ }); cDPlayer.getCd(); System.err.println("BEAN DEF NAMES : " + Arrays.toString(context.getBeanDefinitionNames())); }
From source file:project.latex.balloon.BalloonController.java
/** * @param args the command line arguments *//*from w w w . j a va 2 s. c o m*/ public static void main(String[] args) { PropertyConfigurator.configure("logger.properties"); logger.info("Project Latex Balloon Controller, version 0.1"); ApplicationContext context = new FileSystemXmlApplicationContext("beans.xml"); BalloonController balloonController = (BalloonController) context.getBean("balloonController"); logger.info("Balloon created"); balloonController.run(); }
From source file:org.jasig.schedassist.impl.owner.ScheduleOwnerAuditor.java
/** * Depends on the presence of a Spring {@link ApplicationContext} at the location * on the classpath defined by the {@link #CONFIG_SYSTEM_PROPERTY} System property. * /* www .jav a 2 s. c o m*/ * @param args */ public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext(CONFIG); ScheduleOwnerAuditor auditor = (ScheduleOwnerAuditor) context.getBean("scheduleOwnerAuditor"); List<PersistenceScheduleOwner> allOwnerRecords = auditor.gatherAllScheduleOwnerRecords(); for (PersistenceScheduleOwner owner : allOwnerRecords) { auditor.auditRecord(owner); } }
From source file:be.ugent.maf.cellmissy.gui.controller.MSDGenerator.java
public static void main(String[] args) { // get the application context ApplicationContext context = ApplicationContextProvider.getInstance().getApplicationContext(); // get the services we need ExperimentService experimentService = (ExperimentService) context.getBean("experimentService"); ProjectService projectService = (ProjectService) context.getBean("projectService"); WellService wellService = (WellService) context.getBean("wellService"); SingleCellConditionPreProcessor singleCellConditionPreProcessor = (SingleCellConditionPreProcessor) context .getBean("singleCellConditionPreProcessor"); SingleCellConditionOperator singleCellConditionOperator = (SingleCellConditionOperator) context .getBean("singleCellConditionOperator"); // get all the experiments from DB Project project = projectService.findById(4L); List<Experiment> experiments = experimentService.findExperimentsByProjectId(project.getProjectid()); // root folder File folder = new File("C:\\Users\\Paola\\Desktop\\benchmark\\cellmissy"); for (Experiment experiment : experiments) { if (experiment.getExperimentNumber() == 1) { List<List<TrackDataHolder>> biologicalConditions = new ArrayList<>(); double instrumentConversionFactor = experiment.getInstrument().getConversionFactor(); double magnificationValue = experiment.getMagnification().getMagnificationValue(); double conversionFactor = instrumentConversionFactor * magnificationValue / 10; // fetch the migration data System.out//from w w w .j av a 2 s . c om .println("fetching data for project: " + project + ", experiment: " + experiment + " ..."); for (PlateCondition plateCondition : experiment.getPlateConditionList()) { List<Well> wells = new ArrayList<>(); for (Well well : plateCondition.getWellList()) { Well fetchedWell = wellService.fetchMigrationData(well.getWellid()); wells.add(fetchedWell); } plateCondition.setWellList(wells); } for (PlateCondition plateCondition : experiment.getPlateConditionList()) { // create a new object to hold pre-processing results SingleCellConditionDataHolder singleCellConditionDataHolder = new SingleCellConditionDataHolder( plateCondition); System.out.println("****************computations started for condition: " + plateCondition); // do the computations singleCellConditionPreProcessor.generateDataHolders(singleCellConditionDataHolder); singleCellConditionPreProcessor.generateDataStructure(singleCellConditionDataHolder); singleCellConditionPreProcessor.preProcessStepsAndCells(singleCellConditionDataHolder, conversionFactor, experiment.getExperimentInterval()); singleCellConditionPreProcessor .generateRawTrackCoordinatesMatrix(singleCellConditionDataHolder); singleCellConditionPreProcessor .generateShiftedTrackCoordinatesMatrix(singleCellConditionDataHolder); singleCellConditionOperator.operateOnStepsAndCells(singleCellConditionDataHolder); List<TrackDataHolder> trackDataHolders = singleCellConditionDataHolder.getTrackDataHolders(); biologicalConditions.add(trackDataHolders); } try (BufferedWriter bufferedWriter = new BufferedWriter( new FileWriter(new File(folder, "bench_msd.txt")))) { // header of the file bufferedWriter.append("traj_id" + " " + "t_lag" + " " + "msd"); bufferedWriter.newLine(); for (List<TrackDataHolder> conditionTracks : biologicalConditions) { for (TrackDataHolder trackDataHolder : conditionTracks) { StepCentricDataHolder stepCentricDataHolder = trackDataHolder .getStepCentricDataHolder(); double[][] msd = stepCentricDataHolder.getMSD(); for (int i = 0; i < msd.length; i++) { bufferedWriter.append("" + stepCentricDataHolder.getTrack().getTrackid()); bufferedWriter.append(" "); bufferedWriter.append("" + msd[i][0]); bufferedWriter.append(" "); bufferedWriter.append("" + msd[i][1]); bufferedWriter.newLine(); } } } System.out.println("txt file succ. created!"); } catch (IOException ex) { } } } }
From source file:org.lieuofs.extraction.etatpays.ExtractionPays.java
/** * @param args//from w w w . j a v a2 s . c o m */ public static void main(String[] args) throws IOException { ApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "beans_lieuofs.xml" }); EtatTerritoireCritere critere = new EtatTerritoireCritere(); //critere.setEstEtat(Boolean.FALSE); EtatTerritoireDao dao = (EtatTerritoireDao) context.getBean("etatTerritoireDao"); Set<EtatTerritoirePersistant> etats = dao.rechercher(critere); EtatWriter etatWriter = new NumOFSEtatWriter(); BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream("ExtractionPaysOFSReconnuRecemment.txt"), "UTF-8")); List<EtatTerritoirePersistant> listeTriee = new ArrayList<EtatTerritoirePersistant>(etats); Collections.sort(listeTriee, new Comparator<EtatTerritoirePersistant>() { @Override public int compare(EtatTerritoirePersistant o1, EtatTerritoirePersistant o2) { //return o1.getFormeCourte("fr").compareTo(o2.getFormeCourte("fr")); return o1.getNumeroOFS() - o2.getNumeroOFS(); } }); for (EtatTerritoirePersistant etat : filtre(listeTriee)) { String etatStr = etatWriter.ecrireEtat(etat); if (null != etatStr) { writer.append(etatStr); } } writer.close(); }
From source file:org.jasig.schedassist.impl.relationship.CSVRelationshipDataSourceImpl.java
/** * Main method to allow command line invocation of the {@link #reloadData(Resource)} method. * This method attempts to load a {@link ClassPathXmlApplicationContext} from the * location specified in the System property: <pre>/*from ww w. j av a 2 s .c o m*/ -Dorg.jasig.schedassist.impl.relationship.CSVRelationshipDataSourceImpl.CONFIG </pre> * The default value for this property is "csv-relationship-dataSource.xml" (in the default package). * This Spring applicationContext must contain a fully configured {@link RelationshipDataSource} * bean. * * @param args */ public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext(CONFIG); RelationshipDataSource csvDataSource = (RelationshipDataSource) context.getBean("csvDataSource"); csvDataSource.reloadData(); }