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 import org.omg.CORBA.TypeCode ; 29 import org.omg.CORBA.Any ; 30 import org.omg.CORBA.TCKind ; 31 32 39 public class IdlChar extends IdlNode implements IdlWritable { 40 protected IdlChar() { 41 setUserObject(this); 42 type = "char"; 43 value = " "; 44 tc = orb.get_primitive_tc(TCKind.tk_char); 45 } 46 47 protected IdlChar(Any any) { 48 this(); 49 setNode(any); 50 } 51 52 protected IdlChar(TypeCode tc) { 53 this(); 54 setNode(tc); 55 } 56 57 protected void setNode(Any any) { 58 try { 59 setNode(any.type()); 60 value = "" + any.create_input_stream().read_char(); 61 } catch (Exception e) { 62 e.printStackTrace(); 63 } 64 } 65 66 public void setValue(String v) { 67 if (v == null || v.equals("")) { 68 value = " "; 69 } else { 70 value = v; 71 } 72 } 73 74 79 public void write(org.omg.CORBA.portable.OutputStream os) { 80 try { 81 os.write_char(value.charAt(0)); 82 } catch (Throwable e) { 83 e.printStackTrace(); 84 } 85 } 86 87 92 public void read(org.omg.CORBA.portable.InputStream is) { 93 value = "" + is.read_char(); 94 } 95 96 101 public Any toAny() { 102 try { 103 Any any = orb.create_any(); 104 org.omg.CORBA.portable.OutputStream out = any.create_output_stream(); 105 any.type(tc); 106 out.write_char(value.charAt(0)); 107 any.read_value(out.create_input_stream(), tc); 108 return any; 109 } catch (Throwable e) { 110 e.printStackTrace(); 111 } 112 return null; 113 } 114 115 117 127 public IdlChar(String xml) { 128 this(XmlNode.getNode(xml)); 129 } 130 131 136 IdlChar(Node n) { 137 this(); 138 139 if (n == null || !n.getNodeName().toUpperCase().equals("CHAR")) { 140 throw new RuntimeException ("char expected"); 141 } 142 setValue(XmlNode.getText(n)); 143 } 144 145 146 151 public void write(IdlWriter w) { 152 w.write_char(value); 153 } 154 } | Popular Tags |