/*
 *  (c) 2012 University of Bolton
 *  
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 * limitations under the License.
 */
package uk.ac.edukapp.server.configuration;

import java.net.MalformedURLException;
import java.net.URL;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.log4j.Logger;

import uk.ac.bolton.spaws.ParadataManager;
import uk.ac.bolton.spaws.model.impl.Node;
import uk.ac.bolton.spaws.model.impl.Submitter;

public class SpawsServerConfiguration {

	static Logger _logger = Logger.getLogger(SpawsServerConfiguration.class
			.getName());

	// Defaults
	private String nodeUrl = "http://alpha.mimas.ac.uk";
	private String username = "fred";
	private String password = "flintstone";
	private Node node;
	private boolean enabled = true;

	private String submitterName = "edukapp";
	private Submitter submitter;
	
	private static SpawsServerConfiguration instance;

	private SpawsServerConfiguration() {
		try {
			PropertiesConfiguration properties = new PropertiesConfiguration(
					"store.properties");
			if (properties.containsKey("spaws.node.location"))
				nodeUrl = properties.getString("spaws.node.location");
			if (properties.containsKey("spaws.node.username"))
				username = properties.getString("spaws.node.username");
			if (properties.containsKey("spaws.node.password"))
				password = properties.getString("spaws.node.password");
			if (properties.containsKey("spaws.submitter.name"))
				submitterName = properties.getString("spaws.submitter.name");
			if (properties.containsKey("spaws.enabled"))
				enabled = properties.getBoolean("spaws.enabled");
			
		} catch (ConfigurationException e) {
			//
			// No store properties found, so use default
			//
			_logger.warn("No SPAWS node properties found; using defaults");
		}
		try {
			node = new Node(new URL(nodeUrl), username, password);
		} catch (MalformedURLException e) {
			_logger.warn("SPAWS node URL is invalid; using defaults");
			try {
				node = new Node(new URL("http://alpha.mimas.ac.uk"), username, password);
			} catch (MalformedURLException e1) {
				// Should never happen...
			}

		}
		
		submitter = new Submitter();
		submitter.setSubmitter(submitterName);
	}

	public static SpawsServerConfiguration getInstance() {
		if (instance == null)
			instance = new SpawsServerConfiguration();
		return instance;
	}

	public Node getNode(){
		return node;
	}
	
	public Submitter getSubmitter(){
		return submitter;
	}
	
	public ParadataManager getParadataManager() throws Exception{
		return new ParadataManager(submitter, node);
	}
	
	public boolean isEnabled(){
		return enabled;
	}
}

@@ -2747,16 +2747,107 @@
 rName);%0A
+%09%09submitter.setSigner(submitterName);%0A%09%09submitter.setSubmissionAttribution(submitterName);%0A
 %09%7D%0A%0A%09pub

Include more submitter info in SPAWS config