KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > corba > logservice > LogSRIImpl


1 // ====================================================================
2
//
3
// ECM: The Extensible Container Model
4
// Copyright (C) 2004 THALES
5
// Contact: openccm-ecm@objectweb.org
6
//
7
// This library is free software; you can redistribute it and/or
8
// modify it under the terms of the GNU Lesser General Public
9
// License as published by the Free Software Foundation; either
10
// version 2.1 of the License, or any later version.
11
//
12
// This library is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
// Lesser General Public License for more details.
16
//
17
// You should have received a copy of the GNU Lesser General Public
18
// License along with this library; if not, write to the Free Software
19
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20
// USA
21
//
22
// Initial developer(s): Mathieu Vadet.
23
// Initial Funding: IST COACH European project (IST-2001-34445)
24
// http://www.ist-coach.org
25
//
26
// ====================================================================
27

28
29
30 package org.objectweb.corba.logservice;
31
32 import org.objectweb.corba.runtime.*;
33
34 /**
35  ** <p>This class implements a server request interceptor for the log service.
36  ** This SRI extract the propagated 'id' information and place it in the current.</p>
37  **
38  ** @see org.objectweb.corba.logservice.LogCurrentImpl LogCurrentImpl
39  ** @see org.objectweb.corba.logservice.LogCRIImpl LogCRIImpl
40  **/

41 public class LogSRIImpl
42 extends org.omg.CORBA.LocalObject JavaDoc
43 implements org.omg.PortableInterceptor.ServerRequestInterceptor JavaDoc
44 {
45     //
46
private org.omg.IOP.Codec JavaDoc _codec;
47     private int _slot_id;
48
49     public
50     LogSRIImpl(org.omg.IOP.Codec JavaDoc codec,
51                int slotid)
52     {
53         _codec = codec;
54         _slot_id = slotid;
55     }
56
57     //
58
// internal operations
59
//
60

61     private void
62     setIdInServiceContext(org.omg.PortableInterceptor.ServerRequestInfo JavaDoc info)
63     {
64         // get server id from slot
65
org.omg.CORBA.Any JavaDoc cid = null;
66         try {
67             cid = info.get_slot(_slot_id);
68         } catch (org.omg.PortableInterceptor.InvalidSlot JavaDoc ex) {
69         }
70
71         if (cid==null) {
72             // TODO: change
73
return ;
74         }
75
76         // set server id in service context
77
org.omg.IOP.ServiceContext JavaDoc sctx = new org.omg.IOP.ServiceContext JavaDoc();
78         sctx.context_id = LOG_IOP_SERVICE_ID.value;
79         try {
80             sctx.context_data = _codec.encode(cid);
81         } catch (org.omg.IOP.CodecPackage.InvalidTypeForEncoding JavaDoc ex) {
82         }
83
84         info.add_reply_service_context(sctx, true);
85     }
86
87     //
88
// IDL:omg.org/PortableInterceptor/RequestInterceptor:1.0
89
//
90

91     final public String JavaDoc
92     name()
93     {
94         return "LogSRIImpl";
95     }
96
97     final public void
98     destroy()
99     {
100         _codec = null;
101     }
102
103     //
104
// IDL:omg.org/PortableInterceptor/ServerRequestInterceptor:1.0
105
//
106

107     final public void
108     receive_request_service_contexts(org.omg.PortableInterceptor.ServerRequestInfo JavaDoc info)
109     throws org.omg.PortableInterceptor.ForwardRequest JavaDoc
110     {
111         System.err.println("### LogSRIImpl::receive_request_service_contexts called");
112         // get log service context
113
org.omg.IOP.ServiceContext JavaDoc sctx = null;
114         try {
115             sctx = info.get_request_service_context(LOG_IOP_SERVICE_ID.value);
116         } catch (org.omg.CORBA.SystemException JavaDoc ex) {
117             System.err.println("!!! LogSRIImpl::receive_request_service_contexts: Service context not found");
118         }
119
120         if (sctx==null) {
121             System.err.println("!!! LogSRIImpl::receive_request_service_contexts: Service context not found");
122             return ;
123         }
124
125         // extract client id from context
126
org.omg.CORBA.Any JavaDoc cid = null;
127         try {
128             cid = _codec.decode(sctx.context_data);
129         } catch (org.omg.IOP.CodecPackage.FormatMismatch JavaDoc ex) {
130         }
131
132         // set client id in slot
133
try {
134             info.set_slot(_slot_id, cid);
135         } catch (org.omg.PortableInterceptor.InvalidSlot JavaDoc ex) {
136         }
137    }
138
139     final public void
140     receive_request(org.omg.PortableInterceptor.ServerRequestInfo JavaDoc info)
141     throws org.omg.PortableInterceptor.ForwardRequest JavaDoc
142     {
143         System.err.println("### LogSRIImpl::receive_request called on operation: "+info.operation());
144     }
145
146     final public void
147     send_reply(org.omg.PortableInterceptor.ServerRequestInfo JavaDoc info)
148     {
149         System.err.println("### LogSRIImpl::send_reply called on operation: "+info.operation());
150         // insert the server id in the reply
151
setIdInServiceContext(info);
152     }
153
154     final public void
155     send_exception(org.omg.PortableInterceptor.ServerRequestInfo JavaDoc info)
156     throws org.omg.PortableInterceptor.ForwardRequest JavaDoc
157     {
158         System.err.println("### LogSRIImpl::send_exception called on operation: "+info.operation());
159         // insert the server id in the reply
160
setIdInServiceContext(info);
161     }
162
163     final public void
164     send_other(org.omg.PortableInterceptor.ServerRequestInfo JavaDoc info)
165     throws org.omg.PortableInterceptor.ForwardRequest JavaDoc
166     {
167         System.err.println("### LogSRIImpl::send_other called on operation: "+info.operation());
168         // insert the server id in the reply
169
setIdInServiceContext(info);
170     }
171 }
172
Popular Tags