// Path: src/main/java/edu/stanford/junction/api/activity/JunctionService.java
// 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");
// 		
// 		// TODO: register(String sb) doesn't make sense any more.
// 		// Get rid of 'services' in general; just stick an actor to an activity.
// 		XMPPSwitchboardConfig config = new XMPPSwitchboardConfig(switchboard);
// 		JunctionMaker maker = (JunctionMaker) JunctionMaker.getInstance(config);
// 
// 		try{
// 			Junction jx = maker.newJunction(desc, this);
// 			mJunctionMap.put(switchboard, jx);
// 		}
// 		catch(JunctionException e){
// 			System.err.println("Failed to register JunctionService");
// 			e.printStackTrace(System.err);
// 		}
// 	}
// 	
// 	public void setRole(String role) {
// 		mRole=role;
// 	}
// }
// 
// Path: src/main/java/edu/stanford/junction/api/messaging/MessageHandler.java
// public abstract class MessageHandler {
// 	/**
// 	 * Stream-selecting filters;
// 	 * These filters allow Junction to route messages
// 	 * using the network's capabilities.
// 	 * 
// 	 * If we are sending to a fixed actor, try and establish a direct connection.
// 	 * If we are sending to a fixed role or multiple actors, we can
// 	 * potentially multicast.
// 	 * 
// 	 * These methods should return static results (list of actors does not change
// 	 * over the lifetime of the handler)
// 	 */
// 	public List<String> supportedRoles() { return null; } // default is to not filter on roles.
// 	public List<String> supportedActors() { return null; } // default is to not filter on actors.
// 	public List<String> supportedChannels() { return null; } // default is to not filter on channel.
// 	
// 	/**
// 	 * Message-level filter
// 	 * 
// 	 * These filters may be convenient for the end-user.
// 	 * May be useful to support RPC, for example
// 	 * 
// 	 */
// 	public boolean supportsMessage(JSONObject message) { return true; }
// 	// TODO: have a dynamic filter and a static one.
// 	// the static one defines a message template, and this template can be
// 	// shared (like an XML XSD document)
// 	
// 	/**
// 	 * Message handling
// 	 */
// 	public abstract void onMessageReceived(MessageHeader header, JSONObject message);
// 	
// 	/**
// 	 * How to add response capabilities?
// 	 * This should be bridged with Junction.sendMessageToXXX
// 	 * We might need a MessageTarget or something.
// 	 */
// 	// getMessageRecipients;
// 	// getMessageSender;
// 	// replyToSender; 
// 	// replyAll
// }
// 
// Path: src/main/java/edu/stanford/junction/api/messaging/MessageHeader.java
// public class MessageHeader {
// 	private Junction jx;
// 	private JSONObject message;
// 	public String from;
// 	
// 	public MessageHeader(Junction jx, JSONObject message, String from) {
// 		this.jx=jx;
// 		this.message=message;
// 		this.from=from;
// 	}
// 	
// 	
// 	public MessageTarget getReplyTarget() {
// 		if (message.has(Junction.NS_JX)) {
// 			JSONObject h = message.optJSONObject(Junction.NS_JX);
// 			if (h.has("replyTo")) {
// 				return MessageTargetFactory.getInstance(jx).getTarget(h.optString("replyTo"));
// 			}
// 		}
// 		
// 		return MessageTargetFactory.getInstance(jx).getTarget("actor:"+from);
// 	}
// 	
// 	public String getSender() {
// 		return from;
// 	}
// 	
// 	public Junction getJunction() { return jx; }
// }


import org.json.JSONObject;
import edu.stanford.junction.api.activity.JunctionService;
import edu.stanford.junction.api.messaging.MessageHandler;
import edu.stanford.junction.api.messaging.MessageHeader;
/*
 * Copyright (C) 2010 Stanford University
 *
 * 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 edu.stanford.junction.simulator;



/**
 * This class allows a remote client to subscribe to a channel without having
 * to open a new connection for it. It may be useful for a singleton service 
 * expecting to connect to many activities.
 * @author bdodson
 *
 */
public class ForwardingService extends JunctionService {
	private String mChannel; // TODO: this needs to be on another server
	
	private ForwardingService() {}
	public static JunctionService newInstance() {
		return new ForwardingService();
	}
	
	@Override
	public String getServiceName() {
		return "JunctionMaker";
	}

	@Override
	public void onActivityStart() {
	}
	
	@Override
	public void onActivityJoin() {
	}

