KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jdon > strutsutil > ModelBaseAction


1 /*
2  * Copyright 2003-2006 the original author or authors.
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 implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  *
15  */

16 package com.jdon.strutsutil;
17
18 import javax.servlet.ServletContext JavaDoc;
19 import javax.servlet.http.HttpServletRequest JavaDoc;
20 import javax.servlet.http.HttpServletResponse JavaDoc;
21
22 import org.apache.struts.action.Action;
23 import org.apache.struts.action.ActionForm;
24 import org.apache.struts.action.ActionForward;
25 import org.apache.struts.action.ActionMapping;
26
27 import com.jdon.container.finder.ComponentKeys;
28 import com.jdon.controller.WebAppUtil;
29 import com.jdon.model.ModelManager;
30 import com.jdon.strutsutil.util.CreateViewPageUtil;
31 import com.jdon.strutsutil.util.EditeViewPageUtil;
32 import com.jdon.strutsutil.util.ViewPageUtil;
33 import com.jdon.util.Debug;
34
35 /**
36  * @author <a HREF="mailto:banqiao@jdon.com">banq</a>
37  *
38  */

39 public abstract class ModelBaseAction extends Action{
40
41     private final static String JavaDoc module = ModelBaseAction.class.getName();
42     
43     protected ModelManager modelManager;
44     protected CreateViewPageUtil createViewPage;
45     protected EditeViewPageUtil editeViewPage;
46     protected ViewPageUtil viewPageUtil;
47
48
49     public void intContext(ServletContext JavaDoc sc){
50       if (modelManager == null){
51         modelManager = (ModelManager)WebAppUtil.getComponentInstance(ComponentKeys.MODEL_MANAGER, sc);
52         createViewPage = new CreateViewPageUtil(modelManager);
53         editeViewPage = new EditeViewPageUtil(modelManager);
54         viewPageUtil = new ViewPageUtil(modelManager);
55       }
56     }
57     
58     public abstract ActionForward execute(ActionMapping actionMapping,
59             ActionForm actionForm,
60             HttpServletRequest JavaDoc request,
61             HttpServletResponse JavaDoc response) throws Exception JavaDoc ;
62
63     protected void checkConfigName(ActionMapping actionMapping) throws Exception JavaDoc {
64         if (actionMapping.findForward(FormBeanUtil.FORWARD_FAILURE_NAME) == null)
65           Debug.logError(
66               "not found the forward name '" + FormBeanUtil.FORWARD_FAILURE_NAME +
67               "' in struts-config.xml", module);
68         else if (actionMapping.findForward(FormBeanUtil.FORWARD_SUCCESS_NAME) == null)
69           Debug.logError(
70               "not found the forward name '" + FormBeanUtil.FORWARD_SUCCESS_NAME +
71               "' in struts-config.xml", module);
72
73       }
74 }
75
Popular Tags