Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/collection/ServiceCluster.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/collection/ServiceCluster.java (revision 24974)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/collection/ServiceCluster.java (revision 24975)
@@ -1,25 +1,24 @@
/*
-* ServiceCluster.java
-* Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ * ServiceCluster.java
+ * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
// leave the package name as is for now - should be changed to something better
// cluster? groups?
package org.greenstone.gsdl3.collection;
-
import org.greenstone.gsdl3.util.*;
import org.greenstone.gsdl3.core.*;
@@ -27,8 +26,8 @@
// java XML classes we're using
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
import java.io.*;
@@ -41,44 +40,49 @@
/* ServiceCluster - a groups of services that are related in some way
-* Implements ModuleInterface. Contains a list of services provided by the cluster, along with metadata about the cluster itself.
-* a collection is a special type of cluster
-* @author Katherine Don
-* @version $Revision$
-* @see ModuleInterface
-*/
-public class ServiceCluster
-implements ModuleInterface {
-
- static Logger logger = Logger.getLogger(org.greenstone.gsdl3.collection.ServiceCluster.class.getName());
+ * Implements ModuleInterface. Contains a list of services provided by the cluster, along with metadata about the cluster itself.
+ * a collection is a special type of cluster
+ * @author Katherine Don
+ * @version $Revision$
+ * @see ModuleInterface
+ */
+public class ServiceCluster implements ModuleInterface
+{
+
+ static Logger logger = Logger.getLogger(org.greenstone.gsdl3.collection.ServiceCluster.class.getName());
protected static final String CONFIG_ENCODING = "utf-8";
protected static final String DEFAULT_LANG = "en"; // hack for now, should be read from the coll cfg file? or site cfg file for cluster
-
- /** base directory for the site that this cluster belongs to*/
+
+ /** base directory for the site that this cluster belongs to */
protected String site_home = null;
/** http address of the site that this cluster belongs to */
protected String site_http_address = null;
- /** The name of the cluster - for a collection, this is the collection name*/
+ /** The name of the cluster - for a collection, this is the collection name */
protected String cluster_name = null;
/** collection type : mg, mgpp or lucene */
protected String col_type = "";
- /** database type : gdbm, jdbm or sqlite*/
+ /** database type : gdbm, jdbm or sqlite */
protected String db_type = "";
-
+
/** a reference to the message router */
protected MessageRouter router = null;
- /** The map of services.
- *
- * Maps Services to ServiceRack objects
- * @see ServiceRack
- *
- */
- protected HashMap service_map=null;
- /** maps pseudo service names to real service names - needed if we have two services with the same name for one collection */
- protected HashMap service_name_map=null;
-
+ /**
+ * The map of services.
+ *
+ * Maps Services to ServiceRack objects
+ *
+ * @see ServiceRack
+ *
+ */
+ protected HashMap service_map = null;
+ /**
+ * maps pseudo service names to real service names - needed if we have two
+ * services with the same name for one collection
+ */
+ protected HashMap service_name_map = null;
+
/** XML converter for String to DOM and vice versa */
- protected XMLConverter converter=null;
+ protected XMLConverter converter = null;
/** container doc for description elements */
@@ -96,30 +100,38 @@
/** list of plugin */
protected Element plugin_item_list = null;
-
- public void setSiteHome(String home) {
+
+ public void setSiteHome(String home)
+ {
this.site_home = home;
}
- public void setSiteAddress(String address) {
+ public void setSiteAddress(String address)
+ {
this.site_http_address = address;
}
- public void cleanUp() {
+ public void cleanUp()
+ {
Iterator i = this.service_map.values().iterator();
- while (i.hasNext()) {
- ServiceRack s = (ServiceRack)i.next();
+ while (i.hasNext())
+ {
+ ServiceRack s = (ServiceRack) i.next();
s.cleanUp();
}
}
- public void setClusterName(String name) {
- this.cluster_name = name;
+
+ public void setClusterName(String name)
+ {
+ this.cluster_name = name;
this.description.setAttribute(GSXML.NAME_ATT, name);
}
- public void setMessageRouter(MessageRouter m) {
+ public void setMessageRouter(MessageRouter m)
+ {
this.router = m;
}
- public ServiceCluster() {
+ public ServiceCluster()
+ {
this.service_map = new HashMap();
this.service_name_map = new HashMap();
@@ -127,25 +139,26 @@
this.doc = this.converter.newDOM();
this.description = this.doc.createElement(GSXML.CLUSTER_ELEM);
- this.display_item_list = this.doc.createElement(GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER);
- this.metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
- this.plugin_item_list = this.doc.createElement(GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER);
+ this.display_item_list = this.doc.createElement(GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER);
+ this.metadata_list = this.doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);
+ this.plugin_item_list = this.doc.createElement(GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER);
}
/**
- * Configures the cluster.
- *
- * gsdlHome and clusterName must be set before configure is called.
- *
- * reads the site configuration file, and configures itself
- * this calls configure(Element) with the XML element node from the config
- * file.
- * configure(Element) should be used if the config file has already been
- * parsed. This method will work with any subclass.
- *
- * @return true if configure successful, false otherwise.
- */
- public boolean configure() {
-
- if (this.site_home == null || this.cluster_name== null) {
+ * Configures the cluster.
+ *
+ * gsdlHome and clusterName must be set before configure is called.
+ *
+ * reads the site configuration file, and configures itself this calls
+ * configure(Element) with the XML element node from the config file.
+ * configure(Element) should be used if the config file has already been
+ * parsed. This method will work with any subclass.
+ *
+ * @return true if configure successful, false otherwise.
+ */
+ public boolean configure()
+ {
+
+ if (this.site_home == null || this.cluster_name == null)
+ {
logger.error("site_home and cluster_name must be set before configure called!");
return false;
@@ -155,68 +168,79 @@
File config_file = new File(GSFile.siteConfigFile(this.site_home));
- if (!config_file.exists()) {
- logger.error("couldn't configure cluster: "+this.cluster_name +", "+config_file+" does not exist");
+ if (!config_file.exists())
+ {
+ logger.error("couldn't configure cluster: " + this.cluster_name + ", " + config_file + " does not exist");
return false;
}
Document doc = this.converter.getDOM(config_file, CONFIG_ENCODING);
- if (doc == null) {
- logger.error("couldn't parse config file "+config_file.getPath());
- return false;
- }
-
+ if (doc == null)
+ {
+ logger.error("couldn't parse config file " + config_file.getPath());
+ return false;
+ }
+
// get the appropriate service cluster element
- Element cluster_list = (Element)GSXML.getChildByTagName(doc.getDocumentElement(), GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER);
- Element sc = GSXML.getNamedElement(cluster_list, GSXML.CLUSTER_ELEM,
- GSXML.NAME_ATT, this.cluster_name);
-
+ Element cluster_list = (Element) GSXML.getChildByTagName(doc.getDocumentElement(), GSXML.CLUSTER_ELEM + GSXML.LIST_MODIFIER);
+ Element sc = GSXML.getNamedElement(cluster_list, GSXML.CLUSTER_ELEM, GSXML.NAME_ATT, this.cluster_name);
+
return this.configure(sc);
}
-
-
- public boolean configure(Element service_cluster_info) {
-
+
+ public boolean configure(Element service_cluster_info)
+ {
+
// get the metadata - for now just add it to the list
- Element meta_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
- if (meta_list !=null) {
- if (!addMetadata(meta_list)) {
-
+ Element meta_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);
+ if (meta_list != null)
+ {
+ if (!addMetadata(meta_list))
+ {
+
logger.error(" couldn't configure the metadata");
}
}
-
+
// get the display info
- Element display_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER);
- if (display_list !=null) {
- if (!addDisplayItems(display_list)) {
-
+ Element display_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER);
+ if (display_list != null)
+ {
+ if (!addDisplayItems(display_list))
+ {
+
logger.error("couldn't configure the display items");
}
}
-
+
//get the plugin info
Element import_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.IMPORT_ELEM);
if (import_list != null)
{
- Element plugin_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER);
- if (plugin_list !=null) {
- if (!addPlugins(plugin_list)) {
-
+ Element plugin_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER);
+ if (plugin_list != null)
+ {
+ if (!addPlugins(plugin_list))
+ {
+
logger.error("couldn't configure the plugins");
}
}
- }
-
+ }
+
// do the service racks
// empty the service map in case this is a reconfigure
clearServices();
- Element service_rack_list = (Element)GSXML.getChildByTagName(service_cluster_info, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
- if (service_rack_list == null) {
+ Element service_rack_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.SERVICE_CLASS_ELEM + GSXML.LIST_MODIFIER);
+ if (service_rack_list == null)
+ {
// is this an error? could you ever have a service cluster
// without service racks???
logger.error("cluster has no service racks!!");
- } else {
-
- if (!configureServiceRackList(service_rack_list, null)) {
+ }
+ else
+ {
+
+ if (!configureServiceRackList(service_rack_list, null))
+ {
logger.error("couldn't configure the service racks!!");
return false;
@@ -226,28 +250,38 @@
return true;
}
-
- /** adds metadata from a metadataList into the metadata_list xml
- */
- protected boolean addMetadata(Element metadata_list) {
- if (metadata_list == null) return false;
+
+ /**
+ * adds metadata from a metadataList into the metadata_list xml
+ */
+ protected boolean addMetadata(Element metadata_list)
+ {
+ if (metadata_list == null)
+ return false;
NodeList metanodes = metadata_list.getElementsByTagName(GSXML.METADATA_ELEM);
- if (metanodes.getLength()>0) {
- for(int k=0; k 0)
+ {
+ for (int k = 0; k < metanodes.getLength(); k++)
+ {
this.metadata_list.appendChild(this.doc.importNode(metanodes.item(k), true));
}
}
-
+
return true;
}
- protected boolean addDisplayItems(Element display_list) {
-
- if (display_list==null) return false;
+ protected boolean addDisplayItems(Element display_list)
+ {
+
+ if (display_list == null)
+ return false;
NodeList displaynodes = display_list.getElementsByTagName(GSXML.DISPLAY_TEXT_ELEM);
- if (displaynodes.getLength()>0) {
- for(int k=0; k 0)
+ {
+ for (int k = 0; k < displaynodes.getLength(); k++)
+ {
Element d = (Element) displaynodes.item(k);
String lang = d.getAttribute(GSXML.LANG_ATT);
- if (lang==null||lang.equals("")) {
+ if (lang == null || lang.equals(""))
+ {
//set the lang to teh default
d.setAttribute(GSXML.LANG_ATT, DEFAULT_LANG);
@@ -255,21 +289,25 @@
String name = d.getAttribute(GSXML.NAME_ATT);
Element this_item = GSXML.getNamedElement(this.display_item_list, GSXML.DISPLAY_TEXT_ELEM, GSXML.NAME_ATT, name);
- if (this_item==null) {
+ if (this_item == null)
+ {
this_item = this.doc.createElement(GSXML.DISPLAY_TEXT_ELEM);
this_item.setAttribute(GSXML.NAME_ATT, name);
this.display_item_list.appendChild(this_item);
}
-
+
this_item.appendChild(this.doc.importNode(d, true));
}
}
-
+
return true;
}
-
- protected boolean addPlugins(Element plugin_list) {
- if (plugin_list == null) return false;
+
+ protected boolean addPlugins(Element plugin_list)
+ {
+ if (plugin_list == null)
+ return false;
NodeList pluginNodes = plugin_list.getElementsByTagName(GSXML.PLUGIN_ELEM);
- if (pluginNodes.getLength() > 0) {
+ if (pluginNodes.getLength() > 0)
+ {
for (int k = 0; k < pluginNodes.getLength(); k++)
{
@@ -277,28 +315,33 @@
}
}
-
+
return true;
}
-
- protected void clearServices() {
+ protected void clearServices()
+ {
service_map.clear();
- this.service_list = this.doc.createElement(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER);
- }
- /** creates and configures all the services - extra_info is some more xml
-that is passed to teh service - eg used for coll config files for Collection
- */
- protected boolean configureServiceRackList(Element service_rack_list,
- Element extra_info) {
+ this.service_list = this.doc.createElement(GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER);
+ }
+
+ /**
+ * creates and configures all the services - extra_info is some more xml
+ * that is passed to teh service - eg used for coll config files for
+ * Collection
+ */
+ protected boolean configureServiceRackList(Element service_rack_list, Element extra_info)
+ {
// create all the services
NodeList nodes = service_rack_list.getElementsByTagName(GSXML.SERVICE_CLASS_ELEM);
- if (nodes.getLength()==0) {
- logger.error("ServiceCluster configuration error: cluster "+this.cluster_name+" has no service modules!");
- return false;
- }
-
- for(int i=0; i
- * @return the result Element - should be
- */
- protected Element processMessage(Element request) {
+ /**
+ * handles requests made to the ServiceCluster itself
+ *
+ * @param req
+ * - the request Element-
+ * @return the result Element - should be
+ */
+ protected Element processMessage(Element request)
+ {
Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);
@@ -474,8 +544,9 @@
String lang = request.getAttribute(GSXML.LANG_ATT);
response.setAttribute(GSXML.TYPE_ATT, type);
-
- if (type.equals(GSXML.REQUEST_TYPE_DESCRIBE)) {
+
+ if (type.equals(GSXML.REQUEST_TYPE_DESCRIBE))
+ {
// create the collection element
- Element description = (Element)this.description.cloneNode(false);
+ Element description = (Element) this.description.cloneNode(false);
// set collection type : mg or mgpp
description.setAttribute(GSXML.TYPE_ATT, col_type);
@@ -484,7 +555,8 @@
response.appendChild(description);
// check the param list
- Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
- if (param_list == null) {
- addAllDisplayInfo(description, lang);
+ Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
+ if (param_list == null)
+ {
+ addAllDisplayInfo(description, lang);
description.appendChild(this.service_list);
description.appendChild(this.metadata_list);
@@ -492,20 +564,29 @@
return response;
}
-
+
// go through the param list and see what components are wanted
NodeList params = param_list.getElementsByTagName(GSXML.PARAM_ELEM);
- for (int i=0; i