Java Code Examples for sun.rmi.rmic.IndentingWriter#p()

The following examples show how to use sun.rmi.rmic.IndentingWriter#p() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IDLGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Write forward reference for given type
 * @param t Given type
 * @param p The output stream.
 */
protected void writeForwardReference(
                                     Type t,
                                     IndentingWriter p )
    throws IOException {
    String qName = t.getQualifiedName();
    if ( "java.lang.String".equals( qName ) ) ;
    else if ( "org.omg.CORBA.Object".equals( qName ) ) return ;    //no fwd dcl

    writeIfndef( t,0,!isException,isForward,p );
        writeModule1( t,p );
        p.pln();p.pI();
        switch ( t.getTypeCode() ) {
    case TYPE_NC_CLASS:
        case TYPE_NC_INTERFACE: p.p( "abstract valuetype " ); break;
        case TYPE_ABSTRACT:     p.p( "abstract interface " ); break;
        case TYPE_VALUE:        p.p( "valuetype " ); break;
    case TYPE_REMOTE:
    case TYPE_CORBA_OBJECT: p.p( "interface " ); break;
        default: ;                              //all other types were filtered
        }
        p.pln( t.getIDLName() + ";" );
        p.pO();p.pln();
        writeModule2( t,p );
    writeEndif( p );
    }
 
Example 2
Source File: IDLGenerator.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Write an IDL constant
 * @param constant The current CompoundType.Member constant
 * @param p The output stream.
 */
protected void writeConstant(
                             CompoundType.Member constant,
                             IndentingWriter p )
    throws IOException {
    Type t = constant.getType();
    p.p( "const " );
    p.p( getQualifiedIDLName( t ) );
    p.p( " " + constant.getIDLName() + " = " + constant.getValue() );
    p.pln( ";" );
}
 
Example 3
Source File: IDLGenerator.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Write an IDL Attribute
 * @param attr The current CompoundType.Method attribute
 * @param p The output stream.
 */
protected void writeAttribute(
                              CompoundType.Method attr,
                              IndentingWriter p )
    throws IOException {
    if ( attr.getAttributeKind() == ATTRIBUTE_SET ) return;  //use getters only
    Type t = attr.getReturnType();
    if ( !attr.isReadWriteAttribute() ) p.p( "readonly " );
    p.p( "attribute " + getQualifiedIDLName( t ) + " " );
    p.pln( attr.getAttributeName() + ";" );
}
 
Example 4
Source File: IDLGenerator.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Write IDL banner into the output stream for a given Type
 * @param t The given Type.
 * @param dim The dimension required if t is an ArrayType.
 * @param isException true if writing an exception.
 * @param p The output stream.
 */
protected void writeBanner(
                           Type t,
                           int dim,
                           boolean isException,
                           IndentingWriter p )
    throws IOException {
    String[] modNames = getIDLModuleNames( t );             //module name array
    String fName = unEsc( t.getIDLName() );                 //file name default
    if ( isException && t.isClass() ) {
        ClassType ct = (ClassType)t;                    //file name for Exception
        fName = unEsc( ct.getIDLExceptionName() );
    }
    if ( dim > 0 && t.isArray() ) {
        Type et = t.getElementType();                    //file name for sequence
        fName = "seq" + dim + "_" + unEsc( et.getIDLName().replace( ' ','_' ) );
    }

    p.pln( "/**" );
    p.p( " * " );
    for ( int i1 = 0; i1 < modNames.length; i1++ )
        p.p( modNames[i1] + "/" );
    p.pln( fName + ".idl" );
    p.pln( " * Generated by rmic -idl. Do not edit" );
    String d = DateFormat.getDateTimeInstance(
                                              DateFormat.FULL,DateFormat.FULL,Locale.getDefault() )
        .format( new Date() );
    String ocStr = "o'clock";
    int ocx = d.indexOf( ocStr );             //remove unwanted o'clock, if any
    p.p ( " * " );
    if ( ocx > -1 )
        p.pln( d.substring( 0,ocx ) + d.substring( ocx + ocStr.length() ) );
    else p.pln( d );
    p.pln( " */" );
    p.pln();
}
 
