KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > services > binding > ServiceBinding


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.services.binding;
23
24 import java.net.InetAddress JavaDoc;
25 import java.net.UnknownHostException JavaDoc;
26
27 /** A ServiceBinding is a {name,virtualHost,port,interfaceAddress}
28  * quad specifying a named binding for a service.
29  *
30  * @author <a HREF="mailto:bitpushr@rochester.rr.com">Mike Finn</a>.
31  * @author Scott.Stark@jboss.org
32  * @version $Revision: 37459 $
33  */

34 public class ServiceBinding implements Cloneable JavaDoc
35 {
36    /** The name of the binding. A null or empty name implies the default
37      binding for a service.
38     */

39    private String JavaDoc name = null;
40    /** The virtual host name. This is the interface name used to
41     construct the bindAddress value. A null value implies bind on any
42     interface.
43     */

44    private String JavaDoc hostName = null;
45    /** The port the service should listen on. A 0 value implies an
46     anonymous port.
47     */

48    private int port = 0;
49    /** The interface on which the service should bind its listening port. A
50     null address implies bind on any interface.
51     */

52    private InetAddress JavaDoc bindAddress = null;
53
54    /** Make a copy of the ServiceBinding
55     */

56    public Object JavaDoc clone()
57    {
58       Object JavaDoc copy = null;
59       try
60       {
61          copy = super.clone();
62       }
63       catch(CloneNotSupportedException JavaDoc cantHappend)
64       {
65       }
66       return copy;
67    }
68
69    /**
70     * Creates a new instance of ServiceDescriptor
71     *
72     * @param name The name of the binding. A null or empty name
73     * implies that default binding for a service.
74     * @param hostName The virtual host name. This is the interface name used to
75     * construct the bindAddress value. A null value implies bind on any
76     * interface.
77     * @param port The port the service should listen on. A 0 value implies an
78     * anonymous port.
79     *
80     * @exception UnknownHostException If hostName is not resolvable.
81     */

82    public ServiceBinding(String JavaDoc name, String JavaDoc hostName, int port)
83       throws UnknownHostException JavaDoc
84    {
85       this.setName(name);
86       this.setHostName(hostName);
87       this.setBindAddress(hostName);
88       this.setPort(port);
89    }
90
91    /**
92     * Getter for property name.
93     *
94     * @return The name of the binding
95     */

96    public String JavaDoc getName()
97    {
98       return this.name;
99    }
100
101    /**
102     * Setter for property name.
103     *
104     * @param name the name of the binding
105     */

106    public void setName(String JavaDoc name)
107    {
108       this.name = name;
109    }
110
111    /**
112     * Sets the bindAddress attribute of the ServiceDescriptor object
113     *
114     * @param pInetAddr The new bindAddress value
115     */

116    public void setBindAddress(InetAddress JavaDoc bindAddress)
117    {
118       this.bindAddress = bindAddress;
119    }
120    
121    /**
122     * Sets the bindAddress, given a hostname
123     *
124     * @param pHostName The hostname with which to create an InetAddress
125     *
126     * @exception UnknownHostException Hostname is not resolvable
127     */

128    public void setBindAddress(String JavaDoc hostName)
129       throws UnknownHostException JavaDoc
130    {
131       this.bindAddress = InetAddress.getByName(hostName);
132    }
133
134    /**
135     * Gets the bindAddress attribute of the ServiceDescriptor object
136     *
137     * @return The listen address
138     */

139    public InetAddress JavaDoc getBindAddress()
140    {
141       return this.bindAddress;
142    }
143
144    /**
145     * Sets the port attribute of the ServiceDescriptor object
146     *
147     * @param pPort The new listen port number
148     */

149    public void setPort(int port)
150    {
151       this.port = port;
152    }
153
154    /**
155     * Gets the port attribute of the ServiceDescriptor object
156     *
157     * @return The listen port number
158     */

159    public int getPort()
160    {
161       return this.port;
162    }
163
164    /**
165     * Returns host name
166     *
167     * @return the hostname or address
168     */

169    public String JavaDoc getHostName()
170    {
171       return this.hostName;
172    }
173
174    /**
175     * Sets the host name
176     *
177     * @param hostName, the hostname or address
178     */

179    public void setHostName(String JavaDoc hostName)
180    {
181       this.hostName = hostName;
182    }
183
184    /**
185     * Create string representation of the service descriptor
186     *
187     * @return String containing service descriptor properties
188     */

189    public String JavaDoc toString()
190    {
191       StringBuffer JavaDoc sBuf = new StringBuffer JavaDoc("ServiceBinding [name=");
192       String JavaDoc host = getHostName();
193
194       if (hostName == null)
195       {
196          host = "<ANY>";
197       }
198
199       sBuf.append(this.getName());
200       sBuf.append(";hostName=");
201       sBuf.append(host);
202       sBuf.append(";bindAddress=");
203       sBuf.append(this.getBindAddress().toString());
204       sBuf.append(";port=");
205       sBuf.append(this.getPort());
206       sBuf.append("]");
207       return sBuf.toString();
208    }
209 }
210
Popular Tags