View Javadoc

1   /*******************************************************************************
2    *  Copyright (c) 2005, 2006, 2007 Imola Informatica.
3    *  All rights reserved. This program and the accompanying materials
4    *  are made available under the terms of the LGPL License v2.1
5    *  which accompanies this distribution, and is available at
6    *  http://www.gnu.org/licenses/lgpl.html
7    *******************************************************************************/
8   package it.imolinfo.jbi4ejb.jbi.component;
9   
10  import it.imolinfo.jbi4ejb.Logger;
11  import it.imolinfo.jbi4ejb.LoggerFactory;
12  import it.imolinfo.jbi4ejb.exception.EJBWSDLGenerationException;
13  import it.imolinfo.jbi4ejb.jbi.Messages;
14  import it.imolinfo.jbi4ejb.jbi.component.runtime.AbstractComponentLifeCycle;
15  import it.imolinfo.jbi4ejb.jbi.component.runtime.ComponentRuntime;
16  import it.imolinfo.jbi4ejb.jbi.component.runtime.MessageExchangeReceiver;
17  import it.imolinfo.jbi4ejb.jbi.component.runtime.RuntimeContext;
18  import it.imolinfo.jbi4ejb.jbi.xfire.EjbTransport;
19  
20  import javax.jbi.JBIException;
21  import javax.management.ObjectName;
22  import javax.management.StandardMBean;
23  
24  import org.codehaus.xfire.DefaultXFire;
25  import org.codehaus.xfire.XFire;
26  import org.codehaus.xfire.transport.Transport;
27  
28  /**
29   * Jbi4Ejb <code>ComponentLifeCycle</code> implementation. 
30   * 
31   * @author <a href="mailto:mpiraccini@imolinfo.it">Marco Piraccini</a>
32   */
33  public class Jbi4EjbLifeCycle extends AbstractComponentLifeCycle {
34      
35      /** The logger. */
36      private static final Logger LOG = LoggerFactory.getLogger(Jbi4EjbLifeCycle.class);    
37      private static final Messages MESSAGES = Messages.getMessages(Jbi4EjbLifeCycle.class);
38      
39      /** xfire. */
40      private XFire xfire;
41          
42      /**
43       * Instantiates a new jbi4 ejb life cycle.
44       * 
45       * @param compRuntime the component runtime
46       */
47      public Jbi4EjbLifeCycle(ComponentRuntime compRuntime) {
48          super(compRuntime);                        
49      }       
50      
51      /**
52       * chance to extended classes to do the component specific init.
53       * @throws javax.jbi.JBIException if some problem occurs
54       */
55      protected void onInit() throws JBIException {        
56          xfire = createXFire();
57      }
58      
59      /**
60       * Init the Message Exchange Handler factory.
61       * @throws JBIException if some problem occurs
62       * @see it.imolinfo.jbi4ejb.jbi.component.runtime.AbstractComponentLifeCycle#initMessageExchangeHandlerFactory()
63       */
64      protected void initMessageExchangeHandlerFactory() throws JBIException {
65                  
66          if (! ( this.getComponentRuntime().getServiceUnitManager() instanceof Jbi4EjbSUManager)) {
67          	String msg=MESSAGES.getString("EJB000101_Service_Unit_Manager_wrong_type");
68              LOG.error(msg);
69              throw new JBIException(msg);
70          }
71          Jbi4EjbSUManager suManager = (Jbi4EjbSUManager)this.getComponentRuntime().getServiceUnitManager();
72          RuntimeContext.getInstance().setMessageExchangeHandlerFactory(                
73                  new Jbi4EjbMessageExchangeHandlerFactory(suManager));
74      }
75      
76      /**
77       * Create the message exchange receiver.
78       * @see it.imolinfo.jbi4ejb.jbi.component.runtime.AbstractComponentLifeCycle#createMessageExchangeReceiver()
79       * @see it.imolinfo.jbi4ejb.jbi.component.runtime.MessageExchangeReceiver
80       * @throws Exception if some problem occurs
81       * @return the <code>MessageExchangeReceiver</code>
82       */
83      protected MessageExchangeReceiver createMessageExchangeReceiver() throws Exception {
84          // JMXBinding component sample only provides synchornous isnbound message exchange.
85          // so no need to have the message receiver to get the message exchanges from delivery channel.
86          // return null;
87          return new MessageExchangeReceiver();
88      }
89          
90      /**
91       * Do nothing.
92       * @throws JBIException if some problem occurs
93       *  @see it.imolinfo.jbi4ejb.jbi.component.runtime.AbstractComponentLifeCycle#activateServiceConsumers()
94       */
95      protected void activateServiceConsumers() throws JBIException {       
96          // DO nothing: no consumer for this component
97      }
98          
99      /**
100      * Do nothing.
101      * @throws JBIException if some problem occurs
102      * @see it.imolinfo.jbi4ejb.jbi.component.runtime.AbstractComponentLifeCycle#deactivateServiceConsumers()
103      */
104     protected void deactivateServiceConsumers() throws JBIException {
105         // DO nothing: no consumer for this component
106     }
107     
108     /**
109      * Do nothing.
110      * @throws JBIException if some problem occurs
111      * @see it.imolinfo.jbi4ejb.jbi.component.runtime.AbstractComponentLifeCycle#activateServiceProviders()
112      */    
113     protected void activateServiceProviders() throws JBIException {        
114         // Do nothing
115     }
116     
117     /**
118     * Do nothing.
119     * @throws JBIException if some problem occurs
120     * @see it.imolinfo.jbi4ejb.jbi.component.runtime.AbstractComponentLifeCycle#deactivateServiceProviders()
121     */        
122     protected void deactivateServiceProviders() throws JBIException {
123         // Do nothing
124     }
125     
126     /**
127      * no extension mbean.
128      * 
129      * @return alway null
130      */
131     protected ObjectName createExtensionMBeanName() {
132         return null;
133     }
134     
135     /**
136      * no extension mbean.
137      * 
138      * @return always null
139      */
140     protected StandardMBean createExtensionMBean() {
141         return null;
142     }
143 
144     /**
145      * Gets xfire.
146      * 
147      * @return the xfire
148      */
149     public XFire getXfire() {
150         return xfire;
151     }
152     
153     /**
154      * Creates XFire.
155      * @return xfire, correctly configured
156      */
157     private static XFire createXFire() {
158         XFire xfire = new DefaultXFire();
159         Object[] transports = xfire.getTransportManager().getTransports().toArray();
160         for (int i = 0; i < transports.length; i++) {
161           xfire.getTransportManager().unregister((Transport) transports[i]);
162         }
163         xfire.getTransportManager().register(new EjbTransport());        
164         return xfire;
165     }      
166     
167 }