1 package org.coach.idltree; 2 3 import org.w3c.dom.Node ; 4 import java.lang.reflect.*; 5 import org.omg.CORBA.TypeCode ; 6 import org.omg.CORBA.Any ; 7 import org.omg.CORBA.TCKind ; 8 import org.coach.util.IorPrinter; 9 10 19 public class IdlInterface extends IdlObject implements IdlWritable { 20 protected String [] operations; 21 22 protected IdlInterface() { 23 setUserObject(this); 24 type = "Object"; 25 value = "null"; 26 tc = orb.get_primitive_tc(TCKind.tk_objref); 27 } 28 29 protected IdlInterface(Any any) { 30 this(); 31 setNode(any.type()); 32 setNode(any); 33 } 34 35 protected IdlInterface(TypeCode tc) { 36 this(); 37 setNode(tc); 38 } 39 40 41 46 public void setValue(String v) { 47 if (v.toUpperCase().equals("NULL")) { 48 value = "null"; 49 id = ""; 50 } else { 51 int idx = v.indexOf("IOR:"); 52 if (idx < 0) { 53 throw new RuntimeException ("value is not an IOR: " + v); 54 } 55 value = v.substring(idx); 56 try { 57 IorPrinter iorPrinter = new IorPrinter(value); 58 id = iorPrinter.getTypeId(); 59 } catch (Exception e) { 60 id = ""; 61 } 62 } 63 } 64 65 67 79 public IdlInterface(String xml) { 80 this(XmlNode.getNode(xml)); 81 } 82 83 88 IdlInterface(Node n) { 89 this(); 90 try { 91 if (n == null || !n.getNodeName().toUpperCase().equals("INTERFACE")) { 92 throw new RuntimeException ("interface expected"); 93 } 94 setNode(XmlNode.type(XmlNode.getId(n))); 95 setValue(XmlNode.getText(n)); 96 operations = XmlNode.getOperations(id); 97 } catch (Exception e) { 98 throw new RuntimeException (e.toString()); 99 } 100 } 101 102 public IdlInterface(String id, boolean dummy) { 103 this(); 104 try { 105 this.id = id; 106 setNode(XmlNode.type(id)); 107 operations = XmlNode.getOperations(id); 108 } catch (Exception e) { 109 e.printStackTrace(); 110 } 111 } 112 113 118 public String [] getOperations() { 119 return operations; 120 } 121 122 123 128 public void write(IdlWriter w) { 129 w.write_interface(id, value); 130 } 131 } | Popular Tags |