// Path: src/main/java/edu/stanford/junction/api/activity/JunctionExtra.java
// public abstract class JunctionExtra {
// 	JunctionActor mParent=null;
// 	
// 	/**
// 	 * Provides access to the associated JunctionActor.
// 	 * @return
// 	 */
// 	public final JunctionActor getActor() {
// 		return mParent;
// 	}
// 	
// 	/**
// 	 * This method should only be called internally.
// 	 * @param actor
// 	 */
// 	public void setActor(JunctionActor actor) {
// 		mParent=actor;
// 	}
// 	
// 	/**
// 	 * Update the parameters that will be sent in an invitation
// 	 */
// 	public void updateInvitationParameters(Map<String,String>params) {
// 		
// 	}
// 	
// 	/**
// 	 * Returns true if the normal event handling should proceed;
// 	 * Return false to stop cascading.
// 	 */
// 	public boolean beforeOnMessageReceived(MessageHeader h, JSONObject msg) { return true; }
// 	public void afterOnMessageReceived(MessageHeader h, JSONObject msg) {}
// 	
// 	
// 	public boolean beforeSendMessageToActor(String actorID, JSONObject msg) { return beforeSendMessage(msg); }
// 	public boolean beforeSendMessageToRole(String role, JSONObject msg) { return beforeSendMessage(msg); }
// 	public boolean beforeSendMessageToSession(JSONObject msg) { return beforeSendMessage(msg); }
// 	
// 	/**
// 	 * Convenience method to which, by default, all message sending methods call through.
// 	 * @param msg
// 	 * @return
// 	 */
// 	public boolean beforeSendMessage(JSONObject msg) { return true; }
// 	//public boolean afterSendMessage(Header h, Message msg) {}
// 	
// 	/**
// 	 * Called before an actor joins an activity.
// 	 * Returning false aborts the attempted join.
// 	 */
// 	public boolean beforeActivityJoin() {
// 		return true;
// 	}
// 	
// 	public void afterActivityJoin() {
// 		
// 	}
// 	
// 	/**
// 	 * Called before an actor joins an activity.
// 	 * Returning false aborts the attempted join.
// 	 */
// 	public boolean beforeActivityCreate() {
// 		return true;
// 	}
// 	
// 	public void afterActivityCreate() {
// 		
// 	}
// 
// 	
// 	//public void beforeGetActivityScript();
// 	
// 	/**
// 	 * Returns an integer priority for this Extra.
// 	 * Lower priority means closer to switchboard;
// 	 * Higher means closer to actor.
// 	 */
// 	public Integer getPriority() { return 20; }
// 	
// 	public void test() {
// 		JunctionActor actor =
// 			new JunctionActor("unittest") {			
// 				@Override
// 				public void onMessageReceived(MessageHeader header, JSONObject message) {
// 					System.out.println(message.toString());
// 				}
// 				
// 				@Override
// 				public List<JunctionExtra> getInitialExtras() {
// 					List<JunctionExtra> extras = new ArrayList<JunctionExtra>();
// 					extras.add(JunctionExtra.this);
// 					return extras;
// 				}
// 			};
// 			
// 		try {
// 			// todo: registeredextras here
// 			SwitchboardConfig config = new XMPPSwitchboardConfig("prpl.stanford.edu");
// 			JunctionMaker.getInstance(config).newJunction(new URI("junction://prpl.stanford.edu/junit-test"), actor);
// 			synchronized(this) {
// 				this.wait();
// 			}
// 		} catch (Exception e) {
// 			e.printStackTrace();
// 		}
// 	}
// }
// 
// 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.JunctionExtra;
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.extra;



/**
 * Handles internal System requests. This may include handover to OOB-transport
 * (or, at least, serves as an example for how to do OOB transport)
 * @author bjdodson
 *
 */
public class JXSystem extends JunctionExtra {	
		protected static final String JX_SYSTEM_NS = "JXSYSTEMMSG";
		
		public JXSystem() {
		
		}

		@Override
		public boolean beforeSendMessage(JSONObject msg) {
			// TODO: if message has JXSYSTEMMSG flag, don't allow.
			return super.beforeSendMessage(msg);
		}
		
