Changeset 3934


Ignore:
Timestamp:
2003-03-20T13:42:04+12:00 (21 years ago)
Author:
kjdon
Message:

configureServiceRack now takes two args - one is an optional elem potentially containing some info that a service may need for configuration eg the collection config file has the format and display elements.
The task of deciding which elements in teh extra info are needed for a service has been moved to the service itself, rather than done in the collection - so configure for service now takes the two args, not one.

Location:
trunk/gsdl3/src/java/org/greenstone/gsdl3/collection
Files:
2 edited

Legend:

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

    r3847 r3934  
    110110    configureServiceRack(service_list, coll_config_xml);
    111111   
    112     //System.out.println("description=");
    113     //System.out.println(converter_.getString(description_));
    114112    return true;
    115113   
    116114    }
    117115
    118     /** we need to overwrite this, cos in a collection, some of the info for the service racks is in the collectionConfig.xml file - this needs to be added to the xml for the service rack before configure is called */
    119     protected boolean configureServiceRack(Element service_rack_list,
    120                        Element coll_config_xml) {
    121    
    122     // create all the services
    123     NodeList nodes = service_rack_list.getElementsByTagName(GSXML.SERVICE_CLASS_ELEM);
    124     if (nodes.getLength()==0) {
    125         System.err.println("Cluster configuration error: cluster "+cluster_name_+" has no service modules!");
    126         return false;
    127     }
    128 
    129     for(int i=0; i<nodes.getLength(); i++) {
    130    
    131         // the xml request to send to the serviceRack to query what
    132         // services it provides
    133         Element message = doc_.createElement(GSXML.MESSAGE_ELEM);
    134         Element request = doc_.createElement(GSXML.REQUEST_ELEM);
    135         message.appendChild(request);
    136         request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE);
    137         request.setAttribute(GSXML.INFO_ATT, GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER);
    138        
    139 
    140         Element n = (Element)nodes.item(i);
    141         String servicetype = n.getAttribute(GSXML.NAME_ATT);
    142        
    143         addExtraServiceRackInfo(n, coll_config_xml); // add in any display or format stuff from collectionConfig.xml
    144 
    145         try {
    146         ServiceRack s = (ServiceRack)Class.forName("org.greenstone.gsdl3.service."+servicetype).newInstance();
    147 
    148         s.setSiteHome(site_home_);
    149         s.setClusterName(cluster_name_);
    150         s.setMessageRouter(router_);
    151         // pass the xml node to the service for configuration
    152         s.configure(n);
    153        
    154         // find out the supported service types for this service module
    155         Node types = s.process(message);
    156         NodeList typenodes = ((Element)types).getElementsByTagName(GSXML.SERVICE_ELEM);   
    157        
    158         for (int j=0; j<typenodes.getLength();j++) {
    159             String service = ((Element) typenodes.item(j)).getAttribute(GSXML.NAME_ATT);       
    160             service_map_.put(service, s);
    161            
    162             // also add info to the ServiceInfo XML element
    163             service_info_.appendChild(doc_.importNode(typenodes.item(j), true));
    164         }
    165         } catch (Exception e) {
    166         System.err.println("ServiceCluster Error:  configure exception: couldn't create service module:org.greenstone.gsdl3.service."+servicetype+"\n"+e.getMessage() + e.getClass() );
    167         e.printStackTrace();
    168         //return false;
    169         }
    170        
    171     }
    172     // add elements to description
    173     description_.appendChild(service_info_);
    174    
    175     return true;
    176    
    177    
    178     }
    179 
    180     /** the service rack desription in buildConfig.xml is not complete -
    181      * any display or format info specified in the collectionConfig.xml file
    182      * is not copied over. So that info needs to be added to the service rack
    183      * description before configuring the service.
    184      * extra info is possible for index and classifier elements so far */
    185     protected boolean addExtraServiceRackInfo(Element service_rack_info,
    186                           Element coll_config_xml) {
    187 
    188     NodeList indexes = service_rack_info.getElementsByTagName(GSXML.INDEX_ELEM);
    189    
    190     if (indexes !=null) {
    191         Element config_search = (Element)GSXML.getChildByTagName(coll_config_xml,
    192                                 GSXML.SEARCH_ELEM);
    193         addFormatInfo(indexes, GSXML.INDEX_ELEM, config_search);
    194 
    195     }
    196 
    197     NodeList classifiers = service_rack_info.getElementsByTagName(GSXML.CLASSIFIER_ELEM);
    198     if (classifiers !=null) {
    199         Element config_browse = (Element)GSXML.getChildByTagName(coll_config_xml,
    200                                 GSXML.BROWSE_ELEM);
    201 
    202         addFormatInfo(classifiers, GSXML.CLASSIFIER_ELEM, config_browse);
    203 
    204     }
    205     return true;
    206     }
    207 
    208     protected boolean addFormatInfo(NodeList node_list, String node_name,
    209                     Element extra_info) {
    210 
    211     //Document doc = node_list.item(0).getOwnerDocument();
    212     for (int i=0; i<node_list.getLength();i++) {
    213         Element node = (Element)node_list.item(i);
    214         String name = node.getAttribute(GSXML.NAME_ATT);
    215         Document doc = node.getOwnerDocument();
    216         Element node_extra = GSXML.getNamedElement(extra_info,
    217                                node_name,
    218                                GSXML.NAME_ATT,
    219                                name);
    220         if (node_extra == null) {
    221         System.out.println("haven't found extra info for "+node_name+" named "+name);
    222         }
    223         // get the display elements if any - displayName
    224         NodeList display_names = node_extra.getElementsByTagName(GSXML.DISPLAYNAME_ELEM);
    225         if (display_names !=null) {
    226         Element display = doc.createElement(GSXML.DISPLAY_ELEM);
    227         for (int j=0; j<display_names.getLength(); j++) {
    228             Element e = (Element)display_names.item(j);
    229            
    230             Element display_name = GSXML.createTextElement(doc, GSXML.DISPLAY_NAME_ELEM, GSXML.getNodeText(e));
    231             display_name.setAttribute(GSXML.LANG_ATT, e.getAttribute(GSXML.LANG_ATT));
    232             display.appendChild(display_name);
    233         }
    234         node.appendChild(display);
    235         }
    236        
    237         // get the format element if any
    238         Element format = (Element)GSXML.getChildByTagName(node_extra, GSXML.FORMAT_ELEM);
    239         if (format==null) {
    240         format = (Element)GSXML.getChildByTagName(extra_info,
    241                               GSXML.FORMAT_ELEM);
    242         }
    243         if (format!=null) { // append to index info
    244        
    245         // find the transform xsl file
    246         String transform_file = GSFile.configFileFormatStylesheet();
    247         if (transform_file.equals("")) {
    248             System.out.println("Collection: couldn't find the config file format transform file!!");
    249             // just append the original instead
    250             node.appendChild(doc.importNode(format, true));
    251         } else {
    252            
    253             Document stylesheet = converter_.getDOM(new File(transform_file));
    254             Element new_format = (Element)transformer_.transform(stylesheet, format);
    255            
    256             node.appendChild(doc.importNode(new_format, true));
    257         }
    258         }
    259     }
    260     return true;
    261     }
    262 
    263    
    264116}
    265117
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/collection/ServiceCluster.java

    r3847 r3934  
    160160    } else {
    161161       
    162         boolean result = configureServiceRack(service_rack_list);
     162        boolean result = configureServiceRack(service_rack_list, null);
    163163        if (result == false) {
    164164        System.err.println("couldn't configure the  service racks!!");
     
    170170    }
    171171   
     172    /** adds metadata from a metadataList into the meta_info_ xml */
    172173    protected boolean configureMetadata(Element metadata_list) {
    173174    NodeList metanodes = metadata_list.getElementsByTagName(GSXML.METADATA_ELEM);
     
    180181    }
    181182   
    182  
    183     protected boolean configureServiceRack(Element service_rack_list) {
     183    /** creates and configures all the services - extra_info is some more xml
     184that is passed to teh service  - eg used for coll config files for Collection
     185    */
     186    protected boolean configureServiceRack(Element service_rack_list,
     187                       Element extra_info) {
    184188   
    185189    // create all the services
     
    211215        s.setMessageRouter(router_);
    212216        // pass the xml node to the service for configuration
    213         s.configure(n);
     217        s.configure(n, extra_info);
    214218       
    215219        // find out the supported service types for this service module
Note: See TracChangeset for help on using the changeset viewer.