Index: trunk/gsdl3/src/java/org/greenstone/gsdl3/collection/Collection.java
===================================================================
--- trunk/gsdl3/src/java/org/greenstone/gsdl3/collection/Collection.java	(revision 4086)
+++ trunk/gsdl3/src/java/org/greenstone/gsdl3/collection/Collection.java	(revision 4097)
@@ -44,5 +44,5 @@
     extends ServiceCluster {
 
-    protected XMLTransformer transformer_ = null;
+    protected XMLTransformer transformer = null;
     /** same as setClusterName */
     public void setCollectionName(String name) {
@@ -51,13 +51,9 @@
 
     public Collection() {
-	service_map_ = new HashMap();
-	converter_ = new XMLConverter();
-	transformer_ = new XMLTransformer();
-	doc_ = converter_.newDOM();
-	description_ = doc_.createElement(GSXML.COLLECTION_ELEM);
-	service_info_ = doc_.createElement(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER);
-	meta_info_ = doc_.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
-	description_.appendChild(meta_info_);
-	description_.appendChild(service_info_);
+	this.service_map = new HashMap();
+	this.converter = new XMLConverter();
+	this.transformer = new XMLTransformer();
+	this.doc = this.converter.newDOM();
+	this.description = this.doc.createElement(GSXML.COLLECTION_ELEM);
 	
     }
@@ -75,45 +71,153 @@
     public boolean configure() {
 	
-	if (site_home_ == null || cluster_name_== null) {
+	if (this.site_home == null || this.cluster_name== null) {
 	    System.err.println("site_home and collection_name must be set before configure called!");
 	    return false;
 	}
-	// read the collection build configuration file
-	File build_config_file = new File(GSFile.collectionBuildConfigFile(site_home_, cluster_name_));
-	File coll_config_file = new File(GSFile.collectionConfigFile(site_home_, cluster_name_));
-
+	
+	Element coll_config_xml = loadCollConfigFile();
+	Element build_config_xml = loadBuildConfigFile();
+	
+	if (coll_config_xml==null||build_config_xml==null) {
+	    return false;
+	}
+	// process the metadata
+	findAndLoadMetadata(coll_config_xml, build_config_xml);
+
+	// now do the services	
+	Element service_list = (Element)GSXML.getChildByTagName(build_config_xml, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
+	configureServiceRack(service_list, coll_config_xml);
+	
+	return true;
+	
+    }
+
+    /** 
+     * overwrite the serviceCluster one cos we use diff config files
+     */
+    protected Element processSystemRequest(Element request) {
+	Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);
+	response.setAttribute(GSXML.FROM_ATT, this.cluster_name);
+	response.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_SYSTEM);
+
+	// a list of system requests - should put any error messages
+	// or success messages into response
+	NodeList commands = request.getElementsByTagName(GSXML.SYSTEM_ELEM);
+	Element coll_config_elem = null;
+	Element build_config_elem = null;
+	for (int i=0; i<commands.getLength(); i++) {
+	    // all the commands should be Elements
+	    Element elem = (Element)commands.item(i);
+	    String action = elem.getAttribute(GSXML.TYPE_ATT);
+	    if (action.equals("configure")) {
+		String subset = elem.getAttribute("subset");
+		if (subset.equals("")) {
+		    // need to reconfigure the collection
+		    if (this.configure()) {
+			Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " collection reconfigured");
+			response.appendChild(s);
+			continue;
+		    } 
+		    
+		    Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " collection could not  be reconfigured");
+		    response.appendChild(s); 
+		    return response; // wont be able to process any more if we cant do this one
+		    
+		} 
+		// else its a specific request
+		
+		// need the coll config files
+		if (coll_config_elem==null) {
+		    coll_config_elem = loadCollConfigFile();
+		    build_config_elem = loadBuildConfigFile();
+		    if (coll_config_elem == null||build_config_elem == null) {
+			// wont be able to do any of teh requests
+			return response;
+		    }    
+		}
+		
+		boolean success = false;
+		if (subset.equals(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER)) {
+		    Element service_rack_list = (Element)GSXML.getChildByTagName(build_config_elem, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
+		    
+		    success = configureServiceRack(service_rack_list, coll_config_elem);
+		} else if (subset.equals(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER)) {
+		    success = findAndLoadMetadata(coll_config_elem, build_config_elem);
+		    
+		} else {
+		    System.err.println("ServiceCluster: cant process system request, configure "+subset);
+		} 
+		
+		String message=null;
+		if (success) {
+		    message = "ServiceCluster: "+ subset + " reconfigured successfully";
+		} else {
+		    message = "ServiceCluster: Error in reconfiguring "+subset;
+		}
+		Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, message);
+		response.appendChild(s);
+	    } else {
+		String module_name = elem.getAttribute(GSXML.SYSTEM_MODULE_NAME_ATT);
+		String module_type = elem.getAttribute(GSXML.SYSTEM_MODULE_TYPE_ATT);
+		if (action.equals("activate")) {
+		    Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, module_type+": "+module_name+" activated -- not yet implemented");
+		    response.appendChild(s);
+		} else if (action.equals("deactivate")) {
+		    Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, module_type+": "+module_name+" deactivated -- not yet implemented");
+		    response.appendChild(s);
+		} else {
+		    System.err.println("Collection: cant process system request, action "+action);
+		    continue;
+		}
+		
+	    }
+	} // for each command
+	return response;
+    }
+    
+    protected Element loadCollConfigFile() {
+
+	File coll_config_file = new File(GSFile.collectionConfigFile(this.site_home, this.cluster_name));
+	
 	if (!coll_config_file.exists()) {
 	    System.err.println(coll_config_file+" does not exist");
-	    System.err.println("couldn't configure collection: "+cluster_name_);
-	    return false;
-	}
-	
+	    System.err.println("couldn't configure collection: "+this.cluster_name);
+	    return null;
+	}
+	// get the xml for both files
+	Element coll_config_elem = this.converter.getDOM(coll_config_file, CONFIG_ENCODING).getDocumentElement();
+	return coll_config_elem;
+
+    }
+    
+    
+    protected Element loadBuildConfigFile() {
+	
+	File build_config_file = new File(GSFile.collectionBuildConfigFile(this.site_home, this.cluster_name));
 	if (!build_config_file.exists()) {
 	    System.err.println(build_config_file+" does not exist");
-	    System.err.println("couldn't configure collection: "+cluster_name_);
-	    return false;
-	}
-	
-	// get the xml for both files
-	Element coll_config_xml = converter_.getDOM(coll_config_file, CONFIG_ENCODING).getDocumentElement();
-	Element build_config_xml = converter_.getDOM(build_config_file, CONFIG_ENCODING).getDocumentElement();
-	
-	// process the metadata
+	    System.err.println("couldn't configure collection: "+this.cluster_name);
+	    return null;
+	}
+	Element build_config_elem = this.converter.getDOM(build_config_file, CONFIG_ENCODING).getDocumentElement();
+
+	return build_config_elem;
+    }
+
+    
+    protected boolean findAndLoadMetadata(Element coll_config_xml, 
+					  Element build_config_xml){
+
+	this.metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
 	Element meta_list = (Element)GSXML.getChildByTagName(coll_config_xml, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
-	configureMetadata(meta_list);
+	addMetadata(meta_list);
 	meta_list = (Element)GSXML.getChildByTagName(build_config_xml, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
-	configureMetadata(meta_list);
-
-	meta_list = doc_.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);
-	GSXML.addMetadata(doc_, meta_list, "httpPath", site_http_address_+"/collect/"+cluster_name_);
-	configureMetadata(meta_list);
-	
-	// now do the services
-	
-	Element service_list = (Element)GSXML.getChildByTagName(build_config_xml, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
-	configureServiceRack(service_list, coll_config_xml);
-	
+	addMetadata(meta_list);
+
+	meta_list = this.doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);
+	GSXML.addMetadata(this.doc, meta_list, "httpPath", this.site_http_address+"/collect/"+this.cluster_name);
+	addMetadata(meta_list);
 	return true;
-	
+
     }
 
