KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > config > source > ClassPathConfigSource


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.config.source;
18
19 import java.io.InputStream JavaDoc;
20 import java.util.Collections JavaDoc;
21 import java.util.List JavaDoc;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25
26 /**
27  * ConfigSource implementation that gets its data via the class path.
28  *
29  * @author gavinc
30  */

31 public class ClassPathConfigSource extends BaseConfigSource
32 {
33     private static Log logger = LogFactory.getLog(ClassPathConfigSource.class);
34     
35     /**
36      * Constructs a class path configuration source that uses a single file
37      *
38      * @param classpath the classpath from which to get config
39      *
40      * @see ClassPathConfigSource#ClassPathConfigSource(List<String>)
41      */

42     public ClassPathConfigSource(String JavaDoc classpath)
43     {
44         this(Collections.singletonList(classpath));
45     }
46
47     /**
48      * Constructs an ClassPathConfigSource using the list of classpath elements
49      *
50      * @param source List of classpath resources to get config from
51      */

52     public ClassPathConfigSource(List JavaDoc<String JavaDoc> sourceStrings)
53     {
54         super(sourceStrings);
55     }
56
57     /**
58      * Retrieves an input stream for the given class path source
59      *
60      * @param sourceString The class path resource to search for
61      * @return The input stream
62      */

63     public InputStream JavaDoc getInputStream(String JavaDoc sourceString)
64     {
65         InputStream JavaDoc is = this.getClass().getClassLoader().getResourceAsStream(sourceString);
66
67         if (is == null && logger.isDebugEnabled())
68         {
69             logger.debug("Failed to obtain input stream to classpath: " + sourceString);
70         }
71
72         return is;
73     }
74 }
75
Popular Tags