servicefactory.java

来自「飞机订票系统」· Java 代码 · 共 37 行

JAVA
37
字号
package org.appfuse.util;

import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;

import org.appfuse.util.exception.AppException;
import org.appfuse.util.exception.AppSystemException;
import org.appfuse.util.exception.ExceptionConstants;
import org.springframework.context.ApplicationContext;
import org.appfuse.service.Manager;

/**
 *
 * Description: Utility for fetching business service object.
 * @author Linux
 * @version 1.0
 */
public class ServiceFactory {
    /** Logger */
    private static Log log = LogFactory.getLog(ServiceFactory.class);
    /** Spring Application context */
    private static ApplicationContext ctx = null;

    public static void init(ApplicationContext context) {
        ctx = context;
    }
    public static Manager getService(String serviceName) throws AppException {
        if (ctx == null) {
            // ApplicationContext Should not be null
            log.error("getService error: ApplicationContext is null");
            throw new AppSystemException("CreateServiceObject Failed",
                             ExceptionConstants.SYS_GENERAL_ERR);
        }
        return (Manager) ctx.getBean(serviceName);
    }
}

⌨️ 快捷键说明

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