edu.washington.cs.sounddetector.server.api
Class MethodConverter

java.lang.Object
  extended by edu.washington.cs.sounddetector.server.api.MethodConverter

public class MethodConverter
extends Object

MethodConverter handles the serialization and deserialization of Method and MethodResult objects. It also provides a way to retrieve the class of a method implementation given its name.

MethodConverter is immutable and threadsafe.

Author:
the.dylan.price@gmail.com

Method Summary
<T extends Method>
T
deserializeMethod(Reader reader, Class<T> type)
          Deserializes from contents of the given reader into a Method of the given type.
<T extends Method>
T
deserializeMethod(String serialized, Class<T> type)
          Deserializes the contents of the given String into a Method of the given type.
<T extends MethodResult<?>>
T
deserializeResult(Reader reader, Class<T> type)
          Deserializes from the contents of the given reader into a MethodResult of the given type.
<T extends MethodResult<?>>
T
deserializeResult(String serialized, Class<T> type)
          Deserializes the contents of the given String into a MethodResult of the given type.
static MethodConverter getInstance()
           
 Class<? extends Method> getMethodClass(String methodName)
          Returns the class implementing the Method interface which corresponds to the given methodName.
 String serializeMethod(Method command)
          Converts the given command into its serialized form which can be sent over the wire.
<T extends Method>
String
serializeResult(MethodResult<T> result)
          Converts the given result into its serialized form which can be sent over the wire.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

serializeMethod

public String serializeMethod(Method command)
                       throws org.codehaus.jackson.JsonGenerationException,
                              org.codehaus.jackson.map.JsonMappingException,
                              IOException
Converts the given command into its serialized form which can be sent over the wire.

Parameters:
command - the command to serialize.
Returns:
the serialized form of command.
Throws:
IOException
org.codehaus.jackson.map.JsonMappingException
org.codehaus.jackson.JsonGenerationException

serializeResult

public <T extends Method> String serializeResult(MethodResult<T> result)
                       throws org.codehaus.jackson.JsonGenerationException,
                              org.codehaus.jackson.map.JsonMappingException,
                              IOException
Converts the given result into its serialized form which can be sent over the wire.

Parameters:
result - the result to serialize
Returns:
the serialized form of the result
Throws:
IOException
org.codehaus.jackson.map.JsonMappingException
org.codehaus.jackson.JsonGenerationException

deserializeMethod

public <T extends Method> T deserializeMethod(Reader reader,
                                              Class<T> type)
                                   throws org.codehaus.jackson.JsonParseException,
                                          org.codehaus.jackson.map.JsonMappingException,
                                          IOException
Deserializes from contents of the given reader into a Method of the given type. Reads from the reader until the Method can be parsed, but does not close it.

Parameters:
reader - a Reader ready to stream the serialized form of a Method. The reader will still be open after the call.
type - the type of Method to deserialize the contents of the reader into.
Returns:
a Method of class 'type', representing the deserialized contents of the characters read from the reader.
Throws:
IOException
org.codehaus.jackson.map.JsonMappingException
org.codehaus.jackson.JsonParseException

deserializeMethod

public <T extends Method> T deserializeMethod(String serialized,
                                              Class<T> type)
                                   throws org.codehaus.jackson.JsonParseException,
                                          org.codehaus.jackson.map.JsonMappingException,
                                          IOException
Deserializes the contents of the given String into a Method of the given type.

Parameters:
serialized - a String containing the serialized form of a Method.
type - the type of Method to deserialize the contents of serialized into.
Returns:
a Method of class 'type', representing the deserialized contents of serialized.
Throws:
IOException
org.codehaus.jackson.map.JsonMappingException
org.codehaus.jackson.JsonParseException

deserializeResult

public <T extends MethodResult<?>> T deserializeResult(Reader reader,
                                                       Class<T> type)
                                            throws org.codehaus.jackson.JsonParseException,
                                                   org.codehaus.jackson.map.JsonMappingException,
                                                   IOException
Deserializes from the contents of the given reader into a MethodResult of the given type. Reads from the reader until the Method can be parsed but does not close it.

Parameters:
reader - a Reader ready to stream the serialized form of a MethodResult. The reader will still be open after the call.
type - the type of MethodResult to deserialize the contents of the reader into.
Returns:
a MethodResult of class 'type', representing the deserialized contents of characters read from the reader.
Throws:
IOException
org.codehaus.jackson.map.JsonMappingException
org.codehaus.jackson.JsonParseException

deserializeResult

public <T extends MethodResult<?>> T deserializeResult(String serialized,
                                                       Class<T> type)
                                            throws org.codehaus.jackson.JsonParseException,
                                                   org.codehaus.jackson.map.JsonMappingException,
                                                   IOException
Deserializes the contents of the given String into a MethodResult of the given type.

Parameters:
serialized - a String containing the serialized form of a MethodResult
type - the type of MethodResult to deserialize the String into
Returns:
a MethodResult of class 'type' representing the deserialized contents of the string
Throws:
IOException
org.codehaus.jackson.map.JsonMappingException
org.codehaus.jackson.JsonParseException

getMethodClass

public Class<? extends Method> getMethodClass(String methodName)
Returns the class implementing the Method interface which corresponds to the given methodName.

Parameters:
methodName - the name of a method. Returns null if no method with the given methodName exists.
Returns:
the class of an implementation of the Method interface which corresponds to the given methodName.

getInstance

public static MethodConverter getInstance()
Returns:
the singleton MethodConverter instance.


Copyright © 2012. All Rights Reserved.