KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > coach > idltree > IdlInterface


1 package org.coach.idltree;
2
3 import org.w3c.dom.Node JavaDoc;
4 import java.lang.reflect.*;
5 import org.omg.CORBA.TypeCode JavaDoc;
6 import org.omg.CORBA.Any JavaDoc;
7 import org.omg.CORBA.TCKind JavaDoc;
8 import org.coach.util.IorPrinter;
9
10 /**
11  * The class IdlInterface represents an CORBA IDL interface ior value. Instances are created through one
12  * of the create() factory methods in IdlNode.
13  * When an IdlInterface object is created the Interface Repository is queried to obtain the
14  * list of operations this interface supports. This list can be obtained with the getOperations() method.
15  * An IdlInterface object has no child nodes.
16  *
17  * @author <a HREF="mailto:batteram@lucent.com">Harold Batteram</a> <b>Lucent Technologies</b>
18  */

19 public class IdlInterface extends IdlObject implements IdlWritable {
20     protected String JavaDoc[] 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 JavaDoc any) {
30         this();
31         setNode(any.type());
32         setNode(any);
33     }
34         
35     protected IdlInterface(TypeCode JavaDoc tc) {
36         this();
37         setNode(tc);
38     }
39     
40
41     /**
42      * Assigns the node value from a string.
43      *
44      * @param v The string from which to convert the value.
45      */

46     public void setValue(String JavaDoc 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 JavaDoc("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 JavaDoc e) {
60                 id = "";
61             }
62         }
63     }
64     
65     // XML section
66

67     /**
68      * Create an IdlInterface node from an Xml representation.
69      *
70      * XML format example:
71      * <pre>
72      * &lt;interface&gt;id="IDL:examples/MyInterface:1.0"&gt;
73      * IOR:000....
74      * &lt;/interface&gt;
75      * </pre>
76      *
77      * @param xml The XML string from which to create an IdlInterface instance.
78      */

79     public IdlInterface(String JavaDoc xml) {
80         this(XmlNode.getNode(xml));
81     }
82       
83     /**
84      * Construct an XmlNode from an Xml node.
85      * Package access only. Called from the Xml parser to construct
86      * an Xml type tree from an Xml representation.
87      */

88     IdlInterface(Node JavaDoc n) {
89         this();
90         try {
91             if (n == null || !n.getNodeName().toUpperCase().equals("INTERFACE")) {
92                 throw new RuntimeException JavaDoc("interface expected");
93             }
94             setNode(XmlNode.type(XmlNode.getId(n)));
95             setValue(XmlNode.getText(n));
96             operations = XmlNode.getOperations(id);
97         } catch (Exception JavaDoc e) {
98             throw new RuntimeException JavaDoc(e.toString());
99         }
100     }
101
102     public IdlInterface(String JavaDoc id, boolean dummy) {
103         this();
104         try {
105             this.id = id;
106             setNode(XmlNode.type(id));
107             operations = XmlNode.getOperations(id);
108         } catch (Exception JavaDoc e) {
109             e.printStackTrace();
110         }
111     }
112     
113     /**
114      * Return the list of operation names of the interface.
115      *
116      * @return The list of operation names of the interface.
117      */

118     public String JavaDoc[] getOperations() {
119         return operations;
120     }
121
122    
123     /**
124      * Write the current value to an IdlWriter object.
125      *
126      * @param w The IdlWriter object to write the current value to.
127      */

128     public void write(IdlWriter w) {
129         w.write_interface(id, value);
130     }
131 }
Popular Tags