KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > protocol > giopmsgheaders > Message_1_0


1 /*
2  * @(#)Message_1_0.java 1.10 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.protocol.giopmsgheaders;
9
10 import java.nio.ByteBuffer JavaDoc;
11 import org.omg.CORBA.INTERNAL JavaDoc;
12 import org.omg.CORBA.CompletionStatus JavaDoc;
13 import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
14
15 import com.sun.corba.se.spi.logging.CORBALogDomains ;
16 import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
17
18 /*
19  * This implements the GIOP 1.0 Message header.
20  *
21  * @author Ram Jeyaraman 05/14/2000
22  * @version 1.0
23  */

24
25 public class Message_1_0
26         extends com.sun.corba.se.impl.protocol.giopmsgheaders.MessageBase {
27
28     private static ORBUtilSystemException wrapper =
29     ORBUtilSystemException.get( CORBALogDomains.RPC_PROTOCOL ) ;
30
31     // Instance variables
32
int magic = (int) 0;
33     GIOPVersion GIOP_version = null;
34     boolean byte_order = false;
35     byte message_type = (byte) 0;
36     int message_size = (int) 0;
37
38     // Constructor
39

40     Message_1_0() {
41     }
42     
43     Message_1_0(int _magic, boolean _byte_order, byte _message_type,
44             int _message_size) {
45         magic = _magic;
46         GIOP_version = GIOPVersion.V1_0;
47         byte_order = _byte_order;
48         message_type = _message_type;
49         message_size = _message_size;
50     }
51
52     // Accessor methods
53

54     public GIOPVersion getGIOPVersion() {
55         return this.GIOP_version;
56     }
57
58     public int getType() {
59         return this.message_type;
60     }
61
62     public int getSize() {
63         return this.message_size;
64     }
65
66     public boolean isLittleEndian() {
67         return this.byte_order;
68     }
69
70     public boolean moreFragmentsToFollow() {
71         return false;
72     }
73
74     // Mutator methods
75

76     public void setSize(ByteBuffer JavaDoc byteBuffer, int size) {
77         this.message_size = size;
78
79         //
80
// Patch the size field in the header.
81
//
82
int patch = size - GIOPMessageHeaderLength;
83         if (!isLittleEndian()) {
84             byteBuffer.put(8, (byte)((patch >>> 24) & 0xFF));
85             byteBuffer.put(9, (byte)((patch >>> 16) & 0xFF));
86             byteBuffer.put(10, (byte)((patch >>> 8) & 0xFF));
87             byteBuffer.put(11, (byte)((patch >>> 0) & 0xFF));
88         } else {
89             byteBuffer.put(8, (byte)((patch >>> 0) & 0xFF));
90             byteBuffer.put(9, (byte)((patch >>> 8) & 0xFF));
91             byteBuffer.put(10, (byte)((patch >>> 16) & 0xFF));
92             byteBuffer.put(11, (byte)((patch >>> 24) & 0xFF));
93         }
94     }
95
96     public FragmentMessage createFragmentMessage() {
97     throw wrapper.fragmentationDisallowed(
98         CompletionStatus.COMPLETED_MAYBE);
99     }
100         
101     // IO methods
102

103     // This should do nothing even if it is called. The Message Header already
104
// is read off java.io.InputStream (not a CDRInputStream) by IIOPConnection
105
// in order to choose the correct CDR Version, msg_type, and msg_size.
106
// So, we would never need to read the Message Header off a CDRInputStream.
107
public void read(org.omg.CORBA.portable.InputStream JavaDoc istream) {
108         /*
109         this.magic = istream.read_long();
110         this.GIOP_version = (new GIOPVersion()).read(istream);
111         this.byte_order = istream.read_boolean();
112         this.message_type = istream.read_octet();
113         this.message_size = istream.read_ulong();
114         */

115     }
116
117     public void write(org.omg.CORBA.portable.OutputStream JavaDoc ostream) {
118         ostream.write_long(this.magic);
119         nullCheck(this.GIOP_version);
120         this.GIOP_version.write(ostream);
121         ostream.write_boolean(this.byte_order);
122         ostream.write_octet(this.message_type);
123         ostream.write_ulong(this.message_size);
124     }
125
126 } // class Message_1_0
127
Popular Tags