	@Override
// Path: src/main/java/edu/stanford/junction/api/activity/JunctionService.java
// 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");
// 		
// 		// TODO: register(String sb) doesn't make sense any more.
// 		// Get rid of 'services' in general; just stick an actor to an activity.
// 		XMPPSwitchboardConfig config = new XMPPSwitchboardConfig(switchboard);
// 		JunctionMaker maker = (JunctionMaker) JunctionMaker.getInstance(config);
// 
// 		try{
// 			Junction jx = maker.newJunction(desc, this);
// 			mJunctionMap.put(switchboard, jx);
// 		}
// 		catch(JunctionException e){
// 			System.err.println("Failed to register JunctionService");
// 			e.printStackTrace(System.err);
// 		}
// 	}
// 	
// 	public void setRole(String role) {
// 		mRole=role;
// 	}
// }
// 
// Path: src/main/java/edu/stanford/junction/api/messaging/MessageHandler.java
// public abstract class MessageHandler {
// 	/**
// 	 * Stream-selecting filters;
// 	 * These filters allow Junction to route messages
// 	 * using the network's capabilities.
// 	 * 
// 	 * If we are sending to a fixed actor, try and establish a direct connection.
// 	 * If we are sending to a fixed role or multiple actors, we can
// 	 * potentially multicast.
// 	 * 
// 	 * These methods should return static results (list of actors does not change
// 	 * over the lifetime of the handler)
// 	 */
// 	public List<String> supportedRoles() { return null; } // default is to not filter on roles.
// 	public List<String> supportedActors() { return null; } // default is to not filter on actors.
// 	public List<String> supportedChannels() { return null; } // default is to not filter on channel.
// 	
// 	/**
// 	 * Message-level filter
// 	 * 
// 	 * These filters may be convenient for the end-user.
// 	 * May be useful to support RPC, for example
// 	 * 
// 	 */
// 	public boolean supportsMessage(JSONObject message) { return true; }
// 	// TODO: have a dynamic filter and a static one.
// 	// the static one defines a message template, and this template can be
// 	// shared (like an XML XSD document)
// 	
// 	/**
// 	 * Message handling
// 	 */
// 	public abstract void onMessageReceived(MessageHeader header, JSONObject message);
// 	
// 	/**
// 	 * How to add response capabilities?
// 	 * This should be bridged with Junction.sendMessageToXXX
// 	 * We might need a MessageTarget or something.
// 	 */
// 	// getMessageRecipients;
// 	// getMessageSender;
// 	// replyToSender; 
// 	// replyAll
// }
// 
// Path: src/main/java/edu/stanford/junction/api/messaging/MessageHeader.java
// public class MessageHeader {
// 	private Junction jx;
// 	private JSONObject message;
// 	public String from;
// 	
// 	public MessageHeader(Junction jx, JSONObject message, String from) {
// 		this.jx=jx;
// 		this.message=message;
// 		this.from=from;
// 	}
// 	
// 	
// 	public MessageTarget getReplyTarget() {
// 		if (message.has(Junction.NS_JX)) {
// 			JSONObject h = message.optJSONObject(Junction.NS_JX);
// 			if (h.has("replyTo")) {
// 				return MessageTargetFactory.getInstance(jx).getTarget(h.optString("replyTo"));
// 			}
// 		}
// 		
// 		return MessageTargetFactory.getInstance(jx).getTarget("actor:"+from);
// 	}
// 	
// 	public String getSender() {
// 		return from;
// 	}
// 	
// 	public Junction getJunction() { return jx; }
// }


// Path: src/main/java/edu/stanford/junction/simulator/ForwardingService.java
import org.json.JSONObject;
import edu.stanford.junction.api.activity.JunctionService;
import edu.stanford.junction.api.messaging.MessageHandler;
import edu.stanford.junction.api.messaging.MessageHeader;

/*
 * Copyright (C) 2010 Stanford University
 *
 * 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 edu.stanford.junction.simulator;



/**
 * This class allows a remote client to subscribe to a channel without having
 * to open a new connection for it. It may be useful for a singleton service 
 * expecting to connect to many activities.
 * @author bdodson
 *
 */
public class ForwardingService extends JunctionService {
	private String mChannel; // TODO: this needs to be on another server
	
	private ForwardingService() {}
	public static JunctionService newInstance() {
		return new ForwardingService();
	}
	
	@Override
	public String getServiceName() {
		return "JunctionMaker";
	}

	@Override
	public void onActivityStart() {
	}
	
	@Override
	public void onActivityJoin() {
	}

	@Override
	public void onMessageReceived(MessageHeader header, JSONObject message) {