Coverage Report - org.mule.impl.model.streaming.StreamingComponent
 
Classes in this File Line Coverage Branch Coverage Complexity
StreamingComponent
0%
0/31
0%
0/8
3.6
 
 1  
 /*
 2  
  * $Id: StreamingComponent.java 7963 2007-08-21 08:53:15Z dirk.olmes $
 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 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.impl.model.streaming;
 12  
 
 13  
 import org.mule.config.i18n.CoreMessages;
 14  
 import org.mule.impl.MuleDescriptor;
 15  
 import org.mule.impl.RequestContext;
 16  
 import org.mule.impl.model.AbstractComponent;
 17  
 import org.mule.umo.ComponentException;
 18  
 import org.mule.umo.UMOEvent;
 19  
 import org.mule.umo.UMOException;
 20  
 import org.mule.umo.UMOMessage;
 21  
 import org.mule.umo.endpoint.UMOEndpoint;
 22  
 import org.mule.umo.lifecycle.Disposable;
 23  
 import org.mule.umo.lifecycle.Initialisable;
 24  
 import org.mule.umo.lifecycle.InitialisationException;
 25  
 import org.mule.umo.model.UMOEntryPoint;
 26  
 import org.mule.umo.model.UMOModel;
 27  
 
 28  
 import java.util.Iterator;
 29  
 
 30  
 /**
 31  
  * TODO
 32  
  */
 33  
 public class StreamingComponent extends AbstractComponent
 34  
 {
 35  
 
 36  
     private static final long serialVersionUID = 2967438446264425730L;
 37  
 
 38  
     protected Object component;
 39  
 
 40  
     protected UMOEntryPoint entryPoint;
 41  
 
 42  
     public StreamingComponent(MuleDescriptor descriptor, UMOModel model)
 43  
     {
 44  0
         super(descriptor, model);
 45  0
     }
 46  
 
 47  
     protected void doInitialise() throws InitialisationException
 48  
     {
 49  
         try
 50  
         {
 51  0
             component = lookupComponent();
 52  
         }
 53  0
         catch (UMOException e)
 54  
         {
 55  0
             throw new InitialisationException(e, this);
 56  0
         }
 57  
 
 58  
         // Validate the component
 59  
         // Right now we do not support transformers on the Streaming model
 60  0
         for (Iterator iterator = descriptor.getInboundRouter().getEndpoints().iterator(); iterator.hasNext();)
 61  
         {
 62  
             //Enforce streaming
 63  0
             UMOEndpoint ep = (UMOEndpoint) iterator.next();
 64  0
             ep.setStreaming(true);
 65  
 //            if (!ep.isStreaming())
 66  
 //            {
 67  
 //                throw new InitialisationException(
 68  
 //                    CoreMessages.streamingEndpointsMustBeUsedWithStreamingModel(), this);
 69  
 //            }
 70  
             // TODO RM*: This restriction could be lifted in future
 71  0
             if (ep.getTransformer() != null)
 72  
             {
 73  0
                 throw new InitialisationException(
 74  
                     CoreMessages.streamingEndpointsDoNotSupportTransformers(), this);
 75  
             }
 76  0
         }
 77  0
         if (component instanceof Initialisable)
 78  
         {
 79  0
             ((Initialisable) component).initialise();
 80  
         }
 81  
 
 82  
         try
 83  
         {
 84  0
             entryPoint = model.getEntryPointResolver().resolveEntryPoint(descriptor);
 85  
         }
 86  0
         catch (Exception e)
 87  
         {
 88  0
             throw new InitialisationException(e, this);
 89  0
         }
 90  
 
 91  0
     }
 92  
 
 93  
     protected UMOMessage doSend(UMOEvent event) throws UMOException
 94  
     {
 95  0
         doDispatch(event);
 96  0
         return null;
 97  
     }
 98  
 
 99  
     protected void doDispatch(UMOEvent event) throws UMOException
 100  
     {
 101  
 
 102  
         try
 103  
         {
 104  0
             entryPoint.invoke(component, RequestContext.getEventContext());
 105  
         }
 106  0
         catch (UMOException e)
 107  
         {
 108  0
             throw e;
 109  
         }
 110  0
         catch (Exception e)
 111  
         {
 112  0
             throw new ComponentException(event.getMessage(), this, e);
 113  0
         }
 114  0
     }
 115  
 
 116  
     protected void doDispose()
 117  
     {
 118  0
         if (component instanceof Disposable)
 119  
         {
 120  0
             ((Disposable) component).dispose();
 121  
         }
 122  0
     }
 123  
 
 124  
 }