View Javadoc

1   /*
2    * $Id: AbstractEndpointComponent.java 7963 2007-08-21 08:53:15Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.providers.jbi.components;
12  
13  import org.mule.MuleManager;
14  import org.mule.impl.endpoint.MuleEndpoint;
15  import org.mule.umo.UMOException;
16  import org.mule.umo.endpoint.UMOEndpoint;
17  
18  import java.util.Map;
19  
20  import javax.jbi.JBIException;
21  
22  /**
23   * A Jbi component that has a Mule muleEndpoint component configured on it. Both the
24   * Dispatcher and Receiver components extend this component.
25   */
26  public abstract class AbstractEndpointComponent extends AbstractJbiComponent
27  {
28  
29      protected UMOEndpoint muleEndpoint;
30  
31      protected String endpoint;
32  
33      protected Map endpointProperties;
34  
35      protected AbstractEndpointComponent()
36      {
37          if (!MuleManager.isInstanciated())
38          {
39              MuleManager.getConfiguration().setEmbedded(true);
40              try
41              {
42                  MuleManager.getInstance().start();
43              }
44              catch (UMOException e)
45              {
46                  e.printStackTrace();
47              }
48          }
49      }
50  
51      public UMOEndpoint getMuleEndpoint()
52      {
53          return muleEndpoint;
54      }
55  
56      public void setMuleEndpoint(UMOEndpoint muleEndpoint)
57      {
58          this.muleEndpoint = muleEndpoint;
59      }
60  
61      public String getEndpoint()
62      {
63          return endpoint;
64      }
65  
66      public void setEndpoint(String endpoint)
67      {
68          this.endpoint = endpoint;
69      }
70  
71      public Map getEndpointProperties()
72      {
73          return endpointProperties;
74      }
75  
76      public void setEndpointProperties(Map endpointProperties)
77      {
78          this.endpointProperties = endpointProperties;
79      }
80  
81      protected void doInit() throws JBIException
82      {
83          try
84          {
85              if (muleEndpoint == null)
86              {
87                  if (endpoint == null)
88                  {
89                      throw new IllegalArgumentException("A Mule muleEndpoint must be set on this component");
90                  }
91                  else
92                  {
93                      muleEndpoint = new MuleEndpoint(endpoint, true);
94                  }
95              }
96  
97              if (endpointProperties != null)
98              {
99                  muleEndpoint.getProperties().putAll(endpointProperties);
100             }
101             muleEndpoint.initialise();
102 
103         }
104         catch (Exception e)
105         {
106             throw new JBIException(e);
107         }
108     }
109 }