Example 5
Source File: CompoundType.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected void printMembers (       IndentingWriter writer,
                                    boolean useQualifiedNames,
                                    boolean useIDLNames,
                                    boolean globalIDLNames) throws IOException {

    CompoundType.Member[] members = getMembers();

    for (int i = 0; i < members.length; i++) {
        if (!members[i].isInnerClassDeclaration()) {
            Type it = members[i].getType();
            String visibility = members[i].getVisibility();
            String name;

            if (useIDLNames) {
                name = members[i].getIDLName();
            } else {
                name = members[i].getName();
            }

            String value = members[i].getValue();

            writer.p(visibility);
            if (visibility.length() > 0) {
                writer.p(" ");
            }
            it.printTypeName(writer,useQualifiedNames,useIDLNames,globalIDLNames);
            writer.p(" " + name);

            if (value != null) {
                writer.pln(" = " + value + ";");
            } else {
                writer.pln(";");
            }
        }
    }
}
 
Example 6
Source File: CompoundType.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
protected void printImplements (IndentingWriter writer,
                                String prefix,
                                boolean useQualifiedNames,
                                boolean useIDLNames,
                                boolean globalIDLNames) throws IOException {

    InterfaceType[] interfaces = getInterfaces();

    String adjective = " implements";

    if (isInterface()) {
        adjective = " extends";
    }

    if (useIDLNames) {
        adjective = ":";
    }

    for (int i = 0; i < interfaces.length; i++) {
        if (!useIDLNames || (!interfaces[i].isType(TYPE_ANY) && !interfaces[i].isType(TYPE_CORBA_OBJECT))) {
            if (i == 0) {
                writer.p(prefix + adjective + " ");
            } else {
                writer.p(", ");
            }
            interfaces[i].printTypeName(writer,useQualifiedNames,useIDLNames,globalIDLNames);
        }
    }
}
 
Example 7
Source File: IDLGenerator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Write valuetype for a boxed IDLEntity.
 * @param t Given CompoundType representing the IDLEntity.
 * @param p The output stream.
 */
protected void writeBoxedIDL(
                             CompoundType t,
                             IndentingWriter p)
    throws IOException {
    String[] boxNames = getIDLModuleNames( t );
    int len = boxNames.length;
    String[] modNames = new String[len - 3];               //remove box modules
    for ( int i1 = 0; i1 < len - 3; i1++ ) modNames[i1] = boxNames[i1 + 3];
    String tName = unEsc( t.getIDLName() );

    writeBanner( t,0,!isException,p );
    writeInclude( t,modNames,tName,p );
    writeIfndef( t,0,!isException,!isForward,p );
    writeModule1( t,p );
    p.pln();p.pI();

    p.p( "valuetype " + tName + " " );
    for ( int i1 = 0; i1 < modNames.length; i1++ )
        p.p( IDL_NAME_SEPARATOR + modNames[i1] );
    p.pln( IDL_NAME_SEPARATOR + tName + ";" );

    p.pO();p.pln();
    writeRepositoryID( t,p );
    p.pln();
    writeModule2( t,p );
    writeEndif( p );
    }
 
Example 8
Source File: ClassType.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Print this type.
 * @param writer The stream to print to.
 * @param useQualifiedNames If true, print qualified names; otherwise, print unqualified names.
 * @param useIDLNames If true, print IDL names; otherwise, print java names.
 * @param globalIDLNames If true and useIDLNames true, prepends "::".
 */
public void print ( IndentingWriter writer,
                    boolean useQualifiedNames,
                    boolean useIDLNames,
                    boolean globalIDLNames) throws IOException {

    if (isInner()) {
        writer.p("// " + getTypeDescription() + " (INNER)");
    } else {
        writer.p("// " + getTypeDescription());
    }
    writer.pln(" (" + getRepositoryID() + ")\n");

    printPackageOpen(writer,useIDLNames);

    if (!useIDLNames) {
        writer.p("public ");
    }

    String prefix = "";
    writer.p("class " + getTypeName(false,useIDLNames,false));
    if (printExtends(writer,useQualifiedNames,useIDLNames,globalIDLNames)) {
        prefix = ",";
    }
    printImplements(writer,prefix,useQualifiedNames,useIDLNames,globalIDLNames);
    writer.plnI(" {");
    printMembers(writer,useQualifiedNames,useIDLNames,globalIDLNames);
    writer.pln();
    printMethods(writer,useQualifiedNames,useIDLNames,globalIDLNames);

    if (useIDLNames) {
        writer.pOln("};");
    } else {
        writer.pOln("}");
    }

    printPackageClose(writer,useIDLNames);
}
 
