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

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.common.SecurityManager;
00034 import org.openmobileis.services.navigation.NavigationBarManager;
00035 import org.openmobileis.services.navigation.NavigationBarService;
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 name;
00054  private String uri;
00055  private boolean isNavigationService = false;
00056 
00057  public Service() {
00058         if (this instanceof NavigationBarService)       {
00059                 isNavigationService = true;
00060         }
00061  }
00062 
00063 /* Call by Service manager to perform to internal process before run call
00064  * @param req the servlet request
00065  * @param req the servlet response
00066  *  @exception ServletException when an exception has occurred
00067  */
00068   public void runService(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException  {
00069         //      LogManager.traceNotice(0, "Service :Begin run");
00070 
00071         // validate if its not a auth pass request
00072         //if yes validate pass. Use by synchro to begin sync.
00073                 if (SecurityManager.getManager().isInitializedPass())   {
00074                         String type = req.getParameter("type");
00075                         if ((type !=null) && (type.equals("setPassword")))      {                               
00076                                 String pwd = req.getParameter("pwd");
00077                                 if (SecurityManager.getManager().validateServicePass(pwd))      {
00078                                     SecurityManager.getManager().setServiceCall();
00079                                 }
00080                         }
00081                 //manage password authentification
00082 //                      if ((SecurityManager.getManager().getMaxTimeout()!=0) &&(pass != null)) { //validate password timeout
00083                         if ((SecurityManager.getManager().getMaxTimeout()!=0) && SecurityManager.getManager().isInitializedPass())      { //validate password timeout
00084                                 if (SecurityManager.getManager().isServiceCallElapseTime())     { // ask pass
00085                                     res.sendRedirect(res.encodeRedirectURL("/showpassform"));
00086                                         return;
00087                                 }
00088                         }
00089                 SecurityManager.getManager().setServiceCall();
00090                 }
00091                 
00092                 //manage navigation bar.
00093                 if (isNavigationService)        {                       
00094                         NavigationBarManager.getManager().setCurrentService((NavigationBarService)this, req);
00095                 }
00096         
00097           
00098           //manage cached data.
00099           if (this.useWebCache())       {
00100           byte[] cachedResp = WebPageCacheManager.getManager().getCachedPage(req, this);
00101           if (cachedResp != null)       {
00102               res.getWriter().print(cachedResp);
00103                 //((WebServerConnection)res).setResponse(cachedResp);
00104                 return;
00105           }
00106         }
00107                 
00108         //      LogManager.traceNotice(0, "Service :BEfore run service");
00109                 this.run(req, res);
00110         //      LogManager.traceNotice(0, "Service :AFTER run service");
00111         
00112     //add to cache
00113     if (this.useWebCache())     {
00114         WebPageCacheManager.getManager().setCachedPage(req, res.getOutputStream().toString().getBytes(), this);
00115         //WebPageCacheManager.getManager().setCachedPage(req, ((WebServerConnection)res).getResponseData(), this);
00116     }
00117   }
00118 
00119 /* Process the service method to implement 
00120  * @param req the servlet request
00121  * @param req the servlet response
00122  *  @exception ServletException when an exception has occurred
00123  */
00124   public abstract void run( HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException;
00125 
00126   /*
00127   * * Return the service name
00128   */
00129    public String getName() {
00130     return name;
00131    }
00132 
00133   /*
00134   * The service manager initialize the service.
00135   * It sets its name from the property file. Subclasses can override this method
00136   * in order to create listeners and register them to the synchro manager
00137   */
00138   public void init (String name) {
00139     this.name = name;
00140   }
00141   
00146   public boolean useWebCache()  {
00147         return false;
00148   }
00149         
00156         public String getNavigationBarLastServiceURI()  {
00157                 return null;
00158         }
00159 
00163         public boolean isNavigationService() {
00164                 return isNavigationService;
00165         }
00166         
00167         public String getServiceUri() {
00168                 return this.uri;
00169         }
00170         
00171         public void setServiceURI(String uri) {
00172                 this.uri = uri;
00173         }
00174 
00175 }

Generated on Thu Oct 6 10:06:33 2005 for OpenMobileIS by  doxygen 1.4.3