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.discovery.log.DiscoveryLogFactory;
022    import org.apache.commons.logging.Log;
023    
024    
025    /**
026     * Recover resource name from System Properties.
027     * 
028     * @author Richard A. Sitze
029     */
030    public class DiscoverNamesInSystemProperties
031        extends ResourceNameDiscoverImpl
032        implements ResourceNameDiscover
033    {
034        private static Log log = DiscoveryLogFactory.newLog(DiscoverNamesInSystemProperties.class);
035        public static void setLog(Log _log) {
036            log = _log;
037        }
038        
039        /** Construct a new resource discoverer
040         */
041        public DiscoverNamesInSystemProperties() {
042        }
043    
044        /**
045         * @return Enumeration of ResourceInfo
046         */
047        public ResourceNameIterator findResourceNames(final String resourceName) {
048            if (log.isDebugEnabled())
049                log.debug("find: resourceName='" + resourceName + "'");
050    
051            return new ResourceNameIterator() {
052                private String resource = System.getProperty(resourceName);
053                
054                public boolean hasNext() {
055                    return resource != null;
056                }
057                
058                public String nextResourceName() {
059                    String element = resource;
060                    resource = null;
061                    return element;
062                }
063            };
064        }
065    }