Example 9
Source File: CompoundType.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected void printImplements (IndentingWriter writer,
                                String prefix,
                                boolean useQualifiedNames,
                                boolean useIDLNames,
                                boolean globalIDLNames) throws IOException {

    InterfaceType[] interfaces = getInterfaces();

    String adjective = " implements";

    if (isInterface()) {
        adjective = " extends";
    }

    if (useIDLNames) {
        adjective = ":";
    }

    for (int i = 0; i < interfaces.length; i++) {
        if (!useIDLNames || (!interfaces[i].isType(TYPE_ANY) && !interfaces[i].isType(TYPE_CORBA_OBJECT))) {
            if (i == 0) {
                writer.p(prefix + adjective + " ");
            } else {
                writer.p(", ");
            }
            interfaces[i].printTypeName(writer,useQualifiedNames,useIDLNames,globalIDLNames);
        }
    }
}
 
Example 10
Source File: InterfaceType.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Print this type.
 * @param writer The stream to print to.
 * @param useQualifiedNames If true, print qualified names; otherwise, print unqualified names.
 * @param useIDLNames If true, print IDL names; otherwise, print java names.
 * @param globalIDLNames If true and useIDLNames true, prepends "::".
 */
public void print ( IndentingWriter writer,
                    boolean useQualifiedNames,
                    boolean useIDLNames,
                    boolean globalIDLNames) throws IOException {

    if (isInner()) {
        writer.p("// " + getTypeDescription() + " (INNER)");
    } else {
        writer.p("// " + getTypeDescription() + "");
    }
    writer.pln(" (" + getRepositoryID() + ")\n");
    printPackageOpen(writer,useIDLNames);

    if (!useIDLNames) {
        writer.p("public ");
    }

    writer.p("interface " + getTypeName(false,useIDLNames,false));
    printImplements(writer,"",useQualifiedNames,useIDLNames,globalIDLNames);
    writer.plnI(" {");
    printMembers(writer,useQualifiedNames,useIDLNames,globalIDLNames);
    writer.pln();
    printMethods(writer,useQualifiedNames,useIDLNames,globalIDLNames);
    writer.pln();

    if (useIDLNames) {
        writer.pOln("};");
    } else {
        writer.pOln("}");
    }
    printPackageClose(writer,useIDLNames);
}
 
Example 11
Source File: IDLGenerator.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Write an IDL data member
 * @param data The current CompoundType.Member data member
 * @param p The output stream.
 */
protected void writeData(
                         CompoundType.Member data,
                         IndentingWriter p )
    throws IOException {
    if ( data.isInnerClassDeclaration() ) return;                      //ignore
    Type t = data.getType();
    if ( data.isPublic() )
        p.p( "public " );
    else p.p( "private " );
    p.pln( getQualifiedIDLName( t ) +  " " +
           data.getIDLName() + ";" );
}
 
Example 12
Source File: CompoundType.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected boolean printExtends (IndentingWriter writer,
                                boolean useQualifiedNames,
                                boolean useIDLNames,
                                boolean globalIDLNames) throws IOException {

    ClassType parent = getSuperclass();

    if (parent != null && (!useIDLNames ||
                           (!parent.isType(TYPE_ANY) && !parent.isType(TYPE_CORBA_OBJECT)))) {
        writer.p(" extends ");
        parent.printTypeName(writer,useQualifiedNames,useIDLNames,globalIDLNames);
        return true;
    }
    return false;
}
 
