KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > fortress > util > FortressCommandFailureHandler


1 /*
2  * Copyright 2003-2004 The Apache Software Foundation
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied.
13  *
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.avalon.fortress.util;
19
20 import org.apache.avalon.fortress.impl.handler.ComponentHandler;
21 import org.apache.avalon.fortress.impl.handler.PrepareHandlerCommand;
22 import org.apache.avalon.framework.logger.AbstractLogEnabled;
23
24 import org.apache.excalibur.event.command.Command;
25 import org.apache.excalibur.event.command.CommandFailureHandler;
26
27 /**
28  * The default CommandFailureHandler used by Fortress to log any
29  * failures encountered while executing commands.
30  *
31  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
32  * @version CVS $Revision: 1.4 $ $Date: 2004/02/28 15:16:26 $
33  * @since 4.1
34  */

35 public class FortressCommandFailureHandler
36     extends AbstractLogEnabled
37     implements CommandFailureHandler
38 {
39     /**
40      * Handle a command failure. If a command throws an exception, it has failed. The
41      * CommandManager will call this method so that we can handle the problem effectively.
42      *
43      * @param command The original Command object that failed
44      * @param throwable The throwable that caused the failure
45      *
46      * @return <code>true</code> if the CommandManager should cease to process commands.
47      */

48     public boolean handleCommandFailure( final Command command, final Throwable JavaDoc throwable )
49     {
50         if ( command instanceof PrepareHandlerCommand )
51         {
52             PrepareHandlerCommand phc = (PrepareHandlerCommand)command;
53             ComponentHandler handler = phc.getHandler();
54             
55             if ( getLogger().isErrorEnabled() )
56             {
57                 getLogger().error( "Could not prepare ComponentHandler for: "
58                     + handler.getComponentClass().getName(), throwable );
59             }
60         }
61         else
62         {
63             if ( getLogger().isErrorEnabled() )
64             {
65                 getLogger().error( "Command failed: " + command, throwable );
66             }
67         }
68         
69         // This handler never requests that commands cease to be processed.
70
return false;
71     }
72 }
73
74
Popular Tags