01: /*
02: * $Id: SocketEndpointURIBuilder.java 10489 2008-01-23 17:53:38Z dfeist $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
10:
11: package org.mule.endpoint;
12:
13: import org.mule.api.endpoint.MalformedEndpointException;
14:
15: import java.net.URI;
16: import java.util.Properties;
17:
18: /**
19: * <code>SocketEndpointBuilder</code> builds an endpointUri based on host and port
20: * only
21: */
22: public class SocketEndpointURIBuilder extends
23: AbstractEndpointURIBuilder {
24: protected void setEndpoint(URI uri, Properties props)
25: throws MalformedEndpointException {
26: // set the endpointUri to be a proper url if host and port are set
27: if (uri.getPort() == -1) {
28: // try the form tcp://6666
29: try {
30: int port = Integer.parseInt(uri.getHost());
31: this .address = uri.getScheme() + "://localhost:" + port;
32: } catch (NumberFormatException e) {
33: // ignore
34: }
35: }
36:
37: if (address == null) {
38: this .address = uri.getScheme() + "://" + uri.getHost();
39: if (uri.getPort() != -1) {
40: this .address += ":" + uri.getPort();
41: }
42: }
43: }
44: }
|