Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A class that gets Accession Number, check for uniqueness
4
 *             and register it into db
5
 *  Copyright: 2000 Regents of the University of California and the
6
 *             National Center for Ecological Analysis and Synthesis
7
 *    Authors: Jivka Bojilova, Matt Jones
8
 *
9
 *   '$Author: leinfelder $'
10
 *     '$Date: 2011-11-02 20:40:12 -0700 (Wed, 02 Nov 2011) $'
11
 * '$Revision: 6595 $'
12
 *
13
 * This program is free software; you can redistribute it and/or modify
14
 * it under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation; either version 2 of the License, or
16
 * (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
 */
27
package edu.ucsb.nceas.metacat.index;
28

    
29
import java.util.List;
30

    
31
import org.apache.commons.logging.Log;
32
import org.apache.commons.logging.LogFactory;
33
import org.springframework.context.ApplicationContext;
34
import org.springframework.context.support.FileSystemXmlApplicationContext;
35

    
36
/**
37
 * The start class of the index.
38
 * @author tao
39
 *
40
 */
41
public class ApplicationController {
42
    
43
    private static String SOLRINDEXES = "solrIndexes";
44
    private List<SolrIndex> solrIndexes = null;
45
    private static ApplicationContext context = null;
46
    private String springConfigFile = "src/main/resources/index-processor-context.xml";
47
    Log log = LogFactory.getLog(ApplicationController.class);
48
    
49
    /**
50
     * Constructor
51
     */
52
    public ApplicationController () {
53
        init();
54
    }
55
    
56
    /**
57
     * Set the Spring configuration file.
58
     * @param springConfigFile  the path of the Spring configuration file
59
     */
60
    public ApplicationController(String springConfigFile) {
61
        this.springConfigFile = springConfigFile;
62
        init();
63
    }
64
    
65
    /**
66
     * Init the list of the SolrIndex objects from the configuration file.
67
     * Start listening to the shared Hazelcast structures
68
     */
69
    private void init() {
70
        context = getContext();
71
        solrIndexes = (List<SolrIndex>) context.getBean(SOLRINDEXES);
72
        
73
        // start the SystemMetadata listener[s] (only expect there to be one)
74
        for (SolrIndex solrIndex: solrIndexes) {
75
        	SystemMetadataEventListener smel = new SystemMetadataEventListener();
76
        	smel.setSolrIndex(solrIndex);
77
        	smel.start();
78
        }
79
        
80
    }
81
    
82
    /*
83
     * Get the ApplicaionContext of Spring.
84
     */
85
    private ApplicationContext getContext() {
86
        if (context == null) {
87
            context = new FileSystemXmlApplicationContext(springConfigFile);
88
        }
89
        return context;
90
    }
91

    
92
    /**
93
     * Get the path of the Spring configuration file.
94
     * @return the path of the Spring configuration file.
95
     */
96
    public String getSpringConfigFile() {
97
        return this.springConfigFile;
98
    }
99
    
100
    /**
101
     * Get the list of the solr index.
102
     * @return the list of the solr index.
103
     */
104
    public List<SolrIndex> getSolrIndexes() {
105
        return this.solrIndexes;
106
    }
107
}
(1-1/4)