Example 13
Source File: StubGenerator.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
void writeTieMethod(IndentingWriter p, CompoundType type,
                    CompoundType.Method method) throws IOException {
    String methodName = method.getName();
    Type paramTypes[] = method.getArguments();
    String paramNames[] = method.getArgumentNames();
    Type returnType = method.getReturnType();
    ValueType[] exceptions = getTieExceptions(method);
    String in = getVariableName("in");
    String ex = getVariableName("ex");
    String out = getVariableName("out");
    String reply = getVariableName("reply");

    for (int i = 0; i < paramTypes.length; i++) {
        p.p(getName(paramTypes[i])+" "+paramNames[i]+" = ");
        writeUnmarshalArgument(p, in, paramTypes[i], null);
        p.pln();
    }

    boolean handleExceptions = exceptions != null;
    boolean doReturn = !returnType.isType(TYPE_VOID);

    if (handleExceptions && doReturn) {
        String objName = testUtil(getName(returnType), returnType);
        p.pln(objName+" result;");
    }

    if (handleExceptions)
        p.plnI("try {");

    if (doReturn) {
        if (handleExceptions) {
            p.p("result = ");
        } else {
            p.p(getName(returnType)+" result = ");
        }
    }

    p.p("target."+methodName+"(");
    for(int i = 0; i < paramNames.length; i++) {
        if (i > 0)
            p.p(", ");
        p.p(paramNames[i]);
    }
    p.pln(");");

    if (handleExceptions) {
        for(int i = 0; i < exceptions.length; i++) {
            p.pOlnI("} catch ("+getName(exceptions[i])+" "+ex+") {");

            // Is this our IDLEntity Exception special case?

            if (exceptions[i].isIDLEntityException() && !exceptions[i].isCORBAUserException()) {

                            // Yes...

                String helperName = IDLNames.replace(exceptions[i].getQualifiedIDLName(false),"::",".");
                helperName += "Helper";
                p.pln(idOutputStream+" "+out +" = "+reply+".createExceptionReply();");
                p.pln(helperName+".write("+out+","+ex+");");

            } else {

                            // No...

                p.pln("String id = \"" + getExceptionRepositoryID(exceptions[i]) + "\";");
            p.plnI(idExtOutputStream + " "+out+" = ");
            p.pln("(" + idExtOutputStream + ") "+reply+".createExceptionReply();");
            p.pOln(out+".write_string(id);");
                p.pln(out+".write_value("+ex+"," + getName(exceptions[i]) + ".class);");
            }

            p.pln("return "+out+";");
        }
        p.pOln("}");
    }

    if (needNewWriteStreamClass(returnType)) {
        p.plnI(idExtOutputStream + " "+out+" = ");
        p.pln("(" + idExtOutputStream + ") "+reply+".createReply();");
        p.pO();
    } else {
        p.pln("OutputStream "+out+" = "+reply+".createReply();");
    }

    if (doReturn) {
        writeMarshalArgument(p, out, returnType, "result");
        p.pln();
    }

    p.pln("return "+out+";");
}
 
Example 14
Source File: StubGenerator.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Write a snippet of Java code to unmarshal a value of type "type"
 * from the java.io.ObjectInput stream named "stream" into a variable
 * named "name" (if "name" is null, the value in unmarshalled and
 * discarded).
 */
void writeUnmarshalArgument(IndentingWriter p,
                            String streamName,
                            Type type,
                            String name) throws IOException {

    int typeCode = getTypeCode(type);

    if (name != null) {
        p.p(name + " = ");
    }

    switch (typeCode) {
    case TYPE_BOOLEAN:
        p.p(streamName + ".read_boolean();");
        break;
    case TYPE_BYTE:
        p.p(streamName + ".read_octet();");
        break;
    case TYPE_CHAR:
        p.p(streamName + ".read_wchar();");
        break;
    case TYPE_SHORT:
        p.p(streamName + ".read_short();");
        break;
    case TYPE_INT:
        p.p(streamName + ".read_long();");
        break;
    case TYPE_LONG:
        p.p(streamName + ".read_longlong();");
        break;
    case TYPE_FLOAT:
        p.p(streamName + ".read_float();");
        break;
    case TYPE_DOUBLE:
        p.p(streamName + ".read_double();");
        break;
    case TYPE_STRING:
        p.p("(String) " + streamName + ".read_value(" + getName(type) + ".class);");
        break;
    case TYPE_ANY:
        if (type.getIdentifier() != idJavaLangObject) {
            p.p("(" + getName(type) + ") ");
        }
        p.p("Util.readAny(" + streamName + ");");
        break;
    case TYPE_CORBA_OBJECT:
        if (type.getIdentifier() == idCorbaObject) {
            p.p("(" + getName(type) + ") " + streamName + ".read_Object();");
        } else {
            p.p("(" + getName(type) + ") " + streamName + ".read_Object(" + getStubName(type) + ".class);");
        }
        break;
    case TYPE_REMOTE:
        String objName = testUtil(getName(type), type);
        p.p("(" + objName + ") " +
            "PortableRemoteObject.narrow(" + streamName + ".read_Object(), " + objName + ".class);");
        break;
    case TYPE_ABSTRACT:
        p.p("(" + getName(type) + ") " + streamName + ".read_abstract_interface();");
        break;
    case TYPE_NC_INTERFACE:
        p.p("(" + getName(type) + ") " + streamName + ".read_value(" + getName(type) + ".class);");
        break;
    case TYPE_VALUE:
        p.p("(" + getName(type) + ") " + streamName + ".read_value(" + getName(type) + ".class);");
        break;
    case TYPE_IMPLEMENTATION:
        p.p("(" + getName(type) + ") " + streamName + ".read_value(" + getName(type) + ".class);");
        break;
    case TYPE_NC_CLASS:
        p.p("(" + getName(type) + ") " + streamName + ".read_value(" + getName(type) + ".class);");
        break;
    case TYPE_ARRAY:
        p.p("(" + getName(type) + ") " + streamName + ".read_value(" + getName(type) + ".class);");
        break;
    case TYPE_JAVA_RMI_REMOTE:
        p.p("(" + getName(type) + ") " +
            "PortableRemoteObject.narrow(" + streamName + ".read_Object(), " + getName(type) + ".class);");
        //      p.p("(" + getName(type) + ") " + streamName + ".read_Object(" + getStubName(type) + ".class);");
        break;
    default:
        throw new Error("unexpected type code: " + typeCode);
    }
}
 
