KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > impl > endpoint > MuleEndpoint


1 /*
2  * $Id: MuleEndpoint.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.impl.endpoint;
12
13 import org.mule.config.i18n.Message;
14 import org.mule.config.i18n.Messages;
15 import org.mule.impl.ImmutableMuleEndpoint;
16 import org.mule.providers.service.ConnectorFactory;
17 import org.mule.umo.UMOException;
18 import org.mule.umo.UMOFilter;
19 import org.mule.umo.UMOTransactionConfig;
20 import org.mule.umo.endpoint.EndpointException;
21 import org.mule.umo.endpoint.UMOEndpoint;
22 import org.mule.umo.endpoint.UMOEndpointURI;
23 import org.mule.umo.endpoint.UMOImmutableEndpoint;
24 import org.mule.umo.lifecycle.InitialisationException;
25 import org.mule.umo.provider.UMOConnector;
26 import org.mule.umo.security.UMOEndpointSecurityFilter;
27 import org.mule.umo.transformer.UMOTransformer;
28
29 import java.util.Map JavaDoc;
30
31 /**
32  * <code>MuleEndpoint</code> describes a Provider in the Mule Server. A endpoint is
33  * a grouping of an endpoint, an endpointUri and a transformer.
34  *
35  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
36  * @version $Revision: 3798 $
37  */

