KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > impl > MuleDescriptor


1 /*
2  * $Id: MuleDescriptor.java 3937 2006-11-20 16:04:25Z lajos $
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;
12
13 import org.apache.commons.logging.Log;
14 import org.apache.commons.logging.LogFactory;
15 import org.mule.MuleException;
16 import org.mule.util.FileUtils;
17 import org.mule.config.MuleConfiguration;
18 import org.mule.config.PoolingProfile;
19 import org.mule.config.QueueProfile;
20 import org.mule.config.ThreadingProfile;
21 import org.mule.impl.container.DescriptorContainerKeyPair;
22 import org.mule.umo.UMODescriptor;
23 import org.mule.umo.UMOInterceptor;
24 import org.mule.umo.endpoint.UMOEndpoint;
25 import org.mule.umo.routing.UMOInboundMessageRouter;
26 import org.mule.umo.routing.UMOOutboundMessageRouter;
27 import org.mule.umo.routing.UMOResponseMessageRouter;
28 import org.mule.umo.transformer.UMOTransformer;
29
30 import java.beans.ExceptionListener JavaDoc;
31 import java.io.FileInputStream JavaDoc;
32 import java.util.List JavaDoc;
33 import java.util.Map JavaDoc;
34 import java.util.Properties JavaDoc;
35
36 /**
37  * <code>MuleDescriptor</code> describes all the properties for a Mule UMO. New
38  * Mule UMOs can be initialised as needed from their descriptor.
39  *
40  */

