1 4 package org.oddjob.doclet; 5 6 import java.io.IOException ; 7 import java.io.InputStream ; 8 import java.util.ArrayList ; 9 import java.util.Collections ; 10 import java.util.HashMap ; 11 import java.util.Iterator ; 12 import java.util.LinkedHashMap ; 13 import java.util.List ; 14 import java.util.Map ; 15 import java.util.Properties ; 16 17 22 public class JobsAndTypes { 23 24 25 private Map jobs = new LinkedHashMap (); 26 27 28 private Map types = new LinkedHashMap (); 29 30 33 private Map other = new HashMap (); 34 35 public JobsAndTypes() { 36 loadProps("/org/oddjob/oddjob.properties", jobs); 37 loadProps("/org/oddjob/values/types.properties", types); 38 loadProps("/org/oddjob/schedules/schedules.properties", other); 39 loadProps("/org/oddjob/scheduling/scheduling.properties", other); 40 loadProps("/org/oddjob/quartz/scheduling.properties", other); 41 } 42 43 void loadProps(String resource, Map into) { 44 Properties props = new Properties (); 45 try { 46 InputStream in = this.getClass().getResourceAsStream(resource); 47 if (in == null) { 48 throw new IllegalStateException ("[" + resource + " does not exsit."); 49 } 50 props.load(in); 51 in.close(); 52 } 53 catch (IOException e) { 54 e.printStackTrace(); 55 } 56 List sorted = new ArrayList (props.keySet()); 57 Collections.sort(sorted); 58 for (Iterator it = sorted.iterator(); it.hasNext(); ) { 59 String tag = (String ) it.next(); 60 into.put(props.get(tag), tag); 61 } 62 } 63 64 public String nameFor(String fqcn) { 65 String name = (String ) jobs.get(fqcn); 66 if (name == null) { 67 name = (String ) types.get(fqcn); 68 } 69 if (name == null) { 70 name = (String ) other.get(fqcn); 71 } 72 return name; 73 } 74 75 public boolean isJob(String fqcn) { 76 return !((String ) jobs.get(fqcn) == null); 77 78 } 79 80 public boolean isType(String fqcn) { 81 return !((String ) types.get(fqcn) == null); 82 83 } 84 85 public boolean contains(String fqcn) { 86 if (jobs.containsKey(fqcn)) { 87 return true; 88 } 89 if (types.containsKey(fqcn)) { 90 return true; 91 } 92 if (other.containsKey(fqcn)) { 93 return true; 94 } 95 return false; 96 } 97 98 103 public String [] types(){ 104 return (String []) types.values().toArray(new String [0]); 105 } 106 107 112 public String [] jobs(){ 113 return (String []) jobs.values().toArray(new String [0]); 114 } 115 116 } 117 | Popular Tags |