/// <summary> /// Constructs a <code>JrpcgenUnion</code> and sets the identifier, the /// descrimant element as well as all attribute elements. /// </summary> /// <remarks> /// Constructs a <code>JrpcgenUnion</code> and sets the identifier, the /// descrimant element as well as all attribute elements. /// </remarks> /// <param name="identifier">Identifier to be declared.</param> /// <param name="descriminant"> /// Descriminant element of class /// <see cref="JrpcgenDeclaration">JrpcgenDeclaration</see> /// . /// </param> /// <param name="elements"> /// Vector of atrribute elements of class /// <see cref="JrpcgenDeclaration">JrpcgenDeclaration</see> /// . /// </param> public JrpcgenUnion(string identifier, org.acplt.oncrpc.apps.jrpcgen.JrpcgenDeclaration descriminant, System.Collections.ArrayList elements) { this.identifier = identifier; this.descriminant = descriminant; this.elements = elements; }
/// <summary> /// Constructs a <code>JrpcgenUnion</code> and sets the identifier, the /// descrimant element as well as all attribute elements. /// </summary> /// <remarks> /// Constructs a <code>JrpcgenUnion</code> and sets the identifier, the /// descrimant element as well as all attribute elements. /// </remarks> /// <param name="identifier">Identifier to be declared.</param> /// <param name="descriminant"> /// Descriminant element of class /// <see cref="JrpcgenDeclaration">JrpcgenDeclaration</see> /// . /// </param> /// <param name="elements"> /// Vector of atrribute elements of class /// <see cref="JrpcgenDeclaration">JrpcgenDeclaration</see> /// . /// </param> public JrpcgenUnion(string identifier, org.acplt.oncrpc.apps.jrpcgen.JrpcgenDeclaration descriminant, System.Collections.ArrayList elements) { this.identifier = identifier; this.descriminant = descriminant; this.elements = elements; }
/// <summary> /// Dumps the structure together with its attribute elements to /// <code>System.out</code>. /// </summary> /// <remarks> /// Dumps the structure together with its attribute elements to /// <code>System.out</code>. /// </remarks> public virtual void dump() { System.Console.Out.WriteLine("STRUCT " + identifier + ":"); int size = elements.Count; for (int idx = 0; idx < size; ++idx) { org.acplt.oncrpc.apps.jrpcgen.JrpcgenDeclaration d = (org.acplt.oncrpc.apps.jrpcgen.JrpcgenDeclaration )elements[idx]; System.Console.Out.Write(" "); d.dump(); } System.Console.Out.WriteLine(); }
internal static void dumpServerStubStructs(StreamWriter @out, org.acplt.oncrpc.apps.jrpcgen.JrpcgenProcedureInfo proc) { // // Check for special return types, like enumerations, which we // map to their corresponding Java base data type. // string resultType = checkForSpecials(proc.resultType); // // If the remote procedure does not have any parameters, then // parameters will be null. Otherwise it contains a vector with // information about the individual parameters, which we use // in order to generate the parameter list. Note that all // parameters are named at this point (they will either have a // user supplied name, or an automatically generated one). // if (proc.parameters != null) { int psize = proc.parameters.Count; // // Now find out what kind of parameter(s) we have. In case // the remote procedure only expects a single parameter, check // whether it is a base type. In this case we later need to // wrap the single parameter. If the remote procedure expects // more than a single parameter, then we always need a // XDR wrapper. // if (psize > 1) { // // // System.Text.StringBuilder paramsBuff = new System.Text.StringBuilder(); @out.WriteLine(" class XdrAble_" + proc.procedureNumber + " : XdrAble {"); for (int pidx = 0; pidx < psize; ++pidx) { org.acplt.oncrpc.apps.jrpcgen.JrpcgenParamInfo pinfo = (org.acplt.oncrpc.apps.jrpcgen.JrpcgenParamInfo )proc.parameters[pidx]; @out.WriteLine(" public " + checkForSpecials(pinfo.parameterType ) + " " + pinfo.parameterName + ";"); } @out.WriteLine(" public void xdrEncode(XdrEncodingStream xdr) {"); @out.WriteLine(" }"); @out.WriteLine(" public void xdrDecode(XdrDecodingStream xdr) {"); // // Emit serialization code for all parameters. // Note that not we do not need to deal with all kinds of // parameters here, as things like "int<5>" are invalid, // a typedef declaration is then necessary. // org.acplt.oncrpc.apps.jrpcgen.JrpcgenDeclaration decl = new org.acplt.oncrpc.apps.jrpcgen.JrpcgenDeclaration (null, null); for (int pidx = 0; pidx < psize; ++pidx) { org.acplt.oncrpc.apps.jrpcgen.JrpcgenParamInfo pinfo = (org.acplt.oncrpc.apps.jrpcgen.JrpcgenParamInfo )proc.parameters[pidx]; decl.kind = org.acplt.oncrpc.apps.jrpcgen.JrpcgenDeclaration.SCALAR; decl.identifier = pinfo.parameterName; decl.type = pinfo.parameterType; @out.Write(" "); @out.Write(codingMethod(decl, false)); } @out.WriteLine(" }"); @out.WriteLine(" };"); } } }
/// <summary> /// Generate source code for client-side stub methods for a particular /// remote program version. /// </summary> /// <remarks> /// Generate source code for client-side stub methods for a particular /// remote program version. The client-side stub methods take the /// parameter(s) from the caller, encode them and throw them over to the /// server. After receiving a reply, they will unpack and return it as /// the outcome of the method call. /// </remarks> /// <param name="out">Printer writer to send source code to.</param> /// <param name="versionInfo"> /// Information about the remote program version for /// which source code is to be generated. /// </param> internal static void dumpClientStubMethods(StreamWriter @out, org.acplt.oncrpc.apps.jrpcgen.JrpcgenVersionInfo versionInfo) { int size = versionInfo.procedures.Count; for (int idx = 0; idx < size; ++idx) { org.acplt.oncrpc.apps.jrpcgen.JrpcgenProcedureInfo proc = (org.acplt.oncrpc.apps.jrpcgen.JrpcgenProcedureInfo )versionInfo.procedures[idx]; string paramClassName = ""; if (proc.parameters != null && proc.parameters.Count > 1) { paramClassName = "XdrAble_" + proc.procedureNumber; @out.WriteLine(" class " + paramClassName + ": XdrAble {"); int psize = proc.parameters.Count; for (int pidx = 0; pidx < psize; ++pidx) { org.acplt.oncrpc.apps.jrpcgen.JrpcgenParamInfo pinfo = (org.acplt.oncrpc.apps.jrpcgen.JrpcgenParamInfo )proc.parameters[pidx]; @out.WriteLine(" public " + checkForSpecials(pinfo.parameterType) + " " + pinfo.parameterName + ";"); } @out.WriteLine(" public void xdrEncode(XdrEncodingStream xdr) {"); // // Emit serialization code for all parameters. // Note that not we do not need to deal with all kinds of // parameters here, as things like "int<5>" are invalid, // a typedef declaration is then necessary. // org.acplt.oncrpc.apps.jrpcgen.JrpcgenDeclaration decl = new org.acplt.oncrpc.apps.jrpcgen.JrpcgenDeclaration (null, null); for (int pidx = 0; pidx < psize; ++pidx) { org.acplt.oncrpc.apps.jrpcgen.JrpcgenParamInfo pinfo = (org.acplt.oncrpc.apps.jrpcgen.JrpcgenParamInfo )proc.parameters[pidx]; decl.kind = org.acplt.oncrpc.apps.jrpcgen.JrpcgenDeclaration.SCALAR; decl.identifier = pinfo.parameterName; decl.type = pinfo.parameterType; @out.Write(" "); @out.Write(codingMethod(decl, true)); } @out.WriteLine(" }"); @out.WriteLine(" public void xdrDecode(XdrDecodingStream xdr) {"); @out.WriteLine(" }"); @out.WriteLine(" };"); } // // First spit out the stub method. While we don't need to // fiddle around with the data types of the method's // parameter(s) and result, we later have to care about // some primitive data types when serializing them. // string resultType = checkForSpecials(proc.resultType); @out.WriteLine(" /**"); @out.WriteLine(" * Call remote procedure " + proc.procedureId + "."); // // If there are no parameters, skip the parameter documentation // section, otherwise dump javadoc @param entries for every // parameter encountered. // if (proc.parameters != null) { System.Collections.IEnumerator @params = proc.parameters.GetEnumerator(); while (@params.MoveNext()) { org.acplt.oncrpc.apps.jrpcgen.JrpcgenParamInfo param = (org.acplt.oncrpc.apps.jrpcgen.JrpcgenParamInfo )@params.Current; @out.WriteLine(" * @param " + param.parameterName + " parameter (of type " + param .parameterType + ") to the remote procedure call."); } } // // Only generate javadoc for result, when it is non-void. // if (proc.resultType.CompareTo("void") != 0) { @out.WriteLine(" * @return Result from remote procedure call (of type " + proc. resultType + ")."); } @out.WriteLine(" * @throws OncRpcException if an ONC/RPC error occurs."); @out.WriteLine(" * @throws IOException if an I/O error occurs."); @out.WriteLine(" */"); @out.Write(" public " + resultType + " " + proc.procedureId + "("); // // If the remote procedure does not have any parameters, then // parameters will be null. Otherwise it contains a vector with // information about the individual parameters, which we use // in order to generate the parameter list. Note that all // parameters are named at this point (they will either have a // user supplied name, or an automatically generated one). // int paramsKind; if (proc.parameters != null) { int psize = proc.parameters.Count; for (int pidx = 0; pidx < psize; ++pidx) { org.acplt.oncrpc.apps.jrpcgen.JrpcgenParamInfo paramInfo = (org.acplt.oncrpc.apps.jrpcgen.JrpcgenParamInfo )proc.parameters[pidx]; if (pidx > 0) { @out.Write(", "); } @out.Write(checkForSpecials(paramInfo.parameterType)); @out.Write(" "); @out.Write(paramInfo.parameterName); } // // Now find out what kind of parameter(s) we have. In case // the remote procedure only expects a single parameter, check // whether it is a base type. In this case we later need to // wrap the single parameter. If the remote procedure expects // more than a single parameter, then we always need a // XDR wrapper. // if (psize > 1) { paramsKind = PARAMS_MORE; } else { // // psize must be equal to one, otherwise proc.parameters // must have been null. // string firstParamType = ((org.acplt.oncrpc.apps.jrpcgen.JrpcgenParamInfo)proc.parameters [0]).parameterType; if (xdrBaseType(checkForSpecials(firstParamType)) == null) { // // No, it is not a base type, so we don't need one // of the special XDR wrapper classes. // paramsKind = PARAMS_SINGLE; } else { // // The single parameter to the remote procedure is // a base type, so we will later need a wrapper. // paramsKind = PARAMS_SINGLE_BASETYPE; } } } else { // // Remote procedure does not expect parameters at all. // paramsKind = PARAMS_VOID; } @out.WriteLine(") {"); // // Do generate code for wrapping parameters here, if necessary. // string xdrParamsName = null; switch (paramsKind) { case PARAMS_VOID: { // Name of variable representing XDR-able arguments xdrParamsName = "args_"; @out.WriteLine(" XdrVoid args_ = XdrVoid.XDR_VOID;"); break; } case PARAMS_SINGLE: { org.acplt.oncrpc.apps.jrpcgen.JrpcgenParamInfo paramInfo = (org.acplt.oncrpc.apps.jrpcgen.JrpcgenParamInfo )proc.parameters[0]; xdrParamsName = paramInfo.parameterName; // // We do not need to emit an args_ declaration here, as we // can immediately make use of the one and only argument // the remote procedure expects. // break; } case PARAMS_SINGLE_BASETYPE: { org.acplt.oncrpc.apps.jrpcgen.JrpcgenParamInfo paramInfo = (org.acplt.oncrpc.apps.jrpcgen.JrpcgenParamInfo )proc.parameters[0]; xdrParamsName = "args_"; string xdrParamsType = xdrBaseType(checkForSpecials(paramInfo.parameterType)); @out.WriteLine(" " + xdrParamsType + " args_ = new " + xdrParamsType + "(" + paramInfo.parameterName + ");"); break; } case PARAMS_MORE: { xdrParamsName = "args_"; int psize = proc.parameters.Count; @out.WriteLine(" " + paramClassName + " args_ = new " + paramClassName + "();"); for (int pidx = 0; pidx < psize; ++pidx) { org.acplt.oncrpc.apps.jrpcgen.JrpcgenParamInfo pinfo = (org.acplt.oncrpc.apps.jrpcgen.JrpcgenParamInfo )proc.parameters[pidx]; @out.WriteLine(" args_." + pinfo.parameterName + " = " + pinfo.parameterName + ";"); } break; } } // // Check the return data type of the result to be of one of // the base data types, like int, boolean, etc. In this case we // have to unwrap the result from one of the special XDR wrapper // classes and return the base data type instead. // string xdrResultType = xdrBaseType(resultType); // // Handle the result of the method: similiar to what we did // above. However, in all other cases we always need to // create a result object, regardless of whether we have to // deal with a basic data type (except void) or with some // "complex" data type. // if (resultType.Equals("void")) { @out.WriteLine(" XdrVoid result_ = XdrVoid.XDR_VOID;"); } else { if (xdrResultType != null) { @out.WriteLine(" " + xdrResultType + " result_ = new " + xdrResultType + "();" ); } else { @out.WriteLine(" " + resultType + " result_ = new " + resultType + "();"); } } // // Now emit the real ONC/RPC call using the (optionally // wrapped) parameter and (optionally wrapped) result. // if (clampProgAndVers) { @out.WriteLine(" client.call(" + baseClassname + "." + proc.procedureId + ", " + baseClassname + "." + versionInfo.versionId + ", " + xdrParamsName + ", result_);" ); } else { @out.WriteLine(" client.call(" + baseClassname + "." + proc.procedureId + ", client.getVersion(), " + xdrParamsName + ", result_);"); } // // In case of a wrapped result we need to return the value // of the wrapper, otherwise we can return the result // itself (which then is not a base data type). As a special // case, we can not return void values...anyone for a // language design with first class void objects?! // if (xdrResultType != null) { // // Data type of result is a Java base data type, so we need // to unwrap the XDR-able result -- if it's not a void, which // we do not need to return at all. // if (!resultType.Equals("void")) { @out.WriteLine(" return result_." + resultType.ToLower() + "Value();"); } } else { // // Data type of result is a complex type (class), so we // do not unwrap it but can return it immediately. // @out.WriteLine(" return result_;"); } // // Close the stub method (just as a hint, as it is // getting rather difficult to see what code is produced // at this stage...) // @out.WriteLine(" }"); @out.WriteLine(); } }
/// <summary> /// Constructs a <code>JrpcgenUnionArm</code> and sets decrimated arm's /// value and the associated attribute element. /// </summary> /// <remarks> /// Constructs a <code>JrpcgenUnionArm</code> and sets decrimated arm's /// value and the associated attribute element. /// </remarks> /// <param name="value">Value for which descriminated arm is valid.</param> /// <param name="element"> /// Descriminated arm element of class /// <see cref="JrpcgenDeclaration">JrpcgenDeclaration</see> /// . /// </param> public JrpcgenUnionArm(string value, org.acplt.oncrpc.apps.jrpcgen.JrpcgenDeclaration element) { this.value = value; this.element = element; }
/// <summary> /// Constructs a <code>JrpcgenUnionArm</code> and sets decrimated arm's /// value and the associated attribute element. /// </summary> /// <remarks> /// Constructs a <code>JrpcgenUnionArm</code> and sets decrimated arm's /// value and the associated attribute element. /// </remarks> /// <param name="value">Value for which descriminated arm is valid.</param> /// <param name="element"> /// Descriminated arm element of class /// <see cref="JrpcgenDeclaration">JrpcgenDeclaration</see> /// . /// </param> public JrpcgenUnionArm(string value, org.acplt.oncrpc.apps.jrpcgen.JrpcgenDeclaration element) { this.value = value; this.element = element; }