		@Override

// Path: src/main/java/edu/stanford/junction/api/activity/JunctionExtra.java
// public abstract class JunctionExtra {
// 	JunctionActor mParent=null;
// 	
// 	/**
// 	 * Provides access to the associated JunctionActor.
// 	 * @return
// 	 */
// 	public final JunctionActor getActor() {
// 		return mParent;
// 	}
// 	
// 	/**
// 	 * This method should only be called internally.
// 	 * @param actor
// 	 */
// 	public void setActor(JunctionActor actor) {
// 		mParent=actor;
// 	}
// 	
// 	/**
// 	 * Update the parameters that will be sent in an invitation
// 	 */
// 	public void updateInvitationParameters(Map<String,String>params) {
// 		
// 	}
// 	
// 	/**
// 	 * Returns true if the normal event handling should proceed;
// 	 * Return false to stop cascading.
// 	 */
// 	public boolean beforeOnMessageReceived(MessageHeader h, JSONObject msg) { return true; }
// 	public void afterOnMessageReceived(MessageHeader h, JSONObject msg) {}
// 	
// 	
// 	public boolean beforeSendMessageToActor(String actorID, JSONObject msg) { return beforeSendMessage(msg); }
// 	public boolean beforeSendMessageToRole(String role, JSONObject msg) { return beforeSendMessage(msg); }
// 	public boolean beforeSendMessageToSession(JSONObject msg) { return beforeSendMessage(msg); }
// 	
// 	/**
// 	 * Convenience method to which, by default, all message sending methods call through.
// 	 * @param msg
// 	 * @return
// 	 */
// 	public boolean beforeSendMessage(JSONObject msg) { return true; }
// 	//public boolean afterSendMessage(Header h, Message msg) {}
// 	
// 	/**
// 	 * Called before an actor joins an activity.
// 	 * Returning false aborts the attempted join.
// 	 */
// 	public boolean beforeActivityJoin() {
// 		return true;
// 	}
// 	
// 	public void afterActivityJoin() {
// 		
// 	}
// 	
// 	/**
// 	 * Called before an actor joins an activity.
// 	 * Returning false aborts the attempted join.
// 	 */
// 	public boolean beforeActivityCreate() {
// 		return true;
// 	}
// 	
// 	public void afterActivityCreate() {
// 		
// 	}
// 
// 	
// 	//public void beforeGetActivityScript();
// 	
// 	/**
// 	 * Returns an integer priority for this Extra.
// 	 * Lower priority means closer to switchboard;
// 	 * Higher means closer to actor.
// 	 */
// 	public Integer getPriority() { return 20; }
// 	
// 	public void test() {
// 		JunctionActor actor =
// 			new JunctionActor("unittest") {			
// 				@Override
// 				public void onMessageReceived(MessageHeader header, JSONObject message) {
// 					System.out.println(message.toString());
// 				}
// 				
// 				@Override
// 				public List<JunctionExtra> getInitialExtras() {
// 					List<JunctionExtra> extras = new ArrayList<JunctionExtra>();
// 					extras.add(JunctionExtra.this);
// 					return extras;
// 				}
// 			};
// 			
// 		try {
// 			// todo: registeredextras here
// 			SwitchboardConfig config = new XMPPSwitchboardConfig("prpl.stanford.edu");
// 			JunctionMaker.getInstance(config).newJunction(new URI("junction://prpl.stanford.edu/junit-test"), actor);
// 			synchronized(this) {
// 				this.wait();
// 			}
// 		} catch (Exception e) {
// 			e.printStackTrace();
// 		}
// 	}
// }
// 
// 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/extra/JXSystem.java
import org.json.JSONObject;
import edu.stanford.junction.api.activity.JunctionExtra;
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.extra;



/**
 * Handles internal System requests. This may include handover to OOB-transport
 * (or, at least, serves as an example for how to do OOB transport)
 * @author bjdodson
 *
 */
public class JXSystem extends JunctionExtra {	
		protected static final String JX_SYSTEM_NS = "JXSYSTEMMSG";
		
		public JXSystem() {
		
		}

		@Override
		public boolean beforeSendMessage(JSONObject msg) {
			// TODO: if message has JXSYSTEMMSG flag, don't allow.
			return super.beforeSendMessage(msg);
		}
		
		@Override

		public boolean beforeOnMessageReceived(MessageHeader h, JSONObject msg) {
