1 16 17 package org.springframework.web.context.support; 18 19 import javax.servlet.ServletContext ; 20 21 import org.springframework.beans.factory.FactoryBean; 22 import org.springframework.web.context.ServletContextAware; 23 24 34 public class ServletContextParameterFactoryBean implements FactoryBean, ServletContextAware { 35 36 private String initParamName; 37 38 private String paramValue; 39 40 41 44 public void setInitParamName(String initParamName) { 45 this.initParamName = initParamName; 46 } 47 48 public void setServletContext(ServletContext servletContext) { 49 if (this.initParamName == null) { 50 throw new IllegalArgumentException ("initParamName is required"); 51 } 52 this.paramValue = servletContext.getInitParameter(this.initParamName); 53 if (this.paramValue == null) { 54 throw new IllegalStateException ("No ServletContext init parameter '" + this.initParamName + "' found"); 55 } 56 } 57 58 59 public Object getObject() throws Exception { 60 return this.paramValue; 61 } 62 63 public Class getObjectType() { 64 return String .class; 65 } 66 67 public boolean isSingleton() { 68 return true; 69 } 70 71 } 72 | Popular Tags |