Example 15
Source File: StubGenerator.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
void writeLocalStubMethodBody (IndentingWriter p,
                               CompoundType.Method method,
                               CompoundType theType) throws IOException {

    String objName;
    String paramNames[] = method.getArgumentNames();
    Type returnType = method.getReturnType();
    ValueType[] exceptions = getStubExceptions(method,false);
    String methodName = method.getName();
    String methodIDLName = method.getIDLName();

    p.plnI("if (!Util.isLocal(this)) {");
    writeNonLocalStubMethodBody(p,method,theType);
    p.pOlnI("} else {");
    String so = getVariableName("so");

    p.pln("ServantObject "+so+" = _servant_preinvoke(\""+methodIDLName+"\","+getName(theType)+".class);");
    p.plnI("if ("+so+" == null) {");
    if (!returnType.isType(TYPE_VOID)) {
        p.p("return ");
    }
    p.p(methodName+"(");
    for (int i = 0; i < paramNames.length; i++) {
        if (i > 0)
            p.p(", ");
        p.p(paramNames[i]);
    }
    p.pln(");");
    if (returnType.isType(TYPE_VOID)) {
        p.pln( "return ;" ) ;
    }

    p.pOln("}");
    p.plnI("try {");

    // Generate code to copy required arguments, and
    // get back the names by which all arguments are known...

    String[] argNames = writeCopyArguments(method,p);

    // Now write the method...

    boolean copyReturn = mustCopy(returnType);
    String resultName = null;
    if (!returnType.isType(TYPE_VOID)) {
        if (copyReturn) {
            resultName = getVariableName("result");
            objName = testUtil(getName(returnType), returnType);
            p.p(objName+" "+resultName + " = ");
        } else {
            p.p("return ");
        }
    }
    objName = testUtil(getName(theType), theType);
    p.p("(("+objName+")"+so+".servant)."+methodName+"(");

    for (int i = 0; i < argNames.length; i++) {
        if (i > 0)
            p.p(", ");
        p.p(argNames[i]);
    }

    if (copyReturn) {
        p.pln(");");
        objName = testUtil(getName(returnType), returnType);
        p.pln("return ("+objName+")Util.copyObject("+resultName+",_orb());");
    } else {
        p.pln(");");
    }

    String e1 = getVariableName("ex");
    String e2 = getVariableName("exCopy");
    p.pOlnI("} catch (Throwable "+e1+") {");

    p.pln("Throwable "+e2+" = (Throwable)Util.copyObject("+e1+",_orb());");
    for(int i = 0; i < exceptions.length; i++) {
        if (exceptions[i].getIdentifier() != idRemoteException &&
            exceptions[i].isType(TYPE_VALUE)) {
            // Added for Bug 4818753
            p.plnI("if ("+e2+" instanceof "+getExceptionName(exceptions[i])+") {");
            p.pln("throw ("+getExceptionName(exceptions[i])+")"+e2+";");
            p.pOln("}");
        }
    }

    p.pln("throw Util.wrapException("+e2+");");
    p.pOlnI("} finally {");
    p.pln("_servant_postinvoke("+so+");");
    p.pOln("}");
    p.pOln("}");
}
 
Example 16
Source File: StubGenerator.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Write a snippet of Java code to marshal a value named "name" of
 * type "type" to the java.io.ObjectOutput stream named "stream".
 */
