KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > common > ConnectInfo


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2002 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.common;
20
21 import java.io.Serializable JavaDoc;
22
23 /**
24  * Contains connection related informations for clients and services
25  */

26 public class ConnectInfo implements Serializable JavaDoc
27 {
28   private String JavaDoc name; //login
29
private String JavaDoc hostname; //where to connect
30
private int port;
31   private String JavaDoc type; //server, service, client or plugin
32

33   private String JavaDoc key;
34
35   /**
36    * Constructor.
37    *
38    * @param name the user name
39    * @param hostname the host where the client is listening
40    * @param port the port where the client is listening
41    * @param key the public key associated with a user to verify its signatures
42    * @param type client or service ?
43    */

44   public ConnectInfo(String JavaDoc name, String JavaDoc hostname, int port,
45                      String JavaDoc key, String JavaDoc type)
46   {
47     this.name = name;
48     this.hostname = hostname;
49     this.port = port;
50     this.type = type;
51     this.key = key;
52
53     Logging.getLogger().fine("** new ConnectInfo: " + this);
54   }
55
56   /**
57    * Useful for debugging
58    *
59    * @return c
60    */

61   public String JavaDoc toString()
62   {
63     return this.name + "@" + this.hostname + ":" +
64            this.port + " (" + this.type + ")";
65   }
66   
67   /**
68    * Useful to transmit ConnectInfos between elements.
69    *
70    * @return a String representing the ConnectInfo
71    */

72   public String JavaDoc getRepresentation()
73   {
74     return this.name + " " + this.hostname + " " +
75            this.port + " " + this.key + " " + this.type;
76   }
77
78   /**
79    * Get the username
80    *
81    * @return the user name
82    */

83   public String JavaDoc getName()
84   {
85     return this.name;
86   }
87   
88   /**
89    * Get the hostname
90    *
91    * @return the host name
92    */

93   public String JavaDoc getHostName()
94   {
95     return this.hostname;
96   }
97   
98   /**
99    * Change the host name
100    *
101    * @param hostname the new hostname
102    */

103   public void setHostName(String JavaDoc hostname)
104   {
105         this.hostname = hostname;
106   }
107   
108   /**
109    * Get the host port
110    *
111    * @return the poer
112    */

113   public int getPort()
114   {
115     return this.port;
116   }
117   
118   /**
119    * Change the port
120    *
121    * @param port the new port
122    */

123   public void setPort(int port)
124   {
125     this.port = port;
126   }
127   
128   /**
129    * Set the public key
130    *
131    * @param key the public key
132    */

133   public void setPublicKey(String JavaDoc key)
134   {
135     this.key = key;
136   }
137
138   /**
139    * Get the public key
140    *
141    * @return the public key
142    */

143   public String JavaDoc getPublicKey()
144   {
145     return this.key;
146   }
147   
148   /**
149    * Is the object pointed by this ConnectInfo a service ?
150    *
151    * @return true if it is a service
152    */

153   public boolean isService()
154   {
155     return this.type.equalsIgnoreCase("service");
156   }
157   
158   /**
159    * Is the object pointed by this ConnectInfo a Server ?
160    *
161    * @return true if it is a server
162    */

163   public boolean isServer()
164   {
165     return this.type.equalsIgnoreCase("Server");
166   }
167   
168   /**
169    * Is the object pointed by this ConnectInfo a Client ?
170    *
171    * @return true if it is a client
172    */

173   public boolean isClient()
174   {
175     return this.type.equalsIgnoreCase("Client");
176   }
177   
178   /**
179    * Is the object pointed by this ConnectInfo a WebClient ?
180    *
181    * @return true if it is a web client
182    */

183   public boolean isWebClient()
184   {
185     return this.type.equalsIgnoreCase("WebClient");
186   }
187   
188   /**
189    * Is the object pointed by this ConnectInfo using SSL ?
190    * @return true if it is using SSL.
191    */

192   public boolean useSSL()
193   {
194     return !this.key.equals("nokey");
195   }
196 }
197
Popular Tags