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

The following examples show how to use com.sun.corba.se.impl.util.Utility. 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: PortableRemoteObject.java    From jdk8u60 with 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 #2
Source File: ORBImpl.java    From openjdk-8 with 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 #3
Source File: JavaStreamObjectCopierImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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 #4
Source File: CDROutputStream_1_0.java    From openjdk-jdk9 with 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 #5
Source File: CDROutputStream_1_0.java    From openjdk-jdk8u-backup with 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 #6
Source File: PortableRemoteObject.java    From openjdk-jdk8u-backup with 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 #7
Source File: CDROutputStream_1_0.java    From TencentKona-8 with 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 #8
Source File: CDROutputStream_1_0.java    From jdk1.8-source-analysis with Apache License 2.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 #9
Source File: ORBImpl.java    From openjdk-jdk8u-backup with 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 #10
Source File: CDROutputStream_1_0.java    From jdk8u60 with 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 #11
Source File: PortableRemoteObject.java    From jdk1.8-source-analysis with Apache License 2.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 #12
Source File: ORBImpl.java    From openjdk-jdk9 with 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 #13
Source File: JavaStreamObjectCopierImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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 #14
Source File: IDLJavaSerializationOutputStream.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * 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 #15
Source File: Util.java    From JDKSourceCode1.8 with MIT License 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 #16
Source File: StubGenerator.java    From openjdk-jdk8u-backup with 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 #17
Source File: CDRInputStream_1_0.java    From jdk1.8-source-analysis with 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 #18
Source File: PortableRemoteObject.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #19
Source File: CDRInputStream_1_0.java    From openjdk-jdk8u-backup with GNU General Public License v2.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 #20
Source File: RMIGenerator.java    From openjdk-jdk8u-backup with 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 #21
Source File: Util.java    From TencentKona-8 with 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 #22
Source File: ORBStreamObjectCopierImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: PortableRemoteObject.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #24
Source File: ServiceContexts.java    From jdk8u60 with 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" ) ;
}
 
Example #25
Source File: Util.java    From openjdk-jdk8u with 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 #26
Source File: ServiceContexts.java    From openjdk-8-source with 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" ) ;
}
 
Example #27
Source File: PortableRemoteObject.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 File: StubGenerator.java    From jdk8u60 with 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 #29
Source File: CDRInputStream_1_0.java    From openjdk-8-source with GNU General Public License v2.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 #30
Source File: RMIGenerator.java    From TencentKona-8 with 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);
}