KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.coach.idltree;
2
3 import org.w3c.dom.Node JavaDoc;
4 import javax.swing.tree.*;
5
6 import java.util.*;
7 import java.io.*;
8 import java.lang.reflect.*;
9 import org.omg.CORBA.ORB JavaDoc;
10 import org.omg.CORBA.TypeCode JavaDoc;
11 import org.omg.CORBA.Any JavaDoc;
12 import org.omg.CORBA.TCKind JavaDoc;
13 import org.coach.util.IorPrinter;
14
15 public class IdlComponent extends IdlInterface implements IdlWritable {
16     protected String JavaDoc[] facets;
17
18     protected IdlComponent() {
19         setUserObject(this);
20         type = "Component";
21         value = "null";
22         tc = orb.get_primitive_tc(TCKind.tk_objref);
23     }
24
25     protected IdlComponent(Any JavaDoc any) {
26         this();
27         setNode(any.type());
28         setNode(any);
29     }
30         
31     protected IdlComponent(TypeCode JavaDoc tc) {
32         this();
33         setNode(tc);
34     }
35
36     /**
37      * Assigns the node value from a string.
38      *
39      * @param v The string from which to convert the value.
40      */

41     public void setValue(String JavaDoc v) {
42         if (v.toUpperCase().equals("NULL")) {
43             value = "null";
44             id = "";
45         } else {
46             int idx = v.indexOf("IOR:");
47             if (idx < 0) {
48                 throw new RuntimeException JavaDoc("value is not an IOR: " + v);
49             }
50             value = v.substring(idx);
51             try {
52                 IorPrinter iorPrinter = new IorPrinter(value);
53                 id = iorPrinter.getTypeId();
54             } catch (Exception JavaDoc e) {
55                 id = "";
56             }
57         }
58     }
59        
60     // XML section
61

62     /**
63      * Create an IdlInterface node from an Xml representation.
64      *
65      * XML format example:
66      * <pre>
67      * &lt;component&gt;id="IDL:examples/MyInterface:1.0"&gt;
68      * IOR:000....
69      * &lt;/component&gt;
70      * </pre>
71      *
72      * @param xml The XML string from which to create an IdlInterface instance.
73      */

74     public IdlComponent(String JavaDoc xml) {
75         this(XmlNode.getNode(xml));
76     }
77       
78     /**
79      * Construct an XmlNode from an Xml node.
80      * Package access only. Called from the Xml parser to construct
81      * an Xml type tree from an Xml representation.
82      */

83     IdlComponent(Node JavaDoc n) {
84         this();
85         try {
86             if (n == null || !n.getNodeName().toUpperCase().equals("COMPONENT")) {
87                 throw new RuntimeException JavaDoc("component expected");
88             }
89             setNode(XmlNode.type(XmlNode.getId(n)));
90             setValue(XmlNode.getText(n));
91             operations = XmlNode.getOperations(id);
92         } catch (Exception JavaDoc e) {
93             throw new RuntimeException JavaDoc(e.toString());
94         }
95     }
96
97     public IdlComponent(String JavaDoc id, boolean dummy) {
98         this();
99         try {
100             this.id = id;
101             setNode(XmlNode.type(id));
102             operations = XmlNode.getOperations(id);
103         } catch (Exception JavaDoc e) {
104             e.printStackTrace();
105         }
106     }
107     
108     public String JavaDoc[] getFacets() {
109         return facets;
110     }
111
112    
113     /**
114      * Write the current value to an IdlWriter object.
115      *
116      * @param w The IdlWriter object to write the current value to.
117      */

118     public void write(IdlWriter w) {
119         w.write_component(id, value);
120     }
121 }
Popular Tags