// Path: src/main/java/jmockmongo/CommandHandler.java
// public interface CommandHandler {
// 
// 	public BSONObject handleCommand(String database, BSONObject command);
// 
// }
// 
// Path: src/main/java/jmockmongo/DeleteHandler.java
// public interface DeleteHandler {
// 
// 	public Result handleDelete(String database, String collection,
// 			boolean singleRemove, BSONObject selector);
// }
// 
// Path: src/main/java/jmockmongo/InsertHandler.java
// public interface InsertHandler {
// 
// 	public Result handleInsert(String database, String collection,
// 			boolean continueOnError, Iterator<BSONObject> data);
// }
// 
// Path: src/main/java/jmockmongo/QueryHandler.java
// public interface QueryHandler {
// 
// 	public BSONObject[] handleQuery(String database, String collection,
// 			BSONObject command);
// 
// }
// 
// Path: src/main/java/jmockmongo/Result.java
// public class Result {
// 
// 	// ok - true indicates the getLastError command completed successfully. This
// 	// does NOT indicate there wasn't a last error.
// 	private final boolean ok;
// 
// 	private final int n;
// 
// 	private final String error;
// 
// 	public Result(int n) {
// 		ok = true;
// 		this.n = n;
// 		this.error = null;
// 	}
// 
// 	public Result(String error) {
// 		ok = true;
// 		n = 0;
// 		this.error = error;
// 	}
// 
// 	public boolean isOk() {
// 		return ok;
// 	}
// 
// 	public int getN() {
// 		return n;
// 	}
// 
// 	public BSONObject toBSON() {
// 		BasicBSONObject r = new BasicBSONObject("ok", ok ? 1 : 0)
// 				.append("n", n);
// 		if (error != null)
// 			r.append("err", error);
// 		return r;
// 	}
// 
// }
// 
// Path: src/main/java/jmockmongo/UpdateHandler.java
// public interface UpdateHandler {
// 
// 	public Result handleUpdate(String database, String collection,
// 			boolean upsert, boolean multiUpdate, BSONObject selector,
// 			BSONObject update);
// 
// }


import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
import java.util.HashMap;
import java.util.Map;
import jmockmongo.CommandHandler;
import jmockmongo.DeleteHandler;
import jmockmongo.InsertHandler;
import jmockmongo.QueryHandler;
import jmockmongo.Result;
import jmockmongo.UpdateHandler;
import org.bson.BSONObject;
import org.bson.BasicBSONObject;
/**
 * Copyright (c) 2012, Thilo Planz. All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the Apache License, Version 2.0
 * as published by the Apache Software Foundation (the "License").
 *
 * 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.
 *
 * You should have received a copy of the License along with this program.
 * If not, see <http://www.apache.org/licenses/LICENSE-2.0>.
 */

package jmockmongo.wire;




public class ReplyHandler extends SimpleChannelUpstreamHandler {

	private final Map<String, CommandHandler> commands = new HashMap<String, CommandHandler>();

	private Result lastError;

	private QueryHandler queryHandler;

	private InsertHandler insertHandler;

	private UpdateHandler updateHandler;

	private DeleteHandler deleteHandler;

// Path: src/main/java/jmockmongo/CommandHandler.java
// public interface CommandHandler {
// 
// 	public BSONObject handleCommand(String database, BSONObject command);
// 
// }
// 
// Path: src/main/java/jmockmongo/DeleteHandler.java
// public interface DeleteHandler {
// 
// 	public Result handleDelete(String database, String collection,
// 			boolean singleRemove, BSONObject selector);
// }
// 
// Path: src/main/java/jmockmongo/InsertHandler.java
// public interface InsertHandler {
// 
// 	public Result handleInsert(String database, String collection,
// 			boolean continueOnError, Iterator<BSONObject> data);
// }
// 
// Path: src/main/java/jmockmongo/QueryHandler.java
// public interface QueryHandler {
// 
// 	public BSONObject[] handleQuery(String database, String collection,
// 			BSONObject command);
// 
// }
// 
// Path: src/main/java/jmockmongo/Result.java
// public class Result {
// 
// 	// ok - true indicates the getLastError command completed successfully. This
// 	// does NOT indicate there wasn't a last error.
// 	private final boolean ok;
// 
// 	private final int n;
// 
// 	private final String error;
// 
// 	public Result(int n) {
// 		ok = true;
// 		this.n = n;
// 		this.error = null;
// 	}
// 
// 	public Result(String error) {
// 		ok = true;
// 		n = 0;
// 		this.error = error;
// 	}
// 
// 	public boolean isOk() {
// 		return ok;
// 	}
// 
// 	public int getN() {
// 		return n;
// 	}
// 
// 	public BSONObject toBSON() {
// 		BasicBSONObject r = new BasicBSONObject("ok", ok ? 1 : 0)
// 				.append("n", n);
// 		if (error != null)
// 			r.append("err", error);
// 		return r;
// 	}
// 
// }
// 
// Path: src/main/java/jmockmongo/UpdateHandler.java
// public interface UpdateHandler {
// 
// 	public Result handleUpdate(String database, String collection,
// 			boolean upsert, boolean multiUpdate, BSONObject selector,
// 			BSONObject update);
// 
// }


// Path: src/main/java/jmockmongo/wire/ReplyHandler.java
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
import java.util.HashMap;
import java.util.Map;
import jmockmongo.CommandHandler;
import jmockmongo.DeleteHandler;
import jmockmongo.InsertHandler;
import jmockmongo.QueryHandler;
import jmockmongo.Result;
import jmockmongo.UpdateHandler;
import org.bson.BSONObject;
import org.bson.BasicBSONObject;

/**
 * Copyright (c) 2012, Thilo Planz. All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the Apache License, Version 2.0
 * as published by the Apache Software Foundation (the "License").
 *
 * 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.
 *
 * You should have received a copy of the License along with this program.
 * If not, see <http://www.apache.org/licenses/LICENSE-2.0>.
 */

package jmockmongo.wire;




public class ReplyHandler extends SimpleChannelUpstreamHandler {

	private final Map<String, CommandHandler> commands = new HashMap<String, CommandHandler>();

	private Result lastError;

	private QueryHandler queryHandler;

	private InsertHandler insertHandler;

	private UpdateHandler updateHandler;

	private DeleteHandler deleteHandler;

	public void setCommandHandler(String command, CommandHandler handler) {