KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > runtime > ServiceArchiveImpl


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.ccm.runtime;
31
32 import org.objectweb.corba.runtime.*;
33
34 /**
35  ** <p></p>
36  **/

37 public class ServiceArchiveImpl
38 extends ArchiveServantBase
39 implements Servant, org.coach.ECM.ServiceArchiveOperations
40 {
41     // system component
42
static final private String JavaDoc _class_name = "ServiceArchiveImpl";
43
44     // servant
45
static final private String JavaDoc _type_id = org.coach.ECM.ServiceArchiveHelper.id();
46
47     // archive
48
private ORBService _orb_service;
49     private String JavaDoc _uuid;
50     private String JavaDoc _archive_location;
51     private String JavaDoc _dtd_location;
52
53     // service archive
54
private String JavaDoc _service_id;
55     private String JavaDoc _code_location;
56     private String JavaDoc _code_entrypoint;
57     private String JavaDoc _csd_location;
58     private String JavaDoc _ccsd_location;
59     // fully scope as CORBAServiceRef is also a java class in this package
60
private org.coach.ECM.CORBAServiceRef _corbaservice_ref;
61
62     // default constructor
63
public
64     ServiceArchiveImpl(ORBService orbs,
65                        String JavaDoc dtdloc,
66                        String JavaDoc uuid,
67                        String JavaDoc loc)
68     {
69         super(uuid, loc);
70
71         // archive
72
_orb_service = orbs;
73         _uuid = uuid;
74         _archive_location = loc;
75         _dtd_location = dtdloc;
76
77         // service archive
78
_service_id = null;
79         _code_location = null;
80         _code_entrypoint = null;
81         _csd_location = null;
82         _ccsd_location = null;
83         _corbaservice_ref = null;
84
85         // initiliaze some internal fields
86
initializeInternalFields();
87     }
88
89     //
90
// abstract operations implementation
91
//
92

93     final protected ORBService
94     getORBService()
95     {
96         return _orb_service;
97     }
98
99     //
100
// internal operations
101
//
102

103     private void
104     initializeInternalFields()
105     {
106         final String JavaDoc opname = "initializeInternalFields";
107         // open zip
108
java.util.zip.ZipFile JavaDoc zip = openZip();
109
110         // extract CSD location
111
java.util.Enumeration JavaDoc entries = zip.entries();
112         java.util.zip.ZipEntry JavaDoc entry = null;
113         java.util.zip.ZipEntry JavaDoc csdentry = null;
114         while (entries.hasMoreElements()) {
115             entry = (java.util.zip.ZipEntry JavaDoc)entries.nextElement();
116             if (entry.getName().endsWith(".csd")) {
117                 csdentry = entry;
118             }
119         }
120
121         // check if CSD found
122
if (csdentry==null) {
123             // NOTE: TODO: should be reported as an exception
124
final String JavaDoc msg = "FAILED (no CSD found in "+_uuid+")";
125             TheLogger.error(_class_name, opname, msg);
126             return ;
127         }
128
129         // copy CSD file locally
130
String JavaDoc csdfname = extractFile(zip, csdentry);
131         _csd_location = csdfname;
132
133         // parse CSD file
134
CSDParser csdparser = CSDParser.parse(_csd_location, _dtd_location, _uuid);
135
136         // obtain code entry point
137
_code_entrypoint = csdparser.code_entrypoint;
138
139         // extract CCSD and code archive
140
entries = zip.entries();
141         java.util.zip.ZipEntry JavaDoc ccsdentry = null;
142         java.util.zip.ZipEntry JavaDoc codelocentry = null;
143         String JavaDoc ccsdname = csdparser.descriptor_location;
144         String JavaDoc codeloc = csdparser.code_location;
145         while (entries.hasMoreElements()) {
146             entry = (java.util.zip.ZipEntry JavaDoc)entries.nextElement();
147             if (entry.getName().equals(ccsdname)) {
148                 ccsdentry = entry;
149             }
150             else if (entry.getName().equals(codeloc)) {
151                 codelocentry = entry;
152             }
153         }
154
155         // check if code archive found
156
if (codelocentry==null) {
157             // NOTE: TODO: should be reported as an exception
158
final String JavaDoc msg = "FAILED (no code library found in "+_uuid+")";
159             TheLogger.error(_class_name, opname, msg);
160             return ;
161         }
162
163         // copy code archive locally
164
String JavaDoc codelocfname = extractFile(zip, codelocentry);
165         _code_location = codelocfname;
166
167         // check if CCSD found
168
if (ccsdentry==null) {
169             // NOTE: TODO: should be reported as an exception
170
final String JavaDoc msg = "FAILED (CCSD file not found in "+_uuid+")";
171             TheLogger.error(_class_name, opname, msg);
172             return ;
173         }
174
175         // copy CCSD file locally
176
String JavaDoc ccsdfname = extractFile(zip, ccsdentry);
177         _ccsd_location = ccsdfname;
178
179         // parse CCSD
180
CCSDParser ccsdparser = CCSDParser.parse(_ccsd_location, _dtd_location, getORBService());
181
182         // get service id
183
_service_id = ccsdparser.getServiceId();
184
185         // get corbaservice ref
186
_corbaservice_ref = ccsdparser.getCORBAServiceRef();
187
188         // close CSD
189
// NOTE: how ?
190
// close CCSD
191
// NOTE: how ?
192

193         // close zip
194
try {
195             zip.close();
196         } catch(java.io.IOException JavaDoc ex) {
197             // NOTE: TODO: should be reported as an exception
198
// ignore for the moment
199
TheLogger.error(_class_name, opname, "IGNORE", ex);
200         }
201     }
202
203     //
204
// IDL:org/objectweb/corba/runtime/SystemComponent:1.0
205
//
206

207     final public void
208     system_configuration_complete(SystemConfiguration cfg)
209     {
210         // initiliaze some internal fields
211
initializeInternalFields();
212     }
213
214     final public void
215     destroy()
216     {
217         // TODO: destroy local files extracted from the zip
218
}
219
220     //
221
// IDL:org/objectweb/corba/runtime/Servant:1.0
222
//
223

224     final public String JavaDoc
225     type_id()
226     {
227         return _type_id;
228     }
229
230     final public org.omg.PortableServer.Servant JavaDoc
231     as_native_servant()
232     {
233         return new org.coach.ECM.ServiceArchivePOATie(this);
234     }
235
236
237     //
238
// IDL:org/objectweb/ccm/runtime/Archive:1.0
239
//
240

241     // public String get_fileinarchive_location(String name, String link)
242
// public String get_href_location(String href)
243
// public String get_link_location(String link)
244
// public String get_ins_as_objref(String ins)
245
// public String uuid()
246

247     //
248
// IDL:coach.org/ECM/ServiceArchive:1.0
249
//
250

251     final public String JavaDoc
252     service_id()
253     {
254         return _service_id;
255     }
256
257     final public String JavaDoc
258     csd_location()
259     {
260         return _csd_location;
261     }
262
263     final public String JavaDoc
264     ccsd_location()
265     {
266         return _ccsd_location;
267     }
268
269     final public String JavaDoc
270     code_location()
271     {
272         return _code_location;
273     }
274
275     final public String JavaDoc
276     code_entrypoint()
277     {
278         return _code_entrypoint;
279     }
280
281     final public org.coach.ECM.CORBAServiceRef
282     get_corbaservice_ref()
283     throws org.coach.ECM.NoCORBAServiceRefRequired
284     {
285         if (_corbaservice_ref==null) {
286             throw new org.coach.ECM.NoCORBAServiceRefRequired();
287         }
288
289         return _corbaservice_ref;
290     }
291
292     final public String JavaDoc
293     exec_xpath_request_in_csd(String JavaDoc req)
294     {
295         final String JavaDoc opname = "exec_xpath_request_in_csd";
296         final String JavaDoc msg = "FAILED (not implemented, rethrown)";
297         TheLogger.debug(_class_name, opname, msg);
298
299         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
300     }
301
302     final public String JavaDoc
303     exec_xpath_request_in_ccsd(String JavaDoc req)
304     {
305         final String JavaDoc opname = "exec_xpath_request_in_ccsd";
306         final String JavaDoc msg = "FAILED (not implemented, rethrown)";
307         TheLogger.debug(_class_name, opname, msg);
308
309         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
310     }
311 }
312
Popular Tags