38 public class MuleEndpoint extends ImmutableMuleEndpoint implements UMOEndpoint
39 {
40     /**
41      * Serial version
42      */

43     private static final long serialVersionUID = 2028442057178326047L;
44
45     public static final String JavaDoc ALWAYS_CREATE_STRING = "ALWAYS_CREATE";
46     public static final String JavaDoc NEVER_CREATE_STRING = "NEVER_CREATE";
47
48     /**
49      * Default constructor This is required right now for the Mule digester to set
50      * the properties through the classes mutators
51      */

52     public MuleEndpoint()
53     {
54         super(null, null, null, null, ENDPOINT_TYPE_SENDER_AND_RECEIVER, 0, null, null);
55     }
56
57     public MuleEndpoint(String JavaDoc name,
58                         UMOEndpointURI endpointUri,
59                         UMOConnector connector,
60                         UMOTransformer transformer,
61                         String JavaDoc type,
62                         int createConnector,
63                         String JavaDoc endpointEncoding,
64                         Map JavaDoc props)
65     {
66         super(name, endpointUri, connector, transformer, type, createConnector, endpointEncoding, props);
67     }
68
69     public MuleEndpoint(UMOImmutableEndpoint endpoint)
70     {
71         super(endpoint);
72     }
73
74     public MuleEndpoint(String JavaDoc uri, boolean receiver) throws UMOException
75     {
76         super(uri, receiver);
77     }
78
79     public Object JavaDoc clone()
80     {
81         UMOEndpoint clone = new MuleEndpoint(name, endpointUri, connector, transformer, type,
82             createConnector, endpointEncoding, properties);
83
84         clone.setTransactionConfig(transactionConfig);
85         clone.setFilter(filter);
86         clone.setSecurityFilter(securityFilter);
87
88         if (remoteSync != null)
89         {
90             clone.setRemoteSync(isRemoteSync());
91         }
92         if (remoteSyncTimeout != null)
93         {
94             clone.setRemoteSyncTimeout(getRemoteSyncTimeout());
95         }
96
97         if (synchronous != null)
98         {
99             clone.setSynchronous(synchronous.booleanValue());
100         }
101
102         clone.setDeleteUnacceptedMessages(deleteUnacceptedMessages);
103
104         clone.setInitialState(initialState);
105         if (initialised.get())
106         {
107             try
108             {
109                 clone.initialise();
110             }
111             catch (InitialisationException e)
112             {
113                 // this really should never happen as the endpoint is already
114
// initialised
115
logger.error(e.getMessage(), e);
116             }
117         }
118
119         return clone;
120     }
121
122     /*
123      * (non-Javadoc)
124      *
125      * @see org.mule.umo.endpoint.UMOEndpoint#setEndpointURI(java.lang.String)
126      */

127     public void setEndpointURI(UMOEndpointURI endpointUri) throws EndpointException
128     {
129         if (connector != null && endpointUri != null
130             && !connector.supportsProtocol(endpointUri.getFullScheme()))
131         {
132             throw new IllegalArgumentException JavaDoc(new Message(
133                 Messages.CONNECTOR_SCHEME_X_INCOMPATIBLE_WITH_ENDPOINT_SCHEME_X, connector.getProtocol(),
134                 endpointUri).getMessage());
135         }
136         this.endpointUri = endpointUri;
137         if (endpointUri != null)
138         {
139             properties.putAll(endpointUri.getParams());
140         }
141     }
142
143     public void setEncoding(String JavaDoc endpointEncoding)
144     {
145         this.endpointEncoding = endpointEncoding;
146     }
147
148     /*
149      * (non-Javadoc)
150      *
151      * @see org.mule.umo.endpoint.UMOEndpoint#setType(String)
152      */

153     public void setType(String JavaDoc type)
154     {
155         this.type = type;
156     }
157
158     /*
159      * (non-Javadoc)
160      *
161      * @see org.mule.umo.endpoint.UMOEndpoint#setConnector(org.mule.umo.provider.UMOConnector)
162      */

163     public void setConnector(UMOConnector connector)
164     {
165         if (connector != null && endpointUri != null
166             && !connector.supportsProtocol(endpointUri.getFullScheme()))
167         {
168             throw new IllegalArgumentException JavaDoc(new Message(
169                 Messages.CONNECTOR_SCHEME_X_INCOMPATIBLE_WITH_ENDPOINT_SCHEME_X, connector.getProtocol(),
170                 endpointUri).getMessage());
171         }
172         this.connector = connector;
173     }
174
175     /*
176      * (non-Javadoc)
177      *
178      * @see org.mule.umo.endpoint.UMOEndpoint#setName(java.lang.String)
179      */

180     public void setName(String JavaDoc name)
181     {
182         this.name = name;
183     }
184
185     /*
186      * (non-Javadoc)
187      *
188      * @see org.mule.umo.endpoint.UMOEndpoint#setTransformer(org.mule.umo.transformer.UMOTransformer)
189      */

190     public void setTransformer(UMOTransformer trans)
191     {
192         transformer = trans;
193         if (transformer != null)
194         {
195             transformer.setEndpoint(this);
196         }
197     }
198
199     /*
200      * (non-Javadoc)
201      *
202      * @see org.mule.umo.endpoint.UMOEndpoint#getPropertiesForURI(java.util.Map)
203      */

204     public void setProperties(Map JavaDoc props)
205     {
206         properties.clear();
207         properties.putAll(props);
208     }
209
210     /*
211      * (non-Javadoc)
212      *
213      * @see org.mule.umo.endpoint.UMOEndpoint#isReadOnly()
214      */

215     public boolean isReadOnly()
216     {
217         return false;
218     }
219
220     /*
221      * (non-Javadoc)
222      *
223      * @see org.mule.umo.endpoint.UMOEndpoint#setTransactionConfig(org.mule.umo.UMOTransactionConfig)
224      */

225     public void setTransactionConfig(UMOTransactionConfig config)
226     {
227         transactionConfig = config;
228     }
229
230     public void setFilter(UMOFilter filter)
231     {
232         this.filter = filter;
233     }
234
235     /**
236      * If a filter is configured on this endpoint, this property will determine if
237      * message that are not excepted by the filter are deleted
238      *
239      * @param delete if message should be deleted, false otherwise
240      */

241     public void setDeleteUnacceptedMessages(boolean delete)
242     {
243         deleteUnacceptedMessages = delete;
244     }
245
246     /**
247      * Sets an UMOEndpointSecurityFilter for this endpoint. If a filter is set all
248      * traffice via this endpoint with be subject to authentication.
249      *
250      * @param filter the UMOSecurityFilter responsible for authenticating message
251      * flow via this endpoint.
252      * @see org.mule.umo.security.UMOEndpointSecurityFilter
253      */

254     public void setSecurityFilter(UMOEndpointSecurityFilter filter)
255     {
256         securityFilter = filter;
257         if (securityFilter != null)
258         {
259             securityFilter.setEndpoint(this);
260         }
261     }
262
263     /**
264      * Determines if requests originating from this endpoint should be synchronous
265      * i.e. execute in a single thread and possibly return an result. This property
266      * is only used when the endpoint is of type 'receiver'.
267      *
268      * @param synchronous whether requests on this endpoint should execute in a
269      * single thread. This property is only used when the endpoint is of
270      * type 'receiver'
271      */

272     public void setSynchronous(boolean synchronous)
273     {
274         this.synchronous = Boolean.valueOf(synchronous);
275     }
276
277     public void setCreateConnector(int action)
278     {
279         createConnector = action;
280     }
281
282     public void setCreateConnectorAsString(String JavaDoc action)
283     {
284         if (ALWAYS_CREATE_STRING.equals(action))
285         {
286             createConnector = ConnectorFactory.ALWAYS_CREATE_CONNECTOR;
287         }
288         else if (NEVER_CREATE_STRING.equals(action))
289         {
290             createConnector = ConnectorFactory.NEVER_CREATE_CONNECTOR;
291         }
292         else
293         {
294             createConnector = ConnectorFactory.GET_OR_CREATE_CONNECTOR;
295         }
296     }
297
298     /**
299      * For certain providers that support the notion of a backchannel such as sockets
300      * (outputStream) or Jms (ReplyTo) Mule can automatically wait for a response
301      * from a backchannel when dispatching over these protocols. This is different
302      * for synchronous as synchronous behavior only applies to in
303      *
304      * @param value whether the endpoint should perfrom sync receives
305      */

306     public void setRemoteSync(boolean value)
307     {
308         this.remoteSync = Boolean.valueOf(value);
309         if (value)
310         {
311             this.synchronous = Boolean.TRUE;
312         }
313     }
314
315     /**
316      * The timeout value for remoteSync invocations
317      *
318      * @param timeout the timeout in milliseconds
319      */

320     public void setRemoteSyncTimeout(int timeout)
321     {
322         this.remoteSyncTimeout = new Integer JavaDoc(timeout);
323     }
324
325     /**
326      * Sets the state the endpoint will be loaded in. The States are 'stopped' and
327      * 'started' (default)
328      *
329      * @param state
330      */

331     public void setInitialState(String JavaDoc state)
332     {
333         this.initialState = state;
334     }
335
336     public void setResponseTransformer(UMOTransformer trans)
337     {
338         responseTransformer = trans;
339     }
340
341     /**
342      * Determines whether the endpoint should deal with requests as streams
343      *
344      * @param stream true if the request should be streamed
345      */

346     public void setStreaming(boolean stream)
347     {
348         this.streaming = stream;
349     }
350
351     /**
352      * Sets a property on the endpoint
353      *
354      * @param key the property key
355      * @param value the value of the property
356      */

357     public void setProperty(String JavaDoc key, Object JavaDoc value)
358     {
359         properties.put(key, value);
360     }
361 }
362
Popular Tags