183a9165584d4e70f46d698c06df35ed66fa56a5
[jSite2.git] / src / net / pterodactylus / jsite / core / Node.java
1 /*
2  * jSite2 - Node.java -
3  * Copyright © 2008 David Roden
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program 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
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 package net.pterodactylus.jsite.core;
21
22 import java.beans.PropertyChangeListener;
23
24 import net.pterodactylus.util.beans.AbstractBean;
25
26 /**
27  * Container for a Freenet node. A Node is capable of notifying
28  * {@link PropertyChangeListener}s if any of the contained properties change.
29  * 
30  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
31  */
32 public class Node extends AbstractBean {
33
34         /** Name of the “name” property. */
35         public static final String PROPERTY_NAME = "name";
36
37         /** Name of the “hostname” property. */
38         public static final String PROPERTY_HOSTNAME = "hostname";
39
40         /** Name of the “port” property. */
41         public static final String PROPERTY_PORT = "port";
42
43         /** The name of the node. */
44         private String name;
45
46         /** The hostname of the node. */
47         private String hostname;
48
49         /** The port number of the node. */
50         private int port;
51
52         //
53         // EVENT MANAGEMENT
54         //
55
56         /**
57          * Returns the user-given name of the node.
58          * 
59          * @return The name of the node
60          */
61         public String getName() {
62                 return name;
63         }
64
65         /**
66          * Sets the user-given name of the node.
67          * 
68          * @param name
69          *            The name of the node
70          */
71         public void setName(String name) {
72                 String oldName = this.name;
73                 this.name = name;
74                 fireIfPropertyChanged(PROPERTY_NAME, oldName, name);
75         }
76
77         /**
78          * Returns the hostname of the node.
79          * 
80          * @return The hostname of the node
81          */
82         public String getHostname() {
83                 return hostname;
84         }
85
86         /**
87          * Sets the hostname of the node.
88          * 
89          * @param hostname
90          *            The hostname of the node
91          */
92         public void setHostname(String hostname) {
93                 String oldHostname = this.hostname;
94                 this.hostname = hostname;
95                 fireIfPropertyChanged(PROPERTY_HOSTNAME, oldHostname, hostname);
96         }
97
98         /**
99          * Returns the port number of the node.
100          * 
101          * @return The port number of the node
102          */
103         public int getPort() {
104                 return port;
105         }
106
107         /**
108          * Sets the port number of the node.
109          * 
110          * @param port
111          *            The port number of the node
112          */
113         public void setPort(int port) {
114                 int oldPort = this.port;
115                 this.port = port;
116                 fireIfPropertyChanged(PROPERTY_PORT, oldPort, port);
117         }
118
119         /**
120          * {@inheritDoc}
121          */
122         @Override
123         public String toString() {
124                 return name + " (" + hostname + ((port == 9481) ? ("") : (":" + port)) + ")";
125         }
126
127 }