Message_1_0.java revision 608:7e06bf1dcb09
1/*
2 * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package com.sun.corba.se.impl.protocol.giopmsgheaders;
27
28import java.nio.ByteBuffer;
29import org.omg.CORBA.INTERNAL;
30import org.omg.CORBA.CompletionStatus;
31import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
32
33import com.sun.corba.se.spi.logging.CORBALogDomains ;
34import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
35
36/*
37 * This implements the GIOP 1.0 Message header.
38 *
39 * @author Ram Jeyaraman 05/14/2000
40 */
41
42public class Message_1_0
43        extends com.sun.corba.se.impl.protocol.giopmsgheaders.MessageBase {
44
45    private static ORBUtilSystemException wrapper =
46        ORBUtilSystemException.get( CORBALogDomains.RPC_PROTOCOL ) ;
47
48    // Instance variables
49    int magic = (int) 0;
50    GIOPVersion GIOP_version = null;
51    boolean byte_order = false;
52    byte message_type = (byte) 0;
53    int message_size = (int) 0;
54
55    // Constructor
56
57    Message_1_0() {
58    }
59
60    Message_1_0(int _magic, boolean _byte_order, byte _message_type,
61            int _message_size) {
62        magic = _magic;
63        GIOP_version = GIOPVersion.V1_0;
64        byte_order = _byte_order;
65        message_type = _message_type;
66        message_size = _message_size;
67    }
68
69    // Accessor methods
70
71    public GIOPVersion getGIOPVersion() {
72        return this.GIOP_version;
73    }
74
75    public int getType() {
76        return this.message_type;
77    }
78
79    public int getSize() {
80            return this.message_size;
81    }
82
83    public boolean isLittleEndian() {
84        return this.byte_order;
85    }
86
87    public boolean moreFragmentsToFollow() {
88        return false;
89    }
90
91    // Mutator methods
92
93    public void setSize(ByteBuffer byteBuffer, int size) {
94            this.message_size = size;
95
96        //
97        // Patch the size field in the header.
98        //
99            int patch = size - GIOPMessageHeaderLength;
100        if (!isLittleEndian()) {
101            byteBuffer.put(8,  (byte)((patch >>> 24) & 0xFF));
102            byteBuffer.put(9,  (byte)((patch >>> 16) & 0xFF));
103            byteBuffer.put(10, (byte)((patch >>> 8)  & 0xFF));
104            byteBuffer.put(11, (byte)((patch >>> 0)  & 0xFF));
105        } else {
106            byteBuffer.put(8,  (byte)((patch >>> 0)  & 0xFF));
107            byteBuffer.put(9,  (byte)((patch >>> 8)  & 0xFF));
108            byteBuffer.put(10, (byte)((patch >>> 16) & 0xFF));
109            byteBuffer.put(11, (byte)((patch >>> 24) & 0xFF));
110        }
111    }
112
113    public FragmentMessage createFragmentMessage() {
114        throw wrapper.fragmentationDisallowed(
115            CompletionStatus.COMPLETED_MAYBE);
116    }
117
118    // IO methods
119
120    // This should do nothing even if it is called. The Message Header already
121    // is read off java.io.InputStream (not a CDRInputStream) by IIOPConnection
122    // in order to choose the correct CDR Version, msg_type, and msg_size.
123    // So, we would never need to read the Message Header off a CDRInputStream.
124    public void read(org.omg.CORBA.portable.InputStream istream) {
125        /*
126        this.magic = istream.read_long();
127        this.GIOP_version = (new GIOPVersion()).read(istream);
128        this.byte_order = istream.read_boolean();
129        this.message_type = istream.read_octet();
130        this.message_size = istream.read_ulong();
131        */
132    }
133
134    public void write(org.omg.CORBA.portable.OutputStream ostream) {
135        ostream.write_long(this.magic);
136        nullCheck(this.GIOP_version);
137        this.GIOP_version.write(ostream);
138        ostream.write_boolean(this.byte_order);
139        ostream.write_octet(this.message_type);
140        ostream.write_ulong(this.message_size);
141    }
142
143} // class Message_1_0
144