1 package org.coach.idltree; 2 3 import org.w3c.dom.Node ; 4 import org.omg.CORBA.TypeCode ; 5 import org.omg.CORBA.Any ; 6 import org.omg.CORBA.TCKind ; 7 import org.coach.util.IorPrinter; 8 9 17 public class IdlObject extends IdlNode implements IdlWritable { 18 protected IdlObject() { 19 setUserObject(this); 20 type = "Object"; 21 value = "null"; 22 tc = orb.get_primitive_tc(TCKind.tk_objref); 23 } 24 25 protected IdlObject(Any any) { 26 this(); 27 setNode(any); 28 } 29 30 protected IdlObject(TypeCode tc) { 31 this(); 32 setNode(tc); 33 } 34 35 protected void setNode(Any any) { 36 try { 37 setNode(any.type()); 38 org.omg.CORBA.Object obj = any.extract_Object(); 40 try { 41 value = orb.object_to_string(obj); 42 IorPrinter iorPrinter = new IorPrinter(value); 43 id = iorPrinter.getTypeId(); 44 } catch (Exception e) { 45 value = "null"; 46 } 47 } catch (Exception e) { 48 e.printStackTrace(); 49 } 50 } 51 52 57 public Any toAny() { 58 try { 59 Any any = orb.create_any(); 60 any.type(tc); 61 if (!value.equals("null")) { 62 any.insert_Object(orb.string_to_object(value)); 63 } 64 return any; 65 } catch (Exception e) { 66 e.printStackTrace(); 67 } 68 return null; 69 } 70 71 76 public void setValue(String v) { 77 if (v.toUpperCase().equals("NULL")) { 78 value = "null"; 79 id = ""; 80 } else { 81 int idx = v.indexOf("IOR:"); 82 if (idx < 0) { 83 throw new RuntimeException ("value is not an IOR: " + v); 84 } 85 value = v.substring(idx); 86 try { 87 IorPrinter iorPrinter = new IorPrinter(value); 88 id = iorPrinter.getTypeId(); 89 } catch (Exception e) { 90 id = ""; 91 } 92 } 93 } 94 95 100 public void write(org.omg.CORBA.portable.OutputStream os) { 101 try { 102 os.write_Object(orb.string_to_object(value)); 103 } catch (Exception e) { 104 e.printStackTrace(); 105 } 106 } 107 108 113 public void read(org.omg.CORBA.portable.InputStream is) { 114 value = orb.object_to_string(is.read_Object()); 115 } 116 117 119 131 public IdlObject(String xml) { 132 this(XmlNode.getNode(xml)); 133 } 134 135 140 IdlObject(Node n) { 141 this(); 142 if (n == null || !n.getNodeName().toUpperCase().equals("OBJECT")) { 143 throw new RuntimeException ("Object expected"); 144 } 145 setValue(XmlNode.getText(n)); 146 } 147 148 153 public void write(IdlWriter w) { 154 w.write_Object(value); 155 } 156 } | Popular Tags |