Example usage for org.springframework.context ApplicationContext getBean

List of usage examples for org.springframework.context ApplicationContext getBean

Introduction

In this page you can find the example usage for org.springframework.context ApplicationContext getBean.

Prototype

Object getBean(String name) throws BeansException;

Source Link

Document

Return an instance, which may be shared or independent, of the specified bean.

Usage

From source file:org.jasig.schedassist.impl.relationship.advising.AdvisorListRelationshipDataSourceImpl.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>//w w w. ja  v  a  2 s. c  om
 -Dorg.jasig.schedassist.impl.relationship.advising.AdvisorListRelationshipDataSourceImpl.CONFIG
 </pre>
 * The default value for this property is "advisorlist-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 advisorListDataSource = (RelationshipDataSource) context
            .getBean("advisorListDataSource");

    advisorListDataSource.reloadData();
}

From source file:org.ala.harvester.EppalockImagesHarvester.java

/**
 * Main method for testing this particular Harvester
 *
 * @param args//from   ww w .  j  a  v a  2 s.  c o m
 */
public static void main(String[] args) throws Exception {
    String[] locations = { "classpath*:spring.xml" };
    ApplicationContext context = new ClassPathXmlApplicationContext(locations);
    EppalockImagesHarvester h = new EppalockImagesHarvester();
    Repository r = (Repository) context.getBean("repository");
    h.setRepository(r);

    //set the connection params   
    h.start(EPPALOCK_INFOSOURCE_ID);
}

From source file:org.ala.report.GoogleSitemapGenerator.java

/**
 * Usage: outputFileName [option: cassandraAddress cassandraPort]
 * /*from www .  j a  v  a  2s. c om*/
 * @param args
 */
public static void main(String[] args) throws Exception {
    ApplicationContext context = SpringUtils.getContext();
    GoogleSitemapGenerator googleSitemapGenerator = context.getBean(GoogleSitemapGenerator.class);

    //check input arguments
    if (args.length == 0) {
        googleSitemapGenerator.setFileName("Sitemap");
    } else if (args.length == 1) {
        googleSitemapGenerator.setFileName(args[0]);
    }
    //              else if (args.length == 2){
    //                      googleSitemapGenerator = new GoogleSitemapGenerator(args[1], 9160);
    //                      googleSitemapGenerator.setFileName(args[0]);
    //              }
    //              else if (args.length == 3){
    //                      googleSitemapGenerator = new GoogleSitemapGenerator(args[1], Integer.parseInt(args[2]));
    //                      googleSitemapGenerator.setFileName(args[0]);
    //              }

    // do sitemap
    try {
        if (googleSitemapGenerator != null) {
            googleSitemapGenerator.doFullScan();
            googleSitemapGenerator.closeConnectionPool();
        } else {
            System.out.println("Invalid input arguments ...." + args);
            System.exit(0);
        }
    } catch (Exception e) {
        System.out.println("***** Fatal Error !!!.... shutdown cassandra connection.");
        e.printStackTrace();
        googleSitemapGenerator.closeConnectionPool();
        System.exit(0);
    }
    System.exit(0);
}

From source file:org.ala.lucene.ExternalIndexLoader.java

/**
 * Run the loading of indexes for institutions, collections, data providers and data resources
 * /*from  w w  w  .j a  v  a 2s  . com*/
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {

    String[] locations = { "classpath*:spring.xml" };

    ApplicationContext context = new ClassPathXmlApplicationContext(locations);
    ExternalIndexLoader l = (ExternalIndexLoader) context.getBean(ExternalIndexLoader.class);

    l.loadRegions();

    //load collections
    l.loadCollections();

    //load institutions
    l.loadInstitutions();

    //load data providers
    l.loadDataProviders();

    //load datasets
    l.loadDatasets();

    //load layers
    l.loadLayers();

    // load WordPress pages
    CreateWordPressIndex cwpi = (CreateWordPressIndex) context.getBean(CreateWordPressIndex.class);
    logger.info("Start of crawling and indexing WP pages.");
    cwpi.loadSitemap();
    cwpi.indexPages();

    System.exit(0);
}

