package edu.stanford.junction.api.activity;

import java.util.HashMap;
import java.util.Map;

import edu.stanford.junction.Junction;
import edu.stanford.junction.JunctionMaker;

// TODO: This class requires a switchboard, and is probably XMPP specific. Fix accordingly.

public abstract class JunctionService extends JunctionActor {
	public static String SERVICE_CHANNEL="jxservice";
	
	private static Map<String,Junction>mJunctionMap;
	{
		mJunctionMap = new HashMap<String,Junction>();
	}
	
	String mRole;
	
	public abstract String getServiceName();
	
	public JunctionService() {
		super((String)null);
	}
	
	@Override
	public String[] getRoles() {
		return new String[] {mRole};
	}
	
	@Override
	public void onActivityStart() {}
	
	public final void register(String switchboard) {
		
		if (mJunctionMap.containsKey(switchboard)) return;
		
		ActivityScript desc = new ActivityScript();
		desc.setHost(switchboard);
		desc.setSessionID(SERVICE_CHANNEL);
		//desc.setActorID(getServiceName());
		desc.setActivityID("junction.service");
		
		Junction jx = null; //JunctionMaker.getInstance().newJunction(desc, this);
		mJunctionMap.put(switchboard, jx);

	}
	
	public void setRole(String role) {
		mRole=role;
	}
}
@@ -169,16 +169,78 @@
 onMaker;
+%0Aimport edu.stanford.junction.impl.xmpp.XMPPSwitchboardConfig;
 %0A%0A// TOD
@@ -1097,16 +1097,18 @@
 );%0A%09%09%0A%09%09
+//
 Junction
@@ -1174,16 +1174,214 @@
  this);%0A
+%09%09XMPPSwitchboardConfig config = new XMPPSwitchboardConfig(switchboard);%0A%09%09JunctionMaker maker = (JunctionMaker) JunctionMaker.getInstance(config);%0A%09%09Junction jx = maker.newJunction(desc, this);%0A%09%09%0A
 %09%09mJunct

fixing junction jx = null