KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > ast > lib > ParameterListImpl


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA & USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Philippe Merle, Mathieu Vadet.
23 Contributor(s): Christophe Demarey.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.ast.lib;
28
29 /** To use AST TypeRef. */
30 import org.objectweb.openccm.ast.api.TypeRef;
31
32 /** To use AST Parameter. */
33 import org.objectweb.openccm.ast.api.Parameter;
34
35 /** To use CORBA parameter mode. */
36 import org.omg.CORBA.ParameterMode JavaDoc;
37
38 /** To use CORBA::ParameterDescription. */
39 import org.omg.CORBA.ParameterDescription JavaDoc;
40
41 /** To use CORBA::StructMember. */
42 import org.omg.CORBA.StructMember JavaDoc;
43
44 /**
45  * ParameterListImpl is a wrapper class for IDL operation parameter lists.
46  *
47  *
48  * Inherits from:
49  *
50  * - ListBaseImpl: The base class for all lists.
51  *
52  * - ParameterList: OMG IDL for operation parameter lists.
53  *
54  *
55  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
56  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
57  *
58  * @version 0.3
59  */

60
61 public class ParameterListImpl
62        extends ListBaseImpl
63        implements org.objectweb.openccm.ast.api.ParameterList
64 {
65     // ==================================================================
66
//
67
// Internal state.
68
//
69
// ==================================================================
70

71     // ==================================================================
72
//
73
// Constructor.
74
//
75
// ==================================================================
76

77     /**
78      * The default constructor.
79      */

80     public ParameterListImpl()
81     {
82         // Call the ListBaseImpl constructor.
83
super();
84     }
85
86     // ==================================================================
87
//
88
// Internal methods.
89
//
90
// ==================================================================
91

92     /**
93      * Add an in parameter.
94      *
95      * @param name The name of the in parameter.
96      * @param type The type reference of the in parameter.
97      */

98     protected void
99     addParam(String JavaDoc name,
100              TypeRef type,
101              ParameterMode JavaDoc mode)
102     {
103         if (type!=null)
104         {
105             super.addObject( new ParameterImpl(name, type, mode) );
106         }
107     }
108
109     // ==================================================================
110
//
111
// Public methods.
112
//
113
// ==================================================================
114

115     /**
116      * Obtain its associated CORBA::ParameterDescriptionSeq.
117      *
118      * @return Its associated CORBA::ParameterDescriptionSeq.
119      */

120     public ParameterDescription JavaDoc[]
121     getParameterDescriptionSeq()
122     {
123         // Create an array with the same length as the list.
124
ParameterDescription JavaDoc[] result = new ParameterDescription JavaDoc[getSize()];
125
126         // Iterate on all elements of the list.
127
java.util.Iterator JavaDoc it = iterator();
128         for(int i=0; it.hasNext(); i++)
129         {
130             // Obtain the current element.
131
ParameterImpl param = (ParameterImpl)it.next();
132
133             // Obtain its associated CORBA::ParameterDescription.
134
result[i] = param.getParameterDescription();
135         }
136
137         // Return the array.
138
return result;
139     }
140
141     /**
142      * Obtain its associated CORBA::StructMemberSeq.
143      *
144      * @return Its associated CORBA::StructMemberSeq.
145      */

146     public StructMember JavaDoc[]
147     getStructMemberSeq()
148     {
149         // Create an array with the same length as the list.
150
StructMember JavaDoc[] result = new StructMember JavaDoc[getSize()];
151
152         // Iterate on all elements of the list.
153
java.util.Iterator JavaDoc it = iterator();
154         for(int i=0; it.hasNext(); i++)
155         {
156             // Obtain the current element.
157
ParameterImpl param = (ParameterImpl)it.next();
158
159             // Obtain its associated CORBA::StructMember.
160
result[i] = param.getStructMember();
161         }
162
163         // Return the array.
164
return result;
165     }
166
167     // ==================================================================
168
//
169
// Methods for OMG IDL org.objectweb.openccm.ast.api.ParameterList
170
//
171
// ==================================================================
172

173     /**
174      * Add an in parameter.
175      *
176      * @param name The name of the in parameter.
177      * @param type The type reference of the in parameter.
178      */

179     public void
180     addInParam(String JavaDoc name,
181                TypeRef type)
182     {
183         addParam(name, type, ParameterMode.PARAM_IN);
184     }
185
186     /**
187      * Add an out parameter.
188      *
189      * @param name The name of the parameter.
190      * @param type The TypeRef of the parameter.
191      */

192     public void
193     addOutParam(String JavaDoc name,
194                 TypeRef type)
195     {
196         addParam(name, type, ParameterMode.PARAM_OUT);
197     }
198
199     /**
200      * Add an inout parameter.
201      *
202      * @param name The name of the parameter.
203      * @param type The TypeRef of the parameter.
204      */

205     public void
206     addInOutParam(String JavaDoc name,
207                   TypeRef type)
208     {
209         addParam(name, type, ParameterMode.PARAM_INOUT);
210     }
211
212     /**
213      * Obtain all the parameters.
214      *
215      * @return All the parameters.
216      */

217     public Parameter[]
218     getParameters()
219     {
220        return (Parameter[])super.toArray(new Parameter[0]);
221     }
222 }
223
Popular Tags