1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.backsource.amsterdam.service;
21 import org.backsource.jmx.MBeanProxyFactory;
22 import org.backsource.amsterdam.service.filter.ServiceFilter;
23 import org.backsource.amsterdam.service.filter.ServiceFilterSupport;
24 import org.backsource.amsterdam.service.publisher.Publisher;
25 import org.backsource.amsterdam.deployment.DeploymentException;
26 /***
27 * A proxy to an external mbean used when no className is specifyed for a
28 * filter or a publisher and the useBean attribute is set to true.
29 *
30 * Its a little bit clumpsy since it implements both ServiceFilter and Publisher!
31 *
32 * @author <a href="mailto:pra@mogul.com">Peter Antman</a>
33 * @version $Revision: 1.1.1.1 $
34 */
35
36 public class UseBeanProxy extends ServiceFilterSupport implements ServiceFilter,Publisher{
37 Handler handler;
38 public UseBeanProxy (){
39
40 }
41
42 /***
43 * Sets up a proxy with correct interface
44 */
45 protected void setUp(Class inf) throws DeploymentException {
46 try {
47 handler = (Handler)MBeanProxyFactory.create(inf,getObjectName().toString() );
48
49 } catch (Exception e) {
50 throw new DeploymentException("Could not create delegate " + e,e);
51 }
52
53 }
54
55
56 public void setServiceOnDelegate(Service service) {
57 if ( handler == null) {
58 throw new IllegalStateException("Handler is null, could not delegate");
59 }
60 handler.setService(service);
61 }
62
63
64 public void handleMessage(ServiceMessage message) throws ServiceException {
65 if ( handler == null) {
66 throw new ServiceException("Handler is null, could not delegate");
67 }
68 handler.handleMessage(message);
69 }
70
71 public void setNext(ServiceFilter filter) {
72 if ( handler == null) {
73 throw new IllegalStateException("Handler is null, could not delegate");
74 }
75 ((ServiceFilter)handler).setNext(filter);
76 }
77
78 public ServiceFilter getNext() {
79 if ( handler == null) {
80 throw new IllegalStateException("Handler is null, could not delegate");
81 }
82 return ((ServiceFilter)handler).getNext();
83 }
84 }