KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > soap > glue > GlueConnector


1 /*
2  * $Id: GlueConnector.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.providers.soap.glue;
12
13 import org.mule.providers.AbstractServiceEnabledConnector;
14 import org.mule.umo.UMOComponent;
15 import org.mule.umo.endpoint.UMOEndpoint;
16 import org.mule.umo.provider.UMOMessageReceiver;
17
18 import java.net.URI JavaDoc;
19 import java.net.URISyntaxException JavaDoc;
20 import java.util.ArrayList JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.Map JavaDoc;
24
25 /**
26  * <code>GlueConnector</code> instanciates a Glue soap server and allows beans to
27  * be dynamically exposed via web services simply by registering with the connector.
28  *
29  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
30  * @version $Revision: 3798 $
31  */

32
33 public class GlueConnector extends AbstractServiceEnabledConnector
34 {
35     private List JavaDoc serverEndpoints = new ArrayList JavaDoc();
36     private Map JavaDoc context;
37
38     public GlueConnector()
39     {
40         super();
41         registerSupportedProtocol("http");
42     }
43
44     public String JavaDoc getProtocol()
45     {
46         return "glue";
47     }
48
49     public UMOMessageReceiver createReceiver(UMOComponent component, UMOEndpoint endpoint) throws Exception JavaDoc
50     {
51         boolean createServer = shouldCreateServer(endpoint.getEndpointURI().getAddress());
52
53         UMOMessageReceiver receiver = serviceDescriptor.createMessageReceiver(this, component, endpoint,
54             new Object JavaDoc[]{Boolean.valueOf(createServer)});
55
56         if (createServer)
57         {
58             serverEndpoints.add(endpoint.getEndpointURI().getAddress());
59         }
60         return receiver;
61     }
62
63     protected Object JavaDoc getReceiverKey(UMOComponent component, UMOEndpoint endpoint)
64     {
65         return endpoint.getEndpointURI().getAddress() + "/" + component.getDescriptor().getName();
66     }
67
68     private boolean shouldCreateServer(String JavaDoc endpoint) throws URISyntaxException JavaDoc
69     {
70         URI JavaDoc uri = new URI JavaDoc(endpoint);
71         String JavaDoc ep = uri.getScheme() + "://" + uri.getHost();
72         if (uri.getPort() != -1)
73         {
74             ep += ":" + uri.getPort();
75         }
76
77         for (Iterator JavaDoc iterator = serverEndpoints.iterator(); iterator.hasNext();)
78         {
79             String JavaDoc s = (String JavaDoc)iterator.next();
80             if (s.startsWith(ep))
81             {
82                 return false;
83             }
84         }
85         return true;
86     }
87
88     public Map JavaDoc getContext()
89     {
90         return context;
91     }
92
93     public void setContext(Map JavaDoc context)
94     {
95         this.context = context;
96     }
97
98     public boolean supportsProtocol(String JavaDoc protocol)
99     {
100         return super.supportsProtocol(protocol) || protocol.toLowerCase().equals("glue:http");
101     }
102 }
103
Popular Tags