KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > idl > StringType


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1997-2004 Gerald Brose.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */

20
21 package org.jacorb.idl;
22
23 /**
24  * @author Gerald Brose
25  * @version $Id: StringType.java,v 1.13 2004/05/06 12:39:58 nicolas Exp $
26  */

27
28 public class StringType
29     extends TemplateTypeSpec
30 {
31     public ConstExpr max = null;
32     private int length = 0;
33     private boolean wide = false;
34
35     public StringType( int num )
36     {
37         super( num );
38     }
39
40     public boolean isWide()
41     {
42         return wide;
43     }
44
45     public void setWide()
46     {
47         wide = true;
48     }
49
50     public Object JavaDoc clone()
51     {
52         StringType s = new StringType( new_num() );
53         s.max = max;
54         if( wide )
55             s.setWide();
56         s.parse();
57         return s;
58     }
59
60     public String JavaDoc typeName()
61     {
62         return "java.lang.String";
63     }
64
65     public String JavaDoc getIDLTypeName()
66     {
67         return ( wide ? "wstring" : "string" );
68     }
69
70     public TypeSpec typeSpec()
71     {
72         return this;
73     }
74
75
76     public void setEnclosingSymbol( IdlSymbol s )
77     {
78         if( enclosing_symbol != null && enclosing_symbol != s )
79             throw new RuntimeException JavaDoc( "Compiler Error: trying to reassign container for "
80                     + name );
81         enclosing_symbol = s;
82     }
83
84     public void print( java.io.PrintWriter JavaDoc pw )
85     {
86     }
87
88     public void setPackage( String JavaDoc s )
89     {
90         s = parser.pack_replace( s );
91         if( max != null )
92             max.setPackage( s );
93     }
94
95     public String JavaDoc toString()
96     {
97         return typeName();
98     }
99
100     public String JavaDoc holderName()
101     {
102         return "org.omg.CORBA.StringHolder";
103     }
104
105     public String JavaDoc getTypeCodeExpression()
106     {
107         if( wide )
108             return "org.omg.CORBA.ORB.init().create_wstring_tc(" + length + ")";
109         else
110             return "org.omg.CORBA.ORB.init().create_string_tc(" + length + ")";
111     }
112
113
114     public String JavaDoc printReadExpression( String JavaDoc strname )
115     {
116         if( wide )
117             return strname + ".read_wstring()";
118         else
119             return strname + ".read_string()";
120     }
121
122     public String JavaDoc printReadStatement( String JavaDoc var_name, String JavaDoc strname )
123     {
124         if( wide )
125             return var_name + "=" + strname + ".read_wstring();";
126         else
127             return var_name + "=" + strname + ".read_string();";
128     }
129
130     public String JavaDoc printWriteStatement( String JavaDoc var_name, String JavaDoc strname )
131     {
132         if( wide )
133             return strname + ".write_wstring(" + var_name + ");";
134         else
135             return strname + ".write_string(" + var_name + ");";
136     }
137
138
139     public String JavaDoc printInsertExpression()
140     {
141         if( wide )
142             return "insert_wstring";
143         else
144             return "insert_string";
145     }
146
147     public String JavaDoc printExtractExpression()
148     {
149         if( wide )
150             return "extract_wstring";
151         else
152             return "extract_string";
153     }
154
155     public void parse()
156     {
157         if( max != null )
158             length = max.pos_int_const();
159     }
160 }
161
162
163
164
165
166
Popular Tags