KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > components > simple > BridgeComponent


1 /*
2  * $Id: BridgeComponent.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.components.simple;
12
13 import org.mule.impl.UMODescriptorAware;
14 import org.mule.routing.inbound.ForwardingConsumer;
15 import org.mule.umo.UMODescriptor;
16 import org.mule.umo.UMOEventContext;
17 import org.mule.umo.lifecycle.Callable;
18 import org.mule.umo.routing.UMOInboundRouter;
19
20 import java.util.Iterator JavaDoc;
21
22 /**
23  * Can be used to bridge inbound requests to an outbound router without any
24  * processing done inbetween.
25  *
26  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
27  * @version $Revision: 3798 $
28  */

29 public class BridgeComponent implements UMODescriptorAware, Callable
30 {
31
32     public void setDescriptor(UMODescriptor descriptor)
33     {
34         // Adding a forwarding consumer will cause the inbound routing to
35
// directly invoke the outbound router, bypassing the component
36

37         // first check there isn't one already registered
38
boolean registered = false;
39         for (Iterator JavaDoc iterator = descriptor.getInboundRouter().getRouters().iterator(); iterator.hasNext();)
40         {
41             UMOInboundRouter router = (UMOInboundRouter)iterator.next();
42             if (router instanceof ForwardingConsumer)
43             {
44                 registered = true;
45             }
46
47         }
48         if (!registered)
49         {
50             descriptor.getInboundRouter().addRouter(new ForwardingConsumer());
51         }
52         // Make sure if other routers on the inbound router, they are honoured
53
descriptor.getInboundRouter().setMatchAll(true);
54     }
55
56     public Object JavaDoc onCall(UMOEventContext context) throws Exception JavaDoc
57     {
58         throw new UnsupportedOperationException JavaDoc(
59             "A bridge should not ever receive an event, instead the event should be directly dispatched from the inbound endpoint to the outbound router. Component is: "
60                             + context.getComponentDescriptor().getName());
61     }
62 }
63
Popular Tags