CallingServiceManager.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  *  Modifications :
00025  *  2004 Creation P.Delrieu
00026  *  2004 Modified by Romain Beaugrand
00027  * 
00028  */
00029 package org.openmobileis.services.common;
00030 
00031 import java.util.Hashtable;
00032 
00033 import javax.servlet.http.HttpServletRequest;
00034 
00035 import org.openmobileis.common.util.collection.Array;
00036 
00053 public final class CallingServiceManager {
00054         
00055         private Array stack;
00056         private Array paramList;
00057         private int stackIndex = 0;
00058     private static CallingServiceManager manager;
00059          
00063         private CallingServiceManager() {
00064                 super();
00065                 stack = new Array(5);
00066                 paramList = new Array(5);
00067         }
00068     
00069     public static CallingServiceManager getManager()    {
00070       if (manager == null){
00071         synchronized(CallingServiceManager.class)   {
00072           if (manager == null)  {
00073             manager = new CallingServiceManager();
00074           }
00075         }
00076       }
00077       return manager;
00078     }
00079 
00086   public Array getRegistedCallingServiceList()  {
00087         return stack;
00088   }
00089   
00094   public Hashtable getCallingServiceParameters()        {
00095         if (stackIndex > 0)     {
00096                 return (Hashtable) paramList.get(stackIndex-1);
00097         }
00098         return null;
00099   }
00100   
00104   public void pushCallingService(String serviceURI, HttpServletRequest req)     {
00105         stack.add(stackIndex,serviceURI);
00106         paramList.add(stackIndex, new Hashtable(req.getParameterMap()));
00107         stackIndex++;
00108   }
00109   
00114   public String popCallingService() {
00115         if (stackIndex > 0)     {
00116                 String uri = (String)stack.remove(stackIndex-1);
00117                 paramList.remove(stackIndex-1);
00118                 stackIndex --;
00119                 return uri;
00120         }
00121         return null;
00122   }
00123   
00129   public String peekCallingService()    {
00130         if (stackIndex > 0)     {
00131                 String uri = (String)stack.get(stackIndex-1);
00132                 return uri;
00133         } 
00134         return null;
00135   }
00136   
00141   public String getCallingServiceURL()  {
00142         if (this.peekCallingService() != null)  {
00143                 return ServiceManager.getManager().getServiceBaseURI()+"/admin/callingservice";
00144         } else {
00145                 return null;
00146         }
00147   }
00148   
00152   public boolean isEmpty()      {
00153         return (stack.size()==0);
00154   }
00155   
00163         public boolean peekToTheSpecifiedCallingService(String serviceURI)      {
00164                 Array clonedStack = (Array)stack.clone();
00165                 Object ret;
00166                 for (int i=stackIndex-1; i>=0; i--)     {
00167                         ret = clonedStack.remove(i);
00168                         if((ret !=null)&&(ret.equals(serviceURI)))      {
00169                                 stack = clonedStack;
00170                                 stackIndex = i+1;
00171                                 stack.add(ret);
00172                                 return true;
00173                         }
00174                         paramList.remove(i);
00175                         
00176                 }
00177                 return false;
00178         }
00179         
00183         public void clearStack()        {
00184                 stack.clear();
00185                 paramList.clear();
00186                 stackIndex = 0;
00187         }
00188 }

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