001    /*
002     * This file is part of muCommander, http://www.mucommander.com
003     * Copyright (C) 2002-2008 Maxence Bernard
004     *
005     * muCommander is free software; you can redistribute it and/or modify
006     * it under the terms of the GNU General Public License as published by
007     * the Free Software Foundation; either version 3 of the License, or
008     * (at your option) any later version.
009     *
010     * muCommander is distributed in the hope that it will be useful,
011     * but WITHOUT ANY WARRANTY; without even the implied warranty of
012     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013     * GNU General Public License for more details.
014     *
015     * You should have received a copy of the GNU General Public License
016     * along with this program.  If not, see <http://www.gnu.org/licenses/>.
017     */
018    
019    package com.mucommander.bonjour;
020    
021    import com.mucommander.file.FileURL;
022    
023    /**
024     * A simple container for a Bonjour service described by a name and URL.
025     *
026     * @author Maxence Bernard
027     */
028    public class BonjourService {
029    
030        /** the unqualified name of the service, e.g. 'foobar' */
031        private String name;
032    
033        /** the url pointing to the service's location */
034        private FileURL url;
035    
036        /** the fully qualified name of the service, e.g. 'foobar._http._tcp.local' */
037        private String fullyQualifiedName;
038    
039    
040        /**
041         * Creates a new BonjourService instance using the given name and URL.
042         *
043         * @param name the unqualified name of the service, e.g. 'foobar'
044         * @param url the url pointing to the service's location
045         * @param fullyQualifiedName the fully qualified name of the service, e.g. 'foobar._http._tcp.local'
046         */
047        public BonjourService(String name, FileURL url, String fullyQualifiedName) {
048            this.name = name;
049            this.url = url;
050            this.fullyQualifiedName = fullyQualifiedName;
051        }
052    
053    
054        /**
055         * Returns the unqualified name of this service, e.g. 'foobar'.
056         *
057         * @return the unqualified name of this service
058         */
059        public String getName() {
060            return name;
061        }
062    
063        /**
064         * Returns the name appended with the URL's scheme.
065         *
066         * @return the name appended with the URL's scheme.
067         */
068        public String getNameWithProtocol() {
069            return name+" ["+url.getScheme().toUpperCase()+"]";
070        }
071    
072        /**
073         * Returns the location of this service.
074         *
075         * @return the location of this service.
076         */
077        public FileURL getURL() {
078            return url;
079        }
080    
081        /**
082         * Returns the fully qualified name of this service, e.g. 'foobar._http._tcp.local'
083         *
084         * @return the fully qualified name of this service
085         */
086        public String getFullyQualifiedName() {
087            return fullyQualifiedName;
088        }
089    
090    
091        ////////////////////////
092        // Overridden methods //
093        ////////////////////////
094    
095        /**
096         * Returns <code>true</code> if the given Object is a BonjourService instance with the same fully qualified name.
097         */
098        public boolean equals(Object o) {
099            if(!(o instanceof BonjourService))
100                return false;
101    
102            return fullyQualifiedName.equals(((BonjourService)o).fullyQualifiedName);
103        }
104    
105    
106        /**
107         * Returns a String representation of this BonjourService in the form name / url.
108         */
109        public String toString() {
110            return name+" / "+url.toString(false);
111        }
112    }