KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > ir3 > Members


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.
23 Contributor(s): Mathieu Vadet, Christophe Demarey.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.ir3;
28
29 /**
30  * Base class for storing member names and types.
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 Members
39 {
40     // ==================================================================
41
//
42
// Internal state.
43
//
44
// ==================================================================
45

46     /** The contained object. */
47     protected Contained_impl contained_;
48
49     /** The container object. */
50     protected Container_impl container_;
51
52     /** The members names.*/
53     protected String JavaDoc[] names_;
54
55     /** The members types.*/
56     protected IDLType_ref[] types_;
57
58     // ==================================================================
59
//
60
// Constructor.
61
//
62
// ==================================================================
63

64     /**
65      * TODO
66      */

67     public
68     Members(Contained_impl contained, Container_impl container)
69     {
70         // init internal state.
71
contained_ = contained;
72         container_ = container;
73         names_ = new String JavaDoc[0];
74         types_ = null;
75     }
76
77     // ==================================================================
78
//
79
// Internal methods.
80
//
81
// ==================================================================
82

83     /**
84      * Check if an array of names.
85      */

86     protected void
87     checkNames(String JavaDoc[] names)
88     {
89         for(int i=0; i<names.length; i++)
90     {
91             String JavaDoc name = names[i];
92
93             for(int j=i+1; j<names.length; j++)
94                 if(name.equalsIgnoreCase(names[j]))
95                     throw contained_.exceptionDuplicateDeclarator(name, j);
96
97             if (container_ != null)
98         {
99                 container_.checkName(name, false, false);
100
101                 if (name.equalsIgnoreCase(contained_.name()))
102                    throw contained_.exceptionNameAlreadyUsedByImmediateScope(name);
103         }
104     }
105     }
106
107     /**
108      * Set names and types.
109      */

110     protected void
111     setNamesTypes(String JavaDoc[] names,
112                   IDLType_ref[] types)
113     {
114         // cut the previous dependency to members types.
115
cutDependencies();
116
117         names_ = names;
118         types_ = types;
119     }
120
121     // ==================================================================
122
//
123
// Public methods.
124
//
125
// ==================================================================
126

127     /**
128      * Returns member names.
129      */

130     public String JavaDoc[]
131     getNames()
132     {
133         return names_;
134     }
135
136     /**
137      * Check if a name is also a member name.
138      */

139     public void
140     checkName(String JavaDoc name)
141     {
142         for(int i=0; i<names_.length; i++)
143             if(name.equalsIgnoreCase(names_[i]))
144                 throw contained_.exceptionNameAlreadyUsed(name);
145     }
146
147     /**
148      * Cut members types dependencies.
149      */

150     public void
151     cutDependencies()
152     {
153         if (types_ != null)
154         {
155             for(int i=0; i<types_.length; i++)
156                 types_[i].cutDependency();
157         }
158     }
159 }
160
Popular Tags