void writeMarshalArgument(IndentingWriter p,
                          String streamName,
                          Type type, String name) throws IOException {

    int typeCode = getTypeCode(type);

    switch (typeCode) {
    case TYPE_BOOLEAN:
        p.p(streamName + ".write_boolean(" + name + ");");
        break;
    case TYPE_BYTE:
        p.p(streamName + ".write_octet(" + name + ");");
        break;
    case TYPE_CHAR:
        p.p(streamName + ".write_wchar(" + name + ");");
        break;
    case TYPE_SHORT:
        p.p(streamName + ".write_short(" + name + ");");
        break;
    case TYPE_INT:
        p.p(streamName + ".write_long(" + name + ");");
        break;
    case TYPE_LONG:
        p.p(streamName + ".write_longlong(" + name + ");");
        break;
    case TYPE_FLOAT:
        p.p(streamName + ".write_float(" + name + ");");
        break;
    case TYPE_DOUBLE:
        p.p(streamName + ".write_double(" + name + ");");
        break;
    case TYPE_STRING:
        p.p(streamName + ".write_value(" + name + "," + getName(type) + ".class);");
        break;
    case TYPE_ANY:
        p.p("Util.writeAny("+ streamName + "," + name + ");");
        break;
    case TYPE_CORBA_OBJECT:
        p.p(streamName + ".write_Object(" + name + ");");
        break;
    case TYPE_REMOTE:
        p.p("Util.writeRemoteObject("+ streamName + "," + name + ");");
        break;
    case TYPE_ABSTRACT:
        p.p("Util.writeAbstractObject("+ streamName + "," + name + ");");
        break;
    case TYPE_NC_INTERFACE:
        p.p(streamName + ".write_value((Serializable)" + name + "," + getName(type) + ".class);");
        break;
    case TYPE_VALUE:
        p.p(streamName + ".write_value(" + name + "," + getName(type) + ".class);");
        break;
    case TYPE_IMPLEMENTATION:
        p.p(streamName + ".write_value((Serializable)" + name + "," + getName(type) + ".class);");
        break;
    case TYPE_NC_CLASS:
        p.p(streamName + ".write_value((Serializable)" + name + "," + getName(type) + ".class);");
        break;
    case TYPE_ARRAY:
        castArray = true;
        p.p(streamName + ".write_value(cast_array(" + name + ")," + getName(type) + ".class);");
        break;
    case TYPE_JAVA_RMI_REMOTE:
        p.p("Util.writeRemoteObject("+ streamName + "," + name + ");");
        break;
    default:
        throw new Error("unexpected type code: " + typeCode);
    }
}
 
Example 17
Source File: CompoundType.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
protected void printMethod (CompoundType.Method it,
                            IndentingWriter writer,
                            boolean useQualifiedNames,
                            boolean useIDLNames,
                            boolean globalIDLNames) throws IOException {


    // Write visibility...

    String visibility = it.getVisibility();

    writer.p(visibility);
    if (visibility.length() > 0) {
        writer.p(" ");
    }

    // Write return type...

    it.getReturnType().printTypeName(writer,useQualifiedNames,useIDLNames,globalIDLNames);

    // Write method name...

    if (useIDLNames) {
        writer.p(" " + it.getIDLName());
    } else {
        writer.p(" " + it.getName());
    }

    // Write arguments...

    writer.p(" (");
    Type[] args = it.getArguments();
    String[] argNames = it.getArgumentNames();

    for (int i = 0; i < args.length; i++) {
        if (i > 0) {
            writer.p(", ");
        }

        if (useIDLNames) {
            writer.p("in ");
        }

        args[i].printTypeName(writer,useQualifiedNames,useIDLNames,globalIDLNames);
        writer.p(" " + argNames[i]);
    }
    writer.p(")");

    // Write exceptions...

    ClassType[] exceptions;

    if (isType(TYPE_IMPLEMENTATION)) {
        exceptions = it.getImplExceptions();
    } else {
        exceptions = it.getExceptions();
    }

    for (int i = 0; i < exceptions.length; i++) {
        if (i == 0) {
            if (useIDLNames) {
                writer.p(" raises (");
            } else {
                writer.p(" throws ");
            }
        } else {
            writer.p(", ");
        }

        if (useIDLNames) {
            if (useQualifiedNames) {
                writer.p(exceptions[i].getQualifiedIDLExceptionName(globalIDLNames));
            } else {
                writer.p(exceptions[i].getIDLExceptionName());
            }
            writer.p(" [a.k.a. ");
            exceptions[i].printTypeName(writer,useQualifiedNames,useIDLNames,globalIDLNames);
            writer.p("]");
        } else {
            exceptions[i].printTypeName(writer,useQualifiedNames,useIDLNames,globalIDLNames);
        }
    }

    if (useIDLNames && exceptions.length > 0) {
        writer.p(")");
    }

    if (it.isInherited()) {
        writer.p(" // Inherited from ");
    writer.p(it.getDeclaredBy());
    }

    writer.pln(";");
}
 
