View Javadoc

1   /*
2    * Copyright (c) 2004 Peter Antman, Mogul  <peter.antman@mogul.com>
3    *
4    * $Id: UseBeanProxy.java,v 1.1.1.1 2004/05/19 12:22:46 pra Exp $
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 2 of the License, or (at your option) any later version
10   * 
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Lesser General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with this library; if not, write to the Free Software
18   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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        } // end of try-catch
52        
53     }
54  
55     // Should we delegate serService to?
56     public void setServiceOnDelegate(Service service)  {
57        if ( handler == null) {
58           throw new IllegalStateException("Handler is null, could not delegate");
59        } // end of if ()
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        } // end of if ()
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        } // end of if ()
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        } // end of if ()
82        return ((ServiceFilter)handler).getNext();
83     }
84  }// UseBeanProxy