KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > descriptor > componentassembly > ccm > deployer > installer > ComponentinstantiationDeployer


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): Briclet Frédéric.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.installer;
28
29
30 //Import all the required packages
31
import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.base.*;
32 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.registrar.*;
33 import org.omg.Components.CCMObject;
34
35 /**
36  * ComponentinstantiationDeployer is used to deploy a component
37  * instance.
38  *
39  * @author <a HREF="mailto:frederic.briclet@lifl.fr">Briclet Frederic</a>
40  *
41  * @version 0.1
42  */

43 public class ComponentinstantiationDeployer
44        extends ComponentinstantiationDeployerContext
45     {
46     // ==================================================================
47
//
48
// Internal state.
49
//
50
// ==================================================================
51

52     private CCMObject component;
53     // ==================================================================
54
//
55
// Internals methods.
56
//
57
// ==================================================================
58
/**
59      * Internal method to setup the componentproperties precised
60      *
61      * @param new_component the component to setup
62      * @throws FatalDeploymentException if a fatal problem occured during the
63      * properties setting.
64      */

65     private void
66     setupComponentProperties(org.omg.Components.CCMObject new_component)
67     throws FatalDeploymentException
68    {
69         try{
70             getComponentpropertiesDeployer()
71             .setupComponentProperties(new_component);
72         }
73         catch(ComponentPropertiesSetupFailureException e){
74              getErrorManager().submitException(e);
75         }
76       
77     }
78     /**
79      * Internal method to make all the component registration
80      *
81      * @param new_component to register
82      * @throws FatalDeploymentException is a problem occured during component registration
83      */

84     private void
85     registerComponent(org.omg.Components.CCMObject new_component)
86     throws FatalDeploymentException
87     {
88         traverse(this,getRegisterwithcomponentDeployers());
89     }
90     
91     /**
92      * Registration visitor used to invoke registration on children
93      * registration deployers.
94      *
95      * @param deployer The registration deployer
96      * @param status The deployer status
97      * @throws FatalDeploymentException is a fatal error occured during registration
98      */

99     public void visit(RegistercomponentDeployer deployer, DeployerInactiveState status)
100     throws FatalDeploymentException
101     {
102          deployer.makeComponentRegistration(component);
103     }
104     
105         
106     // ==================================================================
107
//
108
// Constructor.
109
//
110
// ==================================================================
111

112     // ==================================================================
113
//
114
// Public methods.
115
//
116
// ==================================================================
117

118
119     /**
120      * The deploy method goals are multiples. It must instantiate
121      * the component, setup their property with the cpf file linked
122      * and finally register the component in the define services.
123      * @param homeDeployed the home to use for instiation component.
124      * @throws FatalDeploymentException is a fatal problem occured
125      * @throws ComponentInstantiationFailureException if the component
126      * cannot be instantiated.
127      */

128     public void
129     deploy(org.omg.Components.CCMHome homeDeployed)
130     throws FatalDeploymentException,
131            ComponentInstantiationFailureException
132     {
133         try{
134             //instantiate the component
135
component =
136                 org.omg.Components.KeylessCCMHomeHelper
137                 .narrow(homeDeployed)
138                 .create_component();
139             }
140          catch(Exception JavaDoc e){
141                 getLifeCycleManager().stepAborded();
142                 throw new ComponentInstantiationFailureException(this,e);
143         }
144             
145         // Test if a property file is define
146
if(getComponentpropertiesDeployer()!=null)
147                 setupComponentProperties(component);
148         try{
149             //Register component in registration service
150
registerComponent(component);
151             storeComponentReference(component);
152         }
153         catch(Exception JavaDoc e){ e.printStackTrace();}
154         
155         getLifeCycleManager().stepEndedSuccessFully();
156     }
157  
158     /**
159      * Instantiated component accessor.
160      *
161      * @return the component instantiated.
162      */

163     public CCMObject
164     getComponent()
165     {
166         return component;
167     }
168         
169     /**
170      * Remove the component refence and unbind it
171      *
172      *@throws FatalDeploymentException if a fatal problem occured
173      */

174     public void
175     tearDown()
176     throws FatalDeploymentException
177     {
178         if(getLifeCycleManager().getStatus()
179              instanceof DeployerFailureException)
180          {
181              getLifeCycleManager().stepEndedSuccessFully();
182              return ;
183          }
184         
185         traverse(this,getRegisterwithcomponentDeployers());
186         try{
187             unstoreComponentReference();
188             component.remove();
189         }
190         catch(Exception JavaDoc e){
191             //getErrorManager().submitException(e);
192
}
193         getLifeCycleManager().stepEndedSuccessFully();
194     }
195     
196     /**
197      * The component unregistration visitor.
198      *
199      * @throws FatalDeploymentException if a fatal problem occured
200      */

201     public void
202     visit(RegistercomponentDeployer deployer, DeployerActiveState status)
203     throws FatalDeploymentException
204     {
205         deployer.undoComponentRegistration();
206     }
207     
208     
209    
210          
211 }
212
Popular Tags