Index: lams_admin/src/java/org/lamsfoundation/lams/admin/service/AdminServiceProxy.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/service/AdminServiceProxy.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/service/AdminServiceProxy.java (revision 485064fba50450c1d59b1ca9137aa9846f6147d7) @@ -0,0 +1,60 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +/* $Id$ */ +package org.lamsfoundation.lams.admin.service; + +import javax.servlet.ServletContext; + +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.lamsfoundation.lams.util.MessageService; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; + +/** + * @author jliew + * + * Common class to make it easier to get the Spring beans. + */ +public class AdminServiceProxy { + + private static IUserManagementService manageService; + private static MessageService messageService; + + public static final IUserManagementService getService(ServletContext servletContext){ + if (manageService == null) { + WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); + return (IUserManagementService) ctx.getBean("userManagementServiceTarget"); + } else { + return manageService; + } + } + + public static final MessageService getMessageService(ServletContext servletContext){ + if (messageService == null) { + WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); + return (MessageService)ctx.getBean("adminMessageService"); + } else { + return messageService; + } + } +}