MainSubEditService.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2006 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: pdelrieu@openmobileis.org
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
00023  * 
00024  */
00025 package org.openmobileis.services;
00026 
00027 import java.io.IOException;
00028 import java.util.Map;
00029 
00030 import javax.servlet.ServletException;
00031 import javax.servlet.http.HttpServletRequest;
00032 import javax.servlet.http.HttpServletResponse;
00033 import javax.servlet.http.HttpSession;
00034 
00035 import org.openmobileis.common.util.exception.ServiceException;
00036 import org.openmobileis.common.util.log.LogManager;
00037 import org.openmobileis.services.common.ServiceManager;
00038 
00039 import freemarker.template.TemplateModelRoot;
00040 
00052 public abstract class MainSubEditService extends SimpleEditService {
00053         
00054         public MainSubEditService()     {
00055                 
00056         }
00057 
00058         public String runTemplate (HttpServletRequest req, HttpServletResponse res , TemplateModelRoot templateData) throws ServletException, IOException {
00059                 try     {
00060                         //Look after the session if it's not null
00061                         
00062                         if(req.getSession().getAttribute(this.getSessionDataTempName()) != null){
00063                                 Object sessionDatas = req.getSession().getAttribute(this.getSessionDataTempName());
00064                                 
00065                                 Map map2 = req.getParameterMap();
00066                                 map2.putAll((Map)sessionDatas);
00067                                 //remove the session
00068                                 req.getSession().removeAttribute(this.getSessionDataTempName());
00069                         
00070                         }else{
00071                         
00072                                 String url = req.getParameter("redirectURL");
00073                                 if(url != null){
00074                                         //put the params request in the session and do redirect service
00075                                         HttpSession session = req.getSession(true);
00076                                         session.setAttribute(this.getSessionDataTempName(), req.getParameterMap());
00077                                         ServiceManager.getManager().redirectToServiceURI(url, req, res);
00078                                         return null;
00079                                 }
00080                                 
00081 
00082                         }
00083 
00084                         //run the SimpleEditService()
00085                         return super.runTemplate(req,res,templateData);
00086                         //return this.getTemplateName();
00087                 } catch (Exception ex) {
00088                         LogManager.traceError(0, ex);
00089                         HttpSession session = req.getSession(true);
00090                         session.removeAttribute(this.getSessionDatasName());
00091                         session.removeAttribute(this.getErrorSessionAttributName());
00092                         throw new ServletException(ex);
00093                 }
00094         }
00095         
00096         protected boolean isStoreMode(HttpServletRequest req)   {
00097                 
00098                 String uri = req.getParameter("redirectURL");
00099                 if (uri != null)        {
00100                         EditService service = (EditService)ServiceManager.getManager().getServiceByURI(uri);
00101                         
00102                         if (service.hasSessionData(req))        {
00103                                 service.removeSessionData(req);
00104                                 return false;
00105                         }
00106                 }
00107 
00108                 return true;
00109         }
00110         
00111 
00112         private String getSessionDataTempName(){
00113                 return "Session.MultiEdit.temp";
00114         }
00115         
00116         protected abstract void fillTemplateWithSessionData(Object sessionDatas, TemplateModelRoot templateData) throws ServiceException;       
00117         protected abstract void storeSessionObjectInDB(Object sessionDatas, HttpServletRequest req, TemplateModelRoot templateData) throws ServiceException;    
00118         protected abstract void fillSessionObjectWithRequestData(Object sessionDatas, HttpServletRequest req) throws ServiceException;  
00119         protected abstract String getSessionDatasName();
00120         protected abstract String getTemplateName();
00121         protected abstract Object createSessionObject(HttpServletRequest req) throws ServiceException;
00122         protected abstract String getDisplayServiceURI();
00123         
00124 
00125 }

Generated on Mon Dec 4 11:03:28 2006 for OpenMobileIS by  doxygen 1.5.1-p1