1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 package org.coach.idltree; 26 27 import org.w3c.dom.Node ; 28 29 import org.omg.CORBA.TypeCode ; 30 import org.omg.CORBA.Any ; 31 import org.omg.CORBA.TCKind ; 32 33 40 public class IdlString extends IdlNode implements IdlWritable { 41 protected IdlString() { 42 setUserObject(this); 43 type = "string"; 44 value = ""; 45 tc = orb.get_primitive_tc(TCKind.tk_string); 46 } 47 48 protected IdlString(Any any) { 49 this(); 50 setNode(any); 51 } 52 53 protected IdlString(TypeCode tc) { 54 this(); 55 setNode(tc); 56 } 57 58 protected void setNode(Any any) { 59 try { 60 setNode(any.type()); 61 setValue(any.create_input_stream().read_string()); 62 } catch (Exception e) { 63 e.printStackTrace(); 64 } 65 } 66 67 72 public Any toAny() { 73 try { 74 Any any = orb.create_any(); 75 org.omg.CORBA.portable.OutputStream out = any.create_output_stream(); 76 any.type(tc); 77 out.write_string(value); 78 any.read_value(out.create_input_stream(), tc); 79 return any; 80 } catch (Exception e) { 81 e.printStackTrace(); 82 } 83 return null; 84 } 85 86 91 public void setValue(String v) { 92 if (v == null) { 93 v = ""; 94 } 95 value = v; 96 } 97 98 103 public void write(org.omg.CORBA.portable.OutputStream os) { 104 os.write_string(value); 105 } 106 107 112 public void read(org.omg.CORBA.portable.InputStream is) { 113 value = is.read_string(); 114 } 115 116 118 125 public IdlString(String xml) { 126 this(XmlNode.getNode(xml)); 127 } 128 129 134 IdlString(Node n) { 135 this(); 136 137 if (n == null || !n.getNodeName().toUpperCase().equals("STRING")) { 138 throw new RuntimeException ("string expected"); 139 } 140 setValue(XmlNode.getText(n)); 141 } 142 143 148 public void write(IdlWriter w) { 149 w.write_string(value); 150 } 151 } | Popular Tags |