KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > modfact > corba > provider > CORBAProvider


1 /**
2  * copyright 2002 2003 Laboratoire d'Informatique Paris 6 (LIP6)
3  *
4  * This file is part of ModFact.
5  *
6  * ModFact is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * at your option) any later version.
10  *
11  * ModFact is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with ModFact; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */

20 package org.objectweb.modfact.corba.provider;
21
22 import org.objectweb.modfact.corba.helper.CORBACommon;
23
24 /**
25  * @author Pierre Carpentier
26  *
27  */

28 public class CORBAProvider implements CORBACommon {
29
30     /**
31      * Reads an IOR from a File.
32      * @param orb The ORB.
33      * @param filename The name of the file which contains the IOR.
34      * @return The CORBA Object corresponding to the IOR read.
35      */

36     public org.omg.CORBA.Object JavaDoc readIOR(org.omg.CORBA.ORB JavaDoc orb, String JavaDoc filename) {
37         try {
38             System.err.println("Reading stringified IOR from file " + filename);
39             java.io.BufferedReader JavaDoc input = new java.io.BufferedReader JavaDoc(new java.io.FileReader JavaDoc(filename));
40             String JavaDoc line = input.readLine();
41             return orb.string_to_object(line);
42         } catch (java.io.IOException JavaDoc ex) {
43             System.err.println("Problem opening/reading IOR file: " + ex);
44         } catch (org.omg.CORBA.SystemException JavaDoc ex) {
45             ex.printStackTrace();
46             System.err.println("CORBA system exception in string_to_object: " + ex);
47         }
48         return null;
49     }
50
51     /**
52      * Writes an IOR to a File
53      * @param orb The ORB.
54      * @param obj The CORBA Object to write.
55      * @param filename The name of the file to write.
56      */

57     public void writeIOR(org.omg.CORBA.ORB JavaDoc orb, org.omg.CORBA.Object JavaDoc obj, String JavaDoc filename) {
58         try {
59             System.err.println("Writing stringified IOR to file " + filename);
60             java.io.FileWriter JavaDoc output = new java.io.FileWriter JavaDoc(filename);
61             output.write(orb.object_to_string(obj) + "\n");
62             output.close();
63             return;
64         } catch (java.io.IOException JavaDoc ex) {
65             System.err.println("Problem opening/writing IOR file: " + ex);
66         } catch (org.omg.CORBA.SystemException JavaDoc ex) {
67             ex.printStackTrace();
68             System.err.println("CORBA system exception in object_to_string: " + ex);
69         }
70     }
71
72     /**
73      * Prints an IOR to a print stream
74      * @param orb The ORB.
75      * @param obj The CORBA Object to print.
76      * @param output The print stream which print the IOR (for example : System.out).
77      */

78     public void printIOR(org.omg.CORBA.ORB JavaDoc orb, org.omg.CORBA.Object JavaDoc obj, java.io.PrintStream JavaDoc output) {
79         try {
80             output.println(orb.object_to_string(obj) + "\n");
81             return;
82         } catch (org.omg.CORBA.SystemException JavaDoc ex) {
83             ex.printStackTrace();
84             System.err.println("CORBA system exception in object_to_string: " + ex);
85         }
86     }
87     
88 }
89
Popular Tags