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

📄 netstoreservicefactory.java

📁 一个netstore的完整代码,他使用了j2ee和webservice技术,并使用ojb o/r管理框架,很不错的
💻 JAVA
字号:
package netstore.service;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.apache.struts.action.PlugIn;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.config.ModuleConfig;
import netstore.framework.util.IConstants;
/**
 * A factory for creating Netstore Service Implementations. The specific
 * service to instantiate is determined from the initialization parameter
 * of the ServiceContext. Otherwise, a default implementation is used.
 * @see netstore.service.NetstoreDebugServiceImpl
 */
public class NetstoreServiceFactory implements INetstoreServiceFactory, PlugIn{
  // Hold onto the servlet for the destroy method
  private ActionServlet servlet = null;
  // The default is to use the debug implementation
   String serviceClassname =
   "netstore.service.NetstoreDebugServiceImpl";

   public INetstoreService createService() throws
    ClassNotFoundException, IllegalAccessException, InstantiationException {
    String className = servlet.getInitParameter( IConstants.SERVICE_CLASS_KEY );

    if (className != null ){
      serviceClassname = className;
    }
    

 try{
    INetstoreService instance =
     (INetstoreService)Class.forName(serviceClassname).newInstance();
    instance.setServletContext( servlet.getServletContext() );

    return instance;
 }catch(Exception e){e.printStackTrace(); return null;}

  }

  public void init(ActionServlet servlet, ModuleConfig config)
    throws ServletException{
    // Store the servlet for later
    this.servlet = servlet;

    /* Store the factory for the application. Any Netstore service factory
     * must either store itself in the ServletContext at this key, or extend
     * this class and don't override this method. The Netstore application
     * assumes that a factory class that implements the IStorefrtonServiceFactory
     * is stored at the proper key in the ServletContext.
     */
    servlet.getServletContext().setAttribute( IConstants.SERVICE_FACTORY_KEY, this );
  }

  public void destroy(){
    // Do nothing for now
  }
}

⌨️ 快捷键说明

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