KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > javabb > interceptor > ExceptionInterceptor


1 package org.javabb.interceptor;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
5 import org.javabb.action.infra.ActionSuper;
6
7 import com.opensymphony.xwork.Action;
8 import com.opensymphony.xwork.ActionInvocation;
9 import com.opensymphony.xwork.interceptor.Interceptor;
10
11 /*
12  * Copyright 2004 JavaFree.org
13  *
14  * Licensed under the Apache License, Version 2.0 (the "License");
15  * you may not use this file except in compliance with the License.
16  * You may obtain a copy of the License at
17  *
18  * http://www.apache.org/licenses/LICENSE-2.0
19  *
20  * Unless required by applicable law or agreed to in writing, software
21  * distributed under the License is distributed on an "AS IS" BASIS,
22  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23  * See the License for the specific language governing permissions and
24  * limitations under the License.
25  */

26
27 /**
28  * $Id: ExceptionInterceptor.java
29  * @author Lucas Teixeira - <a HREF="mailto:lucas@javabb.org">lucas@javabb.org </a> <br>
30  */

31 public class ExceptionInterceptor implements Interceptor {
32
33     protected final Log log = LogFactory.getLog(this.getClass());
34     
35     public void destroy() {}
36     public void init() {}
37
38     public String JavaDoc intercept(ActionInvocation actionInvocation) throws Exception JavaDoc {
39         //log.info("Interceptor de exception ativado");
40
ActionSuper action = (ActionSuper) actionInvocation.getAction();
41         try {
42             return actionInvocation.invoke();
43         } catch (Exception JavaDoc e) {
44             action.addActionError("Error: " + e.getMessage());
45             log.error(e.getMessage(), e);
46             return Action.ERROR;
47         }
48     }
49 }
50
Popular Tags