1 21 package org.jacorb.ir.gui.remoteobject; 22 23 import org.jacorb.ir.gui.typesystem.*; 24 import org.jacorb.ir.gui.typesystem.remote.*; 25 import org.omg.CORBA.*; 26 import javax.swing.tree.*; 27 28 32 public class ObjectRepresentantFactory 33 { 34 private static ORB orb = ORB.init(); 35 36 43 public static ObjectRepresentant create(java.lang.Object counterPart, 44 TypeSystemNode type, 45 TypeAssociator referencedBy) 46 { 47 String name = null; 50 if (referencedBy!=null) { 51 name = ((TypeSystemNode)referencedBy).getName(); 52 } 53 54 if (type instanceof IRInterface) { 55 return new RemoteObject((org.omg.CORBA.Object )counterPart, type, name); 56 } 57 if (type instanceof IRStruct) { 58 return new Struct(counterPart, (IRStruct)type, name); 59 } 60 64 return new ObjectRepresentant(counterPart, type, name); 65 } 66 70 public static ObjectRepresentant create(org.omg.CORBA.Object counterPart) { 71 TypeSystemNode typeSystemNode = 72 (IRInterface)RemoteTypeSystem.createTypeSystemNode( 73 InterfaceDefHelper.narrow( counterPart._get_interface_def())); 74 return create(counterPart,typeSystemNode,null); 75 } 76 80 public static ObjectRepresentant createFromIOR (String ior) { 81 org.omg.CORBA.Object obj = orb.string_to_object(ior); 82 return create(obj); 83 } 84 89 protected static void insertFromString (Any result, String value, TCKind kind ) { 90 switch (kind.value()) { 91 case TCKind._tk_null: 92 case TCKind._tk_void: 93 case TCKind._tk_short: 94 result.insert_short(Short.parseShort(value)); 95 break; 96 case TCKind._tk_long: 97 result.insert_long(Integer.parseInt(value)); 98 break; 99 case TCKind._tk_ushort: 100 result.insert_ushort(Short.parseShort(value)); 101 break; 102 case TCKind._tk_ulong: 103 result.insert_ulong(Integer.parseInt(value)); 104 break; 105 case TCKind._tk_float: 106 result.insert_float(new Float (value).floatValue()); 107 break; 108 case TCKind._tk_double: 109 result.insert_double(new Double (value).doubleValue()); 110 break; 111 case TCKind._tk_boolean: 112 result.insert_boolean(new Boolean (value).booleanValue()); 113 break; 114 case TCKind._tk_char: 115 result.insert_char(value.charAt(0)); 116 break; 117 case TCKind._tk_octet: 118 result.insert_octet(new Byte (value).byteValue()); 119 break; 120 127 case TCKind._tk_objref: 128 result.insert_Object(orb.string_to_object(value)); 129 break; 130 133 136 case TCKind._tk_enum: 137 result.insert_long(Integer.parseInt(value)); break; 139 case TCKind._tk_string: 140 result.insert_string(value); 141 break; 142 145 148 151 case TCKind._tk_longlong: 152 result.insert_longlong(Long.parseLong(value)); 153 break; 154 case TCKind._tk_ulonglong: 155 result.insert_ulonglong(Long.parseLong(value)); 156 break; 157 case TCKind._tk_wchar: 158 result.insert_wchar(value.charAt(0)); 159 break; 160 case TCKind._tk_wstring: 161 result.insert_wstring(value); 162 break; 163 default: 164 } 165 } 166 170 public static void main(String args[]) { 171 try { 172 String [] initialServices = orb.list_initial_services(); 173 org.omg.CORBA.Object orep = orb.resolve_initial_references("InterfaceRepository"); 174 Repository rep = RepositoryHelper.narrow( orb.resolve_initial_references("InterfaceRepository")); 175 PrimitiveDef prim = rep.get_primitive(PrimitiveKind.pk_short); 176 177 InterfaceDef intf = InterfaceDefHelper.narrow( prim._get_interface_def()); 178 ObjectRepresentant objr = ObjectRepresentantFactory.create(prim,RemoteTypeSystem.createTypeSystemNode(intf),null); 179 ModelBuilder.getSingleton().buildTreeModelAsync(objr); 180 } 181 catch (Exception e) { 182 e.printStackTrace(); 183 } 184 return; 185 } 186 191 public static java.lang.Object objectFromAny (Any any ) { 192 switch (any.type().kind().value()) { 193 case TCKind._tk_null: 194 return null; 195 case TCKind._tk_void: 196 System.out.println("DII returned an Any of kind void?"); 197 return null; 198 case TCKind._tk_short: 199 return new Short (any.extract_short()); 200 case TCKind._tk_long: 201 return new Integer (any.extract_long()); 202 case TCKind._tk_ushort: 203 return new Short (any.extract_ushort()); 204 case TCKind._tk_ulong: 205 return new Integer (any.extract_ulong()); 206 case TCKind._tk_float: 207 return new Float (any.extract_float()); 208 case TCKind._tk_double: 209 return new Double (any.extract_double()); 210 case TCKind._tk_boolean: 211 return new Boolean (any.extract_boolean()); 212 case TCKind._tk_char: 213 return new Character (any.extract_char()); 214 case TCKind._tk_octet: 215 return new Byte (any.extract_octet()); 216 case TCKind._tk_any: 217 return any.extract_any(); 218 case TCKind._tk_TypeCode: 219 return any.extract_TypeCode(); 220 case TCKind._tk_Principal: 221 return any.extract_Principal(); 222 case TCKind._tk_objref: 223 return any.extract_Object(); 224 227 230 233 case TCKind._tk_string: 234 return any.extract_string(); 235 241 case TCKind._tk_longlong: 242 return new Long (any.extract_longlong()); 243 case TCKind._tk_ulonglong: 244 return new Long (any.extract_ulonglong()); 245 case TCKind._tk_wchar: 246 return new Character (any.extract_wchar()); 247 case TCKind._tk_wstring: 248 return new String (any.extract_wstring()); 249 } 250 return null; 251 } 252 } 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | Popular Tags |