Index: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/BerryBasket.java
===================================================================
--- main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/BerryBasket.java	(revision 25635)
+++ main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/BerryBasket.java	(revision 28966)
@@ -27,4 +27,5 @@
 import java.util.Iterator;
 
+import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
@@ -34,4 +35,5 @@
 import org.greenstone.gsdl3.util.GSPath;
 import org.greenstone.gsdl3.util.UserContext;
+import org.greenstone.gsdl3.util.XMLConverter;
 
 import java.io.Serializable;
@@ -111,5 +113,5 @@
 
 		// set up short_service_info_ - for now just has name and type
-		Element add_service = this.doc.createElement(GSXML.SERVICE_ELEM);
+		Element add_service = this.desc_doc.createElement(GSXML.SERVICE_ELEM);
 		add_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
 		add_service.setAttribute(GSXML.NAME_ATT, ADD_ITEM_SERVICE);
@@ -117,5 +119,5 @@
 
 		// set up short_service_info_ - for now just has name and type
-		Element disp_service = this.doc.createElement(GSXML.SERVICE_ELEM);
+		Element disp_service = this.desc_doc.createElement(GSXML.SERVICE_ELEM);
 		disp_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
 		disp_service.setAttribute(GSXML.NAME_ATT, DISPLAY_ITEMS_SERVICE);
@@ -123,5 +125,5 @@
 
 		// set up short_service_info_ - for now just has name and type
-		Element num_service = this.doc.createElement(GSXML.SERVICE_ELEM);
+		Element num_service = this.desc_doc.createElement(GSXML.SERVICE_ELEM);
 		num_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
 		num_service.setAttribute(GSXML.NAME_ATT, ITEM_NUM_SERVICE);
@@ -129,5 +131,5 @@
 
 		// set up short_service_info_ - for now just has name and type
-		Element delete_service = this.doc.createElement(GSXML.SERVICE_ELEM);
+		Element delete_service = this.desc_doc.createElement(GSXML.SERVICE_ELEM);
 		delete_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
 		delete_service.setAttribute(GSXML.NAME_ATT, DELETE_ITEMS_SERVICE);
@@ -135,5 +137,5 @@
 
 		// set up short_service_info_ - for now just has name and type
-		Element deleteone_service = this.doc.createElement(GSXML.SERVICE_ELEM);
+		Element deleteone_service = this.desc_doc.createElement(GSXML.SERVICE_ELEM);
 		deleteone_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
 		deleteone_service.setAttribute(GSXML.NAME_ATT, DELETE_ITEM_SERVICE);
@@ -141,5 +143,5 @@
 
 		// set up short_service_info_ - for now just has name and type
-		Element mail_service = this.doc.createElement(GSXML.SERVICE_ELEM);
+		Element mail_service = this.desc_doc.createElement(GSXML.SERVICE_ELEM);
 		mail_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
 		mail_service.setAttribute(GSXML.NAME_ATT, SEND_MAIL_SERVICE);
@@ -151,10 +153,10 @@
 
 	/** returns a specific service description */
