package edu.stanford.prpl.junction.impl;

import java.net.URL;

import org.json.JSONException;
import org.json.JSONObject;

import edu.stanford.prpl.junction.api.JunctionAPI;
import edu.stanford.prpl.junction.api.JunctionFactory;

public class JunctionManagerFactory implements JunctionFactory {
	// TODO: I should probably be a singleton per-junction session.
	// So if the JSONObject activity is the same, return the same object.
	
	// For testing, use the same JM.
	static JunctionManager mJunctionInstance;
	static JunctionManagerFactory mFactoryInstance;
	
	
	
	public JunctionManagerFactory getInstance() {
		if (null == mFactoryInstance) {
			mFactoryInstance = new JunctionManagerFactory();
		}
		
		return mFactoryInstance;
	}
	
	public JunctionAPI create(JSONObject activity) {
		if (mJunctionInstance == null) {
			mJunctionInstance = new JunctionManager(activity);
		}
		
		return mJunctionInstance;
	}

	public JunctionAPI create(URL url) {
		if (mJunctionInstance == null) {
			JSONObject desc = new JSONObject();
			try {
				desc.put("host",url.toExternalForm());
			} catch (JSONException e) {
				throw new IllegalArgumentException("Malformed host URL");
			}
			mJunctionInstance = new JunctionManager(desc);
		}
		
		return mJunctionInstance;
	}

}

@@ -739,35 +739,39 @@
 %09public Junction
-API
+Manager
  create(JSONObje
@@ -929,19 +929,23 @@
 Junction
-API
+Manager
  create(

return concrete type