KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > jbi > components > AbstractEndpointComponent


1 /*
2  * $Id: AbstractEndpointComponent.java 3798 2006-11-04 04:07:14Z aperepel $
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 MuleSource MPL
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 javax.jbi.JBIException;
19
20 import java.util.Map JavaDoc;
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  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
27  * @version $Revision: 3798 $
28  */

29 public abstract class AbstractEndpointComponent extends AbstractJbiComponent
30 {
31
32     protected UMOEndpoint muleEndpoint;
33
34     protected String JavaDoc endpoint;
35
36     protected Map JavaDoc endpointProperties;
37
38     protected AbstractEndpointComponent()
39     {
40         if (!MuleManager.isInstanciated())
41         {
42             MuleManager.getConfiguration().setEmbedded(true);
43             try
44             {
45                 MuleManager.getInstance().start();
46             }
47             catch (UMOException e)
48             {
49                 e.printStackTrace();
50             }
51         }
52     }
53
54     public UMOEndpoint getMuleEndpoint()
55     {
56         return muleEndpoint;
57     }
58
59     public void setMuleEndpoint(UMOEndpoint muleEndpoint)
60     {
61         this.muleEndpoint = muleEndpoint;
62     }
63
64     public String JavaDoc getEndpoint()
65     {
66         return endpoint;
67     }
68
69     public void setEndpoint(String JavaDoc endpoint)
70     {
71         this.endpoint = endpoint;
72     }
73
74     public Map JavaDoc getEndpointProperties()
75     {
76         return endpointProperties;
77     }
78
79     public void setEndpointProperties(Map JavaDoc endpointProperties)
80     {
81         this.endpointProperties = endpointProperties;
82     }
83
84     protected void doInit() throws JBIException
85     {
86         try
87         {
88             if (muleEndpoint == null)
89             {
90                 if (endpoint == null)
91                 {
92                     throw new NullPointerException JavaDoc("A Mule muleEndpoint must be set on this component");
93                 }
94                 else
95                 {
96                     muleEndpoint = new MuleEndpoint(endpoint, true);
97                 }
98             }
99
100             if (endpointProperties != null)
101             {
102                 muleEndpoint.getProperties().putAll(endpointProperties);
103             }
104             muleEndpoint.initialise();
105
106         }
107         catch (Exception JavaDoc e)
108         {
109             throw new JBIException(e);
110         }
111     }
112 }
113
Popular Tags