Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

Service.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2005 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: openmobileis@e-care.fr
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  *  Modifications :
00025  *  2004 Creation P.Delrieu
00026  *  2004 Modified by Romain Beaugrand
00027  * 
00028  */
00029 
00030 package org.openmobileis.services;
00031 
00032 import org.openmobileis.services.cache.WebPageCacheManager;
00033 import org.openmobileis.services.navigation.NavigationBarManager;
00034 import org.openmobileis.services.navigation.NavigationBarService;
00035 import org.openmobileis.services.security.SecurityManager;
00036 
00037 import java.io.IOException;
00038 
00039 import javax.servlet.ServletException;
00040 import javax.servlet.http.HttpServletRequest;
00041 import javax.servlet.http.HttpServletResponse;
00042 
00051 public abstract class Service {
00052         
00053  private String uri;
00054  private boolean isNavigationService = false;
00055 
00056  public Service() {
00057         if (this instanceof NavigationBarService)       {
00058                 isNavigationService = true;
00059         }
00060  }
00061 
00062 /* Call by Service manager to perform to internal process before run call
00063  * @param req the servlet request
00064  * @param req the servlet response
00065  *  @exception ServletException when an exception has occurred
00066  */
00067   public void runService(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException  {
00068         //      LogManager.traceNotice(0, "Service :Begin run");
00069 
00070         // validate if its not a auth pass request
00071         //if yes validate pass. Use by synchro to begin sync.
00072                 if (SecurityManager.getManager().isInitializedPass())   {
00073                         String type = req.getParameter("type");
00074                         if ((type !=null) && (type.equals("setPassword")))      {                               
00075                                 String pwd = req.getParameter("pwd");
00076                                 if (SecurityManager.getManager().validateServicePass(pwd))      {
00077                                     SecurityManager.getManager().setServiceCall();
00078                                 }
00079                         }
00080                 //manage password authentification
00081 //                      if ((SecurityManager.getManager().getMaxTimeout()!=0) &&(pass != null)) { //validate password timeout
00082                         if ((SecurityManager.getManager().getMaxTimeout()!=0) && SecurityManager.getManager().isInitializedPass())      { //validate password timeout
00083                                 if (SecurityManager.getManager().isServiceCallElapseTime())     { // ask pass
00084                                     res.sendRedirect(res.encodeRedirectURL("/showpassform"));
00085                                         return;
00086                                 }
00087                         }
00088                 SecurityManager.getManager().setServiceCall();
00089                 }
00090                 
00091                 //manage navigation bar.
00092                 if (isNavigationService)        {                       
00093                         NavigationBarManager.getManager().setCurrentService((NavigationBarService)this, req);
00094                 }
00095         
00096           
00097           //manage cached data.
00098           if (this.useWebCache())       {
00099           byte[] cachedResp = WebPageCacheManager.getManager().getCachedPage(req, this);
00100           if (cachedResp != null)       {
00101               res.getWriter().print(cachedResp);
00102                 //((WebServerConnection)res).setResponse(cachedResp);
00103                 return;
00104           }
00105         }
00106                 
00107         //      LogManager.traceNotice(0, "Service :BEfore run service");
00108                 this.run(req, res);
00109         //      LogManager.traceNotice(0, "Service :AFTER run service");
00110         
00111     //add to cache
00112     if (this.useWebCache())     {
00113         WebPageCacheManager.getManager().setCachedPage(req, res.getOutputStream().toString().getBytes(), this);
00114         //WebPageCacheManager.getManager().setCachedPage(req, ((WebServerConnection)res).getResponseData(), this);
00115     }
00116   }
00117 
00118 /* Process the service method to implement 
00119  * @param req the servlet request
00120  * @param req the servlet response
00121  *  @exception ServletException when an exception has occurred
00122  */
00123   public abstract void run( HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException;
00124 
00125   /*
00126   * * Return the service name
00127   */
00128    public abstract String getName();
00129 
00134   public boolean useWebCache()  {
00135         return false;
00136   }
00137         
00144         public String getNavigationBarLastServiceURI()  {
00145                 return null;
00146         }
00147 
00151         public boolean isNavigationService() {
00152                 return isNavigationService;
00153         }
00154         
00155         public String getServiceUri() {
00156                 return this.uri;
00157         }
00158         
00159         public void setServiceURI(String uri) {
00160                 this.uri = uri;
00161         }
00162 
00163 }

Generated on Wed Dec 14 21:05:35 2005 for OpenMobileIS by  doxygen 1.4.4