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 IdlFixed extends IdlNode implements IdlWritable { 40 protected IdlFixed() { 41 setUserObject(this); 42 type = "fixed"; 43 value = "0"; 44 tc = orb.get_primitive_tc(TCKind.tk_fixed); 45 } 46 47 protected IdlFixed(Any any) { 48 this(); 49 setNode(any); 50 } 51 52 protected IdlFixed(TypeCode tc) { 53 this(); 54 setNode(tc); 55 } 56 57 protected void setNode(Any any) { 58 try { 59 setNode(any.type()); 60 java.math.BigDecimal d = any.create_input_stream().read_fixed(); 61 value = d.toString(); 62 } catch (Exception e) { 63 e.printStackTrace(); 64 } 65 } 66 67 72 public void write(org.omg.CORBA.portable.OutputStream os) { 73 try { 74 os.write_fixed(new java.math.BigDecimal (value)); 75 } catch (Exception e) { 76 e.printStackTrace(); 77 } 78 } 79 80 85 public void read(org.omg.CORBA.portable.InputStream is) { 86 try { 87 java.math.BigDecimal d = is.read_fixed(); 88 value = d.toString(); 89 } catch (Exception e) { 90 e.printStackTrace(); 91 } 92 } 93 94 99 public Any toAny() { 100 try { 101 Any any = orb.create_any(); 102 org.omg.CORBA.portable.OutputStream out = any.create_output_stream(); 103 any.type(tc); 104 out.write_fixed(new java.math.BigDecimal (value)); 105 any.read_value(out.create_input_stream(), tc); 106 return any; 107 } catch (Exception e) { 108 e.printStackTrace(); 109 } 110 return null; 111 } 112 113 118 public void setValue(String v) { 119 try { 120 java.math.BigDecimal bd = new java.math.BigDecimal (v); 121 value = v; 122 } catch (Exception e) { 123 throw new RuntimeException (e.toString()); 124 } 125 } 126 127 129 136 public IdlFixed(String xml) { 137 this(XmlNode.getNode(xml)); 138 } 139 140 145 IdlFixed(Node n) { 146 this(); 147 if (n == null || !n.getNodeName().toUpperCase().equals("FIXED")) { 148 throw new RuntimeException ("fixed expected"); 149 } 150 setValue(XmlNode.getText(n)); 151 } 152 153 158 163 public void write(IdlWriter w) { 164 w.write_fixed(value); 165 } 166 } | Popular Tags |