KickJava   Java API By Example, From Geeks To Geeks.

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


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: ParamDecl.java,v 1.20 2004/05/06 12:39:58 nicolas Exp $
26  */

27
28 import java.io.PrintWriter JavaDoc;
29
30 public class ParamDecl
31     extends IdlSymbol
32 {
33     public static final int MODE_IN = 1;
34     public static final int MODE_OUT = 2;
35     public static final int MODE_INOUT = 3;
36
37     public int paramAttribute;
38     public TypeSpec paramTypeSpec;
39     public SimpleDeclarator simple_declarator;
40
41     public ParamDecl( int num )
42     {
43         super( num );
44     }
45
46     /**
47      * Constructs a new parameter declaration with the given characteristics.
48      */

49     public ParamDecl( int paramAttribute,
50                       TypeSpec paramTypeSpec,
51                       SimpleDeclarator simple_declarator )
52     {
53         super( new_num());
54         this.paramAttribute = paramAttribute;
55         this.paramTypeSpec = paramTypeSpec;
56         this.simple_declarator = simple_declarator;
57     }
58
59     /**
60      * Constructs a new parameter declaration with the given characteristics.
61      */

62     public ParamDecl( int paramAttribute,
63                       TypeSpec paramTypeSpec,
64                       String JavaDoc name)
65     {
66         super( new_num() );
67         this.paramAttribute = paramAttribute;
68         this.paramTypeSpec = paramTypeSpec;
69         this.simple_declarator = new SimpleDeclarator( new_num() );
70         this.simple_declarator.name = name;
71     }
72
73     public void setPackage( String JavaDoc s )
74     {
75         s = parser.pack_replace( s );
76         if( pack_name.length() > 0 )
77             pack_name = s + "." + pack_name;
78         else
79             pack_name = s;
80         paramTypeSpec.setPackage( s );
81     }
82
83     /**
84      * Returns a new ParamDecl with the same characteristics as this one,
85      * except that its mode is changed to 'in'.
86      */

87     public ParamDecl asIn()
88     {
89         return new ParamDecl( MODE_IN,
90                               this.paramTypeSpec,
91                               this.simple_declarator) ;
92     }
93
94     public void parse()
95     {
96         while( paramTypeSpec.typeSpec() instanceof ScopedName )
97         {
98             TypeSpec ts = ( (ScopedName)paramTypeSpec.typeSpec() ).resolvedTypeSpec();
99             if( ts != null )
100                 paramTypeSpec = ts;
101         }
102
103         if( paramTypeSpec == null )
104         {
105             throw new ParseException("parameter TypeSpec is null " + name, this.myPosition );
106         }
107     }
108
109     public void print( PrintWriter JavaDoc ps )
110     {
111         switch( paramAttribute )
112         {
113             case MODE_IN:
114                 ps.print( paramTypeSpec.toString() );
115                 break;
116             case MODE_OUT:
117             case MODE_INOUT:
118                 ps.print( paramTypeSpec.holderName() );
119                 break;
120         }
121         ps.print( " " + simple_declarator );
122     }
123
124     public String JavaDoc printWriteStatement( String JavaDoc ps )
125     {
126         return printWriteStatement( simple_declarator.toString(), ps );
127     }
128
129     public String JavaDoc printWriteStatement( String JavaDoc name, String JavaDoc ps )
130     {
131         if( paramAttribute != ParamDecl.MODE_IN )
132             return paramTypeSpec.typeSpec().printWriteStatement( name + ".value", ps );
133         else
134             return paramTypeSpec.typeSpec().printWriteStatement( name, ps );
135     }
136
137     public String JavaDoc printReadExpression( String JavaDoc ps )
138     {
139         return paramTypeSpec.typeSpec().printReadExpression( ps );
140     }
141
142     public void accept( IDLTreeVisitor visitor )
143     {
144         visitor.visitParamDecl( this );
145     }
146
147
148 }
149
Popular Tags