Add some basic structures to aid in serialize/deserializing
This commit is contained in:
parent
609ffd6a86
commit
7d862f046f
3 changed files with 52 additions and 1 deletions
26
src/main/java/dev/zontreck/ariaslib/xmlrpc/MethodCall.java
Normal file
26
src/main/java/dev/zontreck/ariaslib/xmlrpc/MethodCall.java
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
package dev.zontreck.ariaslib.xmlrpc;
|
||||||
|
|
||||||
|
|
||||||
|
public class MethodCall {
|
||||||
|
private String methodName;
|
||||||
|
private Object[] params;
|
||||||
|
|
||||||
|
public MethodCall ( String methodName , Object[] params ) {
|
||||||
|
this.methodName = methodName;
|
||||||
|
this.params = params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMethodName ( ) {
|
||||||
|
return methodName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object[] getParams ( ) {
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MethodCall fromDeserializer ( XmlRpcDeserializer deserializer ) throws Exception {
|
||||||
|
String methodName = deserializer.readMethodName ( );
|
||||||
|
Object[] params = deserializer.readMethodParams ( );
|
||||||
|
return new MethodCall ( methodName , params );
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package dev.zontreck.ariaslib.xmlrpc;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class MethodResponse {
|
||||||
|
public Map<String, Object> parameters = new HashMap<> ( );
|
||||||
|
|
||||||
|
public MethodResponse ( ) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String toXml ( ) {
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream ( );
|
||||||
|
XmlRpcStreamWriter streamWriter = new XmlRpcStreamWriter ( baos );
|
||||||
|
|
||||||
|
try {
|
||||||
|
streamWriter.writeMethodResponse ( parameters );
|
||||||
|
return new String ( baos.toByteArray ( ) );
|
||||||
|
} catch ( IOException e ) {
|
||||||
|
throw new RuntimeException ( e );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -53,7 +53,6 @@ public class XmlRpcStreamWriter {
|
||||||
writer.write ( PARAM_END_TAG );
|
writer.write ( PARAM_END_TAG );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.write ( PARAMS_END_TAG );
|
writer.write ( PARAMS_END_TAG );
|
||||||
writer.write ( METHOD_CALL_END_TAG );
|
writer.write ( METHOD_CALL_END_TAG );
|
||||||
writer.flush ( );
|
writer.flush ( );
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue