1 package net.sf.uitags.js; 2 3 import java.io.IOException ; 4 import java.util.Arrays ; 5 import java.util.Iterator ; 6 import java.util.LinkedHashMap ; 7 import java.util.List ; 8 import java.util.Map ; 9 10 import net.sf.uitags.util.ArrayUtils; 11 import net.sf.uitags.util.PropertiesLoadingException; 12 13 import org.apache.commons.collections.ExtendedProperties; 14 15 20 abstract class Suites { 21 25 28 private static final String SUITE_PROPS = "file-names.properties"; 29 30 34 static final String KEYWORD_ALL = "all"; 35 36 37 38 42 45 protected Map mapping = new LinkedHashMap (); 46 47 48 49 53 57 protected Suites() { 58 initSuiteNameToFileNamesMapping(); 59 } 60 61 static Suites getInstance(String suites) { 62 if (suites == null || isKeywordAll(suites)) { 63 return new AllSuites(); 64 } 65 66 String [] suitesAsArray = ArrayUtils.toArrayOfTrimmed(suites); 68 for (int i = 0; i < suitesAsArray.length; i++) { 69 if (isKeywordAll(suitesAsArray[i])) { 70 throw new IllegalArgumentException ( 71 "The keyword 'all' can only be used by itself."); 72 } 73 } 74 75 return new NamedSuites(suitesAsArray); 76 } 77 78 79 80 84 private static boolean isKeywordAll(String suitesAsString) { 85 return suitesAsString.trim().equalsIgnoreCase(KEYWORD_ALL); 86 } 87 88 private void initSuiteNameToFileNamesMapping() { 89 ExtendedProperties props = loadMappingFromProperties(); 90 91 for (Iterator suites = props.getKeys(); suites.hasNext(); ) { 92 String suiteName = (String ) suites.next(); 93 String [] fileNames = props.getStringArray(suiteName); 94 95 for (int i = 0; i < fileNames.length; i++) { 96 fileNames[i] = fileNames[i]; 97 } 98 99 mapping.put(suiteName, Arrays.asList(fileNames)); 100 } 101 } 102 103 private ExtendedProperties loadMappingFromProperties() { 104 ExtendedProperties props = new ExtendedProperties(); 105 try { 106 props.load(this.getClass().getResourceAsStream(SUITE_PROPS)); 107 } 108 catch (IOException e) { 109 throw new PropertiesLoadingException(e, SUITE_PROPS); 110 } 111 112 return props; 113 } 114 115 protected abstract List getFileNames(); 116 } 117 | Popular Tags |