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.commons.discovery.resource.names;
018    
019    import org.apache.commons.discovery.ResourceDiscover;
020    import org.apache.commons.discovery.ResourceNameDiscover;
021    import org.apache.commons.discovery.resource.ClassLoaders;
022    
023    /**
024     * Provide JDK 1.3 style service discovery...
025     *
026     * The caller will first configure the discoverer by creating a
027     * root Discoverer for the files.
028     */
029    public class DiscoverServiceNames extends DiscoverNamesInFile implements ResourceNameDiscover {
030    
031        protected static final String SERVICE_HOME = "META-INF/services/";
032    
033        /**
034         * Construct a new service discoverer.
035         */
036        public DiscoverServiceNames() {
037            super(SERVICE_HOME, null);
038        }
039    
040        /**
041         * Construct a new resource discoverer.
042         *
043         * @param prefix The resource name prefix
044         * @param suffix The resource name suffix
045         */
046        public DiscoverServiceNames(String prefix, String suffix) {
047            super((prefix == null) ? SERVICE_HOME : SERVICE_HOME + prefix, suffix);
048        }
049    
050        /**
051         * Construct a new resource discoverer.
052         *
053         * @param loaders The class loaders holder
054         */
055        public DiscoverServiceNames(ClassLoaders loaders) {
056            super(loaders, SERVICE_HOME, null);
057        }
058    
059        /**
060         * Construct a new resource discoverer.
061         *
062         * @param loaders The class loaders holder
063         * @param prefix The resource name prefix
064         * @param suffix The resource name suffix
065         */
066        public DiscoverServiceNames(ClassLoaders loaders, String prefix, String suffix) {
067            super(loaders, (prefix == null) ? SERVICE_HOME : SERVICE_HOME + prefix, suffix);
068        }
069    
070        /**
071         * Construct a new service discoverer.
072         *
073         * @param discoverer The discoverer to resolve resources
074         */
075        public DiscoverServiceNames(ResourceDiscover discoverer) {
076            super(discoverer, SERVICE_HOME, null);
077        }
078    
079        /**
080         * Construct a new service discoverer.
081         *
082         * @param discoverer The discoverer to resolve resources
083         * @param prefix The resource name prefix
084         * @param suffix The resource name suffix
085         */
086        public DiscoverServiceNames(ResourceDiscover discoverer, String prefix, String suffix) {
087            super(discoverer, (prefix == null) ? SERVICE_HOME : SERVICE_HOME + prefix, suffix);
088        }
089    
090    }