KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > corba > runtime > FileRegistrationSchemeImpl


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.runtime;
31
32 /**
33  ** <p>Default implementation of the <tt>FileRegistrationScheme</tt> scheme.</p>
34  **
35  ** @see org.objectweb.corba.runtime.RegistrationServiceImpl RegistrationServiceImpl
36  **/

37 public class FileRegistrationSchemeImpl
38 extends org.omg.CORBA.LocalObject JavaDoc
39 implements FileRegistrationScheme
40 {
41     // scheme
42
static final private String JavaDoc _class_name = "FileRegistrationSchemeImpl";
43     static final private String JavaDoc _scheme_id = FileRegistrationScheme.SCHEME_ID;
44
45     // default constructor
46
protected
47     FileRegistrationSchemeImpl()
48     {
49     }
50
51     //
52
// entry point
53
//
54

55     static public RegistrationScheme
56     create_scheme()
57     {
58         return new FileRegistrationSchemeImpl();
59     }
60
61     //
62
// IDL:objectweb.org/corba/runtime/RegistrationScheme:1.0
63
//
64

65     final public String JavaDoc
66     scheme_id()
67     {
68         return _scheme_id;
69     }
70
71     //
72
// IDL:objectweb.org/corba/runtime/FileRegistrationScheme:1.0
73
//
74

75     final public void
76     write_ior(String JavaDoc name, org.omg.CORBA.Object JavaDoc ref, ORBService orbs)
77     {
78         // use name as iorfile
79
String JavaDoc iorfile = name;
80
81         // stringify IOR
82
String JavaDoc sref = orbs.object_to_string(ref);
83
84         // write reference to the file
85
java.io.FileOutputStream JavaDoc out = null;
86         try {
87             out = new java.io.FileOutputStream JavaDoc(iorfile);
88             out.write(sref.getBytes());
89             out.close();
90         } catch(Exception JavaDoc ex) {
91             // ignore
92
final String JavaDoc opname = "write_ior";
93             final String JavaDoc msg = "IGNORE (file: "+iorfile+")";
94             TheLogger.debug(_class_name, opname, msg, ex);
95         }
96     }
97
98     final public org.omg.CORBA.Object JavaDoc
99     read_ior(String JavaDoc name, ORBService orbs)
100     {
101         // use name as iorfile
102
String JavaDoc iorfile = name;
103
104         // read reference from the file
105
java.io.BufferedReader JavaDoc in = null;
106         StringBuffer JavaDoc res = new StringBuffer JavaDoc();
107         try {
108             in = new java.io.BufferedReader JavaDoc(new java.io.FileReader JavaDoc(iorfile));
109             while(in.ready()) {
110                 res.append(in.readLine());
111             }
112
113             in.close();
114         } catch(Exception JavaDoc ex) {
115             final String JavaDoc opname = "read_ior";
116             final String JavaDoc msg = "FAILED (file: "+iorfile+")";
117             TheLogger.error(_class_name, opname, msg, ex);
118         }
119
120         // unstringify IOR
121
return orbs.string_to_object(res.toString());
122     }
123 }
124
Popular Tags