View Javadoc

1   package siouxsie.mvc.impl;
2   
3   import java.util.ArrayList;
4   import java.util.Collection;
5   
6   import siouxsie.mvc.IScreenHandler;
7   import siouxsie.mvc.Message;
8   import siouxsie.mvc.Severity;
9   
10  import com.opensymphony.xwork2.ActionInvocation;
11  import com.opensymphony.xwork2.Result;
12  import com.opensymphony.xwork2.inject.Inject;
13  import com.opensymphony.xwork2.interceptor.ExceptionHolder;
14  
15  /**
16   * Display messages from exception in the view.
17   * Handy for business exceptions.
18   * @author Arnaud Cogoluegnes
19   * @version $Id$
20   */
21  public class ScreenExceptionHandler implements Result {
22  
23  	/**
24  	 * 
25  	 */
26  	private static final long serialVersionUID = -7524028200615928256L;
27  	
28  	@Inject
29  	private IScreenHandler screenHandler;
30  	
31  	public IScreenHandler getScreenHandler() {
32  		return screenHandler;
33  	}
34  
35  	public void setScreenHandler(IScreenHandler screenHandler) {
36  		this.screenHandler = screenHandler;
37  	}
38  
39  	/*
40  	 * (non-Javadoc)
41  	 * @see com.opensymphony.xwork2.Result#execute(com.opensymphony.xwork2.ActionInvocation)
42  	 */
43  	public void execute(ActionInvocation invocation) throws Exception {
44  		
45  		// get the exception holder
46  		ExceptionHolder holder = (ExceptionHolder) invocation.getStack().peek();
47  
48  		Exception ex = holder.getException();
49  		
50  		Collection<Message> messages = new ArrayList<Message>();
51  		Message message = new Message(ex.getMessage(),Severity.ERROR);
52  		messages.add(message);
53  		
54  		getScreenHandler().displayMessages(messages);		
55  	}
56  
57  	
58  	
59  
60  }