KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > orb > giop > RequestInputStream


1 package org.jacorb.orb.giop;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-2004 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22
23 import org.jacorb.orb.*;
24 import org.omg.CORBA.MARSHAL JavaDoc;
25 import org.omg.GIOP.*;
26 import org.omg.IOP.ServiceContext JavaDoc;
27
28 /**
29  *
30  * @author Gerald Brose, FU Berlin
31  * @version $Id: RequestInputStream.java,v 1.18 2004/05/06 12:40:00 nicolas Exp $
32  *
33  */

34
35 public class RequestInputStream
36     extends ServiceContextTransportingInputStream
37 {
38     private static byte[] reserved = new byte[3];
39
40     private boolean is_locate_request = false;
41
42     public RequestHeader_1_2 req_hdr = null;
43
44     public RequestInputStream( org.omg.CORBA.ORB JavaDoc orb, byte[] buf )
45     {
46         super( orb, buf );
47
48         if( Messages.getMsgType( buffer ) == MsgType_1_1._Request )
49         {
50             switch( giop_minor )
51             {
52                 case 0 :
53                 {
54                     //GIOP 1.0
55
RequestHeader_1_0 hdr =
56                         RequestHeader_1_0Helper.read( this );
57
58                     TargetAddress addr = new TargetAddress();
59                     addr.object_key( hdr.object_key );
60
61                     req_hdr =
62                         new RequestHeader_1_2( hdr.request_id,
63                                                Messages.responseFlags( hdr.response_expected ),
64                                                reserved,
65                                                addr, //target
66
hdr.operation,
67                                                hdr.service_context );
68                     break;
69                 }
70                 case 1 :
71                 {
72                     //GIOP 1.1
73
RequestHeader_1_1 hdr =
74                         RequestHeader_1_1Helper.read( this );
75
76                     TargetAddress addr = new TargetAddress();
77                     addr.object_key( hdr.object_key );
78
79                     req_hdr =
80                         new RequestHeader_1_2( hdr.request_id,
81                                                Messages.responseFlags( hdr.response_expected ),
82                                                reserved,
83                                                addr, //target
84
hdr.operation,
85                                                hdr.service_context );
86                     break;
87                 }
88                 case 2 :
89                 {
90                     //GIOP 1.2
91
req_hdr = RequestHeader_1_2Helper.read( this );
92
93                     skipHeaderPadding();
94
95                     break;
96                 }
97                 default : {
98                     throw new MARSHAL JavaDoc( "Unknown GIOP minor version: " + giop_minor );
99                 }
100             }
101         }
102         else if( Messages.getMsgType( buffer ) == MsgType_1_1._LocateRequest )
103         {
104             switch( giop_minor )
105             {
106                 case 0 :
107                 {
108                     //GIOP 1.0 = GIOP 1.1, fall through
109
}
110                 case 1 :
111                 {
112                     //GIOP 1.1
113
LocateRequestHeader_1_0 locate_req_hdr =
114                         LocateRequestHeader_1_0Helper.read( this );
115
116                     TargetAddress addr = new TargetAddress();
117                     addr.object_key( locate_req_hdr.object_key );
118
119                     req_hdr =
120                         new RequestHeader_1_2( locate_req_hdr.request_id,
121                                                (byte) 0x03,//response_expected
122
reserved,
123                                                addr,
124                                                "_non_existent",
125                                                Messages.service_context );
126                     break;
127                 }
128                 case 2 :
129                 {
130                     //GIOP 1.2
131
LocateRequestHeader_1_2 locate_req_hdr =
132                         LocateRequestHeader_1_2Helper.read( this );
133
134                     req_hdr =
135                         new RequestHeader_1_2( locate_req_hdr.request_id,
136                                                (byte) 0x03,//response_expected
137
reserved,
138                                                locate_req_hdr.target,
139                                                "_non_existent",
140                                                Messages.service_context );
141                     break;
142                 }
143                 default :
144                 {
145                     throw new MARSHAL JavaDoc( "Unknown GIOP minor version: " + giop_minor );
146                 }
147             }
148
149             is_locate_request = true;
150         }
151         else
152         {
153             throw new MARSHAL JavaDoc( "Error: not a request!" );
154         }
155     }
156
157     public ServiceContext JavaDoc getServiceContext( int id )
158     {
159         for( int i = 0; i < req_hdr.service_context.length; i++ )
160         {
161             if( req_hdr.service_context[i].context_id == id )
162             {
163                 return req_hdr.service_context[i];
164             }
165         }
166
167         return null;
168     }
169
170     public boolean isLocateRequest()
171     {
172         return is_locate_request;
173     }
174
175     protected void finalize() throws Throwable JavaDoc
176     {
177         try
178         {
179             close();
180         }
181         catch( java.io.IOException JavaDoc iox )
182         {
183             //ignore
184
}
185         finally
186         {
187             super.finalize();
188         }
189     }
190 }
191
Popular Tags