KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > remoting > jaxrpc > ServletEndpointSupport


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.remoting.jaxrpc;
18
19 import java.io.File JavaDoc;
20
21 import javax.servlet.ServletContext JavaDoc;
22 import javax.xml.rpc.ServiceException JavaDoc;
23 import javax.xml.rpc.server.ServiceLifecycle JavaDoc;
24 import javax.xml.rpc.server.ServletEndpointContext JavaDoc;
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 /**
36  * Convenience base class for JAX-RPC servlet endpoint implementations.
37  * Provides a reference to the current Spring application context,
38  * e.g. for bean lookup or resource loading.
39  *
40  * <p>The Web Service servlet needs to run in the same web application
41  * as the Spring context to allow for access to Spring's facilities.
42  * In case of Axis, copy the AxisServlet definition into your web.xml,
43  * and set up the endpoint in "server-config.wsdd" (or use the deploy tool).
44  *
45  * <p>This class does not extend WebApplicationContextSupport to not expose
46  * any public setters. For some reason, Axis tries to resolve public setters
47  * in a special way...
48  *
49  * <p>JAX-RPC service endpoints are usually required to implement an
50  * RMI port interface. However, many JAX-RPC implementations accept plain
51  * service endpoint classes too, avoiding the need to maintain an RMI port
52  * interface in addition to an existing non-RMI business interface.
53  * Therefore, implementing the business interface will usually be sufficient.
54  *
55  * @author Juergen Hoeller
56  * @since 16.12.2003
57  * @see #init
58  * @see #getWebApplicationContext
59  * @see org.springframework.web.context.support.WebApplicationObjectSupport
60  */

61 public abstract class ServletEndpointSupport implements ServiceLifecycle JavaDoc {
62
63     protected final Log logger = LogFactory.getLog(getClass());
64     
65     private ServletEndpointContext JavaDoc servletEndpointContext;
66
67     private WebApplicationContext webApplicationContext;
68
69     private MessageSourceAccessor messageSourceAccessor;
70
71
72     /**
73      * Initialize this JAX-RPC servlet endpoint.
74      * Calls onInit after successful context initialization.
75      * @param context ServletEndpointContext
76      * @throws ServiceException if the context is not a ServletEndpointContext
77      * @see #onInit
78      */

79     public final void init(Object JavaDoc context) throws ServiceException JavaDoc {
80         if (!(context instanceof ServletEndpointContext JavaDoc)) {
81             throw new ServiceException JavaDoc("ServletEndpointSupport needs ServletEndpointContext, not [" + context + "]");
82         }
83         this.servletEndpointContext = (ServletEndpointContext JavaDoc) context;
84         ServletContext JavaDoc servletContext = this.servletEndpointContext.getServletContext();
85         this.webApplicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
86         this.messageSourceAccessor = new MessageSourceAccessor(this.webApplicationContext);
87         onInit();
88     }
89
90     /**
91      * Return the current JAX-RPC ServletEndpointContext.
92      */

93     protected final ServletEndpointContext JavaDoc getServletEndpointContext() {
94         return servletEndpointContext;
95     }
96
97     /**
98      * Return the current Spring ApplicationContext.
99      */

100     protected final ApplicationContext getApplicationContext() {
101         return this.webApplicationContext;
102     }
103
104     /**
105      * Return the current Spring WebApplicationContext.
106      */

107     protected final WebApplicationContext getWebApplicationContext() {
108         return this.webApplicationContext;
109     }
110
111     /**
112      * Return a MessageSourceAccessor for the application context
113      * used by this object, for easy message access.
114      */

115     protected final MessageSourceAccessor getMessageSourceAccessor() {
116         return this.messageSourceAccessor;
117     }
118
119     /**
120      * Return the current ServletContext.
121      */

122     protected final ServletContext JavaDoc getServletContext() {
123         return this.webApplicationContext.getServletContext();
124     }
125
126     /**
127      * Return the temporary directory for the current web application,
128      * as provided by the servlet container.
129      * @return the File representing the temporary directory
130      */

131     protected final File JavaDoc getTempDir() {
132         return WebUtils.getTempDir(getServletContext());
133     }
134
135     /**
136      * Callback for custom initialization after the context has been set up.
137      * @throws ServiceException if initialization failed
138      */

139     protected void onInit() throws ServiceException JavaDoc {
140     }
141
142
143     /**
144      * This implementation of destroy is empty.
145      * Can be overridden in subclasses.
146      */

147     public void destroy() {
148     }
149
150 }
151
Popular Tags