KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
25  * Common super class for arrays and sequences
26  *
27  *
28  * @author Gerald Brose
29  * @version $Id: VectorType.java,v 1.13 2004/05/06 12:39:59 nicolas Exp $
30  */

31
32
33 public abstract class VectorType
34     extends TemplateTypeSpec
35 {
36     TypeSpec type_spec;
37
38     public VectorType( int num )
39     {
40         super( num );
41     }
42
43     /**
44      * @return the TypeSpec for the sequence's element type
45      */

46
47     public TypeSpec elementTypeSpec()
48     {
49         TypeSpec t = type_spec.typeSpec();
50
51         /* if the element type is scoped name that refers to another
52            type spec, we have to retrieve that. If that type spec is
53            a base type or a string, we have to return it, otherwise
54            we return the scoped type name.
55         */

56
57         if( t instanceof ScopedName )
58         {
59             t = ( (ScopedName)t ).resolvedTypeSpec().typeSpec();
60         }
61         return t;
62     }
63
64
65     public void setTypeSpec( SimpleTypeSpec sts )
66     {
67         type_spec = sts;
68     }
69
70     /**
71      * @return this sequences Java type name, i.e., the element type with
72      * "[]" appended.
73      */

74
75     public String JavaDoc typeName()
76     {
77         String JavaDoc name;
78
79         if( type_spec.typeSpec() instanceof ScopedName )
80         {
81             name =
82                     ( (ScopedName)type_spec.typeSpec() ).resolvedTypeSpec().toString();
83         }
84         else
85         {
86             name = type_spec.toString();
87         }
88
89         return name + "[]";
90     }
91
92     boolean typedefd()
93     {
94         return typedefd;
95     }
96
97     public String JavaDoc printReadExpression( String JavaDoc streamname )
98     {
99         if( typedefd() )
100             return helperName() + ".read(" + streamname + ")";
101        else
102             return "*****";
103     }
104
105
106     protected String JavaDoc elementTypeExpression()
107     {
108         TypeSpec ts = type_spec.typeSpec();
109
110         if( ts instanceof AliasTypeSpec )
111         {
112             return type_spec.full_name() + "Helper.type()";
113         }
114         else if( ts instanceof BaseType ||
115                 ts instanceof TypeCodeTypeSpec ||
116                 ts instanceof ConstrTypeSpec || // for value types
117
ts instanceof TemplateTypeSpec )
118         {
119             return ts.getTypeCodeExpression();
120         }
121         else
122         {
123             return ts.typeName() + "Helper.type()";
124         }
125     }
126
127     public String JavaDoc elementTypeName()
128     {
129         TypeSpec ts = type_spec;
130         if( ts instanceof ScopedName )
131         {
132             if( logger.isFatalErrorEnabled() )
133                 logger.fatalError( "elementTypeName is outer ScopedName" );
134             ts = ( (ScopedName)type_spec.type_spec ).resolvedTypeSpec();
135
136             while( ts instanceof ScopedName || ts instanceof AliasTypeSpec )
137             {
138                 if( ts instanceof ScopedName )
139                 {
140                     if( logger.isFatalErrorEnabled() )
141                         logger.fatalError( "elementTypeName is inner Alias" );
142                     ts = ( (ScopedName)ts ).resolvedTypeSpec();
143                 }
144                 if( ts instanceof AliasTypeSpec )
145                 {
146                     if( logger.isFatalErrorEnabled() )
147                         logger.fatalError( "elementTypeName is inner Alias" );
148                     ts = ( (AliasTypeSpec)ts ).originalType();
149                 }
150             }
151         }
152         return ts.typeName();
153     }
154
155     /**
156      * @return the length of this array or sequence. For
157      * multi-dimensional vectors, this is the outermost dimension.
158      * For open sequences, this length is 0.
159      */

160
161     public abstract int length();
162
163     public abstract String JavaDoc holderName();
164
165     public abstract String JavaDoc helperName();
166
167
168     public String JavaDoc toString()
169     {
170         return typeName();
171     }
172
173
174 }
175
Popular Tags