+ /**
+ * HELPER: writePropertiesJavaStub() writes the properties of the stub class
+ */
+ private void writePropertiesJavaStub(String intface) {
+
+ println("private IoTRMICall rmiCall;");
+ //println("private IoTRMIObject rmiObj;");
+ println("private String address;");
+ println("private int[] ports;\n");
+ // Get the object Id
+ Integer objId = mapIntfaceObjId.get(intface);
+ println("private final static int objectId = " + objId + ";");
+ mapIntfaceObjId.put(intface, objId++);
+ println("\n");
+ }
+
+
+ /**
+ * HELPER: writeConstructorJavaStub() writes the constructor of the stub class
+ */
+ private void writeConstructorJavaStub(String intface) {
+
+ println("public " + intface + "(int _port, String _address, int _rev, int[] _ports) throws Exception {");
+ println("address = _address;");
+ println("ports = _ports;");
+ println("rmiCall = new IoTRMICall(_port, _address, _rev);");
+ println("}\n");
+ }
+
+
+ /**
+ * HELPER: writeStdMethodBodyJavaStub() writes the standard method body in the stub class
+ */
+ private void writeStdMethodBodyJavaStub(InterfaceDecl intDecl, List<String> methParams,
+ List<String> methPrmTypes, String method) {
+
+ println("int methodId = " + intDecl.getMethodNumId(method) + ";");
+ String retType = intDecl.getMethodType(method);
+ println("Class<?> retType = " + getSimpleType(retType) + ".class;");
+ // Generate array of parameter types
+ print("Class<?>[] paramCls = new Class<?>[] { ");
+ for (int i = 0; i < methParams.size(); i++) {
+ print(getSimpleType(methPrmTypes.get(i)) + ".class");
+ // Check if this is the last element (don't print a comma)
+ if (i != methParams.size() - 1) {
+ print(", ");
+ }
+ }
+ println(" };");
+ // Generate array of parameter objects
+ print("Object[] paramObj = new Object[] { ");
+ for (int i = 0; i < methParams.size(); i++) {
+ print(getSimpleIdentifier(methParams.get(i)));
+ // Check if this is the last element (don't print a comma)
+ if (i != methParams.size() - 1) {
+ print(", ");
+ }
+ }
+ println(" };");
+ // Check if this is "void"
+ if (retType.equals("void")) {
+ println("rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);");
+ } else { // We do have a return value
+ // Check if the return value NONPRIMITIVES
+ if (getParamCategory(retType) == ParamCategory.NONPRIMITIVES) {
+ String[] retGenValType = getTypeOfGeneric(retType);
+ println("Class<?> retGenValType = " + retGenValType[0] + ".class;");
+ println("Object retObj = rmiCall.remoteCall(objectId, methodId, retType, retGenValType, paramCls, paramObj);");
+ println("return (" + retType + ")retObj;");
+ } else {
+ println("Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);");
+ println("return (" + retType + ")retObj;");
+ }
+ }
+ }
+
+