KickJava   Java API By Example, From Geeks To Geeks.

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


1 /***************************************************************************/
2 /* COACH: Component Based Open Source Architecture for */
3 /* Distributed Telecom Applications */
4 /* See: http://www.objectweb.org/ */
5 /* */
6 /* Copyright (C) 2003 Lucent Technologies Nederland BV */
7 /* Bell Labs Advanced Technologies - EMEA */
8 /* */
9 /* Initial developer(s): Harold Batteram */
10 /* */
11 /* This library is free software; you can redistribute it and/or */
12 /* modify it under the terms of the GNU Lesser General Public */
13 /* License as published by the Free Software Foundation; either */
14 /* version 2.1 of the License, or (at your option) any later version. */
15 /* */
16 /* This library is distributed in the hope that it will be useful, */
17 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
18 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
19 /* Lesser General Public License for more details. */
20 /* */
21 /* You should have received a copy of the GNU Lesser General Public */
22 /* License along with this library; if not, write to the Free Software */
23 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
24 /***************************************************************************/
25 package org.coach.idltree;
26
27 import org.w3c.dom.Node JavaDoc;
28 import org.omg.CORBA.TypeCode JavaDoc;
29 import org.omg.CORBA.Any JavaDoc;
30 import org.omg.CORBA.TCKind JavaDoc;
31
32 /**
33  * The class IdlWchar represents an CORBA IDL char value. Instances are created through one
34  * of the create() factory methods in IdlNode.
35  * An IdlWchar object has no child nodes.
36  *
37  * @author <a HREF="mailto:batteram@lucent.com">Harold Batteram</a> <b>Lucent Technologies</b>
38  */

39 public class IdlWchar extends IdlNode implements IdlWritable {
40     protected IdlWchar() {
41         setUserObject(this);
42         type = "wchar";
43         value = " ";
44         tc = orb.get_primitive_tc(TCKind.tk_wchar);
45     }
46
47     protected IdlWchar(Any JavaDoc any) {
48         this();
49         setNode(any);
50     }
51         
52     protected IdlWchar(TypeCode JavaDoc tc) {
53         this();
54         setNode(tc);
55     }
56
57     protected void setNode(Any JavaDoc any) {
58         try {
59             setNode(any.type());
60             value = "" + any.create_input_stream().read_wchar();
61         } catch (Exception JavaDoc e) {
62             e.printStackTrace();
63         }
64     }
65
66     public void setValue(String JavaDoc v) {
67         if (v == null || v.equals("")) {
68             value = " ";
69         } else {
70             value = v;
71         }
72     }
73     
74     /**
75      * Returns the current value as a CORBA Any value.
76      *
77      * @return The current value as a CORBA Any.
78      */

79     public Any JavaDoc toAny() {
80         try {
81             Any JavaDoc any = orb.create_any();
82             org.omg.CORBA.portable.OutputStream JavaDoc out = any.create_output_stream();
83             any.type(tc);
84             out.write_wchar(value.charAt(0));
85             any.read_value(out.create_input_stream(), tc);
86             return any;
87         } catch (Exception JavaDoc e) {
88             e.printStackTrace();
89         }
90         return null;
91     }
92
93     /**
94      * Writes the value to a CORBA outputstream.
95      *
96      * @param is The outputstream to write to.
97      */

98     public void write(org.omg.CORBA.portable.OutputStream JavaDoc os) {
99         os.write_wchar(value.charAt(0));
100     }
101
102     /**
103      * Reads the value from a CORBA inputstream.
104      *
105      * @param is The inputstream to read from.
106      */

107     public void read(org.omg.CORBA.portable.InputStream JavaDoc is) {
108         value = "" + is.read_wchar();
109     }
110     
111     // XML section
112

113     /**
114      * Create an IdlWchar node from an Xml representation.
115      * XML format example:
116      * <pre>
117      * &lt;wchar&gt;3&lt;/wchar&gt;
118      * </pre>
119      */

120     public IdlWchar(String JavaDoc xml) {
121         this(XmlNode.getNode(xml));
122     }
123     
124     /**
125      * Construct an XmlNode from an Xml node.
126      * Package access only. Called from the Xml parser to contruct
127      * an Xml type tree from an Xml representation.
128      */

129     IdlWchar(Node JavaDoc n) {
130         this();
131         if (n == null || !n.getNodeName().toUpperCase().equals("WCHAR")) {
132             throw new RuntimeException JavaDoc("wchar expected");
133         }
134         setValue(XmlNode.getText(n));
135     }
136   
137     /**
138      * Write the current value to an IdlWriter object.
139      *
140      * @param w The IdlWriter object to write the current value to.
141      */

142     public void write(IdlWriter w) {
143         w.write_wchar(value);
144     }
145 }
Popular Tags