下面列出了怎么用org.omg.CORBA.MARSHAL的API类实例代码及写法,或者点击链接到github查看源代码。
public Any read_any() {
Any any = orb.create_any();
TypeCodeImpl tc = new TypeCodeImpl(orb);
// read off the typecode
// REVISIT We could avoid this try-catch if we could peek the typecode
// kind off this stream and see if it is a tk_value. Looking at the
// code we know that for tk_value the Any.read_value() below
// ignores the tc argument anyway (except for the kind field).
// But still we would need to make sure that the whole typecode,
// including encapsulations, is read off.
try {
tc.read_value(parent);
} catch (MARSHAL ex) {
if (tc.kind().value() != TCKind._tk_value)
throw ex;
// We can be sure that the whole typecode encapsulation has been
// read off.
dprintThrowable(ex);
}
// read off the value of the any
any.read_value(parent, tc);
return any;
}
public final int read(byte data[], int offset, int length) throws IOException{
try{
readObjectState.readData(this);
orbStream.read_octet_array(data, offset, length);
return length;
} catch (MARSHAL marshalException) {
if (marshalException.minor
== OMGSystemException.RMIIIOP_OPTIONAL_DATA_INCOMPATIBLE1) {
setState(IN_READ_OBJECT_NO_MORE_OPT_DATA);
return -1;
}
throw marshalException;
} catch(Error e) {
IOException exc = new IOException(e.getMessage());
exc.initCause(e) ;
throw exc ;
}
}
public final int skipBytes(int len) throws IOException{
try{
readObjectState.readData(this);
byte buf[] = new byte[len];
orbStream.read_octet_array(buf, 0, len);
return len;
} catch (MARSHAL marshalException) {
handleOptionalDataMarshalException(marshalException, false);
throw marshalException;
} catch(Error e) {
IOException exc = new IOException(e.getMessage());
exc.initCause(e) ;
throw exc ;
}
}
public final int skipBytes(int len) throws IOException{
try{
readObjectState.readData(this);
byte buf[] = new byte[len];
orbStream.read_octet_array(buf, 0, len);
return len;
} catch (MARSHAL marshalException) {
handleOptionalDataMarshalException(marshalException, false);
throw marshalException;
} catch(Error e) {
IOException exc = new IOException(e.getMessage());
exc.initCause(e) ;
throw exc ;
}
}
public final int skipBytes(int len) throws IOException{
try{
readObjectState.readData(this);
byte buf[] = new byte[len];
orbStream.read_octet_array(buf, 0, len);
return len;
} catch (MARSHAL marshalException) {
handleOptionalDataMarshalException(marshalException, false);
throw marshalException;
} catch(Error e) {
IOException exc = new IOException(e.getMessage());
exc.initCause(e) ;
throw exc ;
}
}
/**
* 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 ;
}
public Any read_any() {
Any any = orb.create_any();
TypeCodeImpl tc = new TypeCodeImpl(orb);
// read off the typecode
// REVISIT We could avoid this try-catch if we could peek the typecode
// kind off this stream and see if it is a tk_value. Looking at the
// code we know that for tk_value the Any.read_value() below
// ignores the tc argument anyway (except for the kind field).
// But still we would need to make sure that the whole typecode,
// including encapsulations, is read off.
try {
tc.read_value(parent);
} catch (MARSHAL ex) {
if (tc.kind().value() != TCKind._tk_value)
throw ex;
// We can be sure that the whole typecode encapsulation has been
// read off.
dprintThrowable(ex);
}
// read off the value of the any
any.read_value(parent, tc);
return any;
}
public final int read(byte data[], int offset, int length) throws IOException{
try{
readObjectState.readData(this);
orbStream.read_octet_array(data, offset, length);
return length;
} catch (MARSHAL marshalException) {
if (marshalException.minor
== OMGSystemException.RMIIIOP_OPTIONAL_DATA_INCOMPATIBLE1) {
setState(IN_READ_OBJECT_NO_MORE_OPT_DATA);
return -1;
}
throw marshalException;
} catch(Error e) {
IOException exc = new IOException(e.getMessage());
exc.initCause(e) ;
throw exc ;
}
}
public final byte readByte() throws IOException{
try{
readObjectState.readData(this);
return orbStream.read_octet();
} catch (MARSHAL marshalException) {
handleOptionalDataMarshalException(marshalException, false);
throw marshalException;
} catch(Error e) {
IOException exc = new IOException(e.getMessage());
exc.initCause(e);
throw exc ;
}
}
public MARSHAL unableLocateValueFactory( CompletionStatus cs, Throwable t ) {
MARSHAL exc = new MARSHAL( UNABLE_LOCATE_VALUE_FACTORY, cs ) ;
if (t != null)
exc.initCause( t ) ;
if (logger.isLoggable( Level.FINE )) {
Object[] parameters = null ;
doLog( Level.FINE, "OMG.unableLocateValueFactory",
parameters, OMGSystemException.class, exc ) ;
}
return exc ;
}
public final short readShort() throws IOException{
try{
readObjectState.readData(this);
return orbStream.read_short();
} catch (MARSHAL marshalException) {
handleOptionalDataMarshalException(marshalException, false);
throw marshalException;
} catch(Error e) {
IOException exc = new IOException(e.getMessage());
exc.initCause(e);
throw exc ;
}
}
public final int readUnsignedByte() throws IOException{
try{
readObjectState.readData(this);
return (orbStream.read_octet() << 0) & 0x000000FF;
} catch (MARSHAL marshalException) {
handleOptionalDataMarshalException(marshalException, false);
throw marshalException;
} catch(Error e) {
IOException exc = new IOException(e.getMessage());
exc.initCause(e);
throw exc ;
}
}
public MARSHAL unsupportedFormatVersion( CompletionStatus cs, Throwable t ) {
MARSHAL exc = new MARSHAL( UNSUPPORTED_FORMAT_VERSION, cs ) ;
if (t != null)
exc.initCause( t ) ;
if (logger.isLoggable( Level.WARNING )) {
Object[] parameters = null ;
doLog( Level.WARNING, "OMG.unsupportedFormatVersion",
parameters, OMGSystemException.class, exc ) ;
}
return exc ;
}
public MARSHAL invalidIndirection( CompletionStatus cs, Throwable t, Object arg0) {
MARSHAL exc = new MARSHAL( INVALID_INDIRECTION, cs ) ;
if (t != null)
exc.initCause( t ) ;
if (logger.isLoggable( Level.WARNING )) {
Object[] parameters = new Object[1] ;
parameters[0] = arg0 ;
doLog( Level.WARNING, "UTIL.invalidIndirection",
parameters, UtilSystemException.class, exc ) ;
}
return exc ;
}
public MARSHAL rmiiiopOptionalDataIncompatible3( CompletionStatus cs, Throwable t ) {
MARSHAL exc = new MARSHAL( RMIIIOP_OPTIONAL_DATA_INCOMPATIBLE3, cs ) ;
if (t != null)
exc.initCause( t ) ;
if (logger.isLoggable( Level.FINE )) {
Object[] parameters = null ;
doLog( Level.FINE, "OMG.rmiiiopOptionalDataIncompatible3",
parameters, OMGSystemException.class, exc ) ;
}
return exc ;
}
public MARSHAL unableLocateValueHelper( CompletionStatus cs, Throwable t ) {
MARSHAL exc = new MARSHAL( UNABLE_LOCATE_VALUE_HELPER, cs ) ;
if (t != null)
exc.initCause( t ) ;
if (logger.isLoggable( Level.WARNING )) {
Object[] parameters = null ;
doLog( Level.WARNING, "UTIL.unableLocateValueHelper",
parameters, UtilSystemException.class, exc ) ;
}
return exc ;
}
public final byte readByte() throws IOException{
try{
readObjectState.readData(this);
return orbStream.read_octet();
} catch (MARSHAL marshalException) {
handleOptionalDataMarshalException(marshalException, false);
throw marshalException;
} catch(Error e) {
IOException exc = new IOException(e.getMessage());
exc.initCause(e);
throw exc ;
}
}
public MARSHAL wcharBadGiopVersionSent( CompletionStatus cs, Throwable t ) {
MARSHAL exc = new MARSHAL( WCHAR_BAD_GIOP_VERSION_SENT, cs ) ;
if (t != null)
exc.initCause( t ) ;
if (logger.isLoggable( Level.WARNING )) {
Object[] parameters = null ;
doLog( Level.WARNING, "OMG.wcharBadGiopVersionSent",
parameters, OMGSystemException.class, exc ) ;
}
return exc ;
}
public final int readUnsignedShort() throws IOException{
try{
readObjectState.readData(this);
return (orbStream.read_ushort() << 0) & 0x0000FFFF;
} catch (MARSHAL marshalException) {
handleOptionalDataMarshalException(marshalException, false);
throw marshalException;
} catch(Error e) {
IOException exc = new IOException(e.getMessage());
exc.initCause(e);
throw exc ;
}
}
public final float readFloat() throws IOException{
try{
readObjectState.readData(this);
return orbStream.read_float();
} catch (MARSHAL marshalException) {
handleOptionalDataMarshalException(marshalException, false);
throw marshalException;
} catch(Error e) {
IOException exc = new IOException(e.getMessage());
exc.initCause(e);
throw exc ;
}
}
public final short readShort() throws IOException{
try{
readObjectState.readData(this);
return orbStream.read_short();
} catch (MARSHAL marshalException) {
handleOptionalDataMarshalException(marshalException, false);
throw marshalException;
} catch(Error e) {
IOException exc = new IOException(e.getMessage());
exc.initCause(e);
throw exc ;
}
}
public final boolean readBoolean() throws IOException{
try{
readObjectState.readData(this);
return orbStream.read_boolean();
} catch (MARSHAL marshalException) {
handleOptionalDataMarshalException(marshalException, false);
throw marshalException;
} catch(Error e) {
IOException exc = new IOException(e.getMessage());
exc.initCause(e);
throw exc ;
}
}
public final double readDouble() throws IOException{
try{
readObjectState.readData(this);
return orbStream.read_double();
} catch (MARSHAL marshalException) {
handleOptionalDataMarshalException(marshalException, false);
throw marshalException;
} catch(Error e) {
IOException exc = new IOException(e.getMessage());
exc.initCause(e);
throw exc ;
}
}
public MARSHAL unsupportedFormatVersion( CompletionStatus cs, Throwable t ) {
MARSHAL exc = new MARSHAL( UNSUPPORTED_FORMAT_VERSION, cs ) ;
if (t != null)
exc.initCause( t ) ;
if (logger.isLoggable( Level.WARNING )) {
Object[] parameters = null ;
doLog( Level.WARNING, "OMG.unsupportedFormatVersion",
parameters, OMGSystemException.class, exc ) ;
}
return exc ;
}
public final String readUTF() throws IOException{
try{
readObjectState.readData(this);
return internalReadUTF(orbStream);
} catch (MARSHAL marshalException) {
handleOptionalDataMarshalException(marshalException, false);
throw marshalException;
} catch(Error e) {
IOException exc = new IOException(e.getMessage());
exc.initCause(e);
throw exc ;
}
}
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);
}
public MARSHAL rmiiiopOptionalDataIncompatible2( CompletionStatus cs, Throwable t ) {
MARSHAL exc = new MARSHAL( RMIIIOP_OPTIONAL_DATA_INCOMPATIBLE2, cs ) ;
if (t != null)
exc.initCause( t ) ;
if (logger.isLoggable( Level.WARNING )) {
Object[] parameters = null ;
doLog( Level.WARNING, "OMG.rmiiiopOptionalDataIncompatible2",
parameters, OMGSystemException.class, exc ) ;
}
return exc ;
}
public final char readChar() throws IOException{
try{
readObjectState.readData(this);
return orbStream.read_wchar();
} catch (MARSHAL marshalException) {
handleOptionalDataMarshalException(marshalException, false);
throw marshalException;
} catch(Error e) {
IOException exc = new IOException(e.getMessage());
exc.initCause(e);
throw exc ;
}
}
public final int readInt() throws IOException{
try{
readObjectState.readData(this);
return orbStream.read_long();
} catch (MARSHAL marshalException) {
handleOptionalDataMarshalException(marshalException, false);
throw marshalException;
} catch(Error e) {
IOException exc = new IOException(e.getMessage());
exc.initCause(e);
throw exc ;
}
}
public final int readUnsignedShort() throws IOException{
try{
readObjectState.readData(this);
return (orbStream.read_ushort() << 0) & 0x0000FFFF;
} catch (MARSHAL marshalException) {
handleOptionalDataMarshalException(marshalException, false);
throw marshalException;
} catch(Error e) {
IOException exc = new IOException(e.getMessage());
exc.initCause(e);
throw exc ;
}
}