KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > fenyo > gnetwatch > targets > TargetIPv4Subnet


1
2 /*
3  * GNetWatch
4  * Copyright 2006, 2007 Alexandre Fenyo
5  * gnetwatch@fenyo.net
6  *
7  * This file is part of GNetWatch.
8  *
9  * GNetWatch is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * GNetWatch is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with GNetWatch; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22  */

23
24 package net.fenyo.gnetwatch.targets;
25
26 import net.fenyo.gnetwatch.*;
27 import net.fenyo.gnetwatch.GUI.GUI;
28 import net.fenyo.gnetwatch.GUI.VisualElement;
29
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32 import java.net.*;
33
34 /**
35  * TargetIPv4Subnet implements an IPv4 subnet defined by a subnet address and a subnet mask.
36  * @author Alexandre Fenyo
37  * @version $Id: TargetIPv4Subnet.java,v 1.10 2007/03/03 00:38:19 fenyo Exp $
38  */

39
40 public class TargetIPv4Subnet extends Target {
41   private static Log log = LogFactory.getLog(TargetIPv4Subnet.class);
42
43   private Inet4Address network; // not null
44
private Inet4Address netmask; // not null
45

46   /**
47    * Constructor.
48    * @param name target name.
49    * @param network network address.
50    * @param netmask netmask value.
51    * @throws AlgorithmException exception.
52    */

53   // GUI thread
54
public TargetIPv4Subnet(final String JavaDoc name, final Inet4Address network, final Inet4Address netmask) throws AlgorithmException {
55     super(name);
56     if (network == null || netmask == null) throw new AlgorithmException("network or netmask is null");
57     this.network = network;
58     this.netmask = netmask;
59     setItem(network.getHostAddress() + "/" + netmask.getHostAddress());
60   }
61
62   /**
63    * Initializes this target.
64    * @param gui current GUI instance.
65    * @return void.
66    */

67   public void initialize(final GUI gui) {
68     super.initialize(gui);
69     if (gui != null) setImageNetwork();
70   }
71
72   /**
73    * Returns the network address of this subnet.
74    * @param none.
75    * @return Inet4Address network address.
76    */

77   // any thread
78
protected Inet4Address getNetwork() {
79     return network;
80   }
81
82   /**
83    * Returns the netmask of this subnet.
84    * @param none.
85    * @return Inet4Address netmask.
86    */

87   // any thread
88
protected Inet4Address getNetmask() {
89     return netmask;
90   }
91
92   /**
93    * Checks that the parameter can be attached to this target.
94    * @param visual_element parameter to check.
95    * @return true if the parameter can be attached to this target.
96    */

97   public boolean canManageThisChild(final VisualElement visual_element) {
98     if (TargetIPv4.class.isInstance(visual_element)) return true;
99     return false;
100   }
101
102   /**
103    * Compares two targets.
104    * @param o target to compare to.
105    * @return true if the targets are equal.
106    */

107   // any thread
108
public boolean equals(final Object JavaDoc o) {
109     if (this == o) return true;
110     if ((o == null) || (o.getClass() != getClass())) return false;
111     final TargetIPv4Subnet target = (TargetIPv4Subnet) o;
112     return getNetwork().equals(target.getNetwork()) &&
113       getNetmask().equals(target.getNetmask());
114   }
115
116   /**
117    * Returns the hashcode for this target.
118    * @param none.
119    * @return int hashcode.
120    */

121   // any thread
122
public int hashCode() {
123     return getNetwork().hashCode() ^ getNetmask().hashCode();
124   }
125 }
126
Popular Tags