41
42 public class MuleDescriptor extends ImmutableMuleDescriptor implements UMODescriptor
43 {
44     public static final String JavaDoc DEFAULT_INSTANCE_REF_NAME = "_instanceRef";
45     /**
46      * logger used by this class
47      */

48     private static Log logger = LogFactory.getLog(MuleDescriptor.class);
49
50     public MuleDescriptor(String JavaDoc name)
51     {
52         super();
53         this.name = name;
54     }
55
56     public MuleDescriptor(MuleDescriptor descriptor)
57     {
58         super(descriptor);
59     }
60
61     /**
62      * Default constructor. Initalises common properties for the MuleConfiguration
63      * object
64      *
65      * @see MuleConfiguration
66      */

67     public MuleDescriptor()
68     {
69         super();
70     }
71
72     public void setThreadingProfile(ThreadingProfile threadingProfile)
73     {
74         this.threadingProfile = threadingProfile;
75     }
76
77     /*
78      * (non-Javadoc)
79      *
80      * @see org.mule.umo.UMODescriptor#setExceptionListener(org.mule.umo.UMOExceptionStrategy)
81      */

82     public void setExceptionListener(ExceptionListener JavaDoc listener)
83     {
84         if (listener == null)
85         {
86             throw new IllegalArgumentException JavaDoc("Exception Strategy cannot be null");
87         }
88         this.exceptionListener = listener;
89         logger.debug("Using exception strategy: " + listener.getClass().getName());
90     }
91
92     /*
93      * (non-Javadoc)
94      *
95      * @see org.mule.umo.UMODescriptor#setName(java.lang.String)
96      */

97     public void setName(String JavaDoc newName)
98     {
99         if (newName == null)
100         {
101             throw new IllegalArgumentException JavaDoc("Name cannot be null");
102         }
103         name = newName;
104     }
105
106     /*
107      * (non-Javadoc)
108      *
109      * @see org.mule.transformers.HasTransformer#setOutboundTransformer(org.mule.umo.transformer.UMOTransformer)
110      */

111     public void setOutboundTransformer(UMOTransformer transformer)
112     {
113         outboundTransformer = transformer;
114     }
115
116     /*
117      * (non-Javadoc)
118      *
119      * @see org.mule.umo.UMODescriptor#setResponseTransformer(UMOTransformer)
120      */

121     public void setResponseTransformer(UMOTransformer transformer)
122     {
123         responseTransformer = transformer;
124     }
125
126     /*
127      * (non-Javadoc)
128      *
129      * @see org.mule.umo.UMODescriptor#getPropertiesForURI(java.util.Properties)
130      */

131     public void setProperties(Map JavaDoc props)
132     {
133         properties = props;
134         String JavaDoc delegate = (String JavaDoc)properties.get(MULE_PROPERTY_DOT_PROPERTIES);
135         if (delegate != null)
136         {
137             try
138             {
139                 FileInputStream JavaDoc is = new FileInputStream JavaDoc(FileUtils.newFile(delegate));
140                 Properties JavaDoc dProps = new Properties JavaDoc();
141                 dProps.load(is);
142                 properties.putAll(dProps);
143             }
144             catch (Exception JavaDoc e)
145             {
146                 logger.warn(MULE_PROPERTY_DOT_PROPERTIES + " was set to " + delegate
147                             + " but the file could not be read, exception is: " + e.getMessage());
148             }
149         }
150     }
151
152     /*
153      * (non-Javadoc)
154      *
155      * @see org.mule.umo.UMODescriptor#setVersion(long)
156      */

157     public void setVersion(String JavaDoc ver)
158     {
159         version = ver;
160     }
161
162     /*
163      * (non-Javadoc)
164      *
165      * @see org.mule.umo.UMODescriptor#setInboundEndpoint(org.mule.impl.UMOEndpoint)
166      */

167     public void setInboundEndpoint(UMOEndpoint endpoint) throws MuleException
168     {
169         inboundEndpoint = endpoint;
170         if (inboundEndpoint != null)
171         {
172             inboundEndpoint.setType(UMOEndpoint.ENDPOINT_TYPE_RECEIVER);
173             if (inboundEndpoint.getTransformer() != null)
174             {
175                 inboundTransformer = inboundEndpoint.getTransformer();
176             }
177         }
178     }
179
180     /*
181      * (non-Javadoc)
182      *
183      * @see org.mule.umo.UMODescriptor#setOutboundEndpoint(org.mule.impl.UMO
184      * ProviderDescriptor)
185      */

186     public void setOutboundEndpoint(UMOEndpoint endpoint) throws MuleException
187     {
188         outboundEndpoint = endpoint;
189         if (outboundEndpoint != null)
190         {
191             outboundEndpoint.setType(UMOEndpoint.ENDPOINT_TYPE_SENDER);
192             if (outboundEndpoint.getTransformer() != null)
193             {
194                 outboundTransformer = outboundEndpoint.getTransformer();
195             }
196         }
197
198     }
199
200     /*
201      * (non-Javadoc)
202      *
203      * @see org.mule.transformers.HasTransformer#setInboundTransformer(org.mule.umo.transformer.UMOTransformer)
204      */

205     public void setInboundTransformer(UMOTransformer transformer)
206     {
207         inboundTransformer = transformer;
208     }
209
210     /*
211      * (non-Javadoc)
212      *
213      * @see org.mule.umo.UMODescriptor#addinteceptor(org.mule.umo.UMOInterceptor)
214      */

215     public void addInterceptor(UMOInterceptor inteceptor)
216     {
217         if (inteceptor != null)
218         {
219             intecerptorList.add(inteceptor);
220         }
221     }
222
223     public void setInterceptors(List JavaDoc inteceptorList)
224     {
225         this.intecerptorList = inteceptorList;
226     }
227
228     /*
229      * (non-Javadoc)
230      *
231      * @see org.mule.umo.UMODescriptor#setPoolingProfile(UMOPoolingProfile)
232      */

233     public void setPoolingProfile(PoolingProfile poolingProfile)
234     {
235         this.poolingProfile = poolingProfile;
236     }
237
238     public void setQueueProfile(QueueProfile queueProfile)
239     {
240         this.queueProfile = queueProfile;
241     }
242
243     /*
244      * (non-Javadoc)
245      *
246      * @see org.mule.umo.UMODescriptor#setImplementation(java.lang.String)
247      */

248     public void setImplementation(Object JavaDoc reference)
249     {
250         if (reference == null)
251         {
252             throw new IllegalArgumentException JavaDoc("ImplementationReference cannot be null");
253         }
254         implementationReference = reference;
255     }
256
257     public void setImplementationInstance(Object JavaDoc instance)
258     {
259         if (name == null)
260         {
261             throw new NullPointerException JavaDoc("UMODescriptor.name");
262         }
263         properties.put(DEFAULT_INSTANCE_REF_NAME, instance);
264         setImplementation(new DescriptorContainerKeyPair(name, DEFAULT_INSTANCE_REF_NAME));
265     }
266
267     public void setInboundRouter(UMOInboundMessageRouter routerList)
268     {
269         this.inboundRouter = routerList;
270     }
271
272     public void setOutboundRouter(UMOOutboundMessageRouter routerList)
273     {
274         outboundRouter = routerList;
275     }
276
277     public void setContainerManaged(boolean value)
278     {
279         containerManaged = value;
280     }
281
282     public void addInitialisationCallback(InitialisationCallback callback)
283     {
284         initialisationCallbacks.add(callback);
285     }
286
287     /**
288      * Response Routers control how events are returned in a request/response call.
289      * It cn be use to aggregate response events before returning, thus acting as a
290      * Join in a forked process. This can be used to make request/response calls a
291      * lot more efficient as independent tasks can be forked, execute concurrently
292      * and then join before the request completes
293      *
294      * @param router the response router for this component
295      * @see org.mule.umo.routing.UMOResponseMessageRouter
296      */

297     public void setResponseRouter(UMOResponseMessageRouter router)
298     {
299         this.responseRouter = router;
300     }
301
302     /**
303      * Determines if only a single instance of this component is created. This is
304      * useful when a component hands off event processing to another engine such as
305      * Rules processing or Bpel and the processing engine allocates and manages its
306      * own threads.
307      *
308      * @param singleton true if this component is a singleton
309      */

310     public void setSingleton(boolean singleton)
311     {
312         this.singleton = singleton;
313     }
314
315     /**
316      * Sets the initial state of this component
317      *
318      * @param state the initial state of this component
319      */

320     public void setInitialState(String JavaDoc state)
321     {
322         this.initialState = state;
323     }
324
325     public void setEncoding(String JavaDoc encoding)
326     {
327         this.encoding = encoding;
328     }
329
330     /**
331      * Sets the name of the contaier where the object for this descriptor resides. If
332      * this value is 'none' the 'implementaiton' attributed is expected to be a fully
333      * qualified class name that will be instanciated.
334      *
335      * @param containerName the container name, or null if it is not known - in which
336      * case each container will be queried for the component
337      * implementation.
338      */

339     public void setContainer(String JavaDoc containerName)
340     {
341         this.container = containerName;
342     }
343 }
344
Popular Tags