KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > webservice > axis > SpringBeanRPCProvider


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.webservice.axis;
18
19 import org.alfresco.repo.webservice.Utils;
20 import org.apache.axis.AxisFault;
21 import org.apache.axis.MessageContext;
22 import org.apache.axis.handlers.soap.SOAPService;
23 import org.apache.axis.providers.java.RPCProvider;
24 import org.springframework.web.context.WebApplicationContext;
25
26 /**
27  * A custom Axis RPC Provider that retrieves services via Spring
28  *
29  * @author gavinc
30  */

31 public class SpringBeanRPCProvider extends RPCProvider
32 {
33    private static final long serialVersionUID = 2173234269124176995L;
34    private static final String JavaDoc OPTION_NAME = "springBean";
35    private WebApplicationContext webAppCtx;
36
37    /**
38     * Retrieves the class of the bean represented by the given name
39     *
40     * @see org.apache.axis.providers.java.JavaProvider#getServiceClass(java.lang.String, org.apache.axis.handlers.soap.SOAPService, org.apache.axis.MessageContext)
41     */

42    @Override JavaDoc
43    protected Class JavaDoc getServiceClass(String JavaDoc beanName, SOAPService service, MessageContext msgCtx) throws AxisFault
44    {
45       Class JavaDoc clazz = null;
46       
47       Object JavaDoc bean = getBean(msgCtx, beanName);
48       if (bean != null)
49       {
50          clazz = bean.getClass();
51       }
52       
53       return clazz;
54    }
55
56    /**
57     * @see org.apache.axis.providers.java.JavaProvider#getServiceClassNameOptionName()
58     */

59    @Override JavaDoc
60    protected String JavaDoc getServiceClassNameOptionName()
61    {
62       return OPTION_NAME;
63    }
64
65    /**
66     * Retrieves the bean with the given name from the current spring context
67     *
68     * @see org.apache.axis.providers.java.JavaProvider#makeNewServiceObject(org.apache.axis.MessageContext, java.lang.String)
69     */

70    @Override JavaDoc
71    protected Object JavaDoc makeNewServiceObject(MessageContext msgCtx, String JavaDoc beanName) throws Exception JavaDoc
72    {
73       return getBean(msgCtx, beanName);
74    }
75    
76    /**
77     * Retrieves the bean with the given name from the current spring context
78     *
79     * @param msgCtx Axis MessageContext
80     * @param beanName Name of the bean to lookup
81     * @return The instance of the bean
82     */

83    private Object JavaDoc getBean(MessageContext msgCtx, String JavaDoc beanName) throws AxisFault
84    {
85       return getWebAppContext(msgCtx).getBean(beanName);
86    }
87    
88    /**
89     * Retrieves the Spring context from the web application
90     *
91     * @param msgCtx Axis MessageContext
92     * @return The Spring web app context
93     */

94    private WebApplicationContext getWebAppContext(MessageContext msgCtx) throws AxisFault
95    {
96       if (this.webAppCtx == null && msgCtx != null)
97       {
98          this.webAppCtx = Utils.getSpringContext(msgCtx);
99       }
100       
101       if (this.webAppCtx == null)
102       {
103          throw new AxisFault("Failed to retrieve the Spring web application context");
104       }
105       
106       return this.webAppCtx;
107    }
108 }
109
Popular Tags