1 26 27 28 package org.objectweb.mobilitools.util.corba; 29 30 31 import org.omg.CORBA.*; 32 import java.io.*; 33 import java.applet.Applet ; 34 import java.util.Properties ; 35 36 37 42 abstract public class CORBA 43 { 44 static ORB orbSingleton = null; 45 46 47 static public void setOrb(ORB orb) 48 { 49 orbSingleton = orb; 50 } 51 52 53 static public ORB getOrb() 54 { 55 if (orbSingleton == null) 56 { 57 orbSingleton = ORB.init(); 58 } 59 return orbSingleton; 60 } 61 62 63 static public ORB setOrb(String [] args, Properties props) 64 { 65 return orbSingleton = ORB.init(args, props); 66 } 67 68 69 static public ORB setOrb(Applet applet, Properties props) 70 { 71 return orbSingleton = ORB.init(applet, props); 72 } 73 74 75 static public boolean refToFile(ORB orb, org.omg.CORBA.Object ref, String filename) 76 { 77 try 78 { 79 String refStr = orb.object_to_string(ref); 80 PrintWriter out = new PrintWriter( 81 new FileOutputStream(filename)); 82 out.println(refStr); 83 out.flush(); 84 } 85 catch(IOException ex) 86 { 87 return false; 88 } 89 return true; 90 } 91 92 93 static public org.omg.CORBA.Object refFromFile(ORB orb, String filename) 94 { 95 String refStr = null; 96 try 97 { 98 BufferedReader in = 99 new BufferedReader(new FileReader(filename)); 100 refStr = in.readLine(); 101 } 102 catch(IOException ex) 103 { 104 return null; 105 } 106 return orb.string_to_object(refStr); 107 } 108 109 110 static public Any object2any(ORB orb, java.lang.Object obj) 111 throws BAD_PARAM 112 { 113 Any result = orb.create_any(); 114 if (obj instanceof Boolean ) 115 { 116 result.insert_boolean(((Boolean )obj).booleanValue()); 117 } 118 else if (obj instanceof Character ) 119 { 120 result.insert_char(((Character )obj).charValue()); 121 } 122 else if (obj instanceof Byte ) 123 { 124 result.insert_octet(((Byte )obj).byteValue()); 125 } 126 else if (obj instanceof String ) 127 { 128 result.insert_string((String )obj); 129 } 130 else if (obj instanceof Short ) 131 { 132 result.insert_short(((Short )obj).shortValue()); 133 } 134 else if (obj instanceof Integer ) 135 { 136 result.insert_long(((Integer )obj).intValue()); 137 } 138 else if (obj instanceof Long ) 139 { 140 result.insert_longlong(((Long )obj).longValue()); 141 } 142 else if (obj instanceof Float ) 143 { 144 result.insert_float(((Float )obj).floatValue()); 145 } 146 else if (obj instanceof Double ) 147 { 148 result.insert_double(((Double )obj).doubleValue()); 149 } 150 else 151 { 152 throw new BAD_PARAM(); 153 } 154 return result; 155 } 156 157 158 static public java.lang.Object any2object(Any any) 159 { 160 java.lang.Object result = null; 161 switch(any.type().kind().value()) 162 { 163 case TCKind._tk_boolean: 164 result = new Boolean (any.extract_boolean()); 165 break; 166 case TCKind._tk_char: 167 result = new Character (any.extract_char()); 168 break; 169 case TCKind._tk_octet: 170 result = new Byte (any.extract_octet()); 171 break; 172 case TCKind._tk_string: 173 result = any.extract_string(); 174 break; 175 case TCKind._tk_short: 176 result = new Short (any.extract_short()); 177 break; 178 case TCKind._tk_long: 179 result = new Integer (any.extract_long()); 180 break; 181 case TCKind._tk_longlong: 182 result = new Long (any.extract_longlong()); 183 break; 184 case TCKind._tk_float: 185 result = new Float (any.extract_float()); 186 break; 187 case TCKind._tk_double: 188 result = new Float (any.extract_double()); 189 break; 190 default: 191 throw new BAD_PARAM(); 192 } 193 return result; 194 } 195 } 196 | Popular Tags |