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.ClassPathXmlApplicationContext;
35
import org.springframework.context.support.FileSystemXmlApplicationContext;
36

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

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