⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 servicelocatorimpl.java

📁 一个ssh结构组成 的BS开发
💻 JAVA
字号:
package cn.hxex.library.view.servicelocator.impl;

import javax.servlet.ServletContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import cn.hxex.library.service.CategoryService;
import cn.hxex.library.service.ProductService;
import cn.hxex.library.service.RecordService;
import cn.hxex.library.service.UserService;
import cn.hxex.library.view.servicelocator.ServiceLocator;
import cn.hxex.library.view.util.FacesUtils;

/**
 * ServiceLocator接口类的实现
 * 
 * @author galaxy
 *
 */
public class ServiceLocatorImpl implements ServiceLocator {
	//the catalog service bean name
	private static final String CATEGORY_SERVICE_BEAN_NAME = "categoryService";

	// the user service bean name
	private static final String USER_SERVICE_BEAN_NAME = "userService";

	// the product service bean name
	private static final String PRODUCT_SERVICE_BEAN_NAME = "productService";

	// the record service bean name
	private static final String RECORD_SERVICE_BEAN_NAME = "recordService";

	//the logger for this class
	private Log logger = LogFactory.getLog(this.getClass());

	//the Spring application context
	private ApplicationContext appContext;

	public ServiceLocatorImpl() {
		ServletContext context = FacesUtils.getServletContext();

		this.appContext = WebApplicationContextUtils
				.getRequiredWebApplicationContext(context);
	}

	/**
	 * Lookup service based on service bean name.
	 * 
	 * @param serviceBeanName the service bean name
	 * @return the service bean
	 */
	public Object lookupService(String serviceBeanName) {
		return appContext.getBean(serviceBeanName);
	}

	/**
	 * Get the <code>CatalogService</code>
	 * 
	 * @return the catalog service
	 */
	public CategoryService getCategoryService() {
		return (CategoryService) lookupService(CATEGORY_SERVICE_BEAN_NAME);
	}

	public UserService getUserService() {
		return (UserService) lookupService(USER_SERVICE_BEAN_NAME);
	}

	public ProductService getProductService() {
		return (ProductService) lookupService(PRODUCT_SERVICE_BEAN_NAME);
	}

	public RecordService getRecordService() {
		return (RecordService) lookupService(RECORD_SERVICE_BEAN_NAME);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -