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

CallingServiceManager.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 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          
00062         public CallingServiceManager() {
00063                 super();
00064                 stack = new Array(5);
00065                 paramList = new Array(5);
00066         }
00067 
00074   public Array getRegistedCallingServiceList()  {
00075         return stack;
00076   }
00077   
00082   public Hashtable getCallingServiceParameters()        {
00083         if (stackIndex > 0)     {
00084                 return (Hashtable) paramList.get(stackIndex-1);
00085         }
00086         return null;
00087   }
00088   
00092   public void pushCallingService(String serviceURI, HttpServletRequest req)     {
00093         stack.add(stackIndex,serviceURI);
00094         paramList.add(stackIndex, new Hashtable(req.getParameterMap()));
00095         stackIndex++;
00096   }
00097   
00102   public String popCallingService() {
00103         if (stackIndex > 0)     {
00104                 String uri = (String)stack.remove(stackIndex-1);
00105                 paramList.remove(stackIndex-1);
00106                 stackIndex --;
00107                 return uri;
00108         }
00109         return null;
00110   }
00111   
00117   public String peekCallingService()    {
00118         if (stackIndex > 0)     {
00119                 String uri = (String)stack.get(stackIndex-1);
00120                 return uri;
00121         } 
00122         return null;
00123   }
00124   
00129   public String getCallingServiceURL()  {
00130         if (this.peekCallingService() != null)  {
00131                 return ServiceManager.getManager().getServiceBaseURI()+"/admin/callingservice";
00132         } else {
00133                 return null;
00134         }
00135   }
00136   
00140   public boolean isEmpty()      {
00141         return (stack.size()==0);
00142   }
00143   
00151         public boolean peekToTheSpecifiedCallingService(String serviceURI)      {
00152                 Array clonedStack = (Array)stack.clone();
00153                 Object ret;
00154                 for (int i=stackIndex-1; i>=0; i--)     {
00155                         ret = clonedStack.remove(i);
00156                         if((ret !=null)&&(ret.equals(serviceURI)))      {
00157                                 stack = clonedStack;
00158                                 stackIndex = i+1;
00159                                 stack.add(ret);
00160                                 return true;
00161                         }
00162                         paramList.remove(i);
00163                         
00164                 }
00165                 return false;
00166         }
00167         
00171         public void clearStack()        {
00172                 stack.clear();
00173                 paramList.clear();
00174                 stackIndex = 0;
00175         }
00176 }

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