Package org.araneaframework.ioc.spring

Source Code of org.araneaframework.ioc.spring.StandardSpringMainServlet

/**
* Copyright 2006 Webmedia Group Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

package org.araneaframework.ioc.spring;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import org.araneaframework.servlet.ServletServiceAdapterComponent;
import org.araneaframework.servlet.core.StandardMainServlet;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;

/**
* @author Jevgeni Kabanov (ekabanov@webmedia.ee)
*/
public class StandardSpringMainServlet extends StandardMainServlet {
 
  public static final String DEFAULT_ARANEA_ROOT = "application.root";
  public static final String ARANEA_ROOT_INIT_PARAMETER_NAME = "aranea-application-root";
 
  private WebApplicationContext beanFactory;

  public void init(ServletConfig config) throws ServletException {
    ContextLoader loader = new ContextLoader();   
    beanFactory = loader.initWebApplicationContext(config.getServletContext());
    super.init(config);
  }
 
  protected ServletServiceAdapterComponent buildRootComponent() {
    String araneaRoot = DEFAULT_ARANEA_ROOT;
   
    if (getServletConfig().getInitParameter(ARANEA_ROOT_INIT_PARAMETER_NAME) != null)
      araneaRoot = getServletConfig().getInitParameter(ARANEA_ROOT_INIT_PARAMETER_NAME);
   
    ServletServiceAdapterComponent adapter =
      (ServletServiceAdapterComponent) beanFactory.getBean(araneaRoot);
    return adapter;
  }
 
  protected Map getEnvironmentEntries() {
    Map result = new HashMap();
    result.put(BeanFactory.class, beanFactory);
    result.put(ApplicationContext.class, beanFactory);
    result.put(WebApplicationContext.class, beanFactory);   
    return result;
  }
}
TOP

Related Classes of org.araneaframework.ioc.spring.StandardSpringMainServlet

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.