View Javadoc

    1   /***
    2    * @(#)ServiceLoaderPlugIn.java
    3    *
    4    * JFoxSOAF, Service-Oriented Application Framework
    5    *
    6    * Copyright(c) JFoxSOAF Team
    7    *
    8    * Licensed under the GNU LGPL, Version 2.1 (the "License");
    9    * you may not use this file except in compliance with the License.
    10   * You may obtain a copy of the License at
    11   *
    12   * http://www.gnu.org/copyleft/lesser.html
    13   *
    14   * Unless required by applicable law or agreed to in writing, software
    15   * distributed under the License is distributed on an "AS IS" BASIS,
    16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    17   * See the License for the specific language governing permissions and
    18   * limitations under the License.
    19   *
    20   * For more information, please visit:
    21   * http://www.jfox.cn/confluence/display/JFoxSOAF/Home
    22   * http://www.huihoo.org/jfox/jfoxsoaf
    23   */
    24
    25  package org.huihoo.jfox.soaf.services.useraccess.struts;
    26
    27  import java.io.InputStream;
    28
    29  import javax.servlet.ServletException;
    30
    31  import org.apache.commons.logging.Log;
    32  import org.apache.commons.logging.LogFactory;
    33  import org.apache.struts.action.ActionServlet;
    34  import org.apache.struts.action.PlugIn;
    35  import org.apache.struts.config.ModuleConfig;
    36  import org.huihoo.jfox.soaf.container.ServiceLoader;
    37  import org.huihoo.jfox.soaf.exception.ServiceConfigurationException;
    38
    39  /***
    40   * <p>
    41   * Struts service loader plugin
    42   * </p>
    43   *
    44   * @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
    45   * @version $Revision: 1.1 $ $Date: 2006/02/15 08:45:44 $
    46   * @version Revision: 1.0
    47   */
    48
    49  public class ServiceLoaderPlugIn implements PlugIn {
    50
    51  	private ServiceLoader serviceLoader = ServiceLoader.getInstance();
    52
    53  	/***
    54  	 * Logging output for this plug in instance.
    55  	 */
    56  	private Log log = LogFactory.getLog(this.getClass());
    57
    58  	/***
    59  	 * The web application resource path of our persistent database storage
    60  	 * file.
    61  	 */
    62  	private String pathname = "/WEB-INF/jfoxsoaf-config.xml";
    63
    64  	/***
    65  	 * Destroy service config.
    66  	 *
    67  	 * @see org.apache.struts.action.PlugIn#destroy()
    68  	 */
    69  	public void destroy() {
    70  	}
    71
    72  	/***
    73  	 * Initialize the service config resources for this module.
    74  	 *
    75  	 * @see org.apache.struts.action.PlugIn#init(org.apache.struts.action.ActionServlet,
    76  	 *      org.apache.struts.config.ModuleConfig)
    77  	 */
    78  	public void init(ActionServlet actionServlet, ModuleConfig moduleConfig)
    79  			throws ServletException {
    80  		if (log.isInfoEnabled()) {
    81  			log.info("Loading service config from '" + pathname + "'");
    82  		}
    83
    84  		try {
    85  			initServiceConfig(actionServlet);
    86  		} catch (ServiceConfigurationException e) {
    87  			log.error("Service configuration initialization failed", e);
    88  			e.printStackTrace();
    89  		}
    90
    91  	}
    92
    93  	/***
    94  	 * @param actionServlet
    95  	 */
    96  	private void initServiceConfig(ActionServlet actionServlet)
    97  			throws ServiceConfigurationException {
    98  		InputStream is = actionServlet.getServletContext().getResourceAsStream(
    99  				pathname);
    100 		serviceLoader.initService(is);
    101 	}
    102
    103 }