UserManager.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 
00026 package org.openmobileis.common.user;
00027 
00028 import java.util.Hashtable;
00029 
00030 import org.openmobileis.common.context.ApplicationContextManager;
00031 import org.openmobileis.common.util.exception.ServiceException;
00032 
00040 public class UserManager {
00041   private static UserManager manager;
00042 //  private UserManagerFactory factory;
00043   private Hashtable factoryList;
00044 
00045   private UserManager() {
00046     factoryList = new Hashtable(10);
00047   }
00048 
00049   public static UserManager getManager() {
00050     if (manager == null)  {
00051       synchronized (UserManager.class) {
00052         if (manager == null)  {
00053           manager = new UserManager();
00054           ApplicationContextManager.getManager().addManager(manager);
00055         }
00056       }
00057     }
00058     return manager;
00059   }
00060   
00061   public void registerUserManagerFactoryForGroup(String group, UserManagerFactory factory) {
00062     factoryList.put(group, factory);
00063   }
00064   
00075   public String authenticateUser(String group, String login, String pass) throws ServiceException, UserNotFoundException {
00076     UserManagerFactory factory = (UserManagerFactory) factoryList.get(group);
00077     if (factory != null)  {
00078       return factory.authenticateUser(login, pass);
00079     } else  {
00080       throw new UserNotFoundException("No UserManagerFactory registered for group :"+group);
00081     }
00082   }
00083 
00084   public void storeUser(String group, User user) throws ServiceException, UserAlreadyExistException {
00085     UserManagerFactory factory = (UserManagerFactory) factoryList.get(group);
00086     if (factory != null)  {
00087       factory.storeUser(user);
00088     } else  {
00089       throw new ServiceException("No UserManagerFactory registered for group :"+group);
00090     }
00091   }
00092 
00093   public User getUser(String group, String userID) throws ServiceException, UserNotFoundException {
00094     UserManagerFactory factory = (UserManagerFactory) factoryList.get(group);
00095     if (factory != null)  {
00096       return factory.getUser(userID);
00097     } else  {
00098       throw new UserNotFoundException("No UserManagerFactory registered for group :"+group);
00099     }
00100   }
00101   
00102   public void deleteUser(String group, String userID) throws ServiceException, UserNotFoundException {
00103     UserManagerFactory factory = (UserManagerFactory) factoryList.get(group);
00104     if (factory != null)  {
00105       factory.deleteUser(userID);
00106     } else  {
00107       throw new UserNotFoundException("No UserManagerFactory registered for group :"+group);
00108     }
00109   }
00110 }

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