KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > descriptor > componentassembly > ccm > deployer > base > DeployerContext


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.base;
28
29 //Package dependencies.
30
import java.io.StringWriter JavaDoc;
31 import java.lang.reflect.InvocationTargetException JavaDoc;
32 import java.lang.reflect.Method JavaDoc;
33 import org.objectweb.apollon.framework.Bean;
34
35 /**
36  * The DeployerContext class is a basic deployer context in charge to provide
37  * basis methos usefull for the deployment.
38  *
39  * @author <a HREF="mailto:briclet@lifl.fr">Frederic Briclet</a>
40  *
41  * @version 0.1
42  */

43 public abstract class DeployerContext
44     implements Deployer
45 {
46
47     // ==================================================================
48
//
49
// Internal state.
50
//
51
// ===================================================================
52
//The current life cycle manager
53
private LifeCycleManager lifeCycleManager;
54     //The current deployer scheduler
55
private DeployerScheduler deployerScheduler;
56     //The current error manager
57
private ErrorManager errorManager;
58     //The bean description of the xml code processed
59
private Bean deployerDescription;
60     //The bean stringifiedDescription
61
private String JavaDoc stringifiedDescription = null;
62
63     // ==================================================================
64
//
65
// Constructors.
66
//
67
// ==================================================================
68

69     // ==================================================================
70
//
71
// Internal methods.
72
//
73
// ==================================================================
74

75     // ==================================================================
76
//
77
// Public methods.
78
//
79
// ==================================================================
80
/**
81      * The getRootDeployerContext is an abstract method which must be implemented
82      * by children because the root deployer context will support differently this
83      * method than another deployer.
84      * @return The RootDeployerContext of this deployment
85      */

86     public abstract RootDeployerContext getRootDeployerContext();
87
88     /**
89      * The visit method is in charge to execute the deployment of the
90      * deployer given in parameter. In this generic implementation the
91      * reflexion is used to invoke the right method in charge to process
92      * the given @param depl Deployer. The current deployer must provide
93      * a "visit" method that take in parameter the @param depl deployer kind
94      * and the current deployer status. The method signature is the following :
95      * void visit(@param depl_type , CurrentDeployerState);
96      *
97      * @Param depl the deployer to process for deployment execution
98      * @FatalDeploymentException if no right visit method is found or if the
99      * deployer execution thrown it.
100      */

101     public void visit(Deployer depl) throws FatalDeploymentException {
102         try {
103             Method JavaDoc m =
104                 this.getClass().getDeclaredMethod(
105                     "visit",
106                     new Class JavaDoc[] {
107                         depl.getClass(),
108                         this.getStatus().getClass()});
109             m.invoke(this, new Object JavaDoc[] { depl, this.getStatus()});
110
111         } catch (NoSuchMethodException JavaDoc e) {
112             //System error
113
throw new FatalDeploymentException
114                         (e,"Deployment architecture corrupted check the deployer "+
115                            "implementation it segurely miss a visit method in right state");
116         } catch (IllegalAccessException JavaDoc e1) {
117             throw new FatalDeploymentException
118                         (e1,"Deployment architecture corrupted");
119         } catch (InvocationTargetException JavaDoc e2) {
120             if(e2.getTargetException() instanceof FatalDeploymentException)
121                 throw (FatalDeploymentException)e2.getTargetException();
122             throw new FatalDeploymentException
123                         ((Exception JavaDoc) e2.getTargetException(),
124                           "Deployment architecture throw an unexpected exception");
125         }
126     }
127
128     /**
129      * The traverse method make the scheduling of the deployers
130      * processing.The scheduling is delegated to the deployment
131      * scheduler which is connected.
132      *
133      * @param deployer The deployer in charge to process @param deployers
134      * @param deployers The deployers to process
135      * @throws FatalDeploymentException if a problem occured during the
136      * deployment or if the the given @param deployers are not supported
137      * by @param deployer.
138      */

139     public void
140     traverse(Deployer deployer, Deployer[] deployers)
141     throws FatalDeploymentException
142     {
143         deployerScheduler.traverse(deployer, deployers);
144     }
145
146     /**
147      * The connectLifeCycleManager method connect a Life Cycle Manager to
148      * the current deployer. This life cycle manager will be used to memorize
149      * the deployer state.
150      *
151      * @param lifeCycleManager The LifeCycleManager to connect
152      */

153     public void
154     connectLifeCycleManager(LifeCycleManager lifeCycleManager)
155     {
156         this.lifeCycleManager = lifeCycleManager;
157     }
158     
159     /**
160      * Accessor method to retrieve the current Life Cycle Manager
161      * @return The current LifeCycleManager
162      */

163     public LifeCycleManager
164     getLifeCycleManager()
165     {
166         return this.lifeCycleManager;
167     }
168     
169
170     /**
171      * The connectErrorManager method connect a Error Manager to the
172      * current deployer
173      *
174      * @param manager The ErrorManager to connect
175      */

176     public void
177     connectErrorManager(ErrorManager manager)
178     {
179         errorManager = manager;
180     }
181            
182     /**
183      * Method accesor to retrieve the current Error Manager
184      *
185      * @return The current error manager
186      */

187     public ErrorManager
188     getErrorManager()
189     {
190         return errorManager;
191     }
192     
193     /**
194      * The connectDeployerScheduler method is used to connect and
195      * deployer scheduler to the current deployer.
196      *
197      * @param deployerScheduler The DeployerScheduler to connect
198      */

199     public void
200     connectDeployerScheduler(DeployerScheduler deployerScheduler)
201     {
202         this.deployerScheduler = deployerScheduler;
203     }
204
205     /**
206      * The connectDeployerDescription is used to connect the xml element
207      * which describe the xml code processed.
208      * @param deployerDescription to connect.
209      */

210     public void
211     connectDeployerDescription(Bean deployerDescription)
212     {
213         this.deployerDescription = deployerDescription;
214     }
215        
216     /**
217      * The getStatus method return the current deployer state.
218      * In this implementation the deployer state is managed by an
219      * external life cycle manager. The getStatus implementation
220      * processing is delegate to the current LifeCycleManager.
221      *
222      * @return DeployerState The current deployer state
223      */

224     public DeployerState
225     getStatus()
226     {
227         return lifeCycleManager.getStatus();
228     }
229
230
231     /**
232      * The getStringifiedDeployerDescription method provide a
233      * readable string reprensentation of the xml code process
234      * by the current deployer.
235      *
236      * @return The stringified representation of the code processed
237      * @throws InitializationError thrown if the deployerDescription is
238      * not connected.
239      */

240     public String JavaDoc
241     getStringifiedDeployerDescription()
242     throws InitializationError
243     {
244         try {
245             if (stringifiedDescription == null) {
246                 StringWriter JavaDoc w = new StringWriter JavaDoc();
247                 deployerDescription.marshal(w);
248                 stringifiedDescription = w.toString();
249             }
250             return stringifiedDescription;
251         } catch (Exception JavaDoc e) {
252             e.printStackTrace();
253             throw new InitializationError
254                         (this,
255                             "The deployer description retrieval failed due to:\n"
256                                 + e.getMessage());
257         }
258     }
259     /**
260      * The getStringifiedDeployerDescriptionNoError method provide a
261      * readable string reprensentation of the xml code process
262      * by the current deployer.
263      *
264      * @return The stringified representation of the code processed
265      */

266     public String JavaDoc
267     getStringifiedDeployerDescriptionNoError()
268     {
269         try {
270             if (stringifiedDescription == null) {
271                 StringWriter JavaDoc w = new StringWriter JavaDoc();
272                 deployerDescription.marshal(w);
273                 stringifiedDescription = w.toString();
274             }
275             return stringifiedDescription;
276         } catch (Exception JavaDoc e) {
277             return "Description not available";
278         }
279     }
280     /**
281      * The getIdentifier method provides a string representation of
282      * the current deployer. This string representation is compute
283      * using the Depoyer class name.
284      */

285     public String JavaDoc
286     getIdentifier()
287     {
288         String JavaDoc name = this.getClass().getName();
289         return name.substring(name.lastIndexOf(".") + 1);
290     }
291     
292     /**
293      * The abstract initialize method must be implemented by the child
294      * deployer context to verify that all the required connection for
295      * deployment processing are established. And all the xml code provided
296      * is valide. a successfull invokation of the initialize method chance
297      * the current deployer state to the following
298      * (classicaly the DeployerInactiveState).
299      *
300      * @throws InitializationError thrown if a connection required missed or if
301      * a data is not well feed or formated.
302      */

303     public abstract void
304     initialize()
305     throws InitializationError;
306
307
308 }
309
Popular Tags