Changeset 29064 for main


Ignore:
Timestamp:
2014-05-19T13:22:12+12:00 (10 years ago)
Author:
kjdon
Message:

simplify code cos we are always only looking for OAIPMH servicerack. keep a reference to it once set it up.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/collection/OAICollection.java

    r28984 r29064  
    11/*
    2  *    Collection.java
     2 *    OAICollection.java
    33 *    Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
    44 *
     
    3434import org.greenstone.gsdl3.core.ModuleInterface;
    3535import org.greenstone.gsdl3.service.ServiceRack;
     36import org.greenstone.gsdl3.service.OAIPMH;
    3637import org.greenstone.gsdl3.util.GSFile;
    3738import org.greenstone.gsdl3.util.GSXML;
     
    5152 * only want to load the OAIPMH service rack, not any of the others
    5253 *
    53  * @author Katherine Don
    54  * @see ModuleInterface
    5554 */
    5655public class OAICollection extends Collection
     
    6160    /** does this collection provide the OAI service */
    6261    protected boolean has_oai = false;
     62
     63  /** a reference to the OAIPMH service rack */
     64  protected OAIPMH oai_service_rack = null;
    6365
    6466    /**
     
    112114    }
    113115
    114 
     116  /** add any extra info for collection from OAIConfig.xml */
     117  public boolean configureOAI(Element oai_config) {
     118    // just pass the element to each service - should only be one
     119    return this.oai_service_rack.configureOAI(oai_config);
     120  }
    115121
    116122  /** override this to only load up OAIPMH serviceRack  - don't need all the rest of them for oai*/
     
    119125
    120126      // find the OAIPMH service
    121       Element oai_service_xml = GSXML.getNamedElement(service_rack_list, GSXML.SERVICE_CLASS_ELEM, GSXML.NAME_ATT, OAIXML.OAI_SERVICE_RACK);
     127      Element oai_service_xml = GSXML.getNamedElement(service_rack_list, GSXML.SERVICE_CLASS_ELEM, GSXML.NAME_ATT, "OAIPMH");
    122128      if (oai_service_xml == null) {
    123129        return false;
     
    130136      message.appendChild(request);
    131137
    132       ServiceRack s = null;
    133      
    134       try {
    135        
    136         // try for a default service in standard package
    137         s = (ServiceRack) Class.forName("org.greenstone.gsdl3.service." + OAIXML.OAI_SERVICE_RACK).newInstance();
    138        
    139       } catch (Exception e) {}
    140        
    141       if (s == null) {
    142        
    143         try {
    144           // name as is, in case package is already specified
    145           s = (ServiceRack) Class.forName(OAIXML.OAI_SERVICE_RACK).newInstance();
    146         } catch (Exception e) {}
    147       }
    148 
    149       if (s == null) {
    150        
    151         logger.error("Couldn't get an instance of class " + OAIXML.OAI_SERVICE_RACK + ", or org.greenstone.gsdl3.service." + OAIXML.OAI_SERVICE_RACK);
    152         return false;
    153       }
    154 
    155 
    156       s.setSiteHome(this.site_home);
    157       s.setSiteAddress(this.site_http_address);
    158       s.setClusterName(this.cluster_name);
    159       s.setServiceCluster(this);
    160       s.setMessageRouter(this.router);
     138      this.oai_service_rack = new OAIPMH();
     139      this.oai_service_rack.setSiteHome(this.site_home);
     140      this.oai_service_rack.setSiteAddress(this.site_http_address);
     141      this.oai_service_rack.setClusterName(this.cluster_name);
     142      this.oai_service_rack.setServiceCluster(this);
     143      this.oai_service_rack.setMessageRouter(this.router);
    161144      // pass the xml node to the service for configuration
    162       if (s.configure(oai_service_xml, extra_info)) {
     145      if (this.oai_service_rack.configure(oai_service_xml, extra_info)) {
    163146       
    164147        // find out the supported service types for this service module
    165         Node types = s.process(message);
     148        Node types = this.oai_service_rack.process(message);
    166149        NodeList typenodes = ((Element) types).getElementsByTagName(GSXML.SERVICE_ELEM);
    167150       
     
    184167            ((Element) typenodes.item(j)).setAttribute(GSXML.NAME_ATT, service);
    185168          }
    186         this.service_map.put(service, s);
     169        this.service_map.put(service, this.oai_service_rack);
    187170        // also add info to the ServiceInfo XML element
    188171        this.service_list.appendChild(this.desc_doc.importNode(typenodes.item(j), true));
Note: See TracChangeset for help on using the changeset viewer.