001/**
002 * Copyright 2003-2005 Arthur van Hoff, Rick Blair
003 *
004 * Licensed to the Apache Software Foundation (ASF) under one or more
005 * contributor license agreements.  See the NOTICE file distributed with
006 * this work for additional information regarding copyright ownership.
007 * The ASF licenses this file to You under the Apache License, Version 2.0
008 * (the "License"); you may not use this file except in compliance with
009 * the License.  You may obtain a copy of the License at
010 *
011 *      http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019package org.apache.activemq.jmdns;
020
021import java.util.EventObject;
022import java.util.logging.Logger;
023
024/**
025 * ServiceEvent.
026 *
027 * @author Werner Randelshofer, Rick Blair
028 * @version %I%, %G%
029 */
030public class ServiceEvent extends EventObject
031{
032    private static Logger logger = Logger.getLogger(ServiceEvent.class.toString());
033    /**
034     * The type name of the service.
035     */
036    private String type;
037    /**
038     * The instance name of the service. Or null, if the event was
039     * fired to a service type listener.
040     */
041    private String name;
042    /**
043     * The service info record, or null if the service could be be resolved.
044     * This is also null, if the event was fired to a service type listener.
045     */
046    private ServiceInfo info;
047
048    /**
049     * Creates a new instance.
050     *
051     * @param source the JmDNS instance which originated the event.
052     * @param type   the type name of the service.
053     * @param name   the instance name of the service.
054     * @param info   the service info record, or null if the service could be be resolved.
055     */
056    public ServiceEvent(JmDNS source, String type, String name, ServiceInfo info)
057    {
058        super(source);
059        this.type = type;
060        this.name = name;
061        this.info = info;
062    }
063
064    /**
065     * Returns the JmDNS instance which originated the event.
066     */
067    public JmDNS getDNS()
068    {
069        return (JmDNS) getSource();
070    }
071
072    /**
073     * Returns the fully qualified type of the service.
074     */
075    public String getType()
076    {
077        return type;
078    }
079
080    /**
081     * Returns the instance name of the service.
082     * Always returns null, if the event is sent to a service type listener.
083     */
084    public String getName()
085    {
086        return name;
087    }
088
089    /**
090     * Returns the service info record, or null if the service could not be
091     * resolved.
092     * Always returns null, if the event is sent to a service type listener.
093     */
094    public ServiceInfo getInfo()
095    {
096        return info;
097    }
098
099    public String toString()
100    {
101        StringBuffer buf = new StringBuffer();
102        buf.append("<" + getClass().getName() + "> ");
103        buf.append(super.toString());
104        buf.append(" name ");
105        buf.append(getName());
106        buf.append(" type ");
107        buf.append(getType());
108        buf.append(" info ");
109        buf.append(getInfo());
110        return buf.toString();
111    }
112
113}