1 16 17 package org.springframework.remoting.jaxrpc; 18 19 import java.io.File ; 20 21 import javax.servlet.ServletContext ; 22 import javax.xml.rpc.ServiceException ; 23 import javax.xml.rpc.server.ServiceLifecycle ; 24 import javax.xml.rpc.server.ServletEndpointContext ; 25 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 29 import org.springframework.context.ApplicationContext; 30 import org.springframework.context.support.MessageSourceAccessor; 31 import org.springframework.web.context.WebApplicationContext; 32 import org.springframework.web.context.support.WebApplicationContextUtils; 33 import org.springframework.web.util.WebUtils; 34 35 61 public abstract class ServletEndpointSupport implements ServiceLifecycle { 62 63 protected final Log logger = LogFactory.getLog(getClass()); 64 65 private ServletEndpointContext servletEndpointContext; 66 67 private WebApplicationContext webApplicationContext; 68 69 private MessageSourceAccessor messageSourceAccessor; 70 71 72 79 public final void init(Object context) throws ServiceException { 80 if (!(context instanceof ServletEndpointContext )) { 81 throw new ServiceException ("ServletEndpointSupport needs ServletEndpointContext, not [" + context + "]"); 82 } 83 this.servletEndpointContext = (ServletEndpointContext ) context; 84 ServletContext servletContext = this.servletEndpointContext.getServletContext(); 85 this.webApplicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); 86 this.messageSourceAccessor = new MessageSourceAccessor(this.webApplicationContext); 87 onInit(); 88 } 89 90 93 protected final ServletEndpointContext getServletEndpointContext() { 94 return servletEndpointContext; 95 } 96 97 100 protected final ApplicationContext getApplicationContext() { 101 return this.webApplicationContext; 102 } 103 104 107 protected final WebApplicationContext getWebApplicationContext() { 108 return this.webApplicationContext; 109 } 110 111 115 protected final MessageSourceAccessor getMessageSourceAccessor() { 116 return this.messageSourceAccessor; 117 } 118 119 122 protected final ServletContext getServletContext() { 123 return this.webApplicationContext.getServletContext(); 124 } 125 126 131 protected final File getTempDir() { 132 return WebUtils.getTempDir(getServletContext()); 133 } 134 135 139 protected void onInit() throws ServiceException { 140 } 141 142 143 147 public void destroy() { 148 } 149 150 } 151 | Popular Tags |