KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > Components > CCMHomeImpl


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): Mathieu Vadet, Philippe Merle.
23 Contributor(s): Sylvain Leblanc, Romain Rouvoy________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.Components;
28
29 /**
30  * This class is a basic implementation of the CCMHome interface.
31  * It also implements all generic operations for CCM homes.
32  *
33  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
34  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
35  *
36  * @version 0.3
37  */

38
39 public abstract class CCMHomeImpl
40 extends CCMHomeBase
41 implements org.omg.Components.KeylessCCMHomeOperations
42 {
43     // ==================================================================
44
//
45
// Internal state.
46
//
47
// ==================================================================
48

49     // ==================================================================
50
//
51
// Constructor.
52
//
53
// ==================================================================
54

55     /**
56      ** The constructor.
57      **
58      **/

59     protected
60     CCMHomeImpl()
61     {
62     }
63
64     // ==================================================================
65
//
66
// Internal methods.
67
//
68
// ==================================================================
69

70     /**
71      **
72      **/

73     protected final java.lang.String JavaDoc
74     _component_uid_()
75     {
76         return _the_home_executor()._the_component_uid();
77     }
78
79     /**
80      **
81      **/

82     protected final java.lang.String JavaDoc
83     _home_uid_()
84     {
85         return _the_home_executor()._the_home_uid();
86     }
87
88     /**
89      **
90      **/

91     protected final org.objectweb.openccm.Containers.HomeServant
92     _home_servant_()
93     {
94         return _the_home_executor()._home_servant();
95     }
96
97     /**
98      ** Create a CCM component reference.
99      **
100      ** @return The CCM component reference.
101      **/

102     protected final org.omg.Components.CCMObject
103     _create()
104     throws org.omg.Components.CreateFailure
105     {
106         org.omg.Components.CCMObject ref = null;
107
108         // create the reference
109
ref = _home_servant_().the_PCA().create_component_reference(_home_servant_());
110                 listener_.on_create(ref);
111
112         // add to the component list.
113
components_.add(ref);
114
115         return ref;
116     }
117
118     /**
119      * Unregister a component from the home.
120      *
121      * @param comp The reference to the component.
122      *
123      * Added for Bug #306.
124      */

125     protected final void
126     unregister_component(org.omg.Components.CCMObject comp)
127     throws org.omg.Components.RemoveFailure
128     {
129         listener_.on_remove(comp);
130
131 // Correction for ORBacus
132
// OLD CODE
133
//
134
// components_.remove(comp);
135
//
136
// NEW CODE
137
//
138

139         // Obtains all component references.
140
org.omg.Components.CCMObject[] components = get_components();
141         // Iterates over these references.
142
for(int i=0; i<components.length; i++)
143         {
144             // if comp is equivalent to a component reference
145
if(comp._is_equivalent(components[i]))
146             {
147                 // then removes this component reference.
148
components_.remove(i);
149                 break;
150             }
151         }
152     }
153
154     // ==================================================================
155
//
156
// Internal methods that must be implemented by subclasses.
157
//
158
// ==================================================================
159

160     /**
161      ** To obtain the home executor.
162      **/

163     protected abstract org.objectweb.openccm.Containers.HomeExecutor
164     _the_home_executor();
165
166     // ==================================================================
167
//
168
// Methods for the Components::CCMHome interface.
169
//
170
// ==================================================================
171

172     //
173
// IDL:omg.org/Components/CCMHome/remove_component:1.0
174
//
175
/**
176      * Removes a component.
177      *
178      * @param comp The reference to the component.
179      */

180     public final void
181     remove_component(org.omg.Components.CCMObject comp)
182     throws org.omg.Components.RemoveFailure
183     {
184 /* Bug #306
185    OLD CODE
186         // TO DO
187         // MUST BE COMPLETED FOR PK HOMES !!!!
188         // i.e. Remove the associated component from the list
189
190         listener_.on_remove(comp);
191
192         components_.remove(comp);
193    */
/*
194         //
195         // TODO : other things such as destroying the reference, deactivating the component,...
196         //
197           // TODO: Must be implemented!
198              throw new org.omg.Components.RemoveFailure();
199       */

200
201 /*
202    NEW CODE
203 */

204
205       // Tests if comp is a component of this home.
206
for(int i=0; i<components_.size(); i++)
207       {
208           org.omg.Components.CCMObject c =
209               (org.omg.Components.CCMObject)components_.get(i);
210
211           // If comp is a component of this home then removes it.
212
if(comp._is_equivalent(c))
213       {
214               comp.remove();
215               return;
216           }
217       }
218
219       // Else comp is not a component of this home.
220
throw new org.omg.Components.RemoveFailure();
221     }
222
223     // ==================================================================
224
//
225
// Methods for the Components::KeylessCCMHome interface.
226
//
227
// ==================================================================
228

229     //
230
// IDL:omg.org/Components/KeylessCCMHome/create_component:1.0
231
//
232
/**
233      ** Creates a keyless component.
234      **
235      ** @return The reference to the created component.
236      **
237      **/

238     public final org.omg.Components.CCMObject
239     create_component()
240     throws org.omg.Components.CreateFailure
241     {
242         return _create();
243     }
244 }
245
246
247
Popular Tags