1 17 package org.alfresco.config.source; 18 19 import java.io.InputStream ; 20 import java.util.ArrayList ; 21 import java.util.Iterator ; 22 import java.util.List ; 23 24 import org.alfresco.config.ConfigException; 25 import org.alfresco.config.ConfigSource; 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 29 35 public abstract class BaseConfigSource implements ConfigSource 36 { 37 private static final Log logger = LogFactory.getLog(BaseConfigSource.class); 38 39 private List <String > sourceStrings; 40 41 47 protected BaseConfigSource(List <String > sourceStrings) 48 { 49 this.sourceStrings = new ArrayList <String >(); 50 for (String sourceString : sourceStrings) 51 { 52 if (sourceString == null || sourceString.trim().length() == 0) 53 { 54 throw new ConfigException("Invalid source value: " + sourceString); 55 } 56 addSourceString(sourceString); 57 } 58 if (sourceStrings.size() == 0) 60 { 61 throw new ConfigException("No sources provided: " + sourceStrings); 62 } 63 } 64 65 69 private void addSourceString(String sourceString) 70 { 71 sourceString = sourceString.trim(); 72 if (sourceString.length() > 0) 73 { 74 sourceStrings.add(sourceString); 75 } 76 } 77 78 84 public final Iterator <InputStream > iterator() 85 { 86 List <InputStream > inputStreams = new ArrayList <InputStream >(sourceStrings.size()); 88 for (String sourceString : sourceStrings) 89 { 90 if (logger.isDebugEnabled()) 91 { 92 logger.debug("Retrieving input stream for source: " + sourceString); 93 } 94 95 InputStream is = getInputStream(sourceString); 96 if (is != null) 97 { 98 inputStreams.add(is); 99 } 100 } 101 return inputStreams.iterator(); 103 } 104 105 113 protected abstract InputStream getInputStream(String sourceString); 114 } 115 | Popular Tags |