1/**
2 *
3 */
4package javax.jmdns.impl;
5
6import java.net.InetAddress;
7
8import javax.jmdns.JmDNS;
9import javax.jmdns.NetworkTopologyEvent;
10import javax.jmdns.NetworkTopologyListener;
11
12/**
13 * @author Cédrik Lime, Pierre Frisch
14 */
15public class NetworkTopologyEventImpl extends NetworkTopologyEvent implements Cloneable {
16
17    /**
18     *
19     */
20    private static final long serialVersionUID = 1445606146153550463L;
21
22    private final InetAddress _inetAddress;
23
24    /**
25     * Constructs a Network Topology Event.
26     *
27     * @param jmDNS
28     * @param inetAddress
29     * @exception IllegalArgumentException
30     *                if source is null.
31     */
32    public NetworkTopologyEventImpl(JmDNS jmDNS, InetAddress inetAddress) {
33        super(jmDNS);
34        this._inetAddress = inetAddress;
35    }
36
37    NetworkTopologyEventImpl(NetworkTopologyListener jmmDNS, InetAddress inetAddress) {
38        super(jmmDNS);
39        this._inetAddress = inetAddress;
40    }
41
42    /*
43     * (non-Javadoc)
44     * @see javax.jmdns.NetworkTopologyEvent#getDNS()
45     */
46    @Override
47    public JmDNS getDNS() {
48        return (this.getSource() instanceof JmDNS ? (JmDNS) getSource() : null);
49    }
50
51    /*
52     * (non-Javadoc)
53     * @see javax.jmdns.NetworkTopologyEvent#getInetAddress()
54     */
55    @Override
56    public InetAddress getInetAddress() {
57        return _inetAddress;
58    }
59
60    @Override
61    public String toString() {
62        StringBuilder buf = new StringBuilder();
63        buf.append("[" + this.getClass().getSimpleName() + "@" + System.identityHashCode(this) + " ");
64        buf.append("\n\tinetAddress: '");
65        buf.append(this.getInetAddress());
66        buf.append("']");
67        // buf.append("' source: ");
68        // buf.append("\n\t" + source + "");
69        // buf.append("\n]");
70        return buf.toString();
71    }
72
73    /*
74     * (non-Javadoc)
75     * @see java.lang.Object#clone()
76     */
77    @Override
78    public NetworkTopologyEventImpl clone() throws CloneNotSupportedException {
79        return new NetworkTopologyEventImpl(getDNS(), getInetAddress());
80    }
81
82}
83