Ignore:
Timestamp:
2005-05-16T11:02:50+12:00 (19 years ago)
Author:
kjdon
Message:

merged from branch ant-install-branch: merge 1

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/core/MessageRouter.java

    r9276 r9874  
    9898    this.converter = new XMLConverter();
    9999    this.doc = this.converter.newDOM();
    100    
    101    
    102     }
    103 
     100    }
     101
     102    public void cleanUp() {
     103    if (this.module_map != null) {
     104        Iterator i = this.module_map.values().iterator();
     105        while (i.hasNext()) {
     106        ((ModuleInterface)i.next()).cleanUp();
     107        }
     108    }
     109    }
    104110    /** site_home must be set before configure called */
    105111    public void setSiteHome(String home) {
     
    133139    this.module_map = new HashMap();
    134140
    135     Element config = this.converter.getDOM(configFile).getDocumentElement();
    136    
    137     Element local_site_name = (Element)GSXML.getChildByTagName(config, GSXML.SITE_NAME_ELEM);
     141    Document config_doc = this.converter.getDOM(configFile);
     142    if (config_doc == null) {
     143System.err.println("MessageRouter: couldn't parse site config file: "+configFile.getPath());
     144        return false;
     145    }
     146    Element config_elem = config_doc.getDocumentElement();
     147   
     148    Element local_site_name = (Element)GSXML.getChildByTagName(config_elem, GSXML.SITE_NAME_ELEM);
    138149    if (local_site_name == null) {
    139150        System.err.println("MessageRouter configure error:no site name in config file");
     
    143154    }
    144155   
    145     Element http_address = (Element)GSXML.getChildByTagName(config, GSXML.SITE_HTTP_ADDRESS_ELEM);
     156    Element http_address = (Element)GSXML.getChildByTagName(config_elem, GSXML.SITE_HTTP_ADDRESS_ELEM);
    146157    if (http_address == null) {
    147158        System.err.println("MessageRouter configure error: no http address  in config file");
     
    151162    }
    152163
    153     Element proxy = (Element)GSXML.getChildByTagName(config, "proxy");
     164    Element proxy = (Element)GSXML.getChildByTagName(config_elem, "proxy");
    154165    if (proxy != null) {
    155166        String host = proxy.getAttribute("host");
     
    180191                     
    181192    // load up the services
    182     Element service_rack_list = (Element)GSXML.getChildByTagName(config, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
     193    Element service_rack_list = (Element)GSXML.getChildByTagName(config_elem, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
    183194    configureServices(service_rack_list);
    184195   
    185196    // load up the service clusters
    186     Element cluster_list = (Element)GSXML.getChildByTagName(config, GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER);   
     197    Element cluster_list = (Element)GSXML.getChildByTagName(config_elem, GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER);   
    187198    configureClusters(cluster_list);
    188199
     
    191202
    192203    // load up the external sites - this also adds their services/clusters/collections to the other lists - so must be done last
    193     Element site_list = (Element)GSXML.getChildByTagName(config, GSXML.SITE_ELEM+GSXML.LIST_MODIFIER);
     204    Element site_list = (Element)GSXML.getChildByTagName(config_elem, GSXML.SITE_ELEM+GSXML.LIST_MODIFIER);
    194205    configureSites(site_list);
    195206   
     
    603614                    continue;
    604615                }
    605                 site_config_elem  = this.converter.getDOM(configFile).getDocumentElement();
     616                Document site_config_doc = this.converter.getDOM(configFile);
     617                if (site_config_doc == null) {
     618                    System.err.println("MessageRouter: couldn't parse site config file: "+configFile.getPath());
     619                    continue;
     620                }
     621                site_config_elem  = site_config_doc.getDocumentElement();
    606622                }
    607623                if (subset.equals(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER)) {
     
    684700    File init_file = new File(GSFile.collectionInitFile(this.site_home, col_name));
    685701    if (init_file.exists()) {
    686         Element init_elem = this.converter.getDOM(init_file).getDocumentElement();
    687         String coll_class_name = init_elem.getAttribute("class");
    688         if (coll_class_name.equals("")) {
    689         c = new Collection();
    690         } else {
    691         try {
    692             c = (Collection)Class.forName("org.greenstone.gsdl3.collection."+coll_class_name).newInstance();
    693         } catch (Exception e) {
    694             System.out.println("MessageRouter: couldn't create a new collection, type "+coll_class_name+", defaulting to class Collection");
    695             c = new Collection();
    696         }
    697         }
    698     } else {
    699         // use the defualt collection
     702        Document init_doc = this.converter.getDOM(init_file);
     703        if (init_doc != null) {
     704        Element init_elem = init_doc.getDocumentElement();
     705        if (init_elem != null) {
     706            String coll_class_name = init_elem.getAttribute("class");
     707            if (!coll_class_name.equals("")) {
     708            try {
     709                c = (Collection)Class.forName("org.greenstone.gsdl3.collection."+coll_class_name).newInstance();
     710            } catch (Exception e) {
     711                System.out.println("MessageRouter: couldn't create a new collection, type "+coll_class_name+", defaulting to class Collection");
     712            }
     713            }
     714        }
     715        }
     716    }
     717    if (c==null) { // we haven't found anpther classname to use
    700718        c = new Collection();
    701719    }
     720   
    702721    c.setCollectionName(col_name);
    703722    c.setSiteHome(this.site_home);
     
    720739   
    721740    }
    722 
     741   
    723742    protected boolean activateSite(String site_name) {
    724743    System.out.println("MessageRouter:Activating site: "+site_name+".");
     
    732751        return false;
    733752    }
    734     Element config = this.converter.getDOM(configFile).getDocumentElement();
    735    
    736     Element site_list = (Element)GSXML.getChildByTagName(config, GSXML.SITE_ELEM+GSXML.LIST_MODIFIER);
     753    Document config_doc = this.converter.getDOM(configFile);
     754    if (config_doc == null) {
     755        System.err.println("MessageRouter: couldn't parse site config file: "+configFile.getPath());
     756        return false;
     757    }
     758    Element config_elem = config_doc.getDocumentElement();
     759   
     760    Element site_list = (Element)GSXML.getChildByTagName(config_elem, GSXML.SITE_ELEM+GSXML.LIST_MODIFIER);
    737761    if (site_list ==null ) {
    738762        System.err.println("MessageRouter:activateSite, no sites found");
     
    789813
    790814        System.out.println("MessageRouter: deactivating "+name);
    791         this.module_map.remove(name);
    792 
     815        ModuleInterface m = (ModuleInterface)this.module_map.remove(name);
     816        m.cleanUp(); // clean up any open files/connections etc - can cause trouble on windows
    793817        // also remove the xml bit from description list
    794818        if (type.equals(GSXML.COLLECTION_ELEM)) {
Note: See TracChangeset for help on using the changeset viewer.