From source file:org.ala.harvester.PpmlHarvester.java

/**
 * Main method for testing this particular Harvester
 *
 * @param args/*from w  w  w  .j  av a 2 s.  c o m*/
 */
public static void main(String[] args) throws Exception {
    String[] locations = { "classpath*:spring.xml" };
    ApplicationContext context = new ClassPathXmlApplicationContext(locations);
    PpmlHarvester h = new PpmlHarvester();
    Repository r = (Repository) context.getBean("repository");
    h.setRepository(r);

    //set the connection params   
    Map<String, String> connectParams = new HashMap<String, String>();

    connectParams.put("endpoint", "http://portphillipmarinelife.net.au/SpeciesMap/index");

    h.setConnectionParams(connectParams);
    h.start(PPML_INFOSOURCE_ID);
}

From source file:org.apache.s4.client.Adapter.java

@SuppressWarnings("static-access")
public static void main(String args[]) throws IOException, InterruptedException {

    Options options = new Options();

    options.addOption(OptionBuilder.withArgName("corehome").hasArg().withDescription("core home").create("c"));

    options.addOption(// w w w  .  j a  v a2s  .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 + "client-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("client_adapter");

    ApplicationContext appContext = new FileSystemXmlApplicationContext(
            new String[] { "file:" + userConfigFilename }, context);

    Map<?, ?> inputStubBeanMap = appContext.getBeansOfType(InputStub.class);
    Map<?, ?> outputStubBeanMap = appContext.getBeansOfType(OutputStub.class);

    if (inputStubBeanMap.size() == 0 && outputStubBeanMap.size() == 0) {
        System.err.println("No user-defined input/output stub beans");
        System.exit(1);
    }

    ArrayList<InputStub> inputStubs = new ArrayList<InputStub>(inputStubBeanMap.size());
    ArrayList<OutputStub> outputStubs = new ArrayList<OutputStub>(outputStubBeanMap.size());

    // add all input stubs
    for (Map.Entry<?, ?> e : inputStubBeanMap.entrySet()) {
        String beanName = (String) e.getKey();
        System.out.println("Adding InputStub " + beanName);
        inputStubs.add((InputStub) e.getValue());
    }

    // add all output stubs
    for (Map.Entry<?, ?> e : outputStubBeanMap.entrySet()) {
        String beanName = (String) e.getKey();
        System.out.println("Adding OutputStub " + beanName);
        outputStubs.add((OutputStub) e.getValue());
    }

    adapter.setInputStubs(inputStubs);
    adapter.setOutputStubs(outputStubs);

}

From source file:org.ala.harvester.MaHarvester.java

/**
 * Main method for testing this particular Harvester
 *
 * @param args//  ww w.  j a v a2  s  .c o  m
 */
public static void main(String[] args) throws Exception {
    String[] locations = { "classpath*:spring.xml" };
    ApplicationContext context = new ClassPathXmlApplicationContext(locations);
    MaHarvester h = new MaHarvester();
    Repository r = (Repository) context.getBean("repository");
    h.setRepository(r);

    //set the connection params   
    Map<String, String> connectParams = new HashMap<String, String>();
    connectParams.put("endpoint", "http://medent.usyd.edu.au/photos/mosquitoesofaustralia.htm");

    h.setConnectionParams(connectParams);
    h.start(MA_INFOSOURCE_ID);
}

From source file:com.athena.chameleon.engine.Starter.java

/**
 * <pre>//from  ww  w  . j  a  v  a  2 s .  com
 * WAS Migration ?  main() ? ? ? .
 *   <ul>
 *      <li>Migration ?  ?? Full Qualified File Name? ??  ? .</li>
 *      <li>? ??   ?? .</li>
 *      <li>Spring Context ?? loading  spring ?  .</li>
 *      <li>Migration engine module? .</li>
 *   </ul>
 * </pre>
 * 
 * @param args
 */
public static void main(String[] args) {
    logger.debug("Starting of Athena Chameleon WAS Migration tool.");

    String sourceFile = null;
    String deployFile = null;
    if (args.length == 0) {
        sourceFile = getSourceFileName();
        deployFile = getApplicationFileName();
    } else if (args.length == 1) {
        sourceFile = args[0].replaceAll("\\\\", "/");
        if (!isExists(sourceFile) || !isValidSourceExtension(sourceFile)) {
            System.out.println(sourceFile
                    + "?()   ?? ?  ? ?.");
            //sourceFile = getSourceFileName();
        }
        deployFile = getApplicationFileName();
    } else if (args.length == 2) {
        sourceFile = args[0].replaceAll("\\\\", "/");
        if (!isExists(sourceFile) || !isValidSourceExtension(sourceFile)) {
            System.out.println(sourceFile
                    + "?()   ?? ?  ? ?.");
            //sourceFile = getSourceFileName();
        }

        deployFile = args[1].replaceAll("\\\\", "/");
        if (!isExists(deployFile) || !isValidApplicationExtension(deployFile)) {
            System.out.println(deployFile
                    + "?()   ?? ?  ? ?.");
            //deployFile = getApplicationFileName();
        }
    } else {
        System.out.println(
                "[Usage] : java -jar athena-chameleon.jar ${Project Source Archive File} ${Application Archive File}");
        System.exit(-1);
    }

    if (StringUtils.isEmpty(sourceFile) && StringUtils.isEmpty(deployFile)) {
        System.out.println(
                "[Error] ? ?   ? ? .");
        System.exit(-1);
    }

    Upload upload = new Upload();
    upload.setProjectNm(getProjectName());
    upload.setAfterWas(getTargetWas());
    upload.setDepartment(getDepartment());
    upload.setPerson(getManagerName());

    logger.debug("Project Source File => [{}]", sourceFile);
    logger.debug("Application Archive File => [{}]", deployFile);

    ApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring/context-*.xml");

    MigrationComponent component = (MigrationComponent) context.getBean("migrationComponent");
    component.migrate(sourceFile, deployFile, upload);
}

From source file:org.ala.harvester.ScottSistersImagesHarvester.java

/**
 * Main method for testing this particular Harvester
 *
 * @param args// w ww .  j a  v  a 2s  . co m
 */
public static void main(String[] args) throws Exception {
    String[] locations = { "classpath*:spring.xml" };
    ApplicationContext context = new ClassPathXmlApplicationContext(locations);
    ScottSistersImagesHarvester h = new ScottSistersImagesHarvester();
    Repository r = (Repository) context.getBean("repository");
    h.setRepository(r);

    //set the connection params   
    h.start(SCOTT_SISTERS_INFOSOURCE_ID);
}

From source file:org.ala.apps.BieReport.java

/**
 * Usage: outputFileName [option: cassandraAddress cassandraPort]
 * /*from www. ja  v a2s . c om*/
 * @param args
 */
public static void main(String[] args) throws Exception {
    //BieReport bieReport = null;

    //check input arguments
    if (args.length < 1) {
        System.out.println("Output File Name Missing ....");
        System.exit(0);
    }
    ApplicationContext context = SpringUtils.getContext();
    BieReport bieReport = context.getBean(BieReport.class);

    //      else if (args.length == 1){
    //         bieReport = new BieReport();
    //      }      
    //      else if (args.length == 2){
    //         bieReport = new BieReport(args[1], 9160);
    //      }
    //      else if (args.length == 3){
    //         bieReport = new BieReport(args[1], Integer.parseInt(args[2]));
    //      }

    // do report
    try {
        if (bieReport != null) {
            bieReport.doFullScanAndCount(args[0]);
            bieReport.closeConnectionPool();
        } else {
            System.out.println("Invalid input arguments ...." + args);
            System.exit(0);
        }
    } catch (Exception e) {
        System.out.println("***** Fatal Error !!!.... shutdown cassandra connection.");
        e.printStackTrace();
        bieReport.closeConnectionPool();
        System.exit(0);
    }
}