View Javadoc

1   // /Copyright 2003-2005 Arthur van Hoff, Rick Blair
2   // Licensed under Apache License version 2.0
3   // Original license LGPL
4   
5   package javax.jmdns.impl;
6   
7   import javax.jmdns.JmDNS;
8   import javax.jmdns.ServiceEvent;
9   import javax.jmdns.ServiceInfo;
10  
11  /**
12   * ServiceEvent.
13   * 
14   * @author Werner Randelshofer, Rick Blair
15   */
16  /**
17   *
18   */
19  public class ServiceEventImpl extends ServiceEvent {
20      /**
21       *
22       */
23      private static final long serialVersionUID = 7107973622016897488L;
24      // private static Logger logger = Logger.getLogger(ServiceEvent.class.getName());
25      /**
26       * The type name of the service.
27       */
28      private final String      _type;
29      /**
30       * The instance name of the service. Or null, if the event was fired to a service type listener.
31       */
32      private final String      _name;
33      /**
34       * The service info record, or null if the service could be be resolved. This is also null, if the event was fired to a service type listener.
35       */
36      private final ServiceInfo _info;
37  
38      /**
39       * Creates a new instance.
40       * 
41       * @param jmDNS
42       *            the JmDNS instance which originated the event.
43       * @param type
44       *            the type name of the service.
45       * @param name
46       *            the instance name of the service.
47       * @param info
48       *            the service info record, or null if the service could be be resolved.
49       */
50      public ServiceEventImpl(JmDNSImpl jmDNS, String type, String name, ServiceInfo info) {
51          super(jmDNS);
52          this._type = type;
53          this._name = name;
54          this._info = info;
55      }
56  
57      /*
58       * (non-Javadoc)
59       * @see javax.jmdns.ServiceEvent#getDNS()
60       */
61      @Override
62      public JmDNS getDNS() {
63          return (JmDNS) getSource();
64      }
65  
66      /*
67       * (non-Javadoc)
68       * @see javax.jmdns.ServiceEvent#getType()
69       */
70      @Override
71      public String getType() {
72          return _type;
73      }
74  
75      /*
76       * (non-Javadoc)
77       * @see javax.jmdns.ServiceEvent#getName()
78       */
79      @Override
80      public String getName() {
81          return _name;
82      }
83  
84      /*
85       * (non-Javadoc)
86       * @see java.util.EventObject#toString()
87       */
88      @Override
89      public String toString() {
90          StringBuilder buf = new StringBuilder();
91          buf.append("[" + this.getClass().getSimpleName() + "@" + System.identityHashCode(this) + " ");
92          buf.append("\n\tname: '");
93          buf.append(this.getName());
94          buf.append("' type: '");
95          buf.append(this.getType());
96          buf.append("' info: '");
97          buf.append(this.getInfo());
98          buf.append("']");
99          // buf.append("' source: ");
100         // buf.append("\n\t" + source + "");
101         // buf.append("\n]");
102         return buf.toString();
103     }
104 
105     /*
106      * (non-Javadoc)
107      * @see javax.jmdns.ServiceEvent#getInfo()
108      */
109     @Override
110     public ServiceInfo getInfo() {
111         return _info;
112     }
113 
114     /*
115      * (non-Javadoc)
116      * @see javax.jmdns.ServiceEvent#clone()
117      */
118     @Override
119     public ServiceEventImpl clone() {
120         ServiceInfoImpl newInfo = new ServiceInfoImpl(this.getInfo());
121         return new ServiceEventImpl((JmDNSImpl) this.getDNS(), this.getType(), this.getName(), newInfo);
122     }
123 
124 }