**/
private void writeSkeletonDispatchCase(IndentingWriter p, int opnum)
throws IOException
{
RemoteClass.Method method = remoteMethods[opnum];
MethodDoc methodDoc = method.methodDoc();
String methodName = methodDoc.name();
Type paramTypes[] = method.parameterTypes();
String paramNames[] = nameParameters(paramTypes);
Type returnType = methodDoc.returnType();
p.pOlnI("case " + opnum + ": // " +
Util.getFriendlyUnqualifiedSignature(methodDoc));
/*
* Use nested block statement inside case to provide an independent
* namespace for local variables used to unmarshal parameters for
* this remote method.
*/
p.pOlnI("{");
if (paramTypes.length > 0) {
/*
* Declare local variables to hold arguments.
*/
for (int i = 0; i < paramTypes.length; i++) {
p.pln(paramTypes[i].toString() + " " + paramNames[i] + ";");
}
/*
* Unmarshal arguments from call stream.
*/
p.plnI("try {");
p.pln("java.io.ObjectInput in = call.getInputStream();");
boolean objectsRead = writeUnmarshalArguments(p, "in",
paramTypes, paramNames);
p.pOlnI("} catch (java.io.IOException e) {");
p.pln("throw new " + UNMARSHAL_EXCEPTION +
"(\"error unmarshalling arguments\", e);");
/*
* If any only if readObject has been invoked, we must catch
* ClassNotFoundException as well as IOException.
*/
if (objectsRead) {
p.pOlnI("} catch (java.lang.ClassNotFoundException e) {");
p.pln("throw new " + UNMARSHAL_EXCEPTION +
"(\"error unmarshalling arguments\", e);");
}
p.pOlnI("} finally {");
p.pln("call.releaseInputStream();");
p.pOln("}");
} else {
p.pln("call.releaseInputStream();");
}
if (!Util.isVoid(returnType)) {
/*
* Declare variable to hold return type, if not void.
*/
p.p(returnType.toString() + " $result = ");
// REMIND: why $?
}
/*
* Invoke the method on the server object. If the remote
* implementation class is private, then we don't have a
* reference cast to it, and so we try to cast to the remote
* object reference to the method's declaring interface here.
*/
String target = remoteClass.classDoc().isPrivate() ?
"((" + methodDoc.containingClass().qualifiedName() + ") obj)" :
"server";
p.p(target + "." + methodName + "(");
for (int i = 0; i < paramNames.length; i++) {
if (i > 0)
p.p(", ");