01: /******************************************************************************
02: * JBoss, a division of Red Hat *
03: * Copyright 2006, Red Hat Middleware, LLC, and individual *
04: * contributors as indicated by the @authors tag. See the *
05: * copyright.txt in the distribution for a full listing of *
06: * individual contributors. *
07: * *
08: * This is free software; you can redistribute it and/or modify it *
09: * under the terms of the GNU Lesser General Public License as *
10: * published by the Free Software Foundation; either version 2.1 of *
11: * the License, or (at your option) any later version. *
12: * *
13: * This software is distributed in the hope that it will be useful, *
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16: * Lesser General Public License for more details. *
17: * *
18: * You should have received a copy of the GNU Lesser General Public *
19: * License along with this software; if not, write to the Free *
20: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
21: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
22: ******************************************************************************/package org.jboss.portal.wsrp.services;
23:
24: import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
25:
26: import javax.xml.rpc.Service;
27: import java.util.Map;
28:
29: /**
30: * Perform common logic to soap based service factories. This one cache the service retrieved from the JNDI lookup.
31: *
32: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
33: * @version $Revision: 8784 $
34: */
35: public abstract class AbstractSOAPServiceFactory extends
36: AbstractJNDIServiceFactory {
37:
38: /** Cache the services. */
39: private Map services = new ConcurrentReaderHashMap();
40:
41: protected void createService() throws Exception {
42: super .createService();
43: }
44:
45: protected void destroyService() throws Exception {
46: services = null;
47:
48: //
49: super .destroyService();
50: }
51:
52: /**
53: * Retrieve the stub from the service. The stub is not thread safe and must be customized for each thead.
54: *
55: * @param serviceClass the requested service class
56: * @param service the service implementation obtained from the JNDI lookup
57: * @return an implementation based on the provided service
58: * @throws Exception
59: */
60: protected abstract Object getStubFromService(Class serviceClass,
61: Service service) throws Exception;
62:
63: public Object getService(Class serviceClass) throws Exception {
64: if (serviceClass == null) {
65: throw new IllegalArgumentException(
66: "Null class not accepted to perform lookup");
67: }
68:
69: //
70: String key = serviceClass.getName();
71:
72: // Get the cached service, it's ok because they are thread safe
73: Service service = (Service) services.get(key);
74: if (service == null) {
75: service = (Service) super .getService(serviceClass);
76:
77: //
78: if (service != null) {
79: services.put(key, service);
80: }
81: }
82:
83: // Get the stub from the service, remember that the stub itself is not threadsafe
84: // and must be customized for every request to this method.
85: if (service != null) {
86: return getStubFromService(serviceClass, service);
87: } else {
88: return null;
89: }
90: }
91: }
|