KickJava   Java API By Example, From Geeks To Geeks.

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


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>Implementation of a client request interceptor for the log service.
36  ** This CRI propagates the 'id' information of the current to the server side.</p>
37  **
38  ** @see org.objectweb.corba.logservice.LogCurrentImpl LogCurrentImpl
39  ** @see org.objectweb.corba.logservice.LogSRIImpl LogSRIImpl
40  **/

41 public class LogCRIImpl
42 extends org.omg.CORBA.LocalObject JavaDoc
43 implements org.omg.PortableInterceptor.ClientRequestInterceptor JavaDoc
44 {
45     //
46
private org.omg.IOP.Codec JavaDoc _codec;
47     private int _slot_id;
48
49     public
50     LogCRIImpl(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 org.omg.PortableInterceptor.Current JavaDoc
62     getPICurrent()
63     {
64         org.omg.CORBA.Object JavaDoc obj = null;
65         org.omg.PortableInterceptor.Current JavaDoc current = null;
66         org.omg.CORBA.ORB JavaDoc orb = org.omg.CORBA.ORB.init();
67         try {
68             obj = orb.resolve_initial_references("PICurrent");
69         } catch (org.omg.CORBA.ORBPackage.InvalidName JavaDoc ex) {
70         } catch (Exception JavaDoc ex) {
71             System.err.println("!!! LogCRIImpl::getPICurrent exception caught: "+ex.getMessage());
72         } catch (Error JavaDoc err) {
73             System.err.println("!!! LogCRIImpl::getPICurrent error caught: "+err.getMessage());
74         }
75
76         return org.omg.PortableInterceptor.CurrentHelper.narrow(obj);
77     }
78
79     private void
80     setIdInServiceContext(org.omg.PortableInterceptor.ClientRequestInfo JavaDoc info)
81     {
82         // get client id from slot
83
org.omg.CORBA.Any JavaDoc cid = null;
84         try {
85             cid = info.get_slot(_slot_id);
86         } catch (org.omg.PortableInterceptor.InvalidSlot JavaDoc ex) {
87             System.err.println("!!! LogCRIImpl::setIdInServiceContext: invalid slot");
88         }
89
90         if ((cid==null) || (cid.type().kind()==org.omg.CORBA.TCKind.tk_null)) {
91             System.err.println("!!! LogCRIImpl::setIdInServiceContext: slot has no value");
92             return ;
93         }
94
95         // set client id in service context
96
org.omg.IOP.ServiceContext JavaDoc sctx = new org.omg.IOP.ServiceContext JavaDoc();
97         sctx.context_id = LOG_IOP_SERVICE_ID.value;
98         try {
99             sctx.context_data = _codec.encode(cid);
100         } catch (org.omg.IOP.CodecPackage.InvalidTypeForEncoding JavaDoc ex) {
101             System.err.println("!!! LogCRIImpl::setIdInServiceContext: invalid type for encoding in service context");
102         }
103
104         info.add_request_service_context(sctx, true);
105     }
106
107     private void
108     getIdFromServiceContext(org.omg.PortableInterceptor.ClientRequestInfo JavaDoc info)
109     {
110         // get log service context
111
org.omg.IOP.ServiceContext JavaDoc sctx = null;
112         try {
113             sctx = info.get_reply_service_context(LOG_IOP_SERVICE_ID.value);
114         } catch (org.omg.CORBA.SystemException JavaDoc ex) {
115             System.err.println("!!! LogCRIImpl::getIdFromServiceContext: Service context not found");
116         }
117
118         if (sctx==null) {
119             System.err.println("!!! LogCRIImpl::getIdFromServiceContext: Service context not found");
120             return ;
121         }
122
123         // extract server id from context
124
org.omg.CORBA.Any JavaDoc cid = null;
125         try {
126             cid = _codec.decode(sctx.context_data);
127         } catch (org.omg.IOP.CodecPackage.FormatMismatch JavaDoc ex) {
128         }
129
130         // set server id in slot
131
try {
132             getPICurrent().set_slot(_slot_id, cid);
133         } catch (org.omg.PortableInterceptor.InvalidSlot JavaDoc ex) {
134         }
135     }
136
137     //
138
// IDL:omg.org/PortableInterceptor/RequestInterceptor:1.0
139
//
140

141     final public String JavaDoc
142     name()
143     {
144         return "LogCRIImpl";
145     }
146
147     final public void
148     destroy()
149     {
150     }
151
152     //
153
// IDL:omg.org/PortableInterceptor/ClientRequestInterceptor:1.0
154
//
155

156     final public void
157     send_request(org.omg.PortableInterceptor.ClientRequestInfo JavaDoc info)
158     throws org.omg.PortableInterceptor.ForwardRequest JavaDoc
159     {
160         System.err.println("### LogCRIImpl::send_request called on operation: "+info.operation());
161         // insert the client id in the request
162
setIdInServiceContext(info);
163     }
164
165     final public void
166     send_poll(org.omg.PortableInterceptor.ClientRequestInfo JavaDoc info)
167     {
168         System.err.println("### LogCRIImpl::send_poll called on operation: "+info.operation());
169         // insert the client id in the request
170
setIdInServiceContext(info);
171     }
172
173     final public void
174     receive_reply(org.omg.PortableInterceptor.ClientRequestInfo JavaDoc info)
175     {
176         System.err.println("### LogCRIImpl::receive_reply called on operation: "+info.operation());
177         // extract the server id from the reply
178
getIdFromServiceContext(info);
179     }
180
181     final public void
182     receive_exception(org.omg.PortableInterceptor.ClientRequestInfo JavaDoc info)
183     throws org.omg.PortableInterceptor.ForwardRequest JavaDoc
184     {
185         System.err.println("### LogCRIImpl::receive_exception called on operation: "+info.operation());
186         // extract the server id from the reply
187
getIdFromServiceContext(info);
188     }
189
190     final public void
191     receive_other(org.omg.PortableInterceptor.ClientRequestInfo JavaDoc info)
192     throws org.omg.PortableInterceptor.ForwardRequest JavaDoc
193     {
194         System.err.println("### LogCRIImpl::receive_other called on operation: "+info.operation());
195         // extract the server id from the reply
196
getIdFromServiceContext(info);
197     }
198 }
199
Popular Tags