KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > descriptor > componentassembly > ccm > deployer > managers > DefaultErrorManager


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 package org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.managers;
27
28
29 import java.util.Hashtable JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.base.DeployerContext;
32 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.base.DeployerFailureException;
33 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.base.DeploymentLogger;
34 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.base.ErrorManager;
35 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.base.FatalDeploymentException;
36 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.base.InitializationError;
37 import org.objectweb.openccm.descriptor.deployerconfig.Deployerconfig;
38 import org.objectweb.openccm.descriptor.deployerconfig.Deployerstatus;
39 import org.objectweb.openccm.descriptor.deployerconfig.Package;
40 import org.objectweb.openccm.descriptor.softpkg.ccm.CorbaComponentFileLoadingFailureException;
41
42 /**
43  * The default error manager in charge to decide in error case in the deployment
44  * must goes on or stops.
45  *
46  * @author <a HREF="mailto:briclet@lifl.fr">Briclet Frédéric</a>
47  *
48  * @version 0.1
49  */

50 public class DefaultErrorManager
51        implements ErrorManager
52     {
53     // ==================================================================
54
//
55
// Internal state.
56
//
57
// ==================================================================
58
private DeployerContext deployer;
59     private Hashtable JavaDoc tolerableError;
60     private DeploymentLogger deploymentLogger;
61     private Deployerconfig deployerConfig;
62     // ==================================================================
63
//
64
// Constructors.
65
//
66
// ==================================================================
67
public DefaultErrorManager(Deployerconfig deployerConfig)
68     {
69         this.deployerConfig=deployerConfig;
70         setupError();
71     }
72     // ==================================================================
73
//
74
// Internal methods.
75
//
76
// ==================================================================
77
/**
78      * Internal method to setup the table of tolerable errors.
79      */

80     private void
81     setupError()
82     {
83         tolerableError=new Hashtable JavaDoc();
84        
85         for(Iterator JavaDoc it=deployerConfig.getTolerablefailure().getXmlpackageList().iterator();it.hasNext();){
86             Package JavaDoc pbi= (Package JavaDoc)it.next();
87             for(Iterator JavaDoc it1=pbi.getDeployerstatusList().iterator();it1.hasNext();){
88                 Deployerstatus dsb=(Deployerstatus)it1.next();
89                 for(Iterator JavaDoc it2=dsb.getDeployerList().iterator();it2.hasNext();){
90                     org.objectweb.openccm.descriptor.deployerconfig.Deployer dbi=
91                         (org.objectweb.openccm.descriptor.deployerconfig.Deployer)it2.next();
92                     tolerableError.put(pbi.getName()+"."+dbi.getName()+"."+dsb.getName(),"empty");
93                 }
94             }
95         }
96             
97     }
98
99     /**
100      * Internal method to decide if the error that occur is tolerable or not.
101      *
102      * @param e The exception which occured
103      * @return true if the error is tolerable false if it is not.
104      */

105     private boolean
106     isTolerableException(DeployerFailureException e)
107     {
108         String JavaDoc deployerName=e.getDeployer().getClass().getName();
109         String JavaDoc deployerStatus=e.getDeployer().getStatus().getStateName();
110         if(tolerableError.containsKey(deployerName+"."+deployerStatus))
111             return true;
112         return false;
113     }
114     /**
115      * Internal accessor to retrieve deployment logger
116      * @return The current deployment logger
117      */

118     protected DeploymentLogger
119     getDeploymentLogger()
120     {
121         return deploymentLogger;
122     }
123     // ==================================================================
124
//
125
// Public methods.
126
//
127
// ==================================================================
128
/**
129      * SubmitException is use to report a initialization error
130      * and decide if the building of the deployment machine must
131      * go on or stop.
132      *
133      * @param e the initialization error to evaluate
134      * @throws InitializationError if deployment machine building must be stopped.
135      */

136     public void
137     submitException(InitializationError e)
138     throws InitializationError
139     {
140
141         if(!isTolerableException(e)){
142             getDeploymentLogger()
143                 .log(e.getMessage());
144             getDeploymentLogger()
145                        .log(">> According to the error configuration it is "
146                             +" a fatal deployment error. Deployment will be stop here.");
147         e.getDeployer().getLifeCycleManager().stepAborded();
148             
149         throw e;
150         }
151         
152         getDeploymentLogger()
153         .log(">> Error occured during initialization of "
154              +e.getDeployer().getIdentifier()+":\n"
155              +e.getMessage());
156              
157         if(e instanceof CorbaComponentFileLoadingFailureException){
158             getDeploymentLogger()
159                 .log(">>Check you CSD file in must specify a link to a "+
160                 "non exisiting file");
161             e.getDeployer().getLifeCycleManager().stepAborded();
162         }
163         else{
164             e.getDeployer().getLifeCycleManager().stepAborded();
165             getDeploymentLogger()
166                     .log(">> "+e.getDeployer().getStringifiedDeployerDescription()+
167                          "\n"+e.getMessage());
168             throw e;
169         }
170
171     }
172     
173     /**
174      * the submitException is used to submit exception that occured
175      * during deployment and choose if the deployment must be continued
176      * or to be stopped.
177      *
178      * @param e the deployer failure that occured.
179      * @throws FatalDeploymentException if deployment must be stopped
180      */

181     public void
182     submitException(DeployerFailureException e)
183     throws FatalDeploymentException
184     {
185
186         try{//TODO:modifier le branchement du logueur
187

188             getDeploymentLogger()
189                           .log(">> An error occured durig the deployment of:");
190                           
191             getDeploymentLogger()
192                     .log(">> "+e.getDeployer().getStringifiedDeployerDescription()+
193                          "\n"+e.getMessage());
194               
195         }
196         catch(Exception JavaDoc ex){
197             System.err.println(ex.getMessage());
198         }
199         if(!isTolerableException(e)){
200             getDeploymentLogger()
201                            .log(">> According to the error configuration it is "
202                                 +" a fatal deployment error. Deployment will be stop here.");
203             e.getDeployer().getLifeCycleManager().stepAborded();
204             
205             throw new FatalDeploymentException(e);
206         }
207         getDeploymentLogger().log(">> According to the error configuration it is "
208                                      +"a unfatal deployment error. Deployment will continue.");
209           
210         e.getDeployer().getLifeCycleManager().stepAborded();
211     
212     }
213     
214     public void connectDeploymentLogger(DeploymentLogger deploymentLogger) {
215         this.deploymentLogger=deploymentLogger;
216     }
217     
218
219     
220 }
221
Popular Tags