messagebase.java

来自「JAVA 所有包」· Java 代码 · 共 949 行 · 第 1/3 页

JAVA
949
字号
    public static CancelRequestMessage createCancelRequest(            GIOPVersion gv, int request_id) {        if (gv.equals(GIOPVersion.V1_0)) { // 1.0            return new CancelRequestMessage_1_0(request_id);        } else if (gv.equals(GIOPVersion.V1_1)) { // 1.1            return new CancelRequestMessage_1_1(request_id);        } else if (gv.equals(GIOPVersion.V1_2)) { // 1.2            return new CancelRequestMessage_1_2(request_id);        } else {	    throw wrapper.giopVersionError(		CompletionStatus.COMPLETED_MAYBE);        }    }    public static Message createCloseConnection(GIOPVersion gv) {        if (gv.equals(GIOPVersion.V1_0)) { // 1.0            return new Message_1_0(Message.GIOPBigMagic, false,                                   Message.GIOPCloseConnection, 0);        } else if (gv.equals(GIOPVersion.V1_1)) { // 1.1            return new Message_1_1(Message.GIOPBigMagic, GIOPVersion.V1_1,                                   FLAG_NO_FRAG_BIG_ENDIAN,                                   Message.GIOPCloseConnection, 0);        } else if (gv.equals(GIOPVersion.V1_2)) { // 1.2            return new Message_1_1(Message.GIOPBigMagic, GIOPVersion.V1_2,                                   FLAG_NO_FRAG_BIG_ENDIAN,                                   Message.GIOPCloseConnection, 0);        } else {	    throw wrapper.giopVersionError(		CompletionStatus.COMPLETED_MAYBE);        }    }    public static Message createMessageError(GIOPVersion gv) {        if (gv.equals(GIOPVersion.V1_0)) { // 1.0            return new Message_1_0(Message.GIOPBigMagic, false,                                   Message.GIOPMessageError, 0);        } else if (gv.equals(GIOPVersion.V1_1)) { // 1.1            return new Message_1_1(Message.GIOPBigMagic, GIOPVersion.V1_1,                                   FLAG_NO_FRAG_BIG_ENDIAN,                                   Message.GIOPMessageError, 0);        } else if (gv.equals(GIOPVersion.V1_2)) { // 1.2            return new Message_1_1(Message.GIOPBigMagic, GIOPVersion.V1_2,                                   FLAG_NO_FRAG_BIG_ENDIAN,                                   Message.GIOPMessageError, 0);        } else {	    throw wrapper.giopVersionError(		CompletionStatus.COMPLETED_MAYBE);        }    }    public static FragmentMessage createFragmentMessage(GIOPVersion gv) {        // This method is not currently used.        // New fragment messages are always created from existing messages.        // Creating a FragmentMessage from InputStream is done in        // createFromStream(..)        return null;    }    public static int getRequestId(Message msg) {        switch (msg.getType()) {        case GIOPRequest :            return ((RequestMessage) msg).getRequestId();        case GIOPReply :            return ((ReplyMessage) msg).getRequestId();        case GIOPLocateRequest :            return ((LocateRequestMessage) msg).getRequestId();        case GIOPLocateReply :            return ((LocateReplyMessage) msg).getRequestId();        case GIOPCancelRequest :            return ((CancelRequestMessage) msg).getRequestId();        case GIOPFragment :            return ((FragmentMessage) msg).getRequestId();        }	throw wrapper.illegalGiopMsgType( 	    CompletionStatus.COMPLETED_MAYBE);    }    /**     * Set a flag in the given buffer (fragment bit, byte order bit, etc)     */    public static void setFlag(ByteBuffer byteBuffer, int flag) {        byte b = byteBuffer.get(6);        b |= flag;        byteBuffer.put(6,b);    }    /**     * Clears a flag in the given buffer     */    public static void clearFlag(byte[] buf, int flag) {        buf[6] &= (0xFF ^ flag);    }    private static void AreFragmentsAllowed(byte major, byte minor, byte flag,            byte msgType) {        if ( (major == 0x01) && (minor == 0x00) ) { // 1.0            if (msgType == GIOPFragment) {		throw wrapper.fragmentationDisallowed( 		    CompletionStatus.COMPLETED_MAYBE);            }        }        if ( (flag & MORE_FRAGMENTS_BIT) == MORE_FRAGMENTS_BIT ) {            switch (msgType) {            case GIOPCancelRequest :            case GIOPCloseConnection :            case GIOPMessageError :		throw wrapper.fragmentationDisallowed( 		    CompletionStatus.COMPLETED_MAYBE);            case GIOPLocateRequest :            case GIOPLocateReply :                if ( (major == 0x01) && (minor == 0x01) ) { // 1.1		    throw wrapper.fragmentationDisallowed( 			CompletionStatus.COMPLETED_MAYBE);                }                break;            }        }    }    /**     * Construct an ObjectKey from a byte[].     *     * @return ObjectKey the object key.     */    static ObjectKey extractObjectKey(byte[] objKey, ORB orb) {        try {            if (objKey != null) {                ObjectKey objectKey = 		    orb.getObjectKeyFactory().create(objKey);                if (objectKey != null) {                    return objectKey;                }            }        } catch (Exception e) {	    // XXX log this exception	}	// This exception is thrown if any exceptions are raised while	// extracting the object key or if the object key is empty.	throw wrapper.invalidObjectKey();    }    /**     * Extract the object key from TargetAddress.     *     * @return ObjectKey the object key.     */    static ObjectKey extractObjectKey(TargetAddress target, ORB orb) {            short orbTargetAddrPref = orb.getORBData().getGIOPTargetAddressPreference();        short reqAddrDisp = target.discriminator();                    switch (orbTargetAddrPref) {        case ORBConstants.ADDR_DISP_OBJKEY :            if (reqAddrDisp != KeyAddr.value) {                throw new AddressingDispositionException(KeyAddr.value);            }            break;        case ORBConstants.ADDR_DISP_PROFILE :            if (reqAddrDisp != ProfileAddr.value) {                throw new AddressingDispositionException(ProfileAddr.value);            }            break;        case ORBConstants.ADDR_DISP_IOR :            if (reqAddrDisp != ReferenceAddr.value) {                throw new AddressingDispositionException(ReferenceAddr.value);            }            break;        case ORBConstants.ADDR_DISP_HANDLE_ALL :            break;        default : 	    throw wrapper.orbTargetAddrPreferenceInExtractObjectkeyInvalid() ;        }                    try {            switch (reqAddrDisp) {            case KeyAddr.value :                byte[] objKey = target.object_key();                if (objKey != null) { // AddressingDisposition::KeyAddr                    ObjectKey objectKey = 			orb.getObjectKeyFactory().create(objKey);                    if (objectKey != null) {                       return objectKey;                   }                }                break;            case ProfileAddr.value :                IIOPProfile iiopProfile = null;                TaggedProfile profile = target.profile();                if (profile != null) { // AddressingDisposition::ProfileAddr                   iiopProfile = IIOPFactories.makeIIOPProfile(orb, profile);                   ObjectKey objectKey = iiopProfile.getObjectKey();                   if (objectKey != null) {                       return objectKey;                   }                }                break;            case ReferenceAddr.value :                IORAddressingInfo iorInfo = target.ior();                if (iorInfo != null) { // AddressingDisposition::IORAddr                    profile = iorInfo.ior.profiles[iorInfo.selected_profile_index];                    iiopProfile = IIOPFactories.makeIIOPProfile(orb, profile);                    ObjectKey objectKey = iiopProfile.getObjectKey();                    if (objectKey != null) {                       return objectKey;                   }                }                break;            default : // this cannot happen                // There is no need for a explicit exception, since the                // TargetAddressHelper.read() would have raised a BAD_OPERATION                // exception by now.                break;            }        } catch (Exception e) {}	// This exception is thrown if any exceptions are raised while	// extracting the object key from the TargetAddress or if all the	// the valid TargetAddress::AddressingDispositions are empty.	throw wrapper.invalidObjectKey() ;    }    private static int readSize(byte b1, byte b2, byte b3, byte b4,            boolean littleEndian) {        int a1, a2, a3, a4;        if (!littleEndian) {            a1 = (b1 << 24) & 0xFF000000;            a2 = (b2 << 16) & 0x00FF0000;            a3 = (b3 << 8)  & 0x0000FF00;            a4 = (b4 << 0)  & 0x000000FF;        } else {            a1 = (b4 << 24) & 0xFF000000;            a2 = (b3 << 16) & 0x00FF0000;            a3 = (b2 << 8)  & 0x0000FF00;            a4 = (b1 << 0)  & 0x000000FF;        }        return (a1 | a2 | a3 | a4);    }    static void nullCheck(Object obj) {        if (obj == null) {	    throw wrapper.nullNotAllowed() ;        }    }    static SystemException getSystemException(        String exClassName, int minorCode, CompletionStatus completionStatus,	String message, ORBUtilSystemException wrapper)    {	SystemException sysEx = null;        try {	    Class clazz = ORBClassLoader.loadClass(exClassName);	    if (message == null) {		sysEx = (SystemException) clazz.newInstance();	    } else {		Class[] types = { String.class };		Constructor constructor = clazz.getConstructor(types);		Object[] args = { message };		sysEx = (SystemException)constructor.newInstance(args);	    }        } catch (Exception someEx) {	    throw wrapper.badSystemExceptionInReply( 		CompletionStatus.COMPLETED_MAYBE, someEx );        }        sysEx.minor = minorCode;        sysEx.completed = completionStatus;        return sysEx;    }    public void callback(MessageHandler handler)        throws java.io.IOException    {        handler.handleInput(this);    }    public ByteBuffer getByteBuffer()    {	return byteBuffer;    }    public void setByteBuffer(ByteBuffer byteBuffer)    {	this.byteBuffer = byteBuffer;    }    public int getThreadPoolToUse()    {	return threadPoolToUse;    }    public byte getEncodingVersion() {	return this.encodingVersion;    }    public void setEncodingVersion(byte version) {	this.encodingVersion = version;    }    private static void dprint(String msg)    {	ORBUtility.dprint("MessageBase", msg);    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?