Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/MessageRouter.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/MessageRouter.java	(revision 28855)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/MessageRouter.java	(revision 28856)
@@ -55,11 +55,4 @@
  * 
  * 
- * @author Katherine Don
- * @version $Revision$
- * @see ModuleInterface
- * @see Collection
- * @see ServiceRack
- * @see Communicator
- * 
  *      Since some service classes are moved into a separate directory in order
  *      for them to be checked out from a different repository, we modify the
@@ -84,6 +77,4 @@
 	protected HashMap<String, ModuleInterface> module_map = null;
 
-	/** container Document to create XML Nodes */
-	protected Document doc = null;
 	/** the full description of this site */
 
@@ -121,5 +112,4 @@
 	{
 		this.converter = new XMLConverter();
-		this.doc = this.converter.newDOM();
 	}
 
@@ -245,4 +235,5 @@
 	{
 
+	  Document doc = this.converter.newDOM();
 		Element message = this.converter.nodeToElement(message_node);
 
@@ -256,5 +247,5 @@
 		NodeList requests = message.getElementsByTagName(GSXML.REQUEST_ELEM);
 
-		Element mainResult = this.doc.createElement(GSXML.MESSAGE_ELEM);
+		Element mainResult = doc.createElement(GSXML.MESSAGE_ELEM);
 
 		// empty request
@@ -264,6 +255,4 @@
 			return mainResult;
 		}
-
-		Document message_doc = message.getOwnerDocument();
 
 		// for now, just process each request one by one, and append the results to mainResult
@@ -298,5 +287,5 @@
 				if (result != null)
 				{
-					mainResult.appendChild(this.doc.importNode(result, true));
+					mainResult.appendChild(doc.importNode(result, true));
 				}
 			}
@@ -311,6 +300,6 @@
 				{
 					// why can't we do this outside the loop??
-					Element mess = this.doc.createElement(GSXML.MESSAGE_ELEM);
-					Element copied_request = (Element) this.doc.importNode(req, true);
+					Element mess = doc.createElement(GSXML.MESSAGE_ELEM);
+					Element copied_request = (Element) doc.importNode(req, true);
 					mess.appendChild(copied_request);
 
@@ -330,5 +319,5 @@
 							if (res != null)
 							{
-								mainResult.appendChild(this.doc.importNode(res, true));
+								mainResult.appendChild(doc.importNode(res, true));
 							}
 						}
@@ -336,5 +325,5 @@
 						{
 							// add in a place holder response
-							Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);
+							Element response = doc.createElement(GSXML.RESPONSE_ELEM);
 							response.setAttribute(GSXML.FROM_ATT, this_mod);
 							mainResult.appendChild(response);
@@ -475,26 +464,27 @@
 
 		// load up the services: serviceRackList
-		this.service_list = this.doc.createElement(GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER);
+		Document doc = this.converter.newDOM();
+		this.service_list = doc.createElement(GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER);
 		Element service_rack_list_elem = (Element) GSXML.getChildByTagName(config_info, GSXML.SERVICE_CLASS_ELEM + GSXML.LIST_MODIFIER);
 		configureServices(service_rack_list_elem);
 
 		// load up the service clusters
-		this.cluster_list = this.doc.createElement(GSXML.CLUSTER_ELEM + GSXML.LIST_MODIFIER);
+		this.cluster_list = doc.createElement(GSXML.CLUSTER_ELEM + GSXML.LIST_MODIFIER);
 		Element cluster_list_elem = (Element) GSXML.getChildByTagName(config_info, GSXML.CLUSTER_ELEM + GSXML.LIST_MODIFIER);
 		configureClusters(cluster_list_elem);
 
 		// load up the collections
-		this.collection_list = this.doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
-		this.private_collection_list = this.doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
-		this.oai_collection_list = this.doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
+		this.collection_list = doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
+		this.private_collection_list = doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
+		this.oai_collection_list = doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
 		configureCollections();
 
 		// load up the external sites - this also adds their services/clusters/collections to the other lists - so must be done last
