001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.xbean.kernel;
018    
019    /**
020     * A simple service name containing a single String.
021     *
022     * @author Dain Sundstrom
023     * @version $Id$
024     * @since 2.0
025     */
026    public class StringServiceName implements ServiceName {
027        /**
028         * The strang name of the service.
029         */
030        private final String name;
031    
032        /**
033         * Create a StringServiceName wrapping specified name.
034         *
035         * @param name the name of the service
036         */
037        public StringServiceName(String name) {
038            if (name == null) throw new NullPointerException("name is null");
039            if (name.length() == 0) throw new IllegalArgumentException("name must be atleast one character long");
040            this.name = name;
041        }
042    
043        public int hashCode() {
044            return name.hashCode();
045        }
046    
047        public boolean equals(Object obj) {
048            if (obj instanceof StringServiceName) {
049                StringServiceName stringServiceName = (StringServiceName) obj;
050                return name.equals(stringServiceName.name);
051            }
052            return false;
053        }
054    
055        public String toString() {
056            return name;
057        }
058    }