Example 18
Source File: StubGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
void writeLocalStubMethodBody (IndentingWriter p,
                               CompoundType.Method method,
                               CompoundType theType) throws IOException {

    String objName;
    String paramNames[] = method.getArgumentNames();
    Type returnType = method.getReturnType();
    ValueType[] exceptions = getStubExceptions(method,false);
    String methodName = method.getName();
    String methodIDLName = method.getIDLName();

    p.plnI("if (!Util.isLocal(this)) {");
    writeNonLocalStubMethodBody(p,method,theType);
    p.pOlnI("} else {");
    String so = getVariableName("so");

    p.pln("ServantObject "+so+" = _servant_preinvoke(\""+methodIDLName+"\","+getName(theType)+".class);");
    p.plnI("if ("+so+" == null) {");
    if (!returnType.isType(TYPE_VOID)) {
        p.p("return ");
    }
    p.p(methodName+"(");
    for (int i = 0; i < paramNames.length; i++) {
        if (i > 0)
            p.p(", ");
        p.p(paramNames[i]);
    }
    p.pln(");");
    if (returnType.isType(TYPE_VOID)) {
        p.pln( "return ;" ) ;
    }

    p.pOln("}");
    p.plnI("try {");

    // Generate code to copy required arguments, and
    // get back the names by which all arguments are known...

    String[] argNames = writeCopyArguments(method,p);

    // Now write the method...

    boolean copyReturn = mustCopy(returnType);
    String resultName = null;
    if (!returnType.isType(TYPE_VOID)) {
        if (copyReturn) {
            resultName = getVariableName("result");
            objName = testUtil(getName(returnType), returnType);
            p.p(objName+" "+resultName + " = ");
        } else {
            p.p("return ");
        }
    }
    objName = testUtil(getName(theType), theType);
    p.p("(("+objName+")"+so+".servant)."+methodName+"(");

    for (int i = 0; i < argNames.length; i++) {
        if (i > 0)
            p.p(", ");
        p.p(argNames[i]);
    }

    if (copyReturn) {
        p.pln(");");
        objName = testUtil(getName(returnType), returnType);
        p.pln("return ("+objName+")Util.copyObject("+resultName+",_orb());");
    } else {
        p.pln(");");
    }

    String e1 = getVariableName("ex");
    String e2 = getVariableName("exCopy");
    p.pOlnI("} catch (Throwable "+e1+") {");

    p.pln("Throwable "+e2+" = (Throwable)Util.copyObject("+e1+",_orb());");
    for(int i = 0; i < exceptions.length; i++) {
        if (exceptions[i].getIdentifier() != idRemoteException &&
            exceptions[i].isType(TYPE_VALUE)) {
            // Added for Bug 4818753
            p.plnI("if ("+e2+" instanceof "+getExceptionName(exceptions[i])+") {");
            p.pln("throw ("+getExceptionName(exceptions[i])+")"+e2+";");
            p.pOln("}");
        }
    }

    p.pln("throw Util.wrapException("+e2+");");
    p.pOlnI("} finally {");
    p.pln("_servant_postinvoke("+so+");");
    p.pOln("}");
    p.pOln("}");
}
 
Example 19
Source File: StubGenerator.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Write a snippet of Java code to unmarshal a value of type "type"
 * from the java.io.ObjectInput stream named "stream" into a variable
 * named "name" (if "name" is null, the value in unmarshalled and
 * discarded).
 */
