Ignore:
Timestamp:
2012-01-26T10:33:16+13:00 (12 years ago)
Author:
sjm84
Message:

Reformatting this file ahead of some changes

File:
1 edited

Legend:

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

    r24221 r24975  
    11/*
    2 *    ServiceCluster.java
    3 *    Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
    4 *
    5 *    This program is free software; you can redistribute it and/or modify
    6 *    it under the terms of the GNU General Public License as published by
    7 *    the Free Software Foundation; either version 2 of the License, or
    8 *    (at your option) any later version.
    9 *
    10 *    This program is distributed in the hope that it will be useful,
    11 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
    12 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13 *    GNU General Public License for more details.
    14 *
    15 *    You should have received a copy of the GNU General Public License
    16 *    along with this program; if not, write to the Free Software
    17 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    18 */
     2 *    ServiceCluster.java
     3 *    Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
     4 *
     5 *    This program is free software; you can redistribute it and/or modify
     6 *    it under the terms of the GNU General Public License as published by
     7 *    the Free Software Foundation; either version 2 of the License, or
     8 *    (at your option) any later version.
     9 *
     10 *    This program is distributed in the hope that it will be useful,
     11 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 *    GNU General Public License for more details.
     14 *
     15 *    You should have received a copy of the GNU General Public License
     16 *    along with this program; if not, write to the Free Software
     17 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     18 */
    1919// leave the package name as is for now - should be changed to something better
    2020// cluster? groups?
    2121package org.greenstone.gsdl3.collection;
    2222
    23 
    2423import org.greenstone.gsdl3.util.*;
    2524import org.greenstone.gsdl3.core.*;
     
    2726
    2827// java XML classes we're using
    29 import org.w3c.dom.Document; 
    30 import org.w3c.dom.Node; 
    31 import org.w3c.dom.Element; 
    32 import org.w3c.dom.NodeList; 
     28import org.w3c.dom.Document;
     29import org.w3c.dom.Node;
     30import org.w3c.dom.Element;
     31import org.w3c.dom.NodeList;
    3332
    3433import java.io.*;
     
    4140
    4241/* ServiceCluster - a groups of services that are related in some way
    43 * Implements ModuleInterface. Contains a list of services provided by the cluster, along with metadata about the cluster itself.
    44 * a collection is a special type of cluster
    45 *  @author <a href="mailto:[email protected]">Katherine Don</a>
    46 *  @version $Revision$
    47 *  @see ModuleInterface
    48 */
    49 public class ServiceCluster  
    50 implements ModuleInterface {
    51 
    52     static Logger logger = Logger.getLogger(org.greenstone.gsdl3.collection.ServiceCluster.class.getName()); 
     42 * Implements ModuleInterface. Contains a list of services provided by the cluster, along with metadata about the cluster itself.
     43 * a collection is a special type of cluster
     44 *  @author <a href="mailto:[email protected]">Katherine Don</a>
     45 *  @version $Revision$
     46 *  @see ModuleInterface
     47 */
     48public class ServiceCluster implements ModuleInterface
     49{
     50
     51    static Logger logger = Logger.getLogger(org.greenstone.gsdl3.collection.ServiceCluster.class.getName());
    5352
    5453    protected static final String CONFIG_ENCODING = "utf-8";
    5554
    5655    protected static final String DEFAULT_LANG = "en"; // hack for now, should be read from the coll cfg file? or site cfg file for cluster
    57    
    58     /** base directory for the site that this cluster belongs to*/
     56
     57    /** base directory for the site that this cluster belongs to */
    5958    protected String site_home = null;
    6059    /** http address of the site that this cluster belongs to */
    6160    protected String site_http_address = null;
    62     /** The name of the cluster - for a collection, this is the collection name*/
     61    /** The name of the cluster - for a collection, this is the collection name */
    6362    protected String cluster_name = null;
    6463    /** collection type : mg, mgpp or lucene */
    6564    protected String col_type = "";
    66     /** database type : gdbm, jdbm or sqlite*/
     65    /** database type : gdbm, jdbm or sqlite */
    6766    protected String db_type = "";
    68    
     67
    6968    /** a reference to the message router */
    7069    protected MessageRouter router = null;
    71     /** The map of services.
    72     *
    73     * Maps Services to ServiceRack objects
    74     * @see ServiceRack
    75     *
    76     */
    77     protected HashMap service_map=null;
    78     /** maps pseudo service names to real service names - needed if we have two services with the same name for one collection */
    79     protected HashMap service_name_map=null;
    80    
     70    /**
     71     * The map of services.
     72     *
     73     * Maps Services to ServiceRack objects
     74     *
     75     * @see ServiceRack
     76     *
     77     */
     78    protected HashMap service_map = null;
     79    /**
     80     * maps pseudo service names to real service names - needed if we have two
     81     * services with the same name for one collection
     82     */
     83    protected HashMap service_name_map = null;
     84
    8185    /** XML converter for String to DOM and vice versa */
    82     protected XMLConverter converter=null;
     86    protected XMLConverter converter = null;
    8387
    8488    /** container doc for description elements */
     
    96100    /** list of plugin */
    97101    protected Element plugin_item_list = null;
    98    
    99     public void setSiteHome(String home) {
     102
     103    public void setSiteHome(String home)
     104    {
    100105        this.site_home = home;
    101106    }
    102107
    103     public void setSiteAddress(String address) {
     108    public void setSiteAddress(String address)
     109    {
    104110        this.site_http_address = address;
    105111    }
    106112
    107     public void cleanUp() {
     113    public void cleanUp()
     114    {
    108115        Iterator i = this.service_map.values().iterator();
    109         while (i.hasNext()) {
    110             ServiceRack s = (ServiceRack)i.next();
     116        while (i.hasNext())
     117        {
     118            ServiceRack s = (ServiceRack) i.next();
    111119            s.cleanUp();
    112120        }
    113121    }
    114     public void setClusterName(String name) {
    115         this.cluster_name = name;   
     122
     123    public void setClusterName(String name)
     124    {
     125        this.cluster_name = name;
    116126        this.description.setAttribute(GSXML.NAME_ATT, name);
    117127    }
    118128
    119     public void setMessageRouter(MessageRouter m) {
     129    public void setMessageRouter(MessageRouter m)
     130    {
    120131        this.router = m;
    121132    }
    122133
    123     public ServiceCluster() {
     134    public ServiceCluster()
     135    {
    124136        this.service_map = new HashMap();
    125137        this.service_name_map = new HashMap();
     
    127139        this.doc = this.converter.newDOM();
    128140        this.description = this.doc.createElement(GSXML.CLUSTER_ELEM);
    129         this.display_item_list = this.doc.createElement(GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER);
    130         this.metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
    131         this.plugin_item_list = this.doc.createElement(GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER);
     141        this.display_item_list = this.doc.createElement(GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER);
     142        this.metadata_list = this.doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);
     143        this.plugin_item_list = this.doc.createElement(GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER);
    132144    }
    133145
    134146    /**
    135     * Configures the cluster.
    136     *
    137     * gsdlHome and clusterName must be set before configure is called.
    138     *
    139     * reads the site configuration file, and configures itself
    140     * this calls configure(Element) with the XML element node from the config
    141     * file.
    142     * configure(Element) should be used if the config file has already been
    143     * parsed.  This method will work with any subclass.
    144     *
    145     * @return true if configure successful, false otherwise.
    146     */
    147     public boolean configure() {
    148 
    149         if (this.site_home == null || this.cluster_name== null) {
     147     * Configures the cluster.
     148     *
     149     * gsdlHome and clusterName must be set before configure is called.
     150     *
     151     * reads the site configuration file, and configures itself this calls
     152     * configure(Element) with the XML element node from the config file.
     153     * configure(Element) should be used if the config file has already been
     154     * parsed. This method will work with any subclass.
     155     *
     156     * @return true if configure successful, false otherwise.
     157     */
     158    public boolean configure()
     159    {
     160
     161        if (this.site_home == null || this.cluster_name == null)
     162        {
    150163            logger.error("site_home and cluster_name must be set before configure called!");
    151164            return false;
     
    155168        File config_file = new File(GSFile.siteConfigFile(this.site_home));
    156169
    157         if (!config_file.exists()) {
    158             logger.error("couldn't configure cluster: "+this.cluster_name +", "+config_file+" does not exist");
     170        if (!config_file.exists())
     171        {
     172            logger.error("couldn't configure cluster: " + this.cluster_name + ", " + config_file + " does not exist");
    159173            return false;
    160174        }
    161175
    162176        Document doc = this.converter.getDOM(config_file, CONFIG_ENCODING);
    163         if (doc == null) {
    164             logger.error("couldn't parse config file "+config_file.getPath());
    165             return false;
    166         }
    167        
     177        if (doc == null)
     178        {
     179            logger.error("couldn't parse config file " + config_file.getPath());
     180            return false;
     181        }
     182
    168183        // get the appropriate service cluster element
    169         Element cluster_list = (Element)GSXML.getChildByTagName(doc.getDocumentElement(), GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER);
    170         Element sc = GSXML.getNamedElement(cluster_list, GSXML.CLUSTER_ELEM,
    171         GSXML.NAME_ATT, this.cluster_name);
    172        
     184        Element cluster_list = (Element) GSXML.getChildByTagName(doc.getDocumentElement(), GSXML.CLUSTER_ELEM + GSXML.LIST_MODIFIER);
     185        Element sc = GSXML.getNamedElement(cluster_list, GSXML.CLUSTER_ELEM, GSXML.NAME_ATT, this.cluster_name);
     186
    173187        return this.configure(sc);
    174188    }
    175    
    176    
    177     public boolean configure(Element service_cluster_info) {
    178        
     189
     190    public boolean configure(Element service_cluster_info)
     191    {
     192
    179193        // get the metadata - for now just add it to the list
    180         Element meta_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
    181         if (meta_list !=null) {
    182             if (!addMetadata(meta_list)) {
    183                
     194        Element meta_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);
     195        if (meta_list != null)
     196        {
     197            if (!addMetadata(meta_list))
     198            {
     199
    184200                logger.error(" couldn't configure the metadata");
    185201            }
    186202        }
    187        
     203
    188204        // get the display info
    189         Element display_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER);
    190         if (display_list !=null) {
    191             if (!addDisplayItems(display_list)) {
    192                
     205        Element display_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER);
     206        if (display_list != null)
     207        {
     208            if (!addDisplayItems(display_list))
     209            {
     210
    193211                logger.error("couldn't configure the display items");
    194212            }
    195213        }
    196        
     214
    197215        //get the plugin info
    198216        Element import_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.IMPORT_ELEM);
    199217        if (import_list != null)
    200218        {
    201             Element plugin_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER);
    202             if (plugin_list !=null) {
    203                 if (!addPlugins(plugin_list)) {
    204                    
     219            Element plugin_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER);
     220            if (plugin_list != null)
     221            {
     222                if (!addPlugins(plugin_list))
     223                {
     224
    205225                    logger.error("couldn't configure the plugins");
    206226                }
    207227            }
    208         }   
    209        
     228        }
     229
    210230        // do the service racks
    211231        // empty the service map in case this is a reconfigure
    212232        clearServices();
    213         Element service_rack_list = (Element)GSXML.getChildByTagName(service_cluster_info, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
    214         if (service_rack_list == null) {
     233        Element service_rack_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.SERVICE_CLASS_ELEM + GSXML.LIST_MODIFIER);
     234        if (service_rack_list == null)
     235        {
    215236            // is this an error? could you ever have a service cluster
    216237            // without service racks???
    217238            logger.error("cluster has no service racks!!");
    218         } else {
    219            
    220             if (!configureServiceRackList(service_rack_list, null)) {
     239        }
     240        else
     241        {
     242
     243            if (!configureServiceRackList(service_rack_list, null))
     244            {
    221245                logger.error("couldn't configure the  service racks!!");
    222246                return false;
     
    226250        return true;
    227251    }
    228    
    229     /** adds metadata from a metadataList into the metadata_list xml
    230     */
    231     protected boolean addMetadata(Element metadata_list) {
    232         if (metadata_list == null) return false;
     252
     253    /**
     254     * adds metadata from a metadataList into the metadata_list xml
     255     */
     256    protected boolean addMetadata(Element metadata_list)
     257    {
     258        if (metadata_list == null)
     259            return false;
    233260        NodeList metanodes = metadata_list.getElementsByTagName(GSXML.METADATA_ELEM);
    234         if (metanodes.getLength()>0) { 
    235             for(int k=0; k<metanodes.getLength(); k++) {
     261        if (metanodes.getLength() > 0)
     262        {
     263            for (int k = 0; k < metanodes.getLength(); k++)
     264            {
    236265                this.metadata_list.appendChild(this.doc.importNode(metanodes.item(k), true));
    237266            }
    238267        }
    239        
     268
    240269        return true;
    241270    }
    242271
    243     protected boolean addDisplayItems(Element display_list) {
    244        
    245         if (display_list==null) return false;
     272    protected boolean addDisplayItems(Element display_list)
     273    {
     274
     275        if (display_list == null)
     276            return false;
    246277        NodeList displaynodes = display_list.getElementsByTagName(GSXML.DISPLAY_TEXT_ELEM);
    247         if (displaynodes.getLength()>0) {   
    248             for(int k=0; k<displaynodes.getLength(); k++) {
     278        if (displaynodes.getLength() > 0)
     279        {
     280            for (int k = 0; k < displaynodes.getLength(); k++)
     281            {
    249282                Element d = (Element) displaynodes.item(k);
    250283                String lang = d.getAttribute(GSXML.LANG_ATT);
    251                 if (lang==null||lang.equals("")) {
     284                if (lang == null || lang.equals(""))
     285                {
    252286                    //set the lang to teh default
    253287                    d.setAttribute(GSXML.LANG_ATT, DEFAULT_LANG);
     
    255289                String name = d.getAttribute(GSXML.NAME_ATT);
    256290                Element this_item = GSXML.getNamedElement(this.display_item_list, GSXML.DISPLAY_TEXT_ELEM, GSXML.NAME_ATT, name);
    257                 if (this_item==null) {
     291                if (this_item == null)
     292                {
    258293                    this_item = this.doc.createElement(GSXML.DISPLAY_TEXT_ELEM);
    259294                    this_item.setAttribute(GSXML.NAME_ATT, name);
    260295                    this.display_item_list.appendChild(this_item);
    261296                }
    262                
     297
    263298                this_item.appendChild(this.doc.importNode(d, true));
    264299            }
    265300        }
    266        
     301
    267302        return true;
    268303    }
    269    
    270     protected boolean addPlugins(Element plugin_list) {
    271         if (plugin_list == null) return false;
     304
     305    protected boolean addPlugins(Element plugin_list)
     306    {
     307        if (plugin_list == null)
     308            return false;
    272309        NodeList pluginNodes = plugin_list.getElementsByTagName(GSXML.PLUGIN_ELEM);
    273         if (pluginNodes.getLength() > 0) {
     310        if (pluginNodes.getLength() > 0)
     311        {
    274312            for (int k = 0; k < pluginNodes.getLength(); k++)
    275313            {
     
    277315            }
    278316        }
    279        
     317
    280318        return true;
    281319    }
    282320
    283    
    284     protected void clearServices() {
     321    protected void clearServices()
     322    {
    285323        service_map.clear();
    286         this.service_list = this.doc.createElement(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER);
    287     }
    288     /** creates and configures all the services - extra_info is some more xml
    289 that is passed to teh service  - eg used for coll config files for Collection
    290     */
    291     protected boolean configureServiceRackList(Element service_rack_list,
    292     Element extra_info) {
     324        this.service_list = this.doc.createElement(GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER);
     325    }
     326
     327    /**
     328     * creates and configures all the services - extra_info is some more xml
     329     * that is passed to teh service - eg used for coll config files for
     330     * Collection
     331     */
     332    protected boolean configureServiceRackList(Element service_rack_list, Element extra_info)
     333    {
    293334
    294335        // create all the services
    295336        NodeList nodes = service_rack_list.getElementsByTagName(GSXML.SERVICE_CLASS_ELEM);
    296         if (nodes.getLength()==0) {
    297             logger.error("ServiceCluster configuration error: cluster "+this.cluster_name+" has no service modules!");
    298             return false;
    299         }
    300 
    301         for(int i=0; i<nodes.getLength(); i++) {
    302            
     337        if (nodes.getLength() == 0)
     338        {
     339            logger.error("ServiceCluster configuration error: cluster " + this.cluster_name + " has no service modules!");
     340            return false;
     341        }
     342
     343        for (int i = 0; i < nodes.getLength(); i++)
     344        {
     345
    303346            // the xml request to send to the serviceRack to query what
    304347            // services it provides
     
    307350            message.appendChild(request);
    308351
    309             Element n = (Element)nodes.item(i);
     352            Element n = (Element) nodes.item(i);
    310353            String servicetype = n.getAttribute(GSXML.NAME_ATT);
    311            
     354
    312355            ServiceRack s = null;
    313            
    314             try {
     356
     357            try
     358            {
    315359                // try for a default service in standard package
    316                 s = (ServiceRack)Class.forName("org.greenstone.gsdl3.service."+servicetype).newInstance();
    317                
    318             } catch (Exception e) {}
    319             if (s == null) {
    320                 try {
     360                s = (ServiceRack) Class.forName("org.greenstone.gsdl3.service." + servicetype).newInstance();
     361
     362            }
     363            catch (Exception e)
     364            {
     365            }
     366            if (s == null)
     367            {
     368                try
     369                {
    321370                    // name as is, in case package is already specified
    322                     s = (ServiceRack)Class.forName(servicetype).newInstance();
    323                 } catch (Exception e) {}
    324             }
    325 
    326             if (s == null) {
    327                 logger.error("Couldn't get an instance of class "+servicetype+", or org.greenstone.gsdl3.service."+servicetype);
     371                    s = (ServiceRack) Class.forName(servicetype).newInstance();
     372                }
     373                catch (Exception e)
     374                {
     375                }
     376            }
     377
     378            if (s == null)
     379            {
     380                logger.error("Couldn't get an instance of class " + servicetype + ", or org.greenstone.gsdl3.service." + servicetype);
    328381                continue;
    329382            }
    330383
    331            
    332384            s.setSiteHome(this.site_home);
    333385            s.setSiteAddress(this.site_http_address);
     
    335387            s.setMessageRouter(this.router);
    336388            // pass the xml node to the service for configuration
    337             if (s.configure(n, extra_info)) {
    338                
     389            if (s.configure(n, extra_info))
     390            {
     391
    339392                // find out the supported service types for this service module
    340393                Node types = s.process(message);
    341                 NodeList typenodes = ((Element)types).getElementsByTagName(GSXML.SERVICE_ELEM);   
    342                
    343                 for (int j=0; j<typenodes.getLength();j++) {
    344                     String service = ((Element) typenodes.item(j)).getAttribute(GSXML.NAME_ATT);       
    345                     if (service_map.get(service)!=null) {
     394                NodeList typenodes = ((Element) types).getElementsByTagName(GSXML.SERVICE_ELEM);
     395
     396                for (int j = 0; j < typenodes.getLength(); j++)
     397                {
     398                    String service = ((Element) typenodes.item(j)).getAttribute(GSXML.NAME_ATT);
     399                    if (service_map.get(service) != null)
     400                    {
    346401                        char extra = '0';
    347                         String new_service = service+extra;   
    348                        
    349                         while (service_map.get(new_service)!=null) {
     402                        String new_service = service + extra;
     403
     404                        while (service_map.get(new_service) != null)
     405                        {
    350406                            extra++;
    351                             new_service = service+extra;
     407                            new_service = service + extra;
    352408                        }
    353409                        this.service_name_map.put(new_service, service);
    354                         service=new_service;
     410                        service = new_service;
    355411                        ((Element) typenodes.item(j)).setAttribute(GSXML.NAME_ATT, service);
    356412                    }
     
    360416                }
    361417            }
    362         } 
    363        
     418        }
     419
    364420        return true;
    365        
    366        
    367     }
    368 
     421
     422    }
    369423
    370424    /**
    371     * Process an XML document - uses Strings
    372     *  just calls process(Node).
    373     *
    374     * @param in the Document to process - a string
    375     * @return the resultant document as a string - contains any error messages
    376     * @see String
    377     */
    378     public String process(String in) {
     425     * Process an XML document - uses Strings just calls process(Node).
     426     *
     427     * @param in
     428     *            the Document to process - a string
     429     * @return the resultant document as a string - contains any error messages
     430     * @see String
     431     */
     432    public String process(String in)
     433    {
    379434
    380435        Document doc = this.converter.getDOM(in);
    381        
     436
    382437        Node res = process(doc);
    383438        return this.converter.getString(res);
    384        
    385     }
    386    
    387     /** process XML as Node
    388     *
    389     */
    390     public Node process(Node message_node) {
     439
     440    }
     441
     442    /**
     443     * process XML as Node
     444     *
     445     */
     446    public Node process(Node message_node)
     447    {
    391448
    392449        Element message = this.converter.nodeToElement(message_node);
     
    395452        Document mess_doc = message.getOwnerDocument();
    396453        Element mainResult = this.doc.createElement(GSXML.MESSAGE_ELEM);
    397         if (requests.getLength()==0) {
    398             logger.error("no requests for cluster:"+this.cluster_name);
     454        if (requests.getLength() == 0)
     455        {
     456            logger.error("no requests for cluster:" + this.cluster_name);
    399457            // no requests
    400458            return mainResult; // for now
    401459        }
    402         for (int i=0; i<requests.getLength(); i++) {
    403             Element request = (Element)requests.item(i);
     460        for (int i = 0; i < requests.getLength(); i++)
     461        {
     462            Element request = (Element) requests.item(i);
    404463            String to = request.getAttribute(GSXML.TO_ATT);
    405464
    406465            // the cluster name should be first, check, then remove
    407466            String clustername = GSPath.getFirstLink(to);
    408             if (!clustername.equals(this.cluster_name)){
    409                 logger.error("cluster name wrong! was "+clustername+" should have been "+this.cluster_name);
     467            if (!clustername.equals(this.cluster_name))
     468            {
     469                logger.error("cluster name wrong! was " + clustername + " should have been " + this.cluster_name);
    410470                continue; // ignore this request
    411471            }
    412472            to = GSPath.removeFirstLink(to);
    413473            request.setAttribute(GSXML.TO_ATT, to);
    414            
    415             if (to.equals("")) { // this command is for me
     474
     475            if (to.equals(""))
     476            { // this command is for me
    416477                Element response = processMessage(request);
    417478                mainResult.appendChild(response);
    418                
    419             } else { // the request is for one of my services
     479
     480            }
     481            else
     482            { // the request is for one of my services
    420483                String service = GSPath.getFirstLink(to);
    421                
    422                 if (!this.service_map.containsKey(service)) {
    423                     logger.error("non-existant service, "+service+", specified!");
     484
     485                if (!this.service_map.containsKey(service))
     486                {
     487                    logger.error("non-existant service, " + service + ", specified!");
    424488                    continue;
    425489                }
    426490                String real_service = service;
    427                 if (this.service_name_map.containsKey(service)) {
    428                     real_service = (String)this.service_name_map.get(service);
     491                if (this.service_name_map.containsKey(service))
     492                {
     493                    real_service = (String) this.service_name_map.get(service);
    429494                    // need to change the to att in the request - give the real service name
    430495                    to = request.getAttribute(GSXML.TO_ATT);
     
    436501                Element single_message = mess_doc.createElement(GSXML.MESSAGE_ELEM);
    437502                single_message.appendChild(request);
    438                 Node response_message = ((ModuleInterface)this.service_map.get(service)).process(single_message);
    439                 if (response_message != null) {
     503                Node response_message = ((ModuleInterface) this.service_map.get(service)).process(single_message);
     504                if (response_message != null)
     505                {
    440506                    Element response = (Element) GSXML.getChildByTagName(response_message, GSXML.RESPONSE_ELEM);
    441507                    String from = response.getAttribute(GSXML.FROM_ATT);
    442                     if (!real_service.equals(service)) {
     508                    if (!real_service.equals(service))
     509                    {
    443510                        // replace the real service name with the pseudo service name
    444511                        from = GSPath.replaceFirstLink(from, service);
     
    446513                        // shoudl this be done here??
    447514                        Element service_elem = (Element) GSXML.getChildByTagName(response, GSXML.SERVICE_ELEM);
    448                         if (service_elem!= null) {
     515                        if (service_elem != null)
     516                        {
    449517                            service_elem.setAttribute(GSXML.NAME_ATT, service);
    450518                        }
     
    454522                    mainResult.appendChild(this.doc.importNode(response, true));
    455523                }
    456                
     524
    457525            } // else
    458            
    459            
     526
    460527        } // for each request
    461528        return mainResult;
    462529    }
    463530
    464     /** handles requests made to the ServiceCluster itself
    465     *
    466     * @param req - the request Element- <request>
    467     * @return the result Element - should be <response>
    468     */
    469     protected Element processMessage(Element request) {
     531    /**
     532     * handles requests made to the ServiceCluster itself
     533     *
     534     * @param req
     535     *            - the request Element- <request>
     536     * @return the result Element - should be <response>
     537     */
     538    protected Element processMessage(Element request)
     539    {
    470540
    471541        Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);
     
    474544        String lang = request.getAttribute(GSXML.LANG_ATT);
    475545        response.setAttribute(GSXML.TYPE_ATT, type);
    476        
    477         if (type.equals(GSXML.REQUEST_TYPE_DESCRIBE)) {
     546
     547        if (type.equals(GSXML.REQUEST_TYPE_DESCRIBE))
     548        {
    478549            // create the collection element
    479             Element description = (Element)this.description.cloneNode(false);
     550            Element description = (Element) this.description.cloneNode(false);
    480551            // set collection type : mg or mgpp
    481552            description.setAttribute(GSXML.TYPE_ATT, col_type);
     
    484555            response.appendChild(description);
    485556            // check the param list
    486             Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    487             if (param_list == null) {               
    488                 addAllDisplayInfo(description, lang);               
     557            Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     558            if (param_list == null)
     559            {
     560                addAllDisplayInfo(description, lang);
    489561                description.appendChild(this.service_list);
    490562                description.appendChild(this.metadata_list);
     
    492564                return response;
    493565            }
    494            
     566
    495567            // go through the param list and see what components are wanted
    496568            NodeList params = param_list.getElementsByTagName(GSXML.PARAM_ELEM);
    497             for (int i=0; i<params.getLength(); i++) {     
    498                
    499                 Element param = (Element)params.item(i);               
     569            for (int i = 0; i < params.getLength(); i++)
     570            {
     571
     572                Element param = (Element) params.item(i);
    500573                // Identify the structure information desired
    501                 if (param.getAttribute(GSXML.NAME_ATT).equals(GSXML.SUBSET_PARAM)) {
     574                if (param.getAttribute(GSXML.NAME_ATT).equals(GSXML.SUBSET_PARAM))
     575                {
    502576                    String info = param.getAttribute(GSXML.VALUE_ATT);
    503                     if (info.equals(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER)) {
     577                    if (info.equals(GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER))
     578                    {
    504579                        description.appendChild(this.service_list);
    505                     } else if (info.equals(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER)) {
     580                    }
     581                    else if (info.equals(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER))
     582                    {
    506583                        description.appendChild(metadata_list);
    507                     } else if (info.equals(GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER)) {
     584                    }
     585                    else if (info.equals(GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER))
     586                    {
    508587                        addAllDisplayInfo(description, lang);
    509                     } else if (info.equals(GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER)) {
     588                    }
     589                    else if (info.equals(GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER))
     590                    {
    510591                        description.appendChild(plugin_item_list);
    511592                    }
     
    515596        }
    516597        /*
    517     if (type.equals(GSXML.REQUEST_TYPE_FORMAT_STRING)) {
    518         logger.error("Received format string request");
    519         String service = request.getAttribute("service");
    520         logger.error("Service is " + service);
    521         String classifier = null;
    522         if(service.equals("ClassifierBrowse"))
    523         {
    524             classifier = request.getAttribute("classifier");
    525             logger.error("Classifier is " + classifier);
    526         }
    527         Element format_element = (Element) GSXML.getChildByTagName(request, GSXML.FORMAT_STRING_ELEM);
    528         String format_string = GSXML.getNodeText(format_element);
    529         logger.error("Format string: " + format_string);
    530         logger.error("Config file location = " + GSFile.collectionConfigFile(this.site_home, this.cluster_name));
    531 
    532         // check for version file
    533 
    534         String directory = new File(GSFile.collectionConfigFile(this.site_home, this.cluster_name)).getParent() + File.pathSeparator;
    535         logger.error("Directory is " + directory);
    536 
    537         String version_filename = "";
    538 
    539         if(service.equals("ClassifierBrowse"))
    540             version_filename = directory + "browse_"+classifier+"_format_statement_version.txt";
     598         * if (type.equals(GSXML.REQUEST_TYPE_FORMAT_STRING)) {
     599         * logger.error("Received format string request"); String service =
     600         * request.getAttribute("service"); logger.error("Service is " +
     601         * service); String classifier = null;
     602         * if(service.equals("ClassifierBrowse")) { classifier =
     603         * request.getAttribute("classifier"); logger.error("Classifier is " +
     604         * classifier); } Element format_element = (Element)
     605         * GSXML.getChildByTagName(request, GSXML.FORMAT_STRING_ELEM); String
     606         * format_string = GSXML.getNodeText(format_element);
     607         * logger.error("Format string: " + format_string);
     608         * logger.error("Config file location = " +
     609         * GSFile.collectionConfigFile(this.site_home, this.cluster_name));
     610         *
     611         * // check for version file
     612         *
     613         * String directory = new
     614         * File(GSFile.collectionConfigFile(this.site_home,
     615         * this.cluster_name)).getParent() + File.pathSeparator;
     616         * logger.error("Directory is " + directory);
     617         *
     618         * String version_filename = "";
     619         *
     620         * if(service.equals("ClassifierBrowse")) version_filename = directory +
     621         * "browse_"+classifier+"_format_statement_version.txt"; else
     622         * version_filename = directory + "query_format_statement_version.txt";
     623         *
     624         * File version_file = new File(version_filename);
     625         * logger.error("Version filename is " + version_filename);
     626         *
     627         * String version_number = "1"; BufferedWriter writer; // = new
     628         * BufferedWriter(new FileWriter(version_filename)); //RandomAccessFile
     629         * version_file_random_access;
     630         *
     631         * try{
     632         *
     633         * if(version_file.exists()) { // Read version BufferedReader reader =
     634         * new BufferedReader(new FileReader(version_filename));
     635         * //version_file_random_access = new RandomAccessFile(version_file,
     636         * "r"); //logger.error(" //version_number =
     637         * version_file_random_access.readInt(); version_number =
     638         * reader.readLine(); int aInt = Integer.parseInt(version_number) + 1;
     639         * version_number = Integer.toString(aInt); reader.close();
     640         * //version_file_random_access.close(); } else{ // Create
     641         * version_file.createNewFile(); // write 1 to file writer = new
     642         * BufferedWriter(new FileWriter(version_filename));
     643         * //version_file_random_access = new RandomAccessFile(version_file,
     644         * "w"); //version_file_random_access.writeInt(version_number);
     645         * writer.write(version_number); writer.close();
     646         * //version_file_random_access.close(); }
     647         *
     648         * // Write version file String format_statement_filename = "";
     649         *
     650         * if(service.equals("ClassifierBrowse")) format_statement_filename =
     651         * directory + "browse_"+classifier+"_format_statement_v" +
     652         * version_number + ".txt"; else format_statement_filename = directory +
     653         * "query_format_statement_v" + version_number + ".txt";
     654         *
     655         * logger.error("Format statement filename is " +
     656         * format_statement_filename);
     657         *
     658         * writer = new BufferedWriter(new
     659         * FileWriter(format_statement_filename)); writer.write(format_string);
     660         * writer.close();
     661         *
     662         * // Update version number //version_file_random_access = new
     663         * RandomAccessFile(version_file, "w");
     664         * //version_file_random_access.writeInt(version_number);
     665         * //version_file_random_access.close();
     666         *
     667         * writer = new BufferedWriter(new FileWriter(version_filename));
     668         * //version_file_random_access = new RandomAccessFile(version_file,
     669         * "w"); //version_file_random_access.writeInt(version_number);
     670         * writer.write(version_number); writer.close();
     671         *
     672         *
     673         *
     674         * } catch (IOException e) { logger.error("IO Exception "+e);
     675         * //System.exit(1); }
     676         *
     677         *
     678         * }
     679         */
     680        if (type.equals(GSXML.REQUEST_TYPE_SYSTEM))
     681        {
     682            response = processSystemRequest(request);
     683        }
    541684        else
    542             version_filename = directory + "query_format_statement_version.txt";
    543 
    544         File version_file = new File(version_filename);
    545         logger.error("Version filename is " + version_filename);
    546 
    547         String version_number = "1";
    548         BufferedWriter writer; // = new BufferedWriter(new FileWriter(version_filename));
    549         //RandomAccessFile version_file_random_access;
    550 
    551         try{
    552 
    553             if(version_file.exists())
    554             {
    555                 // Read version
    556                 BufferedReader reader = new BufferedReader(new FileReader(version_filename));
    557                 //version_file_random_access = new RandomAccessFile(version_file, "r");
    558                 //logger.error("
    559                 //version_number = version_file_random_access.readInt();
    560                 version_number = reader.readLine();
    561                 int aInt = Integer.parseInt(version_number) + 1;
    562                 version_number = Integer.toString(aInt);
    563                 reader.close();
    564                 //version_file_random_access.close();
    565             }
    566             else{
    567                 // Create
    568                 version_file.createNewFile();
    569                 // write 1 to file
    570                 writer = new BufferedWriter(new FileWriter(version_filename));
    571                 //version_file_random_access = new RandomAccessFile(version_file, "w");
    572                 //version_file_random_access.writeInt(version_number);
    573                 writer.write(version_number);
    574                 writer.close();
    575                 //version_file_random_access.close();
    576             }
    577 
    578             // Write version file
    579             String format_statement_filename = "";
    580 
    581             if(service.equals("ClassifierBrowse"))
    582                 format_statement_filename = directory + "browse_"+classifier+"_format_statement_v" + version_number + ".txt";
    583             else
    584                 format_statement_filename = directory + "query_format_statement_v" + version_number + ".txt";
    585 
    586             logger.error("Format statement filename is " + format_statement_filename);
    587 
    588             writer = new BufferedWriter(new FileWriter(format_statement_filename));
    589             writer.write(format_string);
    590             writer.close();
    591 
    592             // Update version number
    593             //version_file_random_access = new RandomAccessFile(version_file, "w");
    594             //version_file_random_access.writeInt(version_number);
    595             //version_file_random_access.close();
    596 
    597             writer = new BufferedWriter(new FileWriter(version_filename));
    598             //version_file_random_access = new RandomAccessFile(version_file, "w");
    599             //version_file_random_access.writeInt(version_number);
    600             writer.write(version_number);
    601             writer.close();
    602 
    603 
    604 
    605         } catch (IOException e) {
    606             logger.error("IO Exception "+e);
    607             //System.exit(1);
    608         }
    609 
    610 
    611     }*/
    612         if (type.equals(GSXML.REQUEST_TYPE_SYSTEM)) {
    613             response = processSystemRequest(request);
    614         } else { // unknown type
    615             logger.error("cant handle request of type "+ type);
    616            
     685        { // unknown type
     686            logger.error("cant handle request of type " + type);
     687
    617688        }
    618689        return response;
    619690    }
    620691
    621     protected Element processSystemRequest(Element request) {
     692    protected Element processSystemRequest(Element request)
     693    {
    622694
    623695        Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);
     
    628700        // or success messages into response
    629701        NodeList commands = request.getElementsByTagName(GSXML.SYSTEM_ELEM);
    630         String message=null;   
    631         for (int i=0; i<commands.getLength(); i++) {
     702        String message = null;
     703        for (int i = 0; i < commands.getLength(); i++)
     704        {
    632705            // all the commands should be Elements
    633             Element elem = (Element)commands.item(i);
     706            Element elem = (Element) commands.item(i);
    634707            String action = elem.getAttribute(GSXML.TYPE_ATT);
    635             if (action.equals(GSXML.SYSTEM_TYPE_CONFIGURE)) {
     708            if (action.equals(GSXML.SYSTEM_TYPE_CONFIGURE))
     709            {
    636710                String subset = elem.getAttribute(GSXML.SYSTEM_SUBSET_ATT);
    637                 if (subset.equals("")) {
     711                if (subset.equals(""))
     712                {
    638713                    // need to reconfigure the service cluster
    639                    
    640                     if (this.configure()) {
     714
     715                    if (this.configure())
     716                    {
    641717                        Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " reconfigured");
    642718                        response.appendChild(s);
    643                        
    644                     } else {
     719
     720                    }
     721                    else
     722                    {
    645723                        Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " could not be reconfigured");
    646                         response.appendChild(s); 
     724                        response.appendChild(s);
    647725                    }
    648                 } else if (this.configureSubset(subset)) {
    649                     Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " "+subset+" reconfigured");
     726                }
     727                else if (this.configureSubset(subset))
     728                {
     729                    Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " " + subset + " reconfigured");
    650730                    response.appendChild(s);
    651                 } else {
    652                     Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " "+subset + " could not be reconfigured");
    653                     response.appendChild(s);
     731                }
     732                else
     733                {
     734                    Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " " + subset + " could not be reconfigured");
     735                    response.appendChild(s);
    654736                }
    655737                continue;
    656738            } // configure action
    657            
     739
    658740            String module_name = elem.getAttribute(GSXML.SYSTEM_MODULE_NAME_ATT);
    659741            String module_type = elem.getAttribute(GSXML.SYSTEM_MODULE_TYPE_ATT);
    660             if (action.equals(GSXML.SYSTEM_TYPE_ACTIVATE)) {
     742            if (action.equals(GSXML.SYSTEM_TYPE_ACTIVATE))
     743            {
    661744                Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, "activate action not yet implemented - does it even make sense in this context??");
    662745                response.appendChild(s);
    663             } else if (action.equals(GSXML.SYSTEM_TYPE_DEACTIVATE)) {
    664                 if (module_type.equals(GSXML.SERVICE_ELEM)) {
     746            }
     747            else if (action.equals(GSXML.SYSTEM_TYPE_DEACTIVATE))
     748            {
     749                if (module_type.equals(GSXML.SERVICE_ELEM))
     750                {
    665751                    // deactivate the service
    666752                    // remove from service_map
    667753                    this.service_map.remove(module_name);
    668754                    Element service_elem = GSXML.getNamedElement(this.service_list, GSXML.SERVICE_ELEM, GSXML.NAME_ATT, module_name);
    669                     service_list.removeChild(service_elem);         
    670                     message = module_type+": "+module_name+" deactivated";
    671                 } else {
    672                     message = "can't deactivate "+module_type+" type modules!";}
     755                    service_list.removeChild(service_elem);
     756                    message = module_type + ": " + module_name + " deactivated";
     757                }
     758                else
     759                {
     760                    message = "can't deactivate " + module_type + " type modules!";
     761                }
    673762                Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, message);
    674763                response.appendChild(s);
    675             } else {
    676                 logger.error("cant process system request, action "+action);
     764            }
     765            else
     766            {
     767                logger.error("cant process system request, action " + action);
    677768                continue;
    678769            }
     
    681772    }
    682773
    683     /**
    684     * do a configure on only part of the collection
    685     */
    686     protected boolean configureSubset(String subset) {
    687        
     774    /**
     775     * do a configure on only part of the collection
     776     */
     777    protected boolean configureSubset(String subset)
     778    {
     779
    688780        File configFile = new File(GSFile.siteConfigFile(this.site_home));
    689         if (!configFile.exists() ) {
    690             logger.error("site config file: "+configFile.getPath()+" not found!");
     781        if (!configFile.exists())
     782        {
     783            logger.error("site config file: " + configFile.getPath() + " not found!");
    691784            // wont be able to do any of the requests
    692785            return false;
    693            
    694         }
    695        
    696         Document site_config_doc  = this.converter.getDOM(configFile);
    697         if (site_config_doc == null) {
    698             logger.error("could not read in site config file: "+configFile.getPath());
    699             return false;
    700         }
    701        
     786
     787        }
     788
     789        Document site_config_doc = this.converter.getDOM(configFile);
     790        if (site_config_doc == null)
     791        {
     792            logger.error("could not read in site config file: " + configFile.getPath());
     793            return false;
     794        }
     795
    702796        Element site_config_elem = site_config_doc.getDocumentElement();
    703         Element cluster_config_elem = GSXML.getNamedElement((Element)GSXML.getChildByTagName(site_config_elem, GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER), GSXML.CLUSTER_ELEM, GSXML.NAME_ATT, this.cluster_name);
    704         if (cluster_config_elem == null) {
    705             logger.error("site config file: "+configFile.getPath()+" has no element for cluster "+this.cluster_name);
     797        Element cluster_config_elem = GSXML.getNamedElement((Element) GSXML.getChildByTagName(site_config_elem, GSXML.CLUSTER_ELEM + GSXML.LIST_MODIFIER), GSXML.CLUSTER_ELEM, GSXML.NAME_ATT, this.cluster_name);
     798        if (cluster_config_elem == null)
     799        {
     800            logger.error("site config file: " + configFile.getPath() + " has no element for cluster " + this.cluster_name);
    706801            // wont be able to do any of teh requests
    707802            return false;
    708            
    709         }
    710         if (subset.equals(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER)) {
    711             Element service_rack_list = (Element)GSXML.getChildByTagName(cluster_config_elem, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
     803
     804        }
     805        if (subset.equals(GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER))
     806        {
     807            Element service_rack_list = (Element) GSXML.getChildByTagName(cluster_config_elem, GSXML.SERVICE_CLASS_ELEM + GSXML.LIST_MODIFIER);
    712808            clearServices();
    713809            return configureServiceRackList(service_rack_list, null);
    714         } else if (subset.equals(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER)) {
    715             this.metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
    716             Element metadata_list = (Element)GSXML.getChildByTagName(cluster_config_elem, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
     810        }
     811        else if (subset.equals(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER))
     812        {
     813            this.metadata_list = this.doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);
     814            Element metadata_list = (Element) GSXML.getChildByTagName(cluster_config_elem, GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);
    717815            return addMetadata(metadata_list);
    718         } else if (subset.equals(GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER)) {
    719             this.plugin_item_list = this.doc.createElement(GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER);
    720             Element import_list = (Element)GSXML.getChildByTagName(cluster_config_elem,GSXML.IMPORT_ELEM);
     816        }
     817        else if (subset.equals(GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER))
     818        {
     819            this.plugin_item_list = this.doc.createElement(GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER);
     820            Element import_list = (Element) GSXML.getChildByTagName(cluster_config_elem, GSXML.IMPORT_ELEM);
    721821            if (import_list != null)
    722822            {
    723                 Element plugin_item_list = (Element)GSXML.getChildByTagName(cluster_config_elem,GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER);
     823                Element plugin_item_list = (Element) GSXML.getChildByTagName(cluster_config_elem, GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER);
    724824                return addPlugins(plugin_item_list);
    725825            }
    726826            else
    727             return false;
    728         } else {
    729             logger.error("cannot process system request, configure "+subset);
    730             return false;
    731         }
    732 
    733     }
    734 
    735 
    736     protected boolean addAllDisplayInfo(Element description, String lang) {
    737        
     827                return false;
     828        }
     829        else
     830        {
     831            logger.error("cannot process system request, configure " + subset);
     832            return false;
     833        }
     834
     835    }
     836
     837    protected boolean addAllDisplayInfo(Element description, String lang)
     838    {
     839
    738840        NodeList items = this.display_item_list.getChildNodes();
    739         for (int i=0; i<items.getLength(); i++) { // for each key
     841        for (int i = 0; i < items.getLength(); i++)
     842        { // for each key
    740843            Element m = (Element) items.item(i);
    741844            // find the child with the correct language
    742845            Element new_m = GSXML.getNamedElement(m, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, lang);
    743             if (new_m==null && lang != DEFAULT_LANG) {
     846            if (new_m == null && lang != DEFAULT_LANG)
     847            {
    744848                // use the default lang
    745849                new_m = GSXML.getNamedElement(m, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, DEFAULT_LANG);
    746850            }
    747             if (new_m==null) {
     851            if (new_m == null)
     852            {
    748853                // just get the first one
    749                 new_m = (Element)GSXML.getChildByTagName(m, GSXML.DISPLAY_TEXT_ELEM);
     854                new_m = (Element) GSXML.getChildByTagName(m, GSXML.DISPLAY_TEXT_ELEM);
    750855            }
    751856            description.appendChild(new_m.cloneNode(true));
    752857        }
    753858        return true;
    754        
    755     }
    756 
    757    
    758     protected Element getDisplayTextElement(String key, String lang) {
    759        
     859
     860    }
     861
     862    protected Element getDisplayTextElement(String key, String lang)
     863    {
     864
    760865        Element this_item = GSXML.getNamedElement(this.display_item_list, GSXML.DISPLAY_TEXT_ELEM, GSXML.NAME_ATT, key);
    761         if (this_item == null) {
     866        if (this_item == null)
     867        {
    762868            return null;
    763869        }
    764870
    765871        Element this_lang = GSXML.getNamedElement(this_item, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, lang);
    766         if (this_lang == null && lang != DEFAULT_LANG) {
     872        if (this_lang == null && lang != DEFAULT_LANG)
     873        {
    767874            // try the default
    768875            this_lang = GSXML.getNamedElement(this_item, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, DEFAULT_LANG);
    769876        }
    770         if (this_lang == null) {
     877        if (this_lang == null)
     878        {
    771879            // just return the first one
    772880            return GSXML.getFirstElementChild(this_item);//(Element)this_item.getFirstChild().cloneNode(true);
    773881        }
    774         return (Element)this_lang.cloneNode(true);
    775        
    776     }
    777     public HashMap getServiceMap() {
     882        return (Element) this_lang.cloneNode(true);
     883
     884    }
     885
     886    public HashMap getServiceMap()
     887    {
    778888        return service_map;
    779889    }
    780890}
    781 
    782 
    783 
    784 
    785 
    786 
Note: See TracChangeset for help on using the changeset viewer.