KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > impl > model > pipeline > PipelineComponent


1 /*
2  * $Id: PipelineComponent.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.model.pipeline;
12
13 import org.mule.config.i18n.Message;
14 import org.mule.config.i18n.Messages;
15 import org.mule.impl.MuleDescriptor;
16 import org.mule.impl.MuleMessage;
17 import org.mule.impl.RequestContext;
18 import org.mule.impl.model.direct.DirectComponent;
19 import org.mule.umo.UMOEvent;
20 import org.mule.umo.UMOException;
21 import org.mule.umo.UMOMessage;
22 import org.mule.umo.lifecycle.Callable;
23 import org.mule.umo.lifecycle.Disposable;
24 import org.mule.umo.lifecycle.Initialisable;
25 import org.mule.umo.lifecycle.InitialisationException;
26 import org.mule.umo.model.UMOModel;
27 import org.mule.umo.provider.DispatchException;
28
29 /**
30  * todo document
31  *
32  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
33  * @version $Revision: 3798 $
34  */

35 public class PipelineComponent extends DirectComponent
36 {
37     /**
38      * Serial version
39      */

40     private static final long serialVersionUID = -2788210157354765190L;
41
42     private Callable callable;
43
44     public PipelineComponent(MuleDescriptor descriptor, UMOModel model)
45     {
46         super(descriptor, model);
47     }
48
49     public void doInitialise() throws InitialisationException
50     {
51
52         super.doInitialise();
53         Object JavaDoc component = null;
54         try
55         {
56             component = lookupComponent();
57         }
58         catch (UMOException e)
59         {
60             throw new InitialisationException(e, this);
61         }
62         if (component instanceof Callable)
63         {
64             callable = (Callable)component;
65         }
66         else
67         {
68             throw new InitialisationException(new Message(Messages.OBJECT_X_NOT_OF_CORRECT_TYPE_SHOULD_BE_X,
69                 component.getClass().getName(), Callable.class.getName()), this);
70         }
71
72         if (component instanceof Initialisable)
73         {
74             ((Initialisable)component).initialise();
75         }
76
77     }
78
79     protected UMOMessage doSend(UMOEvent event) throws UMOException
80     {
81         try
82         {
83             Object JavaDoc result = callable.onCall(RequestContext.getEventContext());
84             UMOMessage returnMessage = null;
85             if (result instanceof UMOMessage)
86             {
87                 returnMessage = (UMOMessage)result;
88             }
89             else
90             {
91                 returnMessage = new MuleMessage(result, event.getMessage());
92             }
93             if (!event.isStopFurtherProcessing())
94             {
95                 // // TODO what about this code?
96
// Map context = RequestContext.clearProperties();
97
// if (context != null) {
98
// returnMessage.addProperties(context);
99
// }
100
if (descriptor.getOutboundRouter().hasEndpoints())
101                 {
102                     UMOMessage outboundReturnMessage = descriptor.getOutboundRouter().route(returnMessage,
103                         event.getSession(), event.isSynchronous());
104                     if (outboundReturnMessage != null)
105                     {
106                         returnMessage = outboundReturnMessage;
107                     }
108                 }
109                 else
110                 {
111                     logger.debug("Outbound router on component '" + descriptor.getName()
112                                  + "' doesn't have any endpoints configured.");
113                 }
114             }
115
116             return returnMessage;
117         }
118         catch (Exception JavaDoc e)
119         {
120             throw new DispatchException(event.getMessage(), event.getEndpoint(), e);
121         }
122     }
123
124     protected void doDispatch(UMOEvent event) throws UMOException
125     {
126         sendEvent(event);
127     }
128
129     protected void doDispose()
130     {
131         if (callable instanceof Disposable)
132         {
133             ((Disposable)callable).dispose();
134         }
135     }
136 }
137
Popular Tags