KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > IDL3 > StructMembersImpl


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2002 USTL - LIFL - GOAL
5 Contact: openccm-team@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): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.ccm.IDL3;
28
29 /**
30  * This class manages IDL struct members.
31  *
32  * @author <a=href="Philippe.Merle@lifl.fr">Philippe Merle</a>
33  * <a=href="Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
34  *
35  * @version 0.3
36  */

37
38 public class StructMembersImpl
39        implements StructMembers
40 {
41     // ==================================================================
42
//
43
// Internal state.
44
//
45
// ==================================================================
46

47     /**
48      ** List of members names.
49      **/

50     private org.objectweb.ccm.util.Vector member_names_;
51
52     /**
53      ** List of members TypeRef.
54      **/

55     private org.objectweb.ccm.util.Vector member_types_;
56
57     // ==================================================================
58
//
59
// Constructor.
60
//
61
// ==================================================================
62

63     /**
64      ** The default constructor.
65      **/

66     public
67     StructMembersImpl()
68     {
69         // Init internal state.
70
member_names_ = new org.objectweb.ccm.util.Vector();
71         member_types_ = new org.objectweb.ccm.util.Vector();
72     }
73
74     // ==================================================================
75
//
76
// Internal methods.
77
//
78
// ==================================================================
79

80     /**
81      ** Obtain its StructMember[].
82      **
83      ** @return An array containing the members of the struct.
84      **/

85     protected org.omg.CORBA.StructMember JavaDoc[]
86     getMemberDefs()
87     {
88         org.omg.CORBA.StructMember JavaDoc[] result =
89             new org.omg.CORBA.StructMember JavaDoc[member_names_.size()];
90
91         for(int i=0; i<result.length; i++)
92         {
93             result[i] = new org.omg.CORBA.StructMember JavaDoc(
94                             (String JavaDoc)member_names_.get(i),
95                             org.objectweb.openccm.corba.TypeCodeUtils.getTC_void(),
96                             ((TypeRef)member_types_.get(i)).getIDLType());
97         }
98
99         return result;
100     }
101
102     /**
103      ** Return the index name.
104      **
105      ** @param index The index of the member that should be returned.
106      **
107      ** @return The name of the member at the specified index.
108      **/

109     protected String JavaDoc
110     nameAt(int index)
111     {
112         return (String JavaDoc)member_names_.get(index);
113     }
114
115     /**
116      **
117      **/

118     protected void
119     destroy()
120     {
121         for (int i=0;i<member_types_.size();i++)
122         {
123             ((TypeRef)member_types_.get(i)).removeRef();
124         }
125     }
126
127     // ==================================================================
128
//
129
// Methods for the StructMembers interface.
130
//
131
// ==================================================================
132

133     /**
134      ** Add a member.
135      **
136      ** @param name The name of the member.
137      ** @param type The TypeRef of the member.
138      **/

139     public void
140     addMember(String JavaDoc name,
141               TypeRef type)
142     {
143         if(type != null)
144         {
145             member_names_.add(name);
146             type.addRef();
147             member_types_.add(type);
148         }
149     }
150
151     /**
152      **
153      **/

154     public String JavaDoc[]
155     getMemberNames()
156     {
157         String JavaDoc[] result = new String JavaDoc[member_names_.size()];
158         for (int i=0;i<result.length;i++)
159         {
160             result[i] = (String JavaDoc)member_names_.get(i);
161         }
162         return result;
163     }
164
165     /**
166      **
167      **/

168     public TypeRef[]
169     getMemberTypes()
170     {
171         TypeRef[] result = new TypeRef[member_types_.size()];
172         for (int i=0;i<result.length;i++)
173         {
174             result[i] = (TypeRef)member_types_.get(i);
175         }
176         return result;
177     }
178 }
179
Popular Tags