KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > shared > SharedFlow


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

18 package shared;
19
20 import java.io.IOException JavaDoc;
21
22 import org.apache.beehive.netui.pageflow.Forward;
23 import org.apache.beehive.netui.pageflow.PageFlowException;
24 import org.apache.beehive.netui.pageflow.SharedFlowController;
25 import org.apache.beehive.netui.pageflow.annotations.Jpf;
26
27 /**
28  * This shared flow can define actions, exception handlers, and state to be shared among page flows
29  * that reference it. A page flow references this shared flow inside a <code>Jpf.Controller</code>
30  * annotation as:
31  * <pre>
32  * sharedFlowRefs={
33  * &#064;Jpf.SharedFlowRef(name="shared", type=shared.SharedFlow.class)
34  * }
35  * </pre>
36  *
37  * Once referenced, the following features apply:
38  * <ul>
39  * <li>
40  * An instance of this shared flow will be created and stored the first time the page
41  * flow is accessed.
42  * </li>
43  * <li>
44  * The page flow (or its pages) can reference actions using the pattern
45  * <i>shared-flow-name.action-name</i>, e.g., "shared.someAction".
46  * </li>
47  * <li>
48  * Unhandled exceptions in the page flow will be handled by <code>Jpf.Catch</code>
49  * annotations in this shared flow.
50  * </li>
51  * <li>
52  * In pages and annotations that bind to data using the expression language, properties
53  * in this shared flow are accessed through the <code>sharedFlow</code> binding context.
54  * </li>
55  * <li>
56  * A page flow can have an automatically-initialized member reference to this shared
57  * flow using the <code>Jpf.SharedFlowField</code> annotation, like this:
58  * <pre>
59  * &#064;Jpf.SharedFlowField(name="shared")
60  * private shared.SharedFlow _mySharedFlowReference;
61  * </pre>
62  * </li>
63  * </ul>
64  */

65 @Jpf.Controller(
66     catches={
67        @Jpf.Catch(type=PageFlowException.class, method="handlePageFlowException"),
68        @Jpf.Catch(type=Exception JavaDoc.class, method="handleException")
69     }
70 )
71 public class SharedFlow
72     extends SharedFlowController
73 {
74     @Jpf.ExceptionHandler(
75         forwards={
76             @Jpf.Forward(name="errorPage", path="/resources/beehive/version1/jsps/error.jsp")
77         }
78     )
79     protected Forward handleException(Exception JavaDoc ex, String JavaDoc actionName, String JavaDoc message, Object JavaDoc form)
80     {
81         System.err.print("[" + getRequest().getContextPath() + "] ");
82         System.err.println("Unhandled exception caught in shared flow " + getDisplayName() + ":");
83         ex.printStackTrace();
84         return new Forward("errorPage");
85     }
86
87     /**
88      * Handler for native page flow exceptions (e.g., ActionNotFoundException, which is thrown when
89      * an unknown page flow action is requested). This handler allows these exceptions to write
90      * informative error pages to the response when the server is not in production mode, and it
91      * allows them to send an appropriate error on the response when the server is in production
92      * mode. To use the standard exception handler for these exceptions, simply remove this method
93      * and the Jpf.Catch annotation that references it.
94      */

95     @Jpf.ExceptionHandler
96     public Forward handlePageFlowException(PageFlowException ex, String JavaDoc actionName, String JavaDoc message, Object JavaDoc form)
97         throws IOException JavaDoc
98     {
99         ex.sendError(getRequest(), getResponse());
100         return null;
101     }
102 }
103
Popular Tags