Changeset 13947


Ignore:
Timestamp:
2007-02-26T11:46:27+13:00 (17 years ago)
Author:
kjdon
Message:

allow specification of full package name for serviceRacks in buildConfig.xml - custom ones may not be in org.greenstone.gsdl3.service package

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/collection/ServiceCluster.java

    r13270 r13947  
    274274        String servicetype = n.getAttribute(GSXML.NAME_ATT);
    275275       
     276        ServiceRack s = null;
     277       
    276278        try {
    277         ServiceRack s = (ServiceRack)Class.forName("org.greenstone.gsdl3.service."+servicetype).newInstance();
    278 
    279         s.setSiteHome(this.site_home);
    280         s.setSiteAddress(this.site_http_address);
    281         s.setClusterName(this.cluster_name);
    282         s.setMessageRouter(this.router);
    283         // pass the xml node to the service for configuration
    284         if (s.configure(n, extra_info)) {
    285            
    286             // find out the supported service types for this service module
    287             Node types = s.process(message);
    288             NodeList typenodes = ((Element)types).getElementsByTagName(GSXML.SERVICE_ELEM);   
    289            
    290             for (int j=0; j<typenodes.getLength();j++) {
    291             String service = ((Element) typenodes.item(j)).getAttribute(GSXML.NAME_ATT);       
    292             if (service_map.get(service)!=null) {
    293                 char extra = '0';
    294                 String new_service = service+extra;   
    295 
    296                 while (service_map.get(new_service)!=null) {
    297                 extra++;
    298                 new_service = service+extra;
    299                 }
    300                 this.service_name_map.put(new_service, service);
    301                 service=new_service;
    302                 ((Element) typenodes.item(j)).setAttribute(GSXML.NAME_ATT, service);
     279        // try for a default service in standard package
     280        s = (ServiceRack)Class.forName("org.greenstone.gsdl3.service."+servicetype).newInstance();
     281       
     282        } catch (Exception e) {}
     283        if (s == null) {
     284        try {
     285            // name as is, in case package is already specified
     286            s = (ServiceRack)Class.forName(servicetype).newInstance();
     287        } catch (Exception e) {}
     288        }
     289
     290        if (s == null) {
     291        logger.error("Couldn't get an instance of class "+servicetype+", or org.greenstone.gsdl3.service."+servicetype);
     292        continue;
     293        }
     294
     295       
     296        s.setSiteHome(this.site_home);
     297        s.setSiteAddress(this.site_http_address);
     298        s.setClusterName(this.cluster_name);
     299        s.setMessageRouter(this.router);
     300        // pass the xml node to the service for configuration
     301        if (s.configure(n, extra_info)) {
     302       
     303        // find out the supported service types for this service module
     304        Node types = s.process(message);
     305        NodeList typenodes = ((Element)types).getElementsByTagName(GSXML.SERVICE_ELEM);   
     306       
     307        for (int j=0; j<typenodes.getLength();j++) {
     308            String service = ((Element) typenodes.item(j)).getAttribute(GSXML.NAME_ATT);       
     309            if (service_map.get(service)!=null) {
     310            char extra = '0';
     311            String new_service = service+extra;   
     312           
     313            while (service_map.get(new_service)!=null) {
     314                extra++;
     315                new_service = service+extra;
    303316            }
    304             this.service_map.put(service, s);
    305             // also add info to the ServiceInfo XML element
    306             this.service_list.appendChild(this.doc.importNode(typenodes.item(j), true));
     317            this.service_name_map.put(new_service, service);
     318            service=new_service;
     319            ((Element) typenodes.item(j)).setAttribute(GSXML.NAME_ATT, service);
    307320            }
    308         }
    309         } catch (Exception e) {
    310         logger.error("configure exception: couldn't create service module:org.greenstone.gsdl3.service."+servicetype+"\n"+e.getMessage() + e.getClass() );
    311         e.printStackTrace();
    312         //return false;
    313         }
    314        
    315     }
     321            this.service_map.put(service, s);
     322            // also add info to the ServiceInfo XML element
     323            this.service_list.appendChild(this.doc.importNode(typenodes.item(j), true));
     324        }
     325        }
     326    }
     327   
    316328    return true;
    317329   
Note: See TracChangeset for help on using the changeset viewer.