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.DynamicAny.*; 29 import org.omg.CORBA.TypeCode ; 30 import org.omg.CORBA.Any ; 31 import org.omg.CORBA.TCKind ; 32 33 40 public class IdlShort extends IdlNode implements IdlWritable { 41 protected IdlShort() { 42 setUserObject(this); 43 type = "short"; 44 value = "0"; 45 tc = orb.get_primitive_tc(TCKind.tk_short); 46 } 47 48 protected IdlShort(Any any) { 49 this(); 50 setNode(any); 51 } 52 53 protected IdlShort(TypeCode tc) { 54 this(); 55 setNode(tc); 56 } 57 58 protected void setNode(Any any) { 59 try { 60 setNode(any.type()); 61 value = "" + any.create_input_stream().read_short(); 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_short(Short.parseShort(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 try { 93 Short.parseShort(v); 94 value = v; 95 } catch (NumberFormatException e) { 96 throw new RuntimeException (e.toString()); 97 } 98 } 99 100 105 public void write(org.omg.CORBA.portable.OutputStream os) { 106 try { 107 os.write_short(Short.parseShort(value)); 108 } catch (Exception e) { 109 e.printStackTrace(); 110 } 111 } 112 113 118 public void read(org.omg.CORBA.portable.InputStream is) { 119 value = "" + is.read_short(); 120 } 121 122 124 131 public IdlShort(String xml) { 132 this(XmlNode.getNode(xml)); 133 } 134 135 140 IdlShort(Node n) { 141 this(); 142 if (n == null || !n.getNodeName().toUpperCase().equals("SHORT")) { 143 throw new RuntimeException ("short expected"); 144 } 145 setValue(XmlNode.getText(n)); 146 } 147 148 153 public void write(IdlWriter w) { 154 w.write_short(value); 155 } 156 } | Popular Tags |