add id to node
[jSite2.git] / src / net / pterodactylus / jsite / core / Node.java
index 854a668..5a8ec89 100644 (file)
 
 package net.pterodactylus.jsite.core;
 
+import java.beans.PropertyChangeListener;
+
+import net.pterodactylus.util.beans.AbstractBean;
+
 /**
- * Container for a Freenet node.
+ * Container for a Freenet node. A Node is capable of notifying
+ * {@link PropertyChangeListener}s if any of the contained properties change.
  * 
  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
- * @version $Id$
  */
-public class Node {
+public class Node extends AbstractBean {
+
+       /** Name of the “name” property. */
+       public static final String PROPERTY_NAME = "name";
+
+       /** Name of the “hostname” property. */
+       public static final String PROPERTY_HOSTNAME = "hostname";
+
+       /** Name of the “port” property. */
+       public static final String PROPERTY_PORT = "port";
+
+       /** Internal ID. */
+       private String id;
 
        /** The name of the node. */
        private String name;
@@ -36,8 +52,24 @@ public class Node {
        /** The port number of the node. */
        private int port;
 
-       /** Whether the node is running on the same machine as jSite. */
-       private boolean sameMachine;
+       /**
+        * Returns the internal ID of the node.
+        * 
+        * @return The internal ID of the node
+        */
+       String getId() {
+               return id;
+       }
+
+       /**
+        * Sets the internal ID of the node.
+        * 
+        * @param id
+        *            The internal ID of the node
+        */
+       void setId(String id) {
+               this.id = id;
+       }
 
        /**
         * Returns the user-given name of the node.
@@ -55,7 +87,9 @@ public class Node {
         *            The name of the node
         */
        public void setName(String name) {
+               String oldName = this.name;
                this.name = name;
+               fireIfPropertyChanged(PROPERTY_NAME, oldName, name);
        }
 
        /**
@@ -74,7 +108,9 @@ public class Node {
         *            The hostname of the node
         */
        public void setHostname(String hostname) {
+               String oldHostname = this.hostname;
                this.hostname = hostname;
+               fireIfPropertyChanged(PROPERTY_HOSTNAME, oldHostname, hostname);
        }
 
        /**
@@ -93,28 +129,9 @@ public class Node {
         *            The port number of the node
         */
        public void setPort(int port) {
+               int oldPort = this.port;
                this.port = port;
-       }
-
-       /**
-        * Returns whether this node is running on the same machine as jSite.
-        * 
-        * @return the sameMachine <code>true</code> if, and only if, the node is
-        *         running on the same machine as jSite
-        */
-       public boolean isSameMachine() {
-               return sameMachine;
-       }
-
-       /**
-        * Sets whether this node is running on the same machine as jSite.
-        * 
-        * @param sameMachine
-        *            <code>true</code> if the node is running on the same machine
-        *            as jSite, <code>false</code> otherwise
-        */
-       public void setSameMachine(boolean sameMachine) {
-               this.sameMachine = sameMachine;
+               fireIfPropertyChanged(PROPERTY_PORT, oldPort, port);
        }
 
        /**