Java Code Examples for com.sun.corba.se.impl.util.Utility

The following examples show how to use com.sun.corba.se.impl.util.Utility. These examples are extracted from open source projects. 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 Project: openjdk-jdk9   Source File: ORBImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Finds and returns a value factory for the given repository ID.
 * The value factory returned was previously registered by a call to
 * {@link #register_value_factory} or is the default factory.
 *
 * @param repositoryID the repository ID.
 * @return the value factory.
 * @exception org.omg.CORBA.BAD_PARAM if unable to locate a factory.
 **/
public synchronized ValueFactory lookup_value_factory(String repositoryID)
{
    checkShutdownState();

    ValueFactory factory =
        (ValueFactory)valueFactoryCache.get(repositoryID);

    if (factory == null) {
        try {
            factory = Utility.getFactory(null, null, null, repositoryID);
        } catch(org.omg.CORBA.MARSHAL ex) {
            throw wrapper.unableFindValueFactory( ex ) ;
        }
    }

    return factory ;
}
 
Example 2
/**
 * Deregisters a server object from the runtime, allowing the object to become
 * available for garbage collection.
 * @param obj the object to unexport.
 * @exception NoSuchObjectException if the remote object is not
 * currently exported.
 */
public void unexportObject(Remote obj)
    throws NoSuchObjectException {

    if (obj == null) {
        throw new NullPointerException("invalid argument");
    }

    if (StubAdapter.isStub(obj) ||
        obj instanceof java.rmi.server.RemoteStub) {
        throw new NoSuchObjectException(
            "Can only unexport a server object.");
    }

    Tie theTie = Util.getTie(obj);
    if (theTie != null) {
        Util.unexportObject(obj);
    } else {
        if (Utility.loadTie(obj) == null) {
            UnicastRemoteObject.unexportObject(obj,true);
        } else {
            throw new NoSuchObjectException("Object not exported.");
        }
    }
}
 
Example 3
Source Project: openjdk-jdk8u-backup   Source File: ORBImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Finds and returns a value factory for the given repository ID.
 * The value factory returned was previously registered by a call to
 * {@link #register_value_factory} or is the default factory.
 *
 * @param repositoryID the repository ID.
 * @return the value factory.
 * @exception org.omg.CORBA.BAD_PARAM if unable to locate a factory.
 **/
public synchronized ValueFactory lookup_value_factory(String repositoryID)
{
    checkShutdownState();

    ValueFactory factory =
        (ValueFactory)valueFactoryCache.get(repositoryID);

    if (factory == null) {
        try {
            factory = Utility.getFactory(null, null, null, repositoryID);
        } catch(org.omg.CORBA.MARSHAL ex) {
            throw wrapper.unableFindValueFactory( ex ) ;
        }
    }

    return factory ;
}
 
Example 4
private void writeIDLValue(Serializable object, String repID)
{
    if (object instanceof StreamableValue) {
        ((StreamableValue)object)._write(parent);

    } else if (object instanceof CustomValue) {
        ((CustomValue)object).marshal(parent);

    } else {
        BoxedValueHelper helper = Utility.getHelper(object.getClass(), null, repID);
        boolean isCustom = false;
        if (helper instanceof ValueHelper && object instanceof CustomMarshal) {
            try {
                if (((ValueHelper)helper).get_type().type_modifier() == VM_CUSTOM.value)
                    isCustom = true;
            } catch(BadKind ex) {
                throw wrapper.badTypecodeForCustomValue( CompletionStatus.COMPLETED_MAYBE,
                    ex ) ;
            }
        }
        if (isCustom)
            ((CustomMarshal)object).marshal(parent);
        else
            helper.write_value(parent, object);
    }
}
 
Example 5
/**
 * Deregisters a server object from the runtime, allowing the object to become
 * available for garbage collection.
 * @param obj the object to unexport.
 * @exception NoSuchObjectException if the remote object is not
 * currently exported.
 */
public void unexportObject(Remote obj)
    throws NoSuchObjectException {

    if (obj == null) {
        throw new NullPointerException("invalid argument");
    }

    if (StubAdapter.isStub(obj) ||
        obj instanceof java.rmi.server.RemoteStub) {
        throw new NoSuchObjectException(
            "Can only unexport a server object.");
    }

    Tie theTie = Util.getTie(obj);
    if (theTie != null) {
        Util.unexportObject(obj);
    } else {
        if (Utility.loadTie(obj) == null) {
            UnicastRemoteObject.unexportObject(obj,true);
        } else {
            throw new NoSuchObjectException("Object not exported.");
        }
    }
}
 
Example 6
private void writeIDLValue(Serializable object, String repID)
{
    if (object instanceof StreamableValue) {
        ((StreamableValue)object)._write(parent);

    } else if (object instanceof CustomValue) {
        ((CustomValue)object).marshal(parent);

    } else {
        BoxedValueHelper helper = Utility.getHelper(object.getClass(), null, repID);
        boolean isCustom = false;
        if (helper instanceof ValueHelper && object instanceof CustomMarshal) {
            try {
                if (((ValueHelper)helper).get_type().type_modifier() == VM_CUSTOM.value)
                    isCustom = true;
            } catch(BadKind ex) {
                throw wrapper.badTypecodeForCustomValue( CompletionStatus.COMPLETED_MAYBE,
                    ex ) ;
            }
        }
        if (isCustom)
            ((CustomMarshal)object).marshal(parent);
        else
            helper.write_value(parent, object);
    }
}
 
Example 7
public Object copy(Object obj) {
    if (obj instanceof Remote) {
        // Yes, so make sure it is connected and converted
        // to a stub (if needed)...
        return Utility.autoConnect(obj,orb,true);
    }

    try {
        ByteArrayOutputStream os = new ByteArrayOutputStream( 10000 ) ;
        ObjectOutputStream oos = new ObjectOutputStream( os ) ;
        oos.writeObject( obj ) ;

        byte[] arr = os.toByteArray() ;
        InputStream is = new ByteArrayInputStream( arr ) ;
        ObjectInputStream ois = new ObjectInputStream( is ) ;

        return ois.readObject();
    } catch (Exception exc) {
        System.out.println( "Failed with exception:" + exc ) ;
        return null ;
    }
}
 
Example 8
Source Project: openjdk-8   Source File: ORBImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Finds and returns a value factory for the given repository ID.
 * The value factory returned was previously registered by a call to
 * {@link #register_value_factory} or is the default factory.
 *
 * @param repositoryID the repository ID.
 * @return the value factory.
 * @exception org.omg.CORBA.BAD_PARAM if unable to locate a factory.
 **/
public synchronized ValueFactory lookup_value_factory(String repositoryID)
{
    checkShutdownState();

    ValueFactory factory =
        (ValueFactory)valueFactoryCache.get(repositoryID);

    if (factory == null) {
        try {
            factory = Utility.getFactory(null, null, null, repositoryID);
        } catch(org.omg.CORBA.MARSHAL ex) {
            throw wrapper.unableFindValueFactory( ex ) ;
        }
    }

    return factory ;
}
 
Example 9
private void writeIDLValue(Serializable object, String repID)
{
    if (object instanceof StreamableValue) {
        ((StreamableValue)object)._write(parent);

    } else if (object instanceof CustomValue) {
        ((CustomValue)object).marshal(parent);

    } else {
        BoxedValueHelper helper = Utility.getHelper(object.getClass(), null, repID);
        boolean isCustom = false;
        if (helper instanceof ValueHelper && object instanceof CustomMarshal) {
            try {
                if (((ValueHelper)helper).get_type().type_modifier() == VM_CUSTOM.value)
                    isCustom = true;
            } catch(BadKind ex) {
                throw wrapper.badTypecodeForCustomValue( CompletionStatus.COMPLETED_MAYBE,
                    ex ) ;
            }
        }
        if (isCustom)
            ((CustomMarshal)object).marshal(parent);
        else
            helper.write_value(parent, object);
    }
}
 
Example 10
private void writeIDLValue(Serializable object, String repID)
{
    if (object instanceof StreamableValue) {
        ((StreamableValue)object)._write(parent);

    } else if (object instanceof CustomValue) {
        ((CustomValue)object).marshal(parent);

    } else {
        BoxedValueHelper helper = Utility.getHelper(object.getClass(), null, repID);
        boolean isCustom = false;
        if (helper instanceof ValueHelper && object instanceof CustomMarshal) {
            try {
                if (((ValueHelper)helper).get_type().type_modifier() == VM_CUSTOM.value)
                    isCustom = true;
            } catch(BadKind ex) {
                throw wrapper.badTypecodeForCustomValue( CompletionStatus.COMPLETED_MAYBE,
                    ex ) ;
            }
        }
        if (isCustom)
            ((CustomMarshal)object).marshal(parent);
        else
            helper.write_value(parent, object);
    }
}
 
Example 11
public Object copy(Object obj) {
    if (obj instanceof Remote) {
        // Yes, so make sure it is connected and converted
        // to a stub (if needed)...
        return Utility.autoConnect(obj,orb,true);
    }

    try {
        ByteArrayOutputStream os = new ByteArrayOutputStream( 10000 ) ;
        ObjectOutputStream oos = new ObjectOutputStream( os ) ;
        oos.writeObject( obj ) ;

        byte[] arr = os.toByteArray() ;
        InputStream is = new ByteArrayInputStream( arr ) ;
        ObjectInputStream ois = new ObjectInputStream( is ) ;

        return ois.readObject();
    } catch (Exception exc) {
        System.out.println( "Failed with exception:" + exc ) ;
        return null ;
    }
}
 
Example 12
Source Project: jdk8u60   Source File: PortableRemoteObject.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Deregisters a server object from the runtime, allowing the object to become
 * available for garbage collection.
 * @param obj the object to unexport.
 * @exception NoSuchObjectException if the remote object is not
 * currently exported.
 */
public void unexportObject(Remote obj)
    throws NoSuchObjectException {

    if (obj == null) {
        throw new NullPointerException("invalid argument");
    }

    if (StubAdapter.isStub(obj) ||
        obj instanceof java.rmi.server.RemoteStub) {
        throw new NoSuchObjectException(
            "Can only unexport a server object.");
    }

    Tie theTie = Util.getTie(obj);
    if (theTie != null) {
        Util.unexportObject(obj);
    } else {
        if (Utility.loadTie(obj) == null) {
            UnicastRemoteObject.unexportObject(obj,true);
        } else {
            throw new NoSuchObjectException("Object not exported.");
        }
    }
}
 
Example 13
Source Project: jdk8u60   Source File: CDROutputStream_1_0.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void writeIDLValue(Serializable object, String repID)
{
    if (object instanceof StreamableValue) {
        ((StreamableValue)object)._write(parent);

    } else if (object instanceof CustomValue) {
        ((CustomValue)object).marshal(parent);

    } else {
        BoxedValueHelper helper = Utility.getHelper(object.getClass(), null, repID);
        boolean isCustom = false;
        if (helper instanceof ValueHelper && object instanceof CustomMarshal) {
            try {
                if (((ValueHelper)helper).get_type().type_modifier() == VM_CUSTOM.value)
                    isCustom = true;
            } catch(BadKind ex) {
                throw wrapper.badTypecodeForCustomValue( CompletionStatus.COMPLETED_MAYBE,
                    ex ) ;
            }
        }
        if (isCustom)
            ((CustomMarshal)object).marshal(parent);
        else
            helper.write_value(parent, object);
    }
}
 
Example 14
Source Project: jdk1.8-source-analysis   Source File: ServiceContexts.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Write the service contexts to the output stream.
 *
 * If they haven't been unmarshaled, we don't have to
 * unmarshal them.
 */
public void write(OutputStream os, GIOPVersion gv)
{
    if (isDebugging(os)) {
        dprint( "Writing service contexts to output stream" ) ;
        Utility.printStackTrace() ;
    }

    int numsc = scMap.size();

    if (addAlignmentOnWrite) {
        if (isDebugging(os))
            dprint( "Adding alignment padding" ) ;

        numsc++ ;
    }

    if (isDebugging(os))
        dprint( "Service context has " + numsc + " components"  ) ;

    os.write_long( numsc ) ;

    writeServiceContextsInOrder(os, gv);

    if (addAlignmentOnWrite) {
        if (isDebugging(os))
            dprint( "Writing alignment padding" ) ;

        os.write_long( JAVAIDL_ALIGN_SERVICE_ID ) ;
        os.write_long( 4 ) ;
        os.write_octet( (byte)0 ) ;
        os.write_octet( (byte)0 ) ;
        os.write_octet( (byte)0 ) ;
        os.write_octet( (byte)0 ) ;
    }

    if (isDebugging(os))
        dprint( "Service context writing complete" ) ;
}
 
Example 15
/**
 * Return the File object that should be used as the source file
 * for the given Java class, using the supplied destination
 * directory for the top of the package hierarchy.
 */
protected static File sourceFileForClass(Identifier className,
                                         Identifier outputClassName,
                                         File destDir,
                                         BatchEnvironment env)
{
    File packageDir = Util.getOutputDirectoryFor(className,destDir,env);
    String outputName = Names.mangleClass(outputClassName).getName().toString();

    // Is there any existing _Tie equivalent leftover from a
    // previous invocation of rmic -iiop? Only do this once per
    // class by looking for skeleton generation...

    if (outputName.endsWith("_Skel")) {
        String classNameStr = className.getName().toString();
        File temp = new File(packageDir, Utility.tieName(classNameStr) + ".class");
        if (temp.exists()) {

            // Found a tie. Is IIOP generation also being done?

            if (!env.getMain().iiopGeneration) {

                // No, so write a warning...

                env.error(0,"warn.rmic.tie.found",
                          classNameStr,
                          temp.getAbsolutePath());
            }
        }
    }

    String outputFileName = outputName + ".java";
    return new File(packageDir, outputFileName);
}
 
Example 16
/**
 * Returns a stub for the given server object.
 * @param obj the server object for which a stub is required. Must either be a subclass
 * of PortableRemoteObject or have been previously the target of a call to
 * {@link #exportObject}.
 * @return the most derived stub for the object.
 * @exception NoSuchObjectException if a stub cannot be located for the given server object.
 */
public Remote toStub (Remote obj)
    throws NoSuchObjectException
{
    Remote result = null;
    if (obj == null) {
        throw new NullPointerException("invalid argument");
    }

    // If the class is already an IIOP stub then return it.
    if (StubAdapter.isStub( obj )) {
        return obj;
    }

    // If the class is already a JRMP stub then return it.
    if (obj instanceof java.rmi.server.RemoteStub) {
        return obj;
    }

    // Has it been exported to IIOP?
    Tie theTie = Util.getTie(obj);

    if (theTie != null) {
        result = Utility.loadStub(theTie,null,null,true);
    } else {
        if (Utility.loadTie(obj) == null) {
            result = java.rmi.server.RemoteObject.toStub(obj);
        }
    }

    if (result == null) {
        throw new NoSuchObjectException("object not exported");
    }

    return result;
}
 
Example 17
Source Project: openjdk-8-source   Source File: Util.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Writes any java.lang.Object as a CORBA any.
 * @param out the stream in which to write the any.
 * @param obj the object to write as an any.
 */
public void writeAny( org.omg.CORBA.portable.OutputStream out,
                     java.lang.Object obj)
{
    org.omg.CORBA.ORB orb = out.orb();

    // Create Any
    Any any = orb.create_any();

    // Make sure we have a connected object...
    java.lang.Object newObj = Utility.autoConnect(obj,orb,false);

    if (newObj instanceof org.omg.CORBA.Object) {
        any.insert_Object((org.omg.CORBA.Object)newObj);
    } else {
        if (newObj == null) {
            // Handle the null case, including backwards
            // compatibility issues
            any.insert_Value(null, createTypeCodeForNull(orb));
        } else {
            if (newObj instanceof Serializable) {
                // If they're our Any and ORB implementations,
                // we may want to do type code related versioning.
                TypeCode tc = createTypeCode((Serializable)newObj, any, orb);
                if (tc == null)
                    any.insert_Value((Serializable)newObj);
                else
                    any.insert_Value((Serializable)newObj, tc);
            } else if (newObj instanceof Remote) {
                ORBUtility.throwNotSerializableForCorba(newObj.getClass().getName());
            } else {
                ORBUtility.throwNotSerializableForCorba(newObj.getClass().getName());
            }
        }
    }

    out.write_any(any);
}
 
Example 18
Source Project: jdk1.8-source-analysis   Source File: CDRInputStream_1_0.java    License: Apache License 2.0 5 votes vote down vote up
private java.lang.Object readIDLValue(int indirection, String repId,
                                      Class clazz, String codebase)
{
    ValueFactory factory ;

    // Always try to find a ValueFactory first, as required by the spec.
    // There are some complications here in the IDL 3.0 mapping (see 1.13.8),
    // but basically we must always be able to override the DefaultFactory
    // or Helper mappings that are also used.  This appears to be the case
    // even in the boxed value cases.  The original code only did the lookup
    // in the case of class implementing either StreamableValue or CustomValue,
    // but abstract valuetypes only implement ValueBase, and really require
    // the use of the repId to find a factory (including the DefaultFactory).
    try {
        // use new-style OBV support (factory object)
        factory = Utility.getFactory(clazz, codebase, orb, repId);
    } catch (MARSHAL marshal) {
        // XXX log marshal at one of the INFO levels

        // Could not get a factory, so try alternatives
        if (!StreamableValue.class.isAssignableFrom(clazz) &&
            !CustomValue.class.isAssignableFrom(clazz) &&
            ValueBase.class.isAssignableFrom(clazz)) {
            // use old-style OBV support (helper object)
            BoxedValueHelper helper = Utility.getHelper(clazz, codebase, repId);
            if (helper instanceof ValueHelper)
                return readIDLValueWithHelper((ValueHelper)helper, indirection);
            else
                return helper.read_value(parent);
        } else {
            // must be a boxed IDLEntity, so make a reflective call to the
            // helper's static read method...
            return readBoxedIDLEntity(clazz, codebase);
        }
    }

    // If there was no error in getting the factory, use it.
    valueIndirection = indirection;  // for callback
    return factory.read_value(parent);
}
 
Example 19
Source Project: dragonwell8_jdk   Source File: RMIGenerator.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the File object that should be used as the source file
 * for the given Java class, using the supplied destination
 * directory for the top of the package hierarchy.
 */
protected static File sourceFileForClass(Identifier className,
                                         Identifier outputClassName,
                                         File destDir,
                                         BatchEnvironment env)
{
    File packageDir = Util.getOutputDirectoryFor(className,destDir,env);
    String outputName = Names.mangleClass(outputClassName).getName().toString();

    // Is there any existing _Tie equivalent leftover from a
    // previous invocation of rmic -iiop? Only do this once per
    // class by looking for skeleton generation...

    if (outputName.endsWith("_Skel")) {
        String classNameStr = className.getName().toString();
        File temp = new File(packageDir, Utility.tieName(classNameStr) + ".class");
        if (temp.exists()) {

            // Found a tie. Is IIOP generation also being done?

            if (!env.getMain().iiopGeneration) {

                // No, so write a warning...

                env.error(0,"warn.rmic.tie.found",
                          classNameStr,
                          temp.getAbsolutePath());
            }
        }
    }

    String outputFileName = outputName + ".java";
    return new File(packageDir, outputFileName);
}
 
Example 20
Source Project: TencentKona-8   Source File: StubGenerator.java    License: GNU General Public License v2.0 5 votes vote down vote up
String getStubNameFor(Type type, boolean qualified) {
    String stubName;
    String className;
    if (qualified) {
        className = type.getQualifiedName();
    } else {
        className = type.getName();
    }
    if (((CompoundType)type).isCORBAObject()) {
        stubName = Utility.idlStubName(className);
    } else {
        stubName = Utility.stubNameForCompiler(className);
    }
    return stubName;
}
 
Example 21
Source Project: openjdk-8   Source File: StubGenerator.java    License: GNU General Public License v2.0 5 votes vote down vote up
String getStubNameFor(Type type, boolean qualified) {
    String stubName;
    String className;
    if (qualified) {
        className = type.getQualifiedName();
    } else {
        className = type.getName();
    }
    if (((CompoundType)type).isCORBAObject()) {
        stubName = Utility.idlStubName(className);
    } else {
        stubName = Utility.stubNameForCompiler(className);
    }
    return stubName;
}
 
Example 22
public Object copy(Object obj) {
    if (obj instanceof Remote) {
        // Yes, so make sure it is connected and converted
        // to a stub (if needed)...
        return Utility.autoConnect(obj,orb,true);
    }

    OutputStream out = (OutputStream)orb.create_output_stream();
    out.write_value((Serializable)obj);
    InputStream in = (InputStream)out.create_input_stream();
    return in.read_value();
}
 
Example 23
/**
 * Checks for objects that are instances of java.rmi.Remote
 * that need to be serialized as proxy (Stub) objects.
 */
protected final Object replaceObject(Object obj) throws IOException {
    try {
        if ((obj instanceof java.rmi.Remote) &&
                !(StubAdapter.isStub(obj))) {
            return Utility.autoConnect(obj, orb, true);
        }
    } catch (Exception e) {
        IOException ie = new IOException("replaceObject failed");
        ie.initCause(e);
        throw ie;
    }
    return obj;
}
 
Example 24
/**
 * Returns a stub for the given server object.
 * @param obj the server object for which a stub is required. Must either be a subclass
 * of PortableRemoteObject or have been previously the target of a call to
 * {@link #exportObject}.
 * @return the most derived stub for the object.
 * @exception NoSuchObjectException if a stub cannot be located for the given server object.
 */
public Remote toStub (Remote obj)
    throws NoSuchObjectException
{
    Remote result = null;
    if (obj == null) {
        throw new NullPointerException("invalid argument");
    }

    // If the class is already an IIOP stub then return it.
    if (StubAdapter.isStub( obj )) {
        return obj;
    }

    // If the class is already a JRMP stub then return it.
    if (obj instanceof java.rmi.server.RemoteStub) {
        return obj;
    }

    // Has it been exported to IIOP?
    Tie theTie = Util.getTie(obj);

    if (theTie != null) {
        result = Utility.loadStub(theTie,null,null,true);
    } else {
        if (Utility.loadTie(obj) == null) {
            result = java.rmi.server.RemoteObject.toStub(obj);
        }
    }

    if (result == null) {
        throw new NoSuchObjectException("object not exported");
    }

    return result;
}
 
Example 25
private java.lang.Object readIDLValue(int indirection, String repId,
                                      Class clazz, String codebase)
{
    ValueFactory factory ;

    // Always try to find a ValueFactory first, as required by the spec.
    // There are some complications here in the IDL 3.0 mapping (see 1.13.8),
    // but basically we must always be able to override the DefaultFactory
    // or Helper mappings that are also used.  This appears to be the case
    // even in the boxed value cases.  The original code only did the lookup
    // in the case of class implementing either StreamableValue or CustomValue,
    // but abstract valuetypes only implement ValueBase, and really require
    // the use of the repId to find a factory (including the DefaultFactory).
    try {
        // use new-style OBV support (factory object)
        factory = Utility.getFactory(clazz, codebase, orb, repId);
    } catch (MARSHAL marshal) {
        // XXX log marshal at one of the INFO levels

        // Could not get a factory, so try alternatives
        if (!StreamableValue.class.isAssignableFrom(clazz) &&
            !CustomValue.class.isAssignableFrom(clazz) &&
            ValueBase.class.isAssignableFrom(clazz)) {
            // use old-style OBV support (helper object)
            BoxedValueHelper helper = Utility.getHelper(clazz, codebase, repId);
            if (helper instanceof ValueHelper)
                return readIDLValueWithHelper((ValueHelper)helper, indirection);
            else
                return helper.read_value(parent);
        } else {
            // must be a boxed IDLEntity, so make a reflective call to the
            // helper's static read method...
            return readBoxedIDLEntity(clazz, codebase);
        }
    }

    // If there was no error in getting the factory, use it.
    valueIndirection = indirection;  // for callback
    return factory.read_value(parent);
}
 
Example 26
Source Project: TencentKona-8   Source File: Util.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Writes any java.lang.Object as a CORBA any.
 * @param out the stream in which to write the any.
 * @param obj the object to write as an any.
 */
public void writeAny( org.omg.CORBA.portable.OutputStream out,
                     java.lang.Object obj)
{
    org.omg.CORBA.ORB orb = out.orb();

    // Create Any
    Any any = orb.create_any();

    // Make sure we have a connected object...
    java.lang.Object newObj = Utility.autoConnect(obj,orb,false);

    if (newObj instanceof org.omg.CORBA.Object) {
        any.insert_Object((org.omg.CORBA.Object)newObj);
    } else {
        if (newObj == null) {
            // Handle the null case, including backwards
            // compatibility issues
            any.insert_Value(null, createTypeCodeForNull(orb));
        } else {
            if (newObj instanceof Serializable) {
                // If they're our Any and ORB implementations,
                // we may want to do type code related versioning.
                TypeCode tc = createTypeCode((Serializable)newObj, any, orb);
                if (tc == null)
                    any.insert_Value((Serializable)newObj);
                else
                    any.insert_Value((Serializable)newObj, tc);
            } else if (newObj instanceof Remote) {
                ORBUtility.throwNotSerializableForCorba(newObj.getClass().getName());
            } else {
                ORBUtility.throwNotSerializableForCorba(newObj.getClass().getName());
            }
        }
    }

    out.write_any(any);
}
 
Example 27
/**
 * Returns a stub for the given server object.
 * @param obj the server object for which a stub is required. Must either be a subclass
 * of PortableRemoteObject or have been previously the target of a call to
 * {@link #exportObject}.
 * @return the most derived stub for the object.
 * @exception NoSuchObjectException if a stub cannot be located for the given server object.
 */
public Remote toStub (Remote obj)
    throws NoSuchObjectException
{
    Remote result = null;
    if (obj == null) {
        throw new NullPointerException("invalid argument");
    }

    // If the class is already an IIOP stub then return it.
    if (StubAdapter.isStub( obj )) {
        return obj;
    }

    // If the class is already a JRMP stub then return it.
    if (obj instanceof java.rmi.server.RemoteStub) {
        return obj;
    }

    // Has it been exported to IIOP?
    Tie theTie = Util.getTie(obj);

    if (theTie != null) {
        result = Utility.loadStub(theTie,null,null,true);
    } else {
        if (Utility.loadTie(obj) == null) {
            result = java.rmi.server.RemoteObject.toStub(obj);
        }
    }

    if (result == null) {
        throw new NoSuchObjectException("object not exported");
    }

    return result;
}
 
Example 28
Source Project: TencentKona-8   Source File: RMIGenerator.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the File object that should be used as the source file
 * for the given Java class, using the supplied destination
 * directory for the top of the package hierarchy.
 */
protected static File sourceFileForClass(Identifier className,
                                         Identifier outputClassName,
                                         File destDir,
                                         BatchEnvironment env)
{
    File packageDir = Util.getOutputDirectoryFor(className,destDir,env);
    String outputName = Names.mangleClass(outputClassName).getName().toString();

    // Is there any existing _Tie equivalent leftover from a
    // previous invocation of rmic -iiop? Only do this once per
    // class by looking for skeleton generation...

    if (outputName.endsWith("_Skel")) {
        String classNameStr = className.getName().toString();
        File temp = new File(packageDir, Utility.tieName(classNameStr) + ".class");
        if (temp.exists()) {

            // Found a tie. Is IIOP generation also being done?

            if (!env.getMain().iiopGeneration) {

                // No, so write a warning...

                env.error(0,"warn.rmic.tie.found",
                          classNameStr,
                          temp.getAbsolutePath());
            }
        }
    }

    String outputFileName = outputName + ".java";
    return new File(packageDir, outputFileName);
}
 
Example 29
Source Project: jdk8u60   Source File: StubGenerator.java    License: GNU General Public License v2.0 5 votes vote down vote up
String getStubNameFor(Type type, boolean qualified) {
    String stubName;
    String className;
    if (qualified) {
        className = type.getQualifiedName();
    } else {
        className = type.getName();
    }
    if (((CompoundType)type).isCORBAObject()) {
        stubName = Utility.idlStubName(className);
    } else {
        stubName = Utility.stubNameForCompiler(className);
    }
    return stubName;
}
 
Example 30
Source Project: jdk8u60   Source File: ServiceContexts.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Write the service contexts to the output stream.
 *
 * If they haven't been unmarshaled, we don't have to
 * unmarshal them.
 */
public void write(OutputStream os, GIOPVersion gv)
{
    if (isDebugging(os)) {
        dprint( "Writing service contexts to output stream" ) ;
        Utility.printStackTrace() ;
    }

    int numsc = scMap.size();

    if (addAlignmentOnWrite) {
        if (isDebugging(os))
            dprint( "Adding alignment padding" ) ;

        numsc++ ;
    }

    if (isDebugging(os))
        dprint( "Service context has " + numsc + " components"  ) ;

    os.write_long( numsc ) ;

    writeServiceContextsInOrder(os, gv);

    if (addAlignmentOnWrite) {
        if (isDebugging(os))
            dprint( "Writing alignment padding" ) ;

        os.write_long( JAVAIDL_ALIGN_SERVICE_ID ) ;
        os.write_long( 4 ) ;
        os.write_octet( (byte)0 ) ;
        os.write_octet( (byte)0 ) ;
        os.write_octet( (byte)0 ) ;
        os.write_octet( (byte)0 ) ;
    }

    if (isDebugging(os))
        dprint( "Service context writing complete" ) ;
}