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.Any ; 29 import org.omg.DynamicAny.*; 30 31 import java.util.*; 32 import java.lang.reflect.*; 33 34 45 public class IdlParameter extends IdlNode implements IdlWritable { 46 protected String name; 47 protected String dir; 48 49 protected IdlParameter() { 50 isLeaf = false; 51 isMutable = false; 52 setUserObject(this); 53 type = "parameter"; 54 } 55 56 protected IdlParameter(String dir, String name, Any any) { 57 this(); 58 try { 59 this.dir = dir; 60 this.name = name; 61 IdlNode n = create(any); 62 n.field = name; 63 add(n); 64 } catch (Exception e) { 65 e.printStackTrace(); 66 } 67 } 68 69 74 public String getName() { 75 return name; 76 } 77 78 85 public String getDirection() { 86 return dir; 87 } 88 89 94 public String toString() { 95 if (dir.equals("return")) { 96 return dir; 97 } else { 98 return dir + " " + name; 99 } 100 } 101 102 107 public IdlNode getParameter() { 108 return (IdlNode)getChildAt(0); 109 } 110 111 116 public void setValue(Any any) { 117 removeAllChildren(); 118 IdlNode n = create(any); 119 n.field = name; 120 add(n); 121 } 122 123 128 public void write(org.omg.CORBA.portable.OutputStream os) { 129 ((IdlNode)getChildAt(0)).write(os); 130 } 131 132 137 public void read(org.omg.CORBA.portable.InputStream is) { 138 ((IdlNode)getChildAt(0)).read(is); 139 } 140 141 143 155 public IdlParameter(String xml) { 156 this(XmlNode.getNode(xml)); 157 } 158 159 IdlParameter(Node n) { 160 this(); 161 try { 162 if (n.getNodeName().toUpperCase().equals("IN")) { 163 dir = "in"; 164 name = XmlNode.getName(n); 165 } else if (n.getNodeName().toUpperCase().equals("OUT")) { 166 dir = "out"; 167 name = XmlNode.getName(n); 168 } else if (n.getNodeName().toUpperCase().equals("INOUT")) { 169 dir = "inout"; 170 name = XmlNode.getName(n); 171 } else if (n.getNodeName().toUpperCase().equals("RETURN")) { 172 name = "return"; 173 dir = "return"; 174 } 175 IdlNode nn = XmlNode.getIdlNode(XmlNode.firstChildElement(n)); 176 nn.setField(name); 177 add(nn); 178 } catch (Exception e) { 179 e.printStackTrace(); 180 throw new RuntimeException (e.toString()); 181 } 182 } 183 184 IdlParameter(String dir, String name, org.omg.CORBA.TypeCode tc) { 185 this(); 186 try { 187 this.dir = dir; 188 this.name = name; 189 IdlNode n = create(tc); 190 n.setField(name); 191 add(n); 192 } catch (Exception e) { 193 e.printStackTrace(); 194 throw new RuntimeException (e.toString()); 195 } 196 } 197 198 203 public void write(IdlWriter w) { 204 write(this, w); 205 } 206 207 public static void write(IdlParameter n, IdlWriter w) { 208 if (n.getDirection().equals("in")) { 209 w.write_start_inpar(n.getName()); 210 XmlNode.write((IdlNode)n.getParameter(), w); 211 w.write_end_inpar(); 212 } else if (n.getDirection().equals("out")) { 213 w.write_start_outpar(n.getName()); 214 XmlNode.write((IdlNode)n.getParameter(), w); 215 w.write_end_outpar(); 216 } else if (n.getDirection().equals("inout")) { 217 w.write_start_inoutpar(n.getName()); 218 XmlNode.write((IdlNode)n.getParameter(), w); 219 w.write_end_inoutpar(); 220 } else if (n.getDirection().equals("return")) { 221 w.write_start_return(); 222 XmlNode.write((IdlNode)n.getParameter(), w); 223 w.write_end_return(); 224 } 225 } 226 } | Popular Tags |