1 56 package org.objectstyle.cayenne.conf; 57 58 import java.util.ArrayList ; 59 import java.util.HashMap ; 60 import java.util.List ; 61 import java.util.Map ; 62 import java.util.Iterator ; 63 64 69 public class ConfigStatus { 70 71 protected List otherFailures = new ArrayList (); 72 protected Map failedMaps = new HashMap (); 73 protected Map failedAdapters = new HashMap (); 74 protected Map failedDataSources = new HashMap (); 75 protected List failedMapRefs = new ArrayList (); 76 protected Map messages = new HashMap (); 77 78 public void addFailedMap(String name, String location, Object extraMessage) { 79 failedMaps.put(name, location); 80 if(extraMessage != null) { 81 messages.put(getMapMessageKey(name, location), extraMessage); 82 } 83 } 84 85 public void addFailedAdapter(String name, String location, String extraMessage) { 86 failedAdapters.put(name, location); 87 if(extraMessage != null) { 88 messages.put(getAdapterMessageKey(name, location), extraMessage); 89 } 90 } 91 92 public void addFailedDataSource(String name, String location, String extraMessage) { 93 failedDataSources.put(name, location); 94 if(extraMessage != null) { 95 messages.put(getDataSourceMessageKey(name, location), extraMessage); 96 } 97 } 98 99 public void addFailedMapRefs(String name, String extraMessage) { 100 failedMapRefs.add(name); 101 if(extraMessage != null) { 102 messages.put(getMapRefMessageKey(name), extraMessage); 103 } 104 } 105 106 protected String getMapMessageKey(String name, String location) { 107 return "map:" + name + ":" + location; 108 } 109 110 111 protected String getAdapterMessageKey(String name, String location) { 112 return "adapter:" + name + ":" + location; 113 } 114 115 protected String getDataSourceMessageKey(String name, String location) { 116 return "dataSource:" + name + ":" + location; 117 } 118 119 protected String getMapRefMessageKey(String name) { 120 return "map-ref:" + name; 121 } 122 123 127 public String describeFailures() { 128 if(!hasFailures()) { 129 return "[No failures]"; 130 } 131 132 StringBuffer buf = new StringBuffer (); 133 134 Iterator it = failedMaps.keySet().iterator(); 135 while(it.hasNext()) { 136 String name = (String )it.next(); 137 String location = (String )failedMaps.get(name); 138 Object message = messages.get(getMapMessageKey(name, location)); 139 buf.append("\n\tdomain.map.name=").append(name).append(", domain.map.location=").append(location); 140 if(message != null) { 141 buf.append(", reason: ").append(message); 142 } 143 } 144 145 it = failedAdapters.keySet().iterator(); 146 while(it.hasNext()) { 147 String node = (String )it.next(); 148 String adapter = (String )failedAdapters.get(node); 149 Object message = messages.get(getAdapterMessageKey(node, adapter)); 150 buf.append("\n\tdomain.node.name=").append(node).append(", domain.node.adapter=").append(adapter); 151 if(message != null) { 152 buf.append(", reason: ").append(message); 153 } 154 } 155 156 it = failedDataSources.keySet().iterator(); 157 while(it.hasNext()) { 158 String node = (String )it.next(); 159 String location = (String )failedDataSources.get(node); 160 Object message = messages.get(getDataSourceMessageKey(node, location)); 161 buf.append("\n\tdomain.node.name=").append(node).append(", domain.node.datasource=").append(location); 162 if(message != null) { 163 buf.append(", reason: ").append(message); 164 } 165 } 166 167 it = failedMapRefs.iterator(); 168 while(it.hasNext()) { 169 String mapName = (String )it.next(); 170 if(failedMaps.get(mapName) == null) { 172 buf.append("\n\tdomain.node.map-ref.name=").append(mapName); 173 174 Object message = messages.get(getMapRefMessageKey(mapName)); 175 if(message != null) { 176 buf.append(", reason: ").append(message); 177 } 178 } 179 } 180 return buf.toString(); 181 } 182 183 187 public List getOtherFailures() { 188 return otherFailures; 189 } 190 191 194 public List getFailedMapRefs() { 195 return failedMapRefs; 196 } 197 198 202 public Map getFailedMaps() { 203 return failedMaps; 204 } 205 206 209 public Map getFailedDataSources() { 210 return failedDataSources; 211 } 212 213 216 public Map getFailedAdapters() { 217 return failedAdapters; 218 } 219 220 223 public boolean hasFailures() { 224 return failedMaps.size() > 0 225 || failedDataSources.size() > 0 226 || failedAdapters.size() > 0 227 || failedMapRefs.size() > 0 228 || otherFailures.size() > 0; 229 } 230 } 231 | Popular Tags |