-		this.site_list = this.doc.createElement(GSXML.SITE_ELEM + GSXML.LIST_MODIFIER);
+		this.site_list = doc.createElement(GSXML.SITE_ELEM + GSXML.LIST_MODIFIER);
 		Element site_list_elem = (Element) GSXML.getChildByTagName(config_info, GSXML.SITE_ELEM + GSXML.LIST_MODIFIER);
 		configureExternalSites(site_list_elem);
 
 		// load up the site metadata
-		this.metadata_list = this.doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);
+		this.metadata_list = doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);
 		Element metadata_list_elem = (Element) GSXML.getChildByTagName(config_info, GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);
 		loadMetadata(metadata_list_elem);
@@ -522,7 +512,7 @@
 			return true;
 		}
-
-		Element service_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
-		Element service_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, "", new UserContext());
+		Document doc = this.converter.newDOM();
+		Element service_message = doc.createElement(GSXML.MESSAGE_ELEM);
+		Element service_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_DESCRIBE, "", new UserContext());
 		service_message.appendChild(service_request);
 
@@ -573,4 +563,5 @@
 				else
 				{
+				  Document service_list_doc = this.service_list.getOwnerDocument();
 					for (int j = 0; j < services.getLength(); j++)
 					{
@@ -580,5 +571,5 @@
 
 						// add short info to service_list_ XML
-						this.service_list.appendChild(this.doc.importNode(services.item(j), true));
+						this.service_list.appendChild(service_list_doc.importNode(services.item(j), true));
 					}
 				}
@@ -610,4 +601,5 @@
 		}
 
+		Document doc = this.cluster_list.getOwnerDocument();
 		for (int i = 0; i < service_clusters.getLength(); i++)
 		{
@@ -628,5 +620,5 @@
 			this.module_map.put(name, sc); // this replaces the old one if there was one already present
 			//add short info to cluster list
-			Element e = this.doc.createElement(GSXML.CLUSTER_ELEM);
+			Element e = doc.createElement(GSXML.CLUSTER_ELEM);
 			e.setAttribute(GSXML.NAME_ATT, name);
 			this.cluster_list.appendChild(e);
@@ -688,5 +680,5 @@
 
 		logger.info("Activating collection: " + col_name + ".");
-
+		Document doc = this.collection_list.getOwnerDocument();
 		// Look for the etc/collectionInit.xml file, and see what sort of Collection to load
 		Collection c = null;
@@ -730,5 +722,5 @@
 			// add to list of collections
 			this.module_map.put(col_name, c);
-			Element e = this.doc.createElement(GSXML.COLLECTION_ELEM);
+			Element e = doc.createElement(GSXML.COLLECTION_ELEM);
 			e.setAttribute(GSXML.NAME_ATT, col_name);
 
@@ -741,5 +733,5 @@
 				if (c.hasOAI())
 				{
-					Element ane = this.doc.createElement(GSXML.COLLECTION_ELEM);
+					Element ane = doc.createElement(GSXML.COLLECTION_ELEM);
 					ane.setAttribute(GSXML.NAME_ATT, col_name);
 					ane.setAttribute(OAIXML.LASTMODIFIED, "" + c.getLastmodified());
@@ -859,5 +851,5 @@
 				// add to map of modules
 				this.module_map.put(name, comm);
-				this.site_list.appendChild(this.doc.importNode(site_elem, true));
+				this.site_list.appendChild(this.site_list.getOwnerDocument().importNode(site_elem, true));
 				// need to get collection list and service
 				// list from here- if the site isn't up yet, the site will
@@ -886,5 +878,5 @@
 	protected boolean loadMetadata(Element config_metadata_list)
 	{
-
+	  
 		// load up the sites
 		logger.info("loading site metadata...");
@@ -902,8 +894,9 @@
 		}
 
+		Document doc = this.metadata_list.getOwnerDocument();
 		for (int i = 0; i < metadata.getLength(); i++)
 		{
 			Element s = (Element) metadata.item(i);
-			this.metadata_list.appendChild(this.doc.importNode(s, true));
+			this.metadata_list.appendChild(doc.importNode(s, true));
 		}
 		return true;
@@ -923,7 +916,7 @@
 
 		logger.info(" getting info from site:" + site_name);
-
-		Element info_request = this.doc.createElement(GSXML.MESSAGE_ELEM);
-		Element req = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, "", new UserContext());
+		Document doc = this.converter.newDOM();
+		Element info_request = doc.createElement(GSXML.MESSAGE_ELEM);
+		Element req = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_DESCRIBE, "", new UserContext());
 		info_request.appendChild(req);
 
