1 19 20 package org.apache.cayenne.conf; 21 22 import java.util.ArrayList ; 23 import java.util.HashMap ; 24 import java.util.List ; 25 import java.util.Map ; 26 import java.util.Iterator ; 27 28 33 public class ConfigStatus { 34 35 protected List otherFailures = new ArrayList (); 36 protected Map failedMaps = new HashMap (); 37 protected Map failedAdapters = new HashMap (); 38 protected Map failedDataSources = new HashMap (); 39 protected List failedMapRefs = new ArrayList (); 40 protected Map messages = new HashMap (); 41 42 public void addFailedMap(String name, String location, Object extraMessage) { 43 failedMaps.put(name, location); 44 if (extraMessage != null) { 45 messages.put(getMapMessageKey(name, location), extraMessage); 46 } 47 } 48 49 public void addFailedAdapter(String name, String location, String extraMessage) { 50 failedAdapters.put(name, location); 51 if (extraMessage != null) { 52 messages.put(getAdapterMessageKey(name, location), extraMessage); 53 } 54 } 55 56 public void addFailedDataSource(String name, String location, String extraMessage) { 57 failedDataSources.put(name, location); 58 if (extraMessage != null) { 59 messages.put(getDataSourceMessageKey(name, location), extraMessage); 60 } 61 } 62 63 public void addFailedMapRefs(String name, String extraMessage) { 64 failedMapRefs.add(name); 65 if (extraMessage != null) { 66 messages.put(getMapRefMessageKey(name), extraMessage); 67 } 68 } 69 70 protected String getMapMessageKey(String name, String location) { 71 return "map:" + name + ":" + location; 72 } 73 74 protected String getAdapterMessageKey(String name, String location) { 75 return "adapter:" + name + ":" + location; 76 } 77 78 protected String getDataSourceMessageKey(String name, String location) { 79 return "dataSource:" + name + ":" + location; 80 } 81 82 protected String getMapRefMessageKey(String name) { 83 return "map-ref:" + name; 84 } 85 86 90 public String describeFailures() { 91 if (!hasFailures()) { 92 return "[No failures]"; 93 } 94 95 StringBuffer buf = new StringBuffer (); 96 97 Iterator it = failedMaps.keySet().iterator(); 98 while (it.hasNext()) { 99 String name = (String ) it.next(); 100 String location = (String ) failedMaps.get(name); 101 Object message = messages.get(getMapMessageKey(name, location)); 102 buf.append("\n\tdomain.map.name=").append(name).append( 103 ", domain.map.location=").append(location); 104 if (message != null) { 105 buf.append(", reason: ").append(message); 106 } 107 } 108 109 it = failedAdapters.keySet().iterator(); 110 while (it.hasNext()) { 111 String node = (String ) it.next(); 112 String adapter = (String ) failedAdapters.get(node); 113 Object message = messages.get(getAdapterMessageKey(node, adapter)); 114 buf.append("\n\tdomain.node.name=").append(node).append( 115 ", domain.node.adapter=").append(adapter); 116 if (message != null) { 117 buf.append(", reason: ").append(message); 118 } 119 } 120 121 it = failedDataSources.keySet().iterator(); 122 while (it.hasNext()) { 123 String node = (String ) it.next(); 124 String location = (String ) failedDataSources.get(node); 125 Object message = messages.get(getDataSourceMessageKey(node, location)); 126 buf.append("\n\tdomain.node.name=").append(node).append( 127 ", domain.node.datasource=").append(location); 128 if (message != null) { 129 buf.append(", reason: ").append(message); 130 } 131 } 132 133 it = failedMapRefs.iterator(); 134 while (it.hasNext()) { 135 String mapName = (String ) it.next(); 136 if (failedMaps.get(mapName) == null) { 138 buf.append("\n\tdomain.node.map-ref.name=").append(mapName); 139 140 Object message = messages.get(getMapRefMessageKey(mapName)); 141 if (message != null) { 142 buf.append(", reason: ").append(message); 143 } 144 } 145 } 146 return buf.toString(); 147 } 148 149 153 public List getOtherFailures() { 154 return otherFailures; 155 } 156 157 160 public List getFailedMapRefs() { 161 return failedMapRefs; 162 } 163 164 167 public Map getFailedMaps() { 168 return failedMaps; 169 } 170 171 174 public Map getFailedDataSources() { 175 return failedDataSources; 176 } 177 178 181 public Map getFailedAdapters() { 182 return failedAdapters; 183 } 184 185 188 public boolean hasFailures() { 189 return failedMaps.size() > 0 190 || failedDataSources.size() > 0 191 || failedAdapters.size() > 0 192 || failedMapRefs.size() > 0 193 || otherFailures.size() > 0; 194 } 195 } 196 | Popular Tags |