void writeUnmarshalArgument(IndentingWriter p,
                            String streamName,
                            Type type,
                            String name) throws IOException {

    int typeCode = getTypeCode(type);

    if (name != null) {
        p.p(name + " = ");
    }

    switch (typeCode) {
    case TYPE_BOOLEAN:
        p.p(streamName + ".read_boolean();");
        break;
    case TYPE_BYTE:
        p.p(streamName + ".read_octet();");
        break;
    case TYPE_CHAR:
        p.p(streamName + ".read_wchar();");
        break;
    case TYPE_SHORT:
        p.p(streamName + ".read_short();");
        break;
    case TYPE_INT:
        p.p(streamName + ".read_long();");
        break;
    case TYPE_LONG:
        p.p(streamName + ".read_longlong();");
        break;
    case TYPE_FLOAT:
        p.p(streamName + ".read_float();");
        break;
    case TYPE_DOUBLE:
        p.p(streamName + ".read_double();");
        break;
    case TYPE_STRING:
        p.p("(String) " + streamName + ".read_value(" + getName(type) + ".class);");
        break;
    case TYPE_ANY:
        if (type.getIdentifier() != idJavaLangObject) {
            p.p("(" + getName(type) + ") ");
        }
        p.p("Util.readAny(" + streamName + ");");
        break;
    case TYPE_CORBA_OBJECT:
        if (type.getIdentifier() == idCorbaObject) {
            p.p("(" + getName(type) + ") " + streamName + ".read_Object();");
        } else {
            p.p("(" + getName(type) + ") " + streamName + ".read_Object(" + getStubName(type) + ".class);");
        }
        break;
    case TYPE_REMOTE:
        String objName = testUtil(getName(type), type);
        p.p("(" + objName + ") " +
            "PortableRemoteObject.narrow(" + streamName + ".read_Object(), " + objName + ".class);");
        break;
    case TYPE_ABSTRACT:
        p.p("(" + getName(type) + ") " + streamName + ".read_abstract_interface();");
        break;
    case TYPE_NC_INTERFACE:
        p.p("(" + getName(type) + ") " + streamName + ".read_value(" + getName(type) + ".class);");
        break;
    case TYPE_VALUE:
        p.p("(" + getName(type) + ") " + streamName + ".read_value(" + getName(type) + ".class);");
        break;
    case TYPE_IMPLEMENTATION:
        p.p("(" + getName(type) + ") " + streamName + ".read_value(" + getName(type) + ".class);");
        break;
    case TYPE_NC_CLASS:
        p.p("(" + getName(type) + ") " + streamName + ".read_value(" + getName(type) + ".class);");
        break;
    case TYPE_ARRAY:
        p.p("(" + getName(type) + ") " + streamName + ".read_value(" + getName(type) + ".class);");
        break;
    case TYPE_JAVA_RMI_REMOTE:
        p.p("(" + getName(type) + ") " +
            "PortableRemoteObject.narrow(" + streamName + ".read_Object(), " + getName(type) + ".class);");
        //      p.p("(" + getName(type) + ") " + streamName + ".read_Object(" + getStubName(type) + ".class);");
        break;
    default:
        throw new Error("unexpected type code: " + typeCode);
    }
}
 
Example 20
Source File: CompoundType.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
protected void printMethod (CompoundType.Method it,
                            IndentingWriter writer,
                            boolean useQualifiedNames,
                            boolean useIDLNames,
                            boolean globalIDLNames) throws IOException {


    // Write visibility...

    String visibility = it.getVisibility();

    writer.p(visibility);
    if (visibility.length() > 0) {
        writer.p(" ");
    }

    // Write return type...

    it.getReturnType().printTypeName(writer,useQualifiedNames,useIDLNames,globalIDLNames);

    // Write method name...

    if (useIDLNames) {
        writer.p(" " + it.getIDLName());
    } else {
        writer.p(" " + it.getName());
    }

    // Write arguments...

    writer.p(" (");
    Type[] args = it.getArguments();
    String[] argNames = it.getArgumentNames();

    for (int i = 0; i < args.length; i++) {
        if (i > 0) {
            writer.p(", ");
        }

        if (useIDLNames) {
            writer.p("in ");
        }

        args[i].printTypeName(writer,useQualifiedNames,useIDLNames,globalIDLNames);
        writer.p(" " + argNames[i]);
    }
    writer.p(")");

    // Write exceptions...

    ClassType[] exceptions;

    if (isType(TYPE_IMPLEMENTATION)) {
        exceptions = it.getImplExceptions();
    } else {
        exceptions = it.getExceptions();
    }

    for (int i = 0; i < exceptions.length; i++) {
        if (i == 0) {
            if (useIDLNames) {
                writer.p(" raises (");
            } else {
                writer.p(" throws ");
            }
        } else {
            writer.p(", ");
        }

        if (useIDLNames) {
            if (useQualifiedNames) {
                writer.p(exceptions[i].getQualifiedIDLExceptionName(globalIDLNames));
            } else {
                writer.p(exceptions[i].getIDLExceptionName());
            }
            writer.p(" [a.k.a. ");
            exceptions[i].printTypeName(writer,useQualifiedNames,useIDLNames,globalIDLNames);
            writer.p("]");
        } else {
            exceptions[i].printTypeName(writer,useQualifiedNames,useIDLNames,globalIDLNames);
        }
    }

    if (useIDLNames && exceptions.length > 0) {
        writer.p(")");
    }

    if (it.isInherited()) {
        writer.p(" // Inherited from ");
    writer.p(it.getDeclaredBy());
    }

    writer.pln(";");
}