@@ -948,5 +941,5 @@
 				// other collections ??
 				e.setAttribute(GSXML.NAME_ATT, GSPath.prependLink(col_name, site_name));
-				this.collection_list.appendChild(this.doc.importNode(e, true));
+				this.collection_list.appendChild(doc.importNode(e, true));
 			}
 		}
@@ -961,5 +954,5 @@
 				String serv_name = e.getAttribute(GSXML.NAME_ATT);
 				e.setAttribute(GSXML.NAME_ATT, GSPath.prependLink(serv_name, site_name));
-				this.service_list.appendChild(this.doc.importNode(e, true));
+				this.service_list.appendChild(doc.importNode(e, true));
 			}
 		}
@@ -974,5 +967,5 @@
 				String clus_name = e.getAttribute(GSXML.NAME_ATT);
 				e.setAttribute(GSXML.NAME_ATT, GSPath.prependLink(clus_name, site_name));
-				this.cluster_list.appendChild(this.doc.importNode(e, true));
+				this.cluster_list.appendChild(doc.importNode(e, true));
 			}
 		}
@@ -1090,6 +1083,7 @@
 
 		// message for self, should be type=describe/configure at this stage
+	        Document doc = this.converter.newDOM();
 		String type = req.getAttribute(GSXML.TYPE_ATT);
-		Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);
+		Element response = doc.createElement(GSXML.RESPONSE_ELEM);
 		response.setAttribute(GSXML.FROM_ATT, "");
 		if (type.equals(GSXML.REQUEST_TYPE_DESCRIBE))
@@ -1100,9 +1094,9 @@
 			if (param_list == null)
 			{
-				response.appendChild(this.collection_list);
-				response.appendChild(this.cluster_list);
-				response.appendChild(this.site_list);
-				response.appendChild(this.service_list);
-				response.appendChild(this.metadata_list);
+			  response.appendChild(doc.importNode(this.collection_list, true));
+				response.appendChild(doc.importNode(this.cluster_list, true));
+				response.appendChild(doc.importNode(this.site_list, true));
+				response.appendChild(doc.importNode(this.service_list, true));
+				response.appendChild(doc.importNode(this.metadata_list, true));
 				return response;
 			}
@@ -1121,21 +1115,21 @@
 					if (info.equals(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER))
 					{
-						response.appendChild(this.collection_list);
+						response.appendChild(doc.importNode(this.collection_list, true));
 					}
 					else if (info.equals(GSXML.CLUSTER_ELEM + GSXML.LIST_MODIFIER))
 					{
-						response.appendChild(this.cluster_list);
+						response.appendChild(doc.importNode(this.cluster_list, true));
 					}
 					else if (info.equals(GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER))
 					{
-						response.appendChild(this.service_list);
+						response.appendChild(doc.importNode(this.service_list, true));
 					}
 					else if (info.equals(GSXML.SITE_ELEM + GSXML.LIST_MODIFIER))
 					{
-						response.appendChild(this.site_list);
+						response.appendChild(doc.importNode(this.site_list, true));
 					}
 					else if (info.equals(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER))
 					{
-						response.appendChild(this.metadata_list);
+						response.appendChild(doc.importNode(this.metadata_list, true));
 					}
 				}
