Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/collections/AttributeWriter.java @ 8202:e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Fri, 05 Sep 2014 12:58:17 +0200 |
parents | 12248d9eb326 |
children | 02782ed6c8de |
comparison
equal
deleted
inserted
replaced
8201:4b8c5a08de04 | 8202:e4606eae8ea5 |
---|---|
55 | 55 |
56 /** The result of the <i>write()</i> operation.*/ | 56 /** The result of the <i>write()</i> operation.*/ |
57 protected CollectionAttribute attribute; | 57 protected CollectionAttribute attribute; |
58 | 58 |
59 | 59 |
60 private static Logger logger = Logger.getLogger(AttributeWriter.class); | 60 private static Logger log = Logger.getLogger(AttributeWriter.class); |
61 | 61 |
62 | 62 |
63 /** | 63 /** |
64 * Create a AttributeWriter. | 64 * Create a AttributeWriter. |
65 * Attributes not present in newAttr will not be included in the document. | 65 * Attributes not present in newAttr will not be included in the document. |
100 * | 100 * |
101 * @return document with merged outputs as described. | 101 * @return document with merged outputs as described. |
102 */ | 102 */ |
103 protected CollectionAttribute write() { | 103 protected CollectionAttribute write() { |
104 | 104 |
105 boolean debug = logger.isDebugEnabled(); | 105 boolean debug = log.isDebugEnabled(); |
106 | 106 |
107 for (Map.Entry<String, Output> entry: newAttr.entrySet()) { | 107 for (Map.Entry<String, Output> entry: newAttr.entrySet()) { |
108 String outName = entry.getKey(); | 108 String outName = entry.getKey(); |
109 Output a = entry.getValue(); | 109 Output a = entry.getValue(); |
110 | 110 |
113 } | 113 } |
114 | 114 |
115 attribute.clearFacets(outName); | 115 attribute.clearFacets(outName); |
116 | 116 |
117 if (debug) { | 117 if (debug) { |
118 logger.debug("Merge Output: " + outName); | 118 log.debug("Merge Output: " + outName); |
119 logger.debug(" old Facets: " + oldFacets.size()); | 119 log.debug(" old Facets: " + oldFacets.size()); |
120 logger.debug(" new Facets: " + newFacets.size()); | 120 log.debug(" new Facets: " + newFacets.size()); |
121 } | 121 } |
122 | 122 |
123 writeOutput(a.getName(), newFacets, oldFacets); | 123 writeOutput(a.getName(), newFacets, oldFacets); |
124 } | 124 } |
125 | 125 |
140 List<Facet> newOutFacets, | 140 List<Facet> newOutFacets, |
141 List<Facet> oldOutFacets | 141 List<Facet> oldOutFacets |
142 ) { | 142 ) { |
143 List<String> compatFacets = this.compatibilities.get(outputName); | 143 List<String> compatFacets = this.compatibilities.get(outputName); |
144 | 144 |
145 if (logger.isDebugEnabled() && compatFacets != null) { | 145 if (log.isDebugEnabled() && compatFacets != null) { |
146 logger.debug("Compabitle Facets:"); | 146 log.debug("Compabitle Facets:"); |
147 for (String compatible: compatFacets) { | 147 for (String compatible: compatFacets) { |
148 logger.debug( "- " + compatible); | 148 log.debug( "- " + compatible); |
149 } | 149 } |
150 } | 150 } |
151 | 151 |
152 try { | 152 try { |
153 writeFacets(outputName, newOutFacets, oldOutFacets, compatFacets); | 153 writeFacets(outputName, newOutFacets, oldOutFacets, compatFacets); |
154 } | 154 } |
155 catch (ArtifactDatabaseException ade) { | 155 catch (ArtifactDatabaseException ade) { |
156 logger.error(ade, ade); | 156 log.error(ade, ade); |
157 } | 157 } |
158 } | 158 } |
159 | 159 |
160 | 160 |
161 /** | 161 /** |
170 List<Facet> oldFacets, | 170 List<Facet> oldFacets, |
171 List<String> compatibleFacets) | 171 List<String> compatibleFacets) |
172 throws ArtifactDatabaseException | 172 throws ArtifactDatabaseException |
173 { | 173 { |
174 if (compatibleFacets == null) { | 174 if (compatibleFacets == null) { |
175 logger.warn("No compatible facets, not generating out " + outputName + "."); | 175 log.warn("No compatible facets, not generating out " + outputName + "."); |
176 return false; | 176 return false; |
177 } | 177 } |
178 | 178 |
179 int num = newFacets.size(); | 179 int num = newFacets.size(); |
180 | 180 |
181 // Add all new Facets either in their old state or (if really | 181 // Add all new Facets either in their old state or (if really |
182 // new) as they are. | 182 // new) as they are. |
183 List<ManagedFacet> currentFacets = new ArrayList<ManagedFacet>(); | 183 List<ManagedFacet> currentFacets = new ArrayList<ManagedFacet>(); |
184 List<ManagedFacet> genuinelyNewFacets = new ArrayList<ManagedFacet>(); | 184 List<ManagedFacet> genuinelyNewFacets = new ArrayList<ManagedFacet>(); |
185 | 185 |
186 boolean debug = logger.isDebugEnabled(); | 186 boolean debug = log.isDebugEnabled(); |
187 if (debug) { | 187 if (debug) { |
188 logger.debug("Compatible facets are " + compatibleFacets); | 188 log.debug("Compatible facets are " + compatibleFacets); |
189 } | 189 } |
190 | 190 |
191 for (Facet fac: newFacets) { | 191 for (Facet fac: newFacets) { |
192 ManagedFacet facet = (ManagedFacet) fac; | 192 ManagedFacet facet = (ManagedFacet) fac; |
193 | 193 |
194 if (debug) { | 194 if (debug) { |
195 logger.debug("Try to add Facet: " + facet.getName()); | 195 log.debug("Try to add Facet: " + facet.getName()); |
196 } | 196 } |
197 | 197 |
198 String bondage = facet.getBoundToOut(); | 198 String bondage = facet.getBoundToOut(); |
199 if (bondage != null && bondage.equals(outputName)) { | 199 if (bondage != null && bondage.equals(outputName)) { |
200 logger.debug("Adding bound facet regardless of compatibility: " + | 200 log.debug("Adding bound facet regardless of compatibility: " + |
201 facet.getName()); | 201 facet.getName()); |
202 } else if (!compatibleFacets.contains(facet.getName())) { | 202 } else if (!compatibleFacets.contains(facet.getName())) { |
203 logger.debug("Have incompatible facet, skip: " + facet.getName()); | 203 log.debug("Have incompatible facet, skip: " + facet.getName()); |
204 continue; | 204 continue; |
205 } else if (facet.getBoundToOut() != null && | 205 } else if (facet.getBoundToOut() != null && |
206 !facet.getBoundToOut().equals(outputName)) { | 206 !facet.getBoundToOut().equals(outputName)) { |
207 logger.debug("Skip facet " + facet.getName() + | 207 log.debug("Skip facet " + facet.getName() + |
208 " because it is bound to: " + facet.getBoundToOut()); | 208 " because it is bound to: " + facet.getBoundToOut()); |
209 continue; | 209 continue; |
210 } else { | 210 } else { |
211 logger.debug("Facet is bound to: " + facet.getBoundToOut()); | 211 log.debug("Facet is bound to: " + facet.getBoundToOut()); |
212 logger.debug("Have compatible facet: " + facet.getName()); | 212 log.debug("Have compatible facet: " + facet.getName()); |
213 } | 213 } |
214 | 214 |
215 ManagedFacet picked = pickFacet(facet, oldFacets); | 215 ManagedFacet picked = pickFacet(facet, oldFacets); |
216 | 216 |
217 if (facet.equals(picked)) { | 217 if (facet.equals(picked)) { |
218 if (!facetInTwoOuts(facet, genuinelyNewFacets)) { | 218 if (!facetInTwoOuts(facet, genuinelyNewFacets)) { |
219 genuinelyNewFacets.add(picked); | 219 genuinelyNewFacets.add(picked); |
220 } | 220 } |
221 else { | 221 else { |
222 logger.debug("Skip clone facet that shall be present in two outs"); | 222 log.debug("Skip clone facet that shall be present in two outs"); |
223 } | 223 } |
224 } | 224 } |
225 else { | 225 else { |
226 currentFacets.add(picked); | 226 currentFacets.add(picked); |
227 } | 227 } |
249 conflicts = false; | 249 conflicts = false; |
250 for (ManagedFacet oldMF: currentFacets) { | 250 for (ManagedFacet oldMF: currentFacets) { |
251 if (newMF.getPosition() == oldMF.getPosition()) { | 251 if (newMF.getPosition() == oldMF.getPosition()) { |
252 conflicts = true; | 252 conflicts = true; |
253 if (debug) { | 253 if (debug) { |
254 logger.debug( | 254 log.debug( |
255 "Positional conflict while merging " + | 255 "Positional conflict while merging " + |
256 "facets, pushing newest facet 1 up (" + | 256 "facets, pushing newest facet 1 up (" + |
257 newMF.getPosition() + ")"); | 257 newMF.getPosition() + ")"); |
258 } | 258 } |
259 newMF.setPosition(newMF.getPosition() + 1); | 259 newMF.setPosition(newMF.getPosition() + 1); |
325 * @return facet if genuinely new, matching old facet otherwise. | 325 * @return facet if genuinely new, matching old facet otherwise. |
326 */ | 326 */ |
327 protected ManagedFacet pickFacet(ManagedFacet facet, List<Facet> oldFacets) | 327 protected ManagedFacet pickFacet(ManagedFacet facet, List<Facet> oldFacets) |
328 { | 328 { |
329 if (oldFacets == null) { | 329 if (oldFacets == null) { |
330 logger.debug("No old facets to compare a new to found."); | 330 log.debug("No old facets to compare a new to found."); |
331 return facet; | 331 return facet; |
332 } | 332 } |
333 | 333 |
334 String hash = facet.getName() + facet.getIndex() + facet.getArtifact(); | 334 String hash = facet.getName() + facet.getIndex() + facet.getArtifact(); |
335 | 335 |