View Javadoc

1   /*
2    * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3    * the spring framework, http://el4j.sf.net
4    * Copyright (C) 2005 by ELCA Informatique SA, Av. de la Harpe 22-24,
5    * 1000 Lausanne, Switzerland, http://www.elca.ch
6    *
7    * EL4J is published under the GNU Lesser General Public License (LGPL)
8    * Version 2.1. See http://www.gnu.org/licenses/
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   * GNU Lesser General Public License for more details.
14   *
15   * For alternative licensing, please contact info@elca.ch
16   */
17  
18  package ch.elca.el4j.services.remoting.protocol;
19  
20  import java.util.HashMap;
21  import java.util.Map;
22  
23  import org.springframework.util.StringUtils;
24  
25  import ch.elca.el4j.services.monitoring.notification.CoreNotificationHelper;
26  import ch.elca.el4j.services.remoting.AbstractRemotingProtocol;
27  import ch.elca.el4j.services.remoting.RemotingProxyFactoryBean;
28  import ch.elca.el4j.services.remoting.RemotingServiceExporter;
29  
30  /**
31   * Empty protocol to simulate protocols. Just the implicit context passing will
32   * be enabled. Client and server must be in same JVM.
33   *
34   * @svnLink $Revision: 3883 $;$Date: 2009-08-04 15:35:01 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/remoting_core/src/main/java/ch/elca/el4j/services/remoting/protocol/RemotingDisabled.java $
35   *
36   * @author Martin Zeltner (MZE)
37   */
38  public class RemotingDisabled extends AbstractRemotingProtocol {
39  
40  	/**
41  	 * Map to cache service objects.
42  	 */
43  	private Map m_serviceObjects = new HashMap();
44  
45  	/**
46  	 * {@inheritDoc}
47  	 */
48  	public Object createProxyBean(RemotingProxyFactoryBean proxyBean,
49  			Class serviceInterfaceWithContext) {
50  		
51  		Object result = null;
52  		
53  		String serviceName = proxyBean.getServiceName();
54  		if (StringUtils.hasText(serviceName)) {
55  			Object serviceObject = m_serviceObjects.get(serviceName);
56  			if (serviceObject == null) {
57  				CoreNotificationHelper.notifyMisconfiguration(
58  						"There is no service for service name '" + serviceName
59  								+ "'. Be sure that server side is started "
60  								+ "before client side.");
61  			} else {
62  				result = serviceObject;
63  			}
64  		} else {
65  			CoreNotificationHelper.notifyMisconfiguration(
66  					"Service name can not be null or empty!");
67  		}
68  		
69  		return result;
70  	}
71  
72  	/**
73  	 * {@inheritDoc}
74  	 */
75  	public Object createExporterBean(RemotingServiceExporter exporterBean,
76  			Class serviceInterfaceWithContext, Object serviceProxy) {
77  		String serviceName = exporterBean.getServiceName();
78  		if (StringUtils.hasText(serviceName)) {
79  			m_serviceObjects.put(serviceName, serviceProxy);
80  		} else {
81  			CoreNotificationHelper.notifyMisconfiguration(
82  					"Service name can not be null or empty!");
83  		}
84  		return serviceProxy;
85  	}
86  
87  	/**
88  	 * {@inheritDoc}
89  	 */
90  	public Class getProxyObjectType() {
91  		return Object.class;
92  	}
93  
94  	/**
95  	 * {@inheritDoc}
96  	 */
97  	public Class getExporterObjectType() {
98  		return Object.class;
99  	}
100 
101 	/**
102 	 * {@inheritDoc}
103 	 */
104 	public void afterPropertiesSet() throws Exception {
105 		// No properties exits for this protocol.
106 	}
107 }