View Javadoc

1   /*
2    * $Id: ResponseMessageProcessorAdapter.java 20781 2010-12-16 13:19:09Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.processor;
12  
13  import org.mule.api.MuleEvent;
14  import org.mule.api.MuleException;
15  import org.mule.api.construct.FlowConstruct;
16  import org.mule.api.construct.FlowConstructAware;
17  import org.mule.api.context.MuleContextAware;
18  import org.mule.api.lifecycle.Disposable;
19  import org.mule.api.lifecycle.Initialisable;
20  import org.mule.api.lifecycle.InitialisationException;
21  import org.mule.api.lifecycle.Lifecycle;
22  import org.mule.api.lifecycle.Startable;
23  import org.mule.api.lifecycle.Stoppable;
24  import org.mule.api.processor.MessageProcessor;
25  
26  public class ResponseMessageProcessorAdapter extends AbstractResponseMessageProcessor implements Lifecycle, FlowConstructAware
27  {
28  
29      protected MessageProcessor responseProcessor;
30      protected FlowConstruct flowConstruct;
31  
32      public ResponseMessageProcessorAdapter()
33      {
34          super();
35      }
36  
37      public ResponseMessageProcessorAdapter(MessageProcessor responseProcessor)
38      {
39          super();
40          this.responseProcessor = responseProcessor;
41      }
42  
43      public void setProcessor(MessageProcessor processor)
44      {
45          this.responseProcessor = processor;
46      }
47  
48      @Override
49      protected MuleEvent processResponse(MuleEvent event) throws MuleException
50      {
51          if (responseProcessor == null)
52          {
53              return event;
54          }
55          else
56          {
57              return responseProcessor.process(event);
58          }
59      }
60  
61      public void initialise() throws InitialisationException
62      {
63          if (responseProcessor instanceof MuleContextAware)
64          {
65              ((MuleContextAware) responseProcessor).setMuleContext(muleContext);
66          }
67          if (responseProcessor instanceof FlowConstructAware)
68          {
69              ((FlowConstructAware) responseProcessor).setFlowConstruct(flowConstruct);
70          }
71          if (responseProcessor instanceof Initialisable)
72          {
73              ((Initialisable) responseProcessor).initialise();
74          }
75      }
76  
77      public void start() throws MuleException
78      {
79          if (responseProcessor instanceof Startable)
80          {
81              ((Startable) responseProcessor).start();
82          }
83      }
84  
85      public void stop() throws MuleException
86      {
87          if (responseProcessor instanceof Stoppable)
88          {
89              ((Stoppable) responseProcessor).stop();
90          }
91      }
92  
93      public void dispose()
94      {
95          if (responseProcessor instanceof Disposable)
96          {
97              ((Disposable) responseProcessor).dispose();
98          }
99      }
100 
101     public void setFlowConstruct(FlowConstruct flowConstruct)
102     {
103         this.flowConstruct = flowConstruct;
104     }
105 
106 }