@@ -1150,5 +1144,5 @@
 			//this is the oai receptionist asking for a list of oai-support collections
 			response.setAttribute(GSXML.TYPE_ATT, OAIXML.OAI_SET_LIST);
-			response.appendChild(this.oai_collection_list);
+			response.appendChild(doc.importNode(this.oai_collection_list, true));
 			return response;
 		}
@@ -1191,9 +1185,9 @@
 						}
 					}
-					Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, message);
+					Element s = GSXML.createTextElement(doc, GSXML.STATUS_ELEM, message);
 					response.appendChild(s);
 				}
 				//else if (action.equals(GSXML.SYSTEM_TYPE_ISPERSISTENT)) {
-				//	Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM,  "Persistent: true.");
+				//	Element s = GSXML.createTextElement(doc, GSXML.STATUS_ELEM,  "Persistent: true.");
 				//	response.appendChild(s);
 				//}
@@ -1205,5 +1199,5 @@
 						// need to reconfigure the MR
 						this.configureLocalSite();
-						Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, "MessageRouter reconfigured successfully");
+						Element s = GSXML.createTextElement(doc, GSXML.STATUS_ELEM, "MessageRouter reconfigured successfully");
 						response.appendChild(s);
 
@@ -1268,5 +1262,5 @@
 							message = "Error in reconfiguring " + subset;
 						}
-						Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, message);
+						Element s = GSXML.createTextElement(doc, GSXML.STATUS_ELEM, message);
 						response.appendChild(s);
 					}
@@ -1283,10 +1277,10 @@
 						if (success)
 						{
-							Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, module_type + ": " + module_name + " deactivated", GSXML.SYSTEM_TYPE_DEACTIVATE, GSXML.SUCCESS);
+							Element s = GSXML.createTextElement(doc, GSXML.STATUS_ELEM, module_type + ": " + module_name + " deactivated", GSXML.SYSTEM_TYPE_DEACTIVATE, GSXML.SUCCESS);
 							response.appendChild(s);
 						}
 						else
 						{
-							Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, module_type + ": " + module_name + " could not be deactivated", GSXML.SYSTEM_TYPE_DEACTIVATE, GSXML.ERROR);
+							Element s = GSXML.createTextElement(doc, GSXML.STATUS_ELEM, module_type + ": " + module_name + " could not be deactivated", GSXML.SYSTEM_TYPE_DEACTIVATE, GSXML.ERROR);
 							response.appendChild(s);
 						}
@@ -1312,10 +1306,10 @@
 						if (success)
 						{
-							Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, module_type + ": " + module_name + " activated", GSXML.SYSTEM_TYPE_ACTIVATE, GSXML.SUCCESS);
+							Element s = GSXML.createTextElement(doc, GSXML.STATUS_ELEM, module_type + ": " + module_name + " activated", GSXML.SYSTEM_TYPE_ACTIVATE, GSXML.SUCCESS);
 							response.appendChild(s);
 						}
 						else
 						{
-							Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, module_type + ": " + module_name + " could not be activated", GSXML.SYSTEM_TYPE_ACTIVATE, GSXML.ERROR);
+							Element s = GSXML.createTextElement(doc, GSXML.STATUS_ELEM, module_type + ": " + module_name + " could not be activated", GSXML.SYSTEM_TYPE_ACTIVATE, GSXML.ERROR);
 							response.appendChild(s);
 						}
@@ -1340,5 +1334,6 @@
 	protected Element modifyMessages(Element request, Element message, Element result)
 	{
-		Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);
+	  Document doc = this.converter.newDOM();
+		Element response = doc.createElement(GSXML.RESPONSE_ELEM);
 		response.setAttribute(GSXML.FROM_ATT, "");
 		response.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_MESSAGING);
