Add CommandParserDispatcher to dispatch PrimitiveRequest to matching CommandParser #188
+5
-1
@@ -1,9 +1,13 @@
|
|||||||
package ch.unibas.dmi.dbis.cs108.casono.server.network.parser;
|
package ch.unibas.dmi.dbis.cs108.casono.server.network.parser;
|
||||||
|
|
||||||
/** Parser to convert the PrimitiveRequest to a Request and performing checks for required fields and data types */
|
/**
|
||||||
|
* Parser to convert the PrimitiveRequest to a Request and performing checks for required fields and
|
||||||
|
* data types
|
||||||
|
*/
|
||||||
public interface CommandParser {
|
public interface CommandParser {
|
||||||
/**
|
/**
|
||||||
* Parses the provided PrimitiveRequest into a command-specific request
|
* Parses the provided PrimitiveRequest into a command-specific request
|
||||||
|
*
|
||||||
* @param primitiveRequest
|
* @param primitiveRequest
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
|||||||
+4
-2
@@ -8,8 +8,9 @@ public class CommandParserDispatcher {
|
|||||||
private final Map<String, CommandParser> parsers = new HashMap<>();
|
private final Map<String, CommandParser> parsers = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a new CommandParser
|
* Register a new CommandParser
|
||||||
* @param command
|
*
|
||||||
|
* @param command
|
||||||
* @param parser the parser class
|
* @param parser the parser class
|
||||||
*/
|
*/
|
||||||
public void register(String command, CommandParser parser) {
|
public void register(String command, CommandParser parser) {
|
||||||
@@ -18,6 +19,7 @@ public class CommandParserDispatcher {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the PrimitiveRequest into a Request using the appropriate CommandParser
|
* Parses the PrimitiveRequest into a Request using the appropriate CommandParser
|
||||||
|
*
|
||||||
* @param primitiveRequest the PrimitiveRequest to parse
|
* @param primitiveRequest the PrimitiveRequest to parse
|
||||||
* @return the parsed Request object
|
* @return the parsed Request object
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
package ch.unibas.dmi.dbis.cs108.casono.server.network.parser;
|
package ch.unibas.dmi.dbis.cs108.casono.server.network.parser;
|
||||||
|
|
||||||
/** Request, produced by the CommandParser */
|
/** Request, produced by the CommandParser */
|
||||||
public interface Request {
|
public interface Request {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
+5
-3
@@ -1,8 +1,10 @@
|
|||||||
package ch.unibas.dmi.dbis.cs108.casono.server.network.parser;
|
package ch.unibas.dmi.dbis.cs108.casono.server.network.parser;
|
||||||
|
|
||||||
/** Exception thrown when the CommandParserDispatcher has no registered handler for the provided
|
/**
|
||||||
* request */
|
* Exception thrown when the CommandParserDispatcher has no registered handler for the provided
|
||||||
public class UnknownCommandException extends RuntimeException{
|
* request
|
||||||
|
*/
|
||||||
|
public class UnknownCommandException extends RuntimeException {
|
||||||
public UnknownCommandException(String message) {
|
public UnknownCommandException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user