-	protected Element getServiceDescription(String service_id, String lang, String subset)
+  protected Element getServiceDescription(Document doc, String service_id, String lang, String subset)
 	{
 
 		if (service_id.equals(ADD_ITEM_SERVICE))
 		{
-			Element add_service = this.doc.createElement(GSXML.SERVICE_ELEM);
+			Element add_service = doc.createElement(GSXML.SERVICE_ELEM);
 			add_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
 			add_service.setAttribute(GSXML.NAME_ATT, ADD_ITEM_SERVICE);
@@ -164,5 +166,5 @@
 		{
 
-			Element disp_service = this.doc.createElement(GSXML.SERVICE_ELEM);
+			Element disp_service = doc.createElement(GSXML.SERVICE_ELEM);
 			disp_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
 			disp_service.setAttribute(GSXML.NAME_ATT, DISPLAY_ITEMS_SERVICE);
@@ -173,5 +175,5 @@
 		{
 
-			Element num_service = this.doc.createElement(GSXML.SERVICE_ELEM);
+			Element num_service = doc.createElement(GSXML.SERVICE_ELEM);
 			num_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
 			num_service.setAttribute(GSXML.NAME_ATT, ITEM_NUM_SERVICE);
@@ -182,5 +184,5 @@
 		{
 
-			Element del_service = this.doc.createElement(GSXML.SERVICE_ELEM);
+			Element del_service = doc.createElement(GSXML.SERVICE_ELEM);
 			del_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
 			del_service.setAttribute(GSXML.NAME_ATT, DELETE_ITEMS_SERVICE);
@@ -191,5 +193,5 @@
 		{
 
-			Element delone_service = this.doc.createElement(GSXML.SERVICE_ELEM);
+			Element delone_service = doc.createElement(GSXML.SERVICE_ELEM);
 			delone_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
 			delone_service.setAttribute(GSXML.NAME_ATT, DELETE_ITEM_SERVICE);
@@ -200,5 +202,5 @@
 		{
 
-			Element mail_service = this.doc.createElement(GSXML.SERVICE_ELEM);
+			Element mail_service = doc.createElement(GSXML.SERVICE_ELEM);
 			mail_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
 			mail_service.setAttribute(GSXML.NAME_ATT, SEND_MAIL_SERVICE);
@@ -214,5 +216,6 @@
 
 		// Create a new (empty) result message
-		Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
+		Document result_doc = XMLConverter.newDOM();
+		Element result = result_doc.createElement(GSXML.RESPONSE_ELEM);
 
 		// Get the parameters of the request
@@ -242,5 +245,5 @@
 				Item newItem = generateItem(collection, item);
 				items.put(item, newItem);
-				result.appendChild(newItem.wrapIntoElement());
+				result.appendChild(newItem.wrapIntoElement(result_doc));
 			}
 		}
@@ -251,5 +254,5 @@
 			items.put(item, newItem);
 			docsMap.put(collection, items);
-			result.appendChild(newItem.wrapIntoElement());
+			result.appendChild(newItem.wrapIntoElement(result_doc));
 		}
 
@@ -307,5 +310,6 @@
 
 		// Create a new (empty) result message
-		Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
+		Document result_doc = XMLConverter.newDOM();
+		Element result = result_doc.createElement(GSXML.RESPONSE_ELEM);
 
 		// Get the parameters of the request
@@ -363,5 +367,6 @@
 
 		// Create a new (empty) result message
-		Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
+		Document result_doc = XMLConverter.newDOM();
+		Element result = result_doc.createElement(GSXML.RESPONSE_ELEM);
 
 		// Get the parameters of the request
@@ -413,5 +418,6 @@
 
 		// Create a new (empty) result message
-		Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
+		Document result_doc = XMLConverter.newDOM();
+		Element result = result_doc.createElement(GSXML.RESPONSE_ELEM);
 
 		int size = 0;
@@ -427,9 +433,9 @@
 			{
 				Item item = (Item) values.next();
-				result.appendChild(item.wrapIntoElement());
-			}
-		}
-
-		Element selement = this.doc.createElement("size");
+				result.appendChild(item.wrapIntoElement(result_doc));
+			}
+		}
+
+		Element selement = result_doc.createElement("size");
 		selement.setAttribute("value", size + "");
 		result.appendChild(selement);
@@ -442,6 +448,7 @@
 
 		// Build a request to obtain some document metadata
-		Element dm_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
-		Element dm_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
+	  Document doc = XMLConverter.newDOM();
+		Element dm_message = doc.createElement(GSXML.MESSAGE_ELEM);
+		Element dm_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
 		dm_message.appendChild(dm_request);
 
@@ -452,5 +459,5 @@
 		meta_names.add("Date");
 
-		Element param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
+		Element param_list = doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
 
 		Element param = null;
@@ -459,5 +466,5 @@
 		{
 			String name = i.next();
-			param = this.doc.createElement(GSXML.PARAM_ELEM);
+			param = doc.createElement(GSXML.PARAM_ELEM);
 			param_list.appendChild(param);
 			param.setAttribute(GSXML.NAME_ATT, "metadata");
@@ -469,5 +476,5 @@
 
 		// create the doc node list for the metadata request
-		Element dm_doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
+		Element dm_doc_list = doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
 		dm_request.appendChild(dm_doc_list);
 
@@ -475,5 +482,5 @@
 		{
 			// Add the documentNode to the list
-			Element dm_doc_node = this.doc.createElement(GSXML.DOC_NODE_ELEM);
+			Element dm_doc_node = doc.createElement(GSXML.DOC_NODE_ELEM);
 			dm_doc_list.appendChild(dm_doc_node);
 			dm_doc_node.setAttribute(GSXML.NODE_ID_ATT, ids.next());
@@ -489,5 +496,6 @@
 
 		// Create a new (empty) result message
-		Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
+		Document result_doc = XMLConverter.newDOM();
+		Element result = result_doc.createElement(GSXML.RESPONSE_ELEM);
 
 		Iterator<String> keys = docsMap.keySet().iterator();
@@ -499,5 +507,5 @@
 			Iterator itemItr = items.values().iterator();
 
-			Element collectionNode = this.doc.createElement("berryList");
+			Element collectionNode = result_doc.createElement("berryList");
 			collectionNode.setAttribute("name", collection);
 			result.appendChild(collectionNode);
@@ -506,5 +514,5 @@
 			{
 				Item item = (Item) itemItr.next();
-				Element itemElement = this.doc.createElement("item");
+				Element itemElement = result_doc.createElement("item");
 
 				collectionNode.appendChild(itemElement);
@@ -524,5 +532,6 @@
 	{
 		// Create a new (empty) result message
-		Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
+	  Document result_doc = XMLConverter.newDOM();
+		Element result = result_doc.createElement(GSXML.RESPONSE_ELEM);
 
 		// Get the parameters of the request
@@ -606,10 +615,10 @@
 
 			logger.info("\nMail was sent successfully.");
-			result.appendChild(this.doc.createTextNode("Mail was sent successfully."));
+			result.appendChild(result_doc.createTextNode("Mail was sent successfully."));
 		}
 		catch (Exception e)
 		{
 			e.printStackTrace();
-			result.appendChild(this.doc.createTextNode(e.getMessage()));
+			result.appendChild(result_doc.createTextNode(e.getMessage()));
 		}
 
@@ -651,5 +660,5 @@
 		}
 
-		public Element wrapIntoElement()
+		public Element wrapIntoElement(Document doc)
 		{
 			Element itemElement = doc.createElement("item");
