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.ResourceNameDiscover;
020    import org.apache.commons.discovery.ResourceNameIterator;
021    import org.apache.commons.logging.Log;
022    import org.apache.commons.logging.LogFactory;
023    
024    /**
025     * Recover resource name from System Properties.
026     */
027    public class DiscoverNamesInSystemProperties extends ResourceNameDiscoverImpl implements ResourceNameDiscover {
028    
029        private static Log log = LogFactory.getLog(DiscoverNamesInSystemProperties.class);
030    
031        /**
032         * Sets the {@code Log} for this class.
033         *
034         * @param _log This class {@code Log}
035         * @deprecated This method is not thread-safe
036         */
037        @Deprecated
038        public static void setLog(Log _log) {
039            log = _log;
040        }
041    
042        /**
043         * Construct a new resource discoverer
044         */
045        public DiscoverNamesInSystemProperties() {
046        }
047    
048        /**
049         * {@inheritDoc}
050         */
051        @Override
052        public ResourceNameIterator findResourceNames(final String resourceName) {
053            if (log.isDebugEnabled()) {
054                log.debug("find: resourceName='" + resourceName + "'");
055            }
056    
057            return new ResourceNameIterator() {
058    
059                private String resource = System.getProperty(resourceName);
060    
061                public boolean hasNext() {
062                    return resource != null;
063                }
064    
065                public String nextResourceName() {
066                    String element = resource;
067                    resource = null;
068                    return element;
069                }
070            };
071        }
072    
073    }