KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > impl > endpoint > UserInfoEndpointBuilder


1 /*
2  * $Id: UserInfoEndpointBuilder.java 4268 2006-12-14 17:08:47Z lajos $
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.impl.endpoint;
12
13 import org.mule.umo.endpoint.MalformedEndpointException;
14
15 import java.net.URI JavaDoc;
16 import java.util.Properties JavaDoc;
17
18 /**
19  * <code>UserInfoEndpointBuilder</code> builds an endpoint with the userinfo and
20  * host details. This endpoint builder is used where endpoints as of the form :
21  * xxx://ross:secret@host:1000
22  *
23  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
24  * @version $Revision: 4268 $
25  */

26 public class UserInfoEndpointBuilder extends AbstractEndpointBuilder
27 {
28     //TODO THis endpoint builder is redundant I think. We should be able to use the URL endpoint builder.
29
//It depends on where deriving classes can work with the URL endpoint builder, but there are a lot of similarities
30
protected void setEndpoint(URI JavaDoc uri, Properties JavaDoc props) throws MalformedEndpointException
31     {
32         // Added by Lajos 2006-12-14 per Ross
33
if(uri.getHost()==null)
34         {
35             if(props.getProperty("address")==null)
36             {
37                 throw new MalformedEndpointException(uri.toString());
38             }
39             else
40             {
41                 return;
42             }
43         }
44
45         // Check and handle '@' symbols in the user info
46
address = uri.getHost();
47         int a = address.indexOf(".");
48         int b = (a == -1 ? -1 : address.indexOf(".", a + 1));
49         if (b > -1)
50         {
51             address = address.substring(a + 1);
52         }
53
54         if (uri.getPort() != -1)
55         {
56             // set the endpointUri to be a proper url if host and port are set
57
this.address += ":" + uri.getPort();
58         }
59
60         if (userInfo != null)
61         {
62             int x = userInfo.indexOf(":");
63             if (x > -1)
64             {
65                 String JavaDoc user = userInfo.substring(0, x);
66                 if (user.indexOf("@") > -1)
67                 {
68                     address = user;
69                 }
70                 else
71                 {
72                     address = user + "@" + address;
73                 }
74             }
75             else
76             {
77                 if (userInfo.indexOf("@") > -1)
78                 {
79                     address = userInfo;
80                 }
81                 else
82                 {
83                     address = userInfo + "@" + address;
84                 }
85             }
86         }
87     }
88 }
89
Popular Tags