KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > util > HostAndPort


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.admin.util;
25 //JDK imports
26
import java.util.StringTokenizer JavaDoc;
27 import java.io.Serializable JavaDoc;
28
29 /**
30     Represents a host and a port in a convenient package that also
31     accepts a convenient constructor.
32  */

33 public class HostAndPort implements Serializable JavaDoc
34 {
35     /* javac 1.3 generated serialVersionUID */
36     public static final long serialVersionUID = 6708656762332072746L;
37     protected String JavaDoc mHost = null;
38     protected int mPort;
39   private boolean secure = false;
40
41
42   public HostAndPort(String JavaDoc host, int port, boolean secure){
43     this.mHost = host;
44     this.mPort = port;
45     this.secure = secure;
46   }
47   
48   public HostAndPort(HostAndPort rhs){
49     this(rhs.mHost,rhs.mPort,rhs.secure);
50   }
51
52     public HostAndPort( String JavaDoc host, int port ) {
53       this(host, port, false);
54     }
55
56   public boolean isSecure(){
57     return this.secure;
58   }
59   
60     
61     
62         public String JavaDoc
63     getHost()
64     {
65         return( mHost );
66     }
67     
68         public int
69     getPort()
70     {
71         return( mPort );
72     }
73     
74     /**
75         Construct a new HostAndPort from a string of the form "host:port"
76         
77         @param str string of the form "host:port"
78     */

79     public HostAndPort( String JavaDoc str )
80     {
81         StringTokenizer JavaDoc tokenizer =
82             new StringTokenizer JavaDoc( str, ":", false);
83         
84         mHost = tokenizer.nextToken();
85         
86         final String JavaDoc portString = tokenizer.nextToken();
87         mPort = new Integer JavaDoc( portString ).intValue();
88     }
89     
90         public String JavaDoc
91     toString()
92     {
93         return( mHost + ":" + mPort );
94     }
95 }
96
Popular Tags