KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > webapp > example > AbstractBacking


1 /*
2  * Copyright 1999-2002,2004 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
17
18 package org.apache.struts.webapp.example;
19
20
21 import java.io.IOException JavaDoc;
22 import javax.faces.FacesException;
23 import javax.faces.context.FacesContext;
24
25
26 /**
27  * <p>Abstract base class for backing beans.</p>
28  */

29
30 abstract class AbstractBacking {
31
32
33     // ------------------------------------------------------- Protected Methods
34

35
36     /**
37      * <p>Return the context relative path for the specified action.</p>
38      *
39      * @param context <code>FacesContext</code> for the current request
40      * @param action Name of the requested action
41      */

42     protected StringBuffer JavaDoc action(FacesContext context, String JavaDoc action) {
43
44         // FIXME - assumes extension mapping for Struts
45
StringBuffer JavaDoc sb = new StringBuffer JavaDoc(action);
46         sb.append(".do");
47         return (sb);
48
49     }
50
51
52     /**
53      * <p>Forward to the specified URL and mark this response as having
54      * been completed.</p>
55      *
56      * @param context <code>FacesContext</code> for the current request
57      * @param url Context-relative URL to forward to
58      *
59      * @exception FacesException if any error occurs
60      */

61     protected void forward(FacesContext context, String JavaDoc url) {
62
63         try {
64             context.getExternalContext().dispatch(url);
65         } catch (IOException JavaDoc e) {
66             throw new FacesException(e);
67         } finally {
68             context.responseComplete();
69         }
70
71     }
72
73
74     /**
75      * <p>Return the context relative base URL for the "logoff"
76      * action.</p>
77      *
78      * @param context <code>FacesContext</code> for the current request
79      */

80     protected StringBuffer JavaDoc logoff(FacesContext context) {
81
82         return (action(context, "/logoff"));
83
84     }
85
86
87     /**
88      * <p>Return the context relative base URL for the "logon"
89      * action.</p>
90      *
91      * @param context <code>FacesContext</code> for the current request
92      */

93     protected StringBuffer JavaDoc logon(FacesContext context) {
94
95         return (action(context, "/logon"));
96
97     }
98
99
100     /**
101      * <p>Return the context relative base URL for the "edit registration"
102      * action.</p>
103      *
104      * @param context <code>FacesContext</code> for the current request
105      */

106     protected StringBuffer JavaDoc registration(FacesContext context) {
107
108         return (action(context, "/editRegistration"));
109
110     }
111
112
113     /**
114      * <p>Return the context relative base URL for the "edit subscriptions"
115      * action.</p>
116      *
117      * @param context <code>FacesContext</code> for the current request
118      */

119     protected StringBuffer JavaDoc subscription(FacesContext context) {
120
121         return (action(context, "/editSubscription"));
122
123     }
124
125
126 }
127
Popular Tags