KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > runtime > cif > lib > ComponentSegmentBase


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

26
27 package org.objectweb.ccm.runtime.cif.lib;
28
29 import org.omg.Components.ExecutorSegmentBase;
30
31 import org.objectweb.ccm.runtime.cif.api.SegmentHome;
32
33 import java.util.HashMap JavaDoc;
34
35 /**
36  * Abstract base class for all component segment classes generated from CIDL.
37  *
38  * This implements the CORBA Components ExecutorLocator Strategy.
39  *
40  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
41  * <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
42  *
43  * @version 0.1
44  */

45
46 public abstract class ComponentSegmentBase
47               extends org.objectweb.corba.util.LocalObjectBase
48            implements org.objectweb.ccm.runtime.cif.api.ComponentSegment,
49                       org.objectweb.ccm.runtime.cif.api.Segment
50 {
51     // ==================================================================
52
//
53
// Internal State.
54
//
55
// ==================================================================
56

57     /**
58      * Table of all executor segments composing a component implementation.
59      */

60     ExecutorSegmentBase[] executor_segments_;
61
62     /** Reference to the executor segment home. */
63     SegmentHome segment_home_;
64
65     // ==================================================================
66
//
67
// Constructor.
68
//
69
// ==================================================================
70

71     /** The default constructor. */
72     public
73     ComponentSegmentBase()
74     {
75         // Inits internal state.
76
executor_segments_ = null;
77         segment_home_ = null;
78     }
79
80     // ==================================================================
81
//
82
// Internal methods.
83
//
84
// ==================================================================
85

86     // ==================================================================
87
//
88
// Public methods for org.objectweb.ccm.runtime.cif.api.Segment
89
//
90
// ==================================================================
91

92     /**
93      * Set the main segment executor (segid = 0).
94      *
95      * @param seg - The main segment.
96      */

97     public void
98     set_main_segment(org.objectweb.ccm.runtime.cif.api.ComponentSegment seg)
99     {
100         // Nothing to do!
101
}
102
103     // ==================================================================
104
//
105
// Public methods for org.objectweb.ccm.runtime.cif.api.ComponentSegment
106
//
107
// ==================================================================
108

109     /**
110      * Sets the number of executor segments.
111      *
112      * This method is called by the constructor of
113      * component segment classes generated from CIDL.
114      *
115      * @param nb_segments The number of executor segments
116      * for this CIDL component executor.
117      */

118     public void
119     set_nb_segments(int nb_segments)
120     {
121         // Allocates the table for all executor segments.
122
executor_segments_ = new ExecutorSegmentBase[nb_segments];
123
124         // Sets the component segment.
125
executor_segments_[0] = this;
126     }
127
128     /**
129      * Sets the associated segment home.
130      *
131      * @param sh The associated segment home.
132      */

133     public void
134     set_segment_home(SegmentHome sh)
135     {
136         segment_home_ = sh;
137     }
138
139     /**
140      * Gets an executor segment.
141      *
142      * If the requested executor segment does not exist
143      * then it is created by the segment home.
144      *
145      * @param segid The executor segment id.
146      *
147      * @return The executor segment.
148      */

149     public ExecutorSegmentBase
150     get_executor_segment(int segid)
151     {
152         // Gets the executor segment in the table.
153
ExecutorSegmentBase result = executor_segments_[segid];
154
155         // If no executor segment
156
if(result == null)
157         {
158             // Uses the executor segment home to create it.
159
result = segment_home_.create_executor_segment(segid);
160             ((org.objectweb.ccm.runtime.cif.api.Segment)result).set_main_segment(this);
161
162             // Stores the executor segment in the table.
163
executor_segments_[segid] = result;
164         }
165
166         // Returns the executor segment.
167
return result;
168     }
169
170     /**
171      * Obtains the segmentation table.
172      *
173      * This method is implemented by component segment classes generated
174      * from CIDL according to segmentation described in CIDL compositions.
175      *
176      * @return A HashMap containing <facet_name, segid> associations.
177      */

178     abstract public java.util.HashMap JavaDoc
179     get_segmentation_table();
180
181     // ==================================================================
182
//
183
// Public methods for OMG IDL ::Components::EnterpriseComponent
184
//
185
// ==================================================================
186

187     //
188
// IDL:omg.org/Components/EnterpriseComponent/configuration_complete:1.0
189
//
190
/**
191      * Complete the component configuration.
192      *
193      * Default empty implementation that could be
194      * overridden by user component executor implementation.
195      *
196      * @exception org.omg.Components.InvalidConfiguration
197      * Thrown if the configuration is invalid.
198      */

199     public void
200     configuration_complete()
201     throws org.omg.Components.InvalidConfiguration
202     {
203         getLogger().trace(this,
204             "Completing configuration: Do nothing by default");
205
206         // Do nothing by default!
207
}
208
209     // ==================================================================
210
//
211
// Public methods for OMG IDL ::Components::ExecutorLocator
212
//
213
// ==================================================================
214

215     //
216
// IDL:omg.org/Components/ExecutorLocator/obtain_executor:1.0
217
//
218
/**
219      * Obtain an executor.
220      *
221      * @param name The facet name.
222      *
223      * @return The executor reference.
224      *
225      * @exception org.omg.Components.CCMException Thrown if any error.
226      */

227     public org.omg.CORBA.Object JavaDoc
228     obtain_executor(java.lang.String JavaDoc name)
229     throws org.omg.Components.CCMException
230     {
231         getLogger().trace(this, "Obtaining executor " + name);
232
233         // Obtains the segmentation table.
234
HashMap JavaDoc segmentation_table = get_segmentation_table();
235
236         // Gets the Integer associated to name.
237
Integer JavaDoc segid = (Integer JavaDoc)segmentation_table.get(name);
238
239         // If no associated segment identifier
240
if(segid == null)
241         {
242             getLogger().error(this,
243                "No executor segment associated to facet " + name);
244
245             throw new org.omg.Components.CCMException();
246         }
247
248         // Returns the executor segment associated to segid.
249
return get_executor_segment(segid.intValue());
250     }
251
252     //
253
// IDL:omg.org/Components/ExecutorLocator/release_executor:1.0
254
//
255
/**
256      * Release an executor.
257      *
258      * @param executor The executor reference.
259      *
260      * @exception org.omg.Components.CCMException Thrown if any error.
261      */

262     public void
263     release_executor(org.omg.CORBA.Object JavaDoc executor)
264     throws org.omg.Components.CCMException
265     {
266         getLogger().trace(this, "Releasing executor " + executor +
267                                 ": Do nothing by default");
268
269         // Do nothing by default!
